From 5019f241dfa353bf24611f65e465cde99db1b32b Mon Sep 17 00:00:00 2001 From: gorhill Date: Wed, 17 Dec 2014 08:02:37 -0500 Subject: [PATCH] this fixes #418; also remove last chrome API reference from portable code --- platform/chromium/vapi-background.js | 53 +++++++++++++++++++++++++++- platform/safari/vapi-background.js | 10 ++++++ src/js/storage.js | 52 +++++---------------------- 3 files changed, 71 insertions(+), 44 deletions(-) diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index 74c656b44..208d3eb94 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -19,7 +19,7 @@ Home: https://github.com/gorhill/uBlock */ -/* global self */ +/* global self, µBlock */ // 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); +}; + +/******************************************************************************/ + })(); /******************************************************************************/ diff --git a/platform/safari/vapi-background.js b/platform/safari/vapi-background.js index 54b073be7..84fce46b2 100644 --- a/platform/safari/vapi-background.js +++ b/platform/safari/vapi-background.js @@ -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() { +}; + +/******************************************************************************/ + })(); diff --git a/src/js/storage.js b/src/js/storage.js index aaa9295d3..43a2837e7 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -212,11 +212,18 @@ } catch (e) { locations = {}; } + var entry; for ( location in locations ) { if ( locations.hasOwnProperty(location) === false ) { 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 @@ -584,48 +591,7 @@ // - Initialize internal state with maybe already existing tabs. // - Schedule next update operation. var onAllDone = function() { - if (vAPI.chrome) { - // 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); - } + vAPI.onLoadAllCompleted(); // https://github.com/gorhill/uBlock/issues/184 // If we restored a selfie, check for updates not too far