Skip to content

Commit

Permalink
Performance fixes for GMAIL in Firefox; issue #18
Browse files Browse the repository at this point in the history
* Cache MutationObserver object for disconnect prior to use
* Changed order of PGPDataSearch call from inline.js
  • Loading branch information
kylehuff committed Jan 25, 2014
1 parent ec3bab7 commit a8924eb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
15 changes: 9 additions & 6 deletions extension/gmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,6 @@ webpg.gmail = {

// A normal document load
} else {
console.log("mutation event");
var dW = webpg.gmail.getCanvasFrameDocument()
.querySelectorAll("div>.dW.E>.J-Jw, div>.nH.nH");

Expand Down Expand Up @@ -963,6 +962,7 @@ webpg.utils.sendRequest({
// Retrieve a reference to the appropriate window object
// Check if the MutationObserver is not present
if (typeof(MutationObserver) === 'undefined') {
console.log("Using depreciated DOMSubtreeModified");
if (webpg.utils.detectedBrowser.vendor === "mozilla") {
webpg.gmail.appcontent = document.getElementById("appcontent") || document;
webpg.gmail.appcontent.addEventListener("DOMContentLoaded",
Expand All @@ -984,7 +984,11 @@ webpg.utils.sendRequest({
} else {
// Otherwise, use the MutationObserver
// create an observer instance
var observer = new MutationObserver(function(mutations) {

if (webpg.gmail_observer !== undefined)
webpg.gmail_observer.disconnect();

webpg.gmail_observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
webpg.gmail.gmailChanges(mutation);
});
Expand All @@ -1000,15 +1004,14 @@ webpg.utils.sendRequest({
// We need to filter based on the URL for mozilla, as we do
// not have the option to set the overlay by URL
if (aEvent.originalTarget.location.host === "mail.google.com") {
observer.disconnect();
observer.observe(webpg.gmail.getCanvasFrameDocument(), config);
webpg.gmail_observer.observe(webpg.gmail.getCanvasFrameDocument(), config);
webpg.gmail.appcontent.removeEventListener("DOMContentLoaded", arguments.callee, true);
}
},
true
false
);
} else {
observer.observe(document.querySelector('body'), config);
webpg.gmail_observer.observe(document.querySelector('body'), config);
}
}
}
Expand Down
37 changes: 18 additions & 19 deletions extension/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,14 @@ webpg.inline = {
} else {
// Otherwise, use the MutationObserver
// create an observer instance
//console.log("Using MutationObserver");
var observer = new MutationObserver(function(mutations) {
console.log("Using MutationObserver");

if (webpg.inline.observer !== undefined)
webpg.inline.observer.disconnect();

webpg.inline.observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.target.nodeName === "IFRAME" && mutation.target.className.indexOf("webpg-") === -1) {
try {
mutation.target.contentDocument.documentElement.removeEventListener("contextmenu",
webpg.overlay.contextHandler, true);
mutation.target.contentDocument.documentElement.addEventListener("contextmenu",
webpg.overlay.contextHandler, true);
} catch (err) {
console.log(err.message);
}
webpg.inline.PGPDataSearch(mutation.target.contentDocument, true, false, mutation.target);
} else if (doc.location.host.indexOf("mail.google.com") > -1) {
if (doc.location.host.indexOf("mail.google.com") > -1) {
try {
doc.querySelectorAll(".Bu.y3")[0].style.display = "none";
doc.querySelectorAll(".AT")[0].style.display = "none";
Expand All @@ -109,6 +103,16 @@ webpg.inline = {
webpg.inline.PGPDataSearch(doc, false, true, mutation.target);
}
}
} else if (mutation.target.nodeName === "IFRAME" && mutation.target.className.indexOf("webpg-") === -1) {
try {
mutation.target.contentDocument.documentElement.removeEventListener("contextmenu",
webpg.overlay.contextHandler, true);
mutation.target.contentDocument.documentElement.addEventListener("contextmenu",
webpg.overlay.contextHandler, true);
} catch (err) {
console.log(err.message);
}
webpg.inline.PGPDataSearch(mutation.target.contentDocument, true, false, mutation.target);
} else {
if (mutation.addedNodes.length > 0) {
if (mutation.addedNodes[0].textContent.search(/-----BEGIN PGP.*?-----/gim) > -1)
Expand All @@ -124,12 +128,7 @@ webpg.inline = {
var doc = (webpg.utils.detectedBrowser.vendor === 'mozilla') ? content.document :
(webpg.inline.doc) ? webpg.inline.doc : document;

try {
observer.disconnect();
observer.observe(doc, config);
} catch (err) {
console.log(err.message);
}
webpg.inline.observer.observe(doc, config);
}
},

Expand Down

1 comment on commit a8924eb

@kylehuff
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I referenced the wrong issue, it should have been kylehuff/webpg-firefox#18

Please sign in to comment.