this fixes #418; also remove last chrome API reference from portable code

This commit is contained in:
gorhill 2014-12-17 08:02:37 -05:00
parent 8ea558e41e
commit 5019f241df
3 changed files with 71 additions and 44 deletions

View File

@ -19,7 +19,7 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* global self */ /* global self, µBlock */
// For background page // For background page
@ -394,6 +394,57 @@ vAPI.lastError = function() {
/******************************************************************************/ /******************************************************************************/
// This is called only once, when everything has been loaded in memory after
// the extension was launched. It can be used to inject content scripts
// in already opened web pages, to remove whatever nuisance could make it to
// the web pages before uBlock was ready.
vAPI.onLoadAllCompleted = function() {
// http://code.google.com/p/chromium/issues/detail?id=410868#c11
// Need to be sure to access `vAPI.lastError()` to prevent
// spurious warnings in the console.
var scriptDone = function() {
vAPI.lastError();
};
var scriptEnd = function(tabId) {
if ( vAPI.lastError() ) {
return;
}
vAPI.tabs.injectScript(tabId, {
file: 'js/contentscript-end.js',
allFrames: true,
runAt: 'document_idle'
}, scriptDone);
};
var scriptStart = function(tabId) {
vAPI.tabs.injectScript(tabId, {
file: 'js/vapi-client.js',
allFrames: true,
runAt: 'document_start'
}, function(){ });
vAPI.tabs.injectScript(tabId, {
file: 'js/contentscript-start.js',
allFrames: true,
runAt: 'document_idle'
}, function(){ scriptEnd(tabId); });
};
var bindToTabs = function(tabs) {
var µb = µBlock;
var i = tabs.length, tab;
while ( i-- ) {
tab = tabs[i];
µb.bindTabToPageStats(tab.id, tab.url);
// https://github.com/gorhill/uBlock/issues/129
scriptStart(tab.id);
}
};
chrome.tabs.query({ url: 'http://*/*' }, bindToTabs);
chrome.tabs.query({ url: 'https://*/*' }, bindToTabs);
};
/******************************************************************************/
})(); })();
/******************************************************************************/ /******************************************************************************/

View File

@ -811,4 +811,14 @@ vAPI.lastError = function() {
/******************************************************************************/ /******************************************************************************/
// This is called only once, when everything has been loaded in memory after
// the extension was launched. It can be used to inject content scripts
// in already opened web pages, to remove whatever nuisance could make it to
// the web pages before uBlock was ready.
vAPI.onLoadAllCompleted = function() {
};
/******************************************************************************/
})(); })();

View File

@ -212,11 +212,18 @@
} catch (e) { } catch (e) {
locations = {}; locations = {};
} }
var entry;
for ( location in locations ) { for ( location in locations ) {
if ( locations.hasOwnProperty(location) === false ) { if ( locations.hasOwnProperty(location) === false ) {
continue; continue;
} }
availableLists['assets/thirdparties/' + location] = locations[location]; entry = locations[location];
// https://github.com/gorhill/uBlock/issues/418
// We now support built-in external filter lists
if ( /^https?:/.test(location) === false ) {
location = 'assets/thirdparties/' + location;
}
availableLists[location] = entry;
} }
// Now get user's selection of lists // Now get user's selection of lists
@ -584,48 +591,7 @@
// - Initialize internal state with maybe already existing tabs. // - Initialize internal state with maybe already existing tabs.
// - Schedule next update operation. // - Schedule next update operation.
var onAllDone = function() { var onAllDone = function() {
if (vAPI.chrome) { vAPI.onLoadAllCompleted();
// http://code.google.com/p/chromium/issues/detail?id=410868#c11
// Need to be sure to access `vAPI.lastError()` to prevent
// spurious warnings in the console.
var scriptDone = function() {
vAPI.lastError();
};
var scriptEnd = function(tabId) {
if ( vAPI.lastError() ) {
return;
}
vAPI.tabs.injectScript(tabId, {
file: 'js/contentscript-end.js',
allFrames: true,
runAt: 'document_idle'
}, scriptDone);
};
var scriptStart = function(tabId) {
vAPI.tabs.injectScript(tabId, {
file: 'js/vapi-client.js',
allFrames: true,
runAt: 'document_start'
}, function(){ });
vAPI.tabs.injectScript(tabId, {
file: 'js/contentscript-start.js',
allFrames: true,
runAt: 'document_idle'
}, function(){ scriptEnd(tabId); });
};
var bindToTabs = function(tabs) {
var i = tabs.length, tab;
while ( i-- ) {
tab = tabs[i];
µb.bindTabToPageStats(tab.id, tab.url);
// https://github.com/gorhill/uBlock/issues/129
scriptStart(tab.id);
}
};
chrome.tabs.query({ url: 'http://*/*' }, bindToTabs);
chrome.tabs.query({ url: 'https://*/*' }, bindToTabs);
}
// https://github.com/gorhill/uBlock/issues/184 // https://github.com/gorhill/uBlock/issues/184
// If we restored a selfie, check for updates not too far // If we restored a selfie, check for updates not too far