Firefox: load content-scripts on extension start

This commit is contained in:
Deathamns 2015-03-12 18:20:48 +01:00
parent 48503f7009
commit 4ad9858357
3 changed files with 52 additions and 3 deletions

View File

@ -299,7 +299,11 @@ const contentObserver = {
}
};
doc.addEventListener('DOMContentLoaded', docReady, true);
if ( doc.readyState === 'loading') {
doc.addEventListener('DOMContentLoaded', docReady, true);
} else {
docReady({ target: doc, type: 'DOMContentLoaded' });
}
}
};

View File

@ -19,13 +19,43 @@
Home: https://github.com/gorhill/uBlock
*/
/******************************************************************************/
(function() {
'use strict';
/******************************************************************************/
Components.utils.import(
let {contentObserver} = Components.utils.import(
Components.stack.filename.replace('Script', 'Module'),
null
);
let injectContentScripts = function(win) {
if ( !win || !win.document ) {
return;
}
contentObserver.observe(win.document);
if ( win.frames && win.frames.length ) {
let i = win.frames.length;
while ( i-- ) {
injectContentScripts(win.frames[i]);
}
}
};
let onLoadCompleted = function() {
removeMessageListener('ublock-load-completed', onLoadCompleted);
injectContentScripts(content);
};
addMessageListener('ublock-load-completed', onLoadCompleted);
/******************************************************************************/
})();
/******************************************************************************/

View File

@ -1849,7 +1849,22 @@ vAPI.lastError = function() {
// in already opened web pages, to remove whatever nuisance could make it to
// the web pages before uBlock was ready.
vAPI.onLoadAllCompleted = function() {};
vAPI.onLoadAllCompleted = function() {
var µb = µBlock;
for ( var tab of this.tabs.getAll() ) {
// We're insterested in only the tabs that were already loaded
if ( tab.hasAttribute('pending') ) {
continue;
}
var tabId = this.tabs.getTabId(tab);
var browser = getBrowserForTab(tab);
µb.bindTabToPageStats(tabId, browser.currentURI.spec);
browser.messageManager.sendAsyncMessage(
location.host + '-load-completed'
);
}
};
/******************************************************************************/