From 37a9f4d7620710a011b6f97e7c005734cc0d27e9 Mon Sep 17 00:00:00 2001 From: Deathamns Date: Thu, 18 Dec 2014 21:24:11 +0100 Subject: [PATCH] Firefox: revert previous change Initializing the extension with AddonManager takes too long (at least for this extension). When starting the browser, tabs loaded before the extension could, and because of that, blocking didn't work. It works better, if it's initialized when the window's DOM is ready. --- platform/firefox/bootstrap.js | 36 ++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/platform/firefox/bootstrap.js b/platform/firefox/bootstrap.js index 330ed84..8003171 100644 --- a/platform/firefox/bootstrap.js +++ b/platform/firefox/bootstrap.js @@ -19,7 +19,7 @@ Home: https://github.com/gorhill/uBlock */ -/* global APP_SHUTDOWN */ +/* global APP_SHUTDOWN, APP_STARTUP */ /* exported startup, shutdown, install, uninstall */ 'use strict'; @@ -30,13 +30,12 @@ let bgProcess; /******************************************************************************/ -function startup(data) { - let {AddonManager} = Components.utils['import']( - 'resource://gre/modules/AddonManager.jsm', - null - ); +function startup(data, reason) { + bgProcess = function(e) { + if (e) { + this.removeEventListener('DOMContentLoaded', bgProcess); + } - AddonManager.getAddonByID(data.id, addon => { let hDoc = Components.classes['@mozilla.org/appshell/appShellService;1'] .getService(Components.interfaces.nsIAppShellService) .hiddenDOMWindow.document; @@ -44,12 +43,23 @@ function startup(data) { bgProcess = hDoc.documentElement.appendChild( hDoc.createElementNS('http://www.w3.org/1999/xhtml', 'iframe') ); - - let bgURI = 'chrome://ublock/content/background.html'; - - // send addon data synchronously to the background script - bgProcess.src = bgURI + '#' + [addon.name, addon.version]; - }); + bgProcess.setAttribute('src', 'chrome://ublock/content/background.html'); + }; + + if (reason === APP_STARTUP) { + let ww = Components.classes['@mozilla.org/embedcomp/window-watcher;1'] + .getService(Components.interfaces.nsIWindowWatcher); + + ww.registerNotification({ + observe: function(win) { + ww.unregisterNotification(this); + win.addEventListener('DOMContentLoaded', bgProcess); + } + }); + } + else { + bgProcess(); + } } /******************************************************************************/