Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: composer.postload.js

Issue 29581892: Issue 5599 - Delay composer initialization if ext object is unavailable (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Created Oct. 17, 2017, 4:41 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: composer.postload.js
===================================================================
--- a/composer.postload.js
+++ b/composer.postload.js
@@ -474,18 +474,21 @@
let overlays = document.getElementsByClassName("__adblockplus__overlay");
while (overlays.length > 0)
overlays[0].parentNode.removeChild(overlays[0]);
ext.onExtensionUnloaded.removeListener(deactivateBlockElement);
}
-if (document instanceof HTMLDocument)
+function initializeComposer()
{
+ if (typeof ext == "undefined")
+ return false;
+
// Use a contextmenu handler to save the last element the user right-clicked
// on. To make things easier, we actually save the DOM event. We have to do
// this because the contextMenu API only provides a URL, not the actual DOM
// element.
// We also need to make sure that the previous right click event,
// if there is one, is removed. We don't know which frame it is in so we must
// send a message to the other frames to clear their old right click events.
document.addEventListener("contextmenu", event =>
@@ -497,19 +500,19 @@
type: "forward",
payload:
{
type: "composer.content.clearPreviousRightClickEvent"
}
});
}, true);
- ext.onMessage.addListener((msg, sender, sendResponse) =>
+ ext.onMessage.addListener((message, sender, sendResponse) =>
Manish Jethani 2017/10/17 16:43:16 Unrelated renaming.
{
- switch (msg.type)
+ switch (message.type)
{
case "composer.content.getState":
if (window == window.top)
{
sendResponse({
active: currentlyPickingElement || blockelementPopupId != null
});
}
@@ -529,17 +532,17 @@
{
currentElement = element;
elementPicked(event);
}
});
}
break;
case "composer.content.finished":
- if (currentElement && msg.remove)
+ if (currentElement && message.remove)
{
// Hide the selected element itself if an added blocking
// filter is causing it to collapse. Note that this
// behavior is incomplete, but the best we can do here,
// e.g. if an added blocking filter matches other elements,
// the effect won't be visible until the page is is reloaded.
checkCollapse(currentElement.prisoner || currentElement);
@@ -550,30 +553,43 @@
break;
case "composer.content.clearPreviousRightClickEvent":
if (!lastRightClickEventIsMostRecent)
lastRightClickEvent = null;
lastRightClickEventIsMostRecent = false;
break;
case "composer.content.dialogOpened":
if (window == window.top)
- blockelementPopupId = msg.popupId;
+ blockelementPopupId = message.popupId;
break;
case "composer.content.dialogClosed":
// The onRemoved hook for the popup can create a race condition, so we
// to be careful here. (This is not perfect, but best we can do.)
- if (window == window.top && blockelementPopupId == msg.popupId)
+ if (window == window.top && blockelementPopupId == message.popupId)
{
browser.runtime.sendMessage({
type: "forward",
payload:
{
type: "composer.content.finished"
}
});
}
break;
}
});
if (window == window.top)
browser.runtime.sendMessage({type: "composer.ready"});
+
+ return true;
}
+
+if (document instanceof HTMLDocument)
+{
+ // There's a bug in Firefox that causes document_end content scripts to run
+ // before document_start content scripts on extension startup. In this case
+ // the ext object is undefined, we fail to initialize, and initializeComposer
+ // returns false. As a workaround, try again after a timeout.
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=1395287
+ if (!initializeComposer())
+ setTimeout(initializeComposer, 2000);
Manish Jethani 2017/10/17 16:43:16 Two seconds is probably fine.
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld