From 33d73b343d5cc0124b6f1a0c6a704ab307af6374 Mon Sep 17 00:00:00 2001 From: gorhill Date: Thu, 1 Jan 2015 19:09:40 -0500 Subject: [PATCH 1/9] this fixes #456 --- src/js/contentscript-end.js | 9 +++++++-- src/js/cosmetic-filtering.js | 8 +++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/js/contentscript-end.js b/src/js/contentscript-end.js index 518f83e0f..d79fe1650 100644 --- a/src/js/contentscript-end.js +++ b/src/js/contentscript-end.js @@ -259,15 +259,20 @@ var messager = vAPI.messaging.channel('contentscript-end.js'); node = nodeList[iNode]; attrValue = node.getAttribute(attr); if ( !attrValue ) { continue; } + // Candidate 1 = generic form + // If specific form is injected, no need to process specific + // form, as the generic will affect all related specific forms selector = '[' + attr + '="' + attrValue + '"]'; - if ( generics[selector] ) { + if ( generics.hasOwnProperty(selector) ) { if ( injectedSelectors.hasOwnProperty(selector) === false ) { injectedSelectors[selector] = true; out.push(selector); + continue; } } + // Candidate 2 = specific form selector = node.tagName.toLowerCase() + selector; - if ( generics[selector] ) { + if ( generics.hasOwnProperty(selector) ) { if ( injectedSelectors.hasOwnProperty(selector) === false ) { injectedSelectors[selector] = true; out.push(selector); diff --git a/src/js/cosmetic-filtering.js b/src/js/cosmetic-filtering.js index e2a8f704a..0a95b0fc5 100644 --- a/src/js/cosmetic-filtering.js +++ b/src/js/cosmetic-filtering.js @@ -778,7 +778,9 @@ FilterContainer.prototype.freezeHighGenerics = function(what) { } var highHighGenericCount = 0; - var reHighLow = /^[a-z]*(\[(?:alt|title)="[^"]+"\])$/; + // https://github.com/gorhill/uBlock/issues/456 + // Include tag name, it's part of the filter + var reHighLow = /^[a-z]*\[(?:alt|title)="[^"]+"\]$/; var reHighMedium = /^\[href\^="https?:\/\/([^"]{8})[^"]*"\]$/; var matches, hash; @@ -788,8 +790,8 @@ FilterContainer.prototype.freezeHighGenerics = function(what) { } // ["title"] and ["alt"] will go in high-low generic bin. matches = reHighLow.exec(selector); - if ( matches && matches.length === 2 ) { - highLowGeneric[matches[1]] = true; + if ( matches && matches.length === 1 ) { + highLowGeneric[matches[0]] = true; highLowGenericCount += 1; continue; } From f3e22070d881b46bc3025ad0f5c1b42ac32704fd Mon Sep 17 00:00:00 2001 From: gorhill Date: Thu, 1 Jan 2015 19:15:00 -0500 Subject: [PATCH 2/9] new revision --- platform/chromium/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/chromium/manifest.json b/platform/chromium/manifest.json index 2adc90084..12b70cf9d 100644 --- a/platform/chromium/manifest.json +++ b/platform/chromium/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "µBlock", - "version": "0.8.2.4", + "version": "0.8.2.5", "default_locale": "en", "description": "__MSG_extShortDesc__", From 057e95bed0a7319888d2a8ae7a579c8fc80f5a71 Mon Sep 17 00:00:00 2001 From: gorhill Date: Thu, 1 Jan 2015 19:16:02 -0500 Subject: [PATCH 3/9] fixed comment --- src/js/contentscript-end.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/contentscript-end.js b/src/js/contentscript-end.js index d79fe1650..8b4935efe 100644 --- a/src/js/contentscript-end.js +++ b/src/js/contentscript-end.js @@ -260,7 +260,7 @@ var messager = vAPI.messaging.channel('contentscript-end.js'); attrValue = node.getAttribute(attr); if ( !attrValue ) { continue; } // Candidate 1 = generic form - // If specific form is injected, no need to process specific + // If generic form is injected, no need to process the specific // form, as the generic will affect all related specific forms selector = '[' + attr + '="' + attrValue + '"]'; if ( generics.hasOwnProperty(selector) ) { From dfe82ed8dd8cbdebe8a503a670dc864d1d6f64fd Mon Sep 17 00:00:00 2001 From: gorhill Date: Thu, 1 Jan 2015 19:43:11 -0500 Subject: [PATCH 4/9] this fixes #457 --- assets/checksums.txt | 2 +- assets/ublock/mirror-candidates.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/checksums.txt b/assets/checksums.txt index 84dff7353..919afb8c9 100644 --- a/assets/checksums.txt +++ b/assets/checksums.txt @@ -1,6 +1,6 @@ 6572a7bce5f1747fee597cb170bd3b98 assets/ublock/privacy.txt 8ebba513a75ed3f7ed964688c2c6071c assets/ublock/filters.txt -4d9e52dd0f2fa7b4ff3c80043096e542 assets/ublock/mirror-candidates.txt +dcf3e05bae803343c9d632f0baf8bedd assets/ublock/mirror-candidates.txt b3ec069f792cec05484e6c45b3591466 assets/ublock/filter-lists.json 132b3ecc9da8a68c3faf740c00af734b assets/thirdparties/adblock-plus-japanese-filter.googlecode.com/hg/abp_jp.txt 94c0a3eab74c42783855f07b22a429cf assets/thirdparties/home.fredfiber.no/langsholt/adblock.txt diff --git a/assets/ublock/mirror-candidates.txt b/assets/ublock/mirror-candidates.txt index 674831478..184ca17f9 100644 --- a/assets/ublock/mirror-candidates.txt +++ b/assets/ublock/mirror-candidates.txt @@ -19,7 +19,7 @@ code.jquery.com # within a data: URI ^code\.jquery\.com\/(?!.*\/themes\/.+\.css) maxcdn.bootstrapcdn.com - ^maxcdn\.bootstrapcdn\.com\/font-awesome\/ + ^maxcdn\.bootstrapcdn\.com\/bootstrap\/.+\/.+\.js netdna.bootstrapcdn.com ^netdna\.bootstrapcdn\.com\/bootstrap\/ ^netdna\.bootstrapcdn\.com\/font-awesome\/ From 2a7e9f8d9898bacc008d7274c08cee5ff90dd44b Mon Sep 17 00:00:00 2001 From: gorhill Date: Thu, 1 Jan 2015 20:58:19 -0500 Subject: [PATCH 5/9] this fixes #456: another unrelated bug unveil from previous fix --- platform/chromium/vapi-client.js | 7 +++++++ src/js/contentscript-end.js | 7 +++++++ src/js/contentscript-start.js | 12 +++++++----- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/platform/chromium/vapi-client.js b/platform/chromium/vapi-client.js index 47edde9a9..057687f51 100644 --- a/platform/chromium/vapi-client.js +++ b/platform/chromium/vapi-client.js @@ -33,6 +33,13 @@ self.vAPI = self.vAPI || {}; +// https://github.com/gorhill/uBlock/issues/456 +// Already injected? +if ( vAPI.vapiClient ) { + return; +} +vAPI.vapiClient = true; + var chrome = self.chrome; var vAPI = self.vAPI; diff --git a/src/js/contentscript-end.js b/src/js/contentscript-end.js index 8b4935efe..13bbb3e77 100644 --- a/src/js/contentscript-end.js +++ b/src/js/contentscript-end.js @@ -33,6 +33,13 @@ if ( vAPI.canExecuteContentScript() !== true ) { throw "uBlock> contentscript-end.js > Skipping " + location.protocol; } +// https://github.com/gorhill/uBlock/issues/456 +// Already injected? +if ( vAPI.contentscriptEnd ) { + return; +} +vAPI.contentscriptEnd = true; + /******************************************************************************/ var messager = vAPI.messaging.channel('contentscript-end.js'); diff --git a/src/js/contentscript-start.js b/src/js/contentscript-start.js index 6106c875d..edc226369 100644 --- a/src/js/contentscript-start.js +++ b/src/js/contentscript-start.js @@ -44,6 +44,13 @@ if ( vAPI.canExecuteContentScript() !== true ) { return; } +// https://github.com/gorhill/uBlock/issues/456 +// Already injected? +if ( vAPI.contentscriptStart ) { + return; +} +vAPI.contentscriptStart = true; + /******************************************************************************/ var localMessager = vAPI.messaging.channel('contentscript-start.js'); @@ -55,11 +62,6 @@ var localMessager = vAPI.messaging.channel('contentscript-start.js'); // These can be inserted before the DOM is loaded. var cosmeticFilters = function(details) { - // Maybe uBlock's style tag was already injected? - var style = document.getElementById('ublock-preload-1ae7a5f130fc79b4fdb8a4272d9426b5'); - if ( style !== null ) { - return; - } var donthideCosmeticFilters = {}; var hideCosmeticFilters = {}; style = document.createElement('style'); From 2d05d51664c23246e34a52b62082b1456d90c198 Mon Sep 17 00:00:00 2001 From: gorhill Date: Thu, 1 Jan 2015 21:14:53 -0500 Subject: [PATCH 6/9] code review for #456 --- platform/chromium/vapi-client.js | 14 +++++++------- src/js/contentscript-end.js | 15 +++++++++++---- src/js/contentscript-start.js | 6 +++--- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/platform/chromium/vapi-client.js b/platform/chromium/vapi-client.js index 057687f51..e4099a20f 100644 --- a/platform/chromium/vapi-client.js +++ b/platform/chromium/vapi-client.js @@ -33,16 +33,16 @@ self.vAPI = self.vAPI || {}; -// https://github.com/gorhill/uBlock/issues/456 -// Already injected? -if ( vAPI.vapiClient ) { - return; -} -vAPI.vapiClient = true; - var chrome = self.chrome; var vAPI = self.vAPI; +// https://github.com/gorhill/uBlock/issues/456 +// Already injected? +if ( vAPI.vapiClientInjected ) { + return; +} +vAPI.vapiClientInjected = true; + vAPI.chrome = true; /******************************************************************************/ diff --git a/src/js/contentscript-end.js b/src/js/contentscript-end.js index 13bbb3e77..6d229130d 100644 --- a/src/js/contentscript-end.js +++ b/src/js/contentscript-end.js @@ -21,12 +21,14 @@ /* global vAPI */ -'use strict'; - /******************************************************************************/ // Injected into content pages +(function() { + +'use strict'; + /******************************************************************************/ if ( vAPI.canExecuteContentScript() !== true ) { @@ -35,10 +37,10 @@ if ( vAPI.canExecuteContentScript() !== true ) { // https://github.com/gorhill/uBlock/issues/456 // Already injected? -if ( vAPI.contentscriptEnd ) { +if ( vAPI.contentscriptEndInjected ) { return; } -vAPI.contentscriptEnd = true; +vAPI.contentscriptEndInjected = true; /******************************************************************************/ @@ -684,3 +686,8 @@ var messager = vAPI.messaging.channel('contentscript-end.js'); })(); /******************************************************************************/ +/******************************************************************************/ + +})(); + +/******************************************************************************/ diff --git a/src/js/contentscript-start.js b/src/js/contentscript-start.js index edc226369..2432562c2 100644 --- a/src/js/contentscript-start.js +++ b/src/js/contentscript-start.js @@ -46,10 +46,10 @@ if ( vAPI.canExecuteContentScript() !== true ) { // https://github.com/gorhill/uBlock/issues/456 // Already injected? -if ( vAPI.contentscriptStart ) { +if ( vAPI.contentscriptStartInjected ) { return; } -vAPI.contentscriptStart = true; +vAPI.contentscriptStartInjected = true; /******************************************************************************/ @@ -64,7 +64,7 @@ var localMessager = vAPI.messaging.channel('contentscript-start.js'); var cosmeticFilters = function(details) { var donthideCosmeticFilters = {}; var hideCosmeticFilters = {}; - style = document.createElement('style'); + var style = document.createElement('style'); style.setAttribute('id', 'ublock-preload-1ae7a5f130fc79b4fdb8a4272d9426b5'); var donthide = details.cosmeticDonthide; var hide = details.cosmeticHide; From b1143614fb2f5bca879c25304f6ebb97ec872ef2 Mon Sep 17 00:00:00 2001 From: gorhill Date: Thu, 1 Jan 2015 21:24:06 -0500 Subject: [PATCH 7/9] new revision --- platform/chromium/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/chromium/manifest.json b/platform/chromium/manifest.json index 12b70cf9d..bbdb6e0d8 100644 --- a/platform/chromium/manifest.json +++ b/platform/chromium/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "µBlock", - "version": "0.8.2.5", + "version": "0.8.2.6", "default_locale": "en", "description": "__MSG_extShortDesc__", From 00995992d2b58dbe7ea46aeff351f0398b34b016 Mon Sep 17 00:00:00 2001 From: gorhill Date: Fri, 2 Jan 2015 13:42:35 -0500 Subject: [PATCH 8/9] this fixes #455 --- platform/chromium/vapi-background.js | 8 ++- src/js/tab.js | 85 +++++++++++++++++++++------- 2 files changed, 70 insertions(+), 23 deletions(-) diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index 208d3eb94..20602cf2b 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -86,18 +86,22 @@ vAPI.tabs.get = function(tabId, callback) { var onTabReady = function(tab) { // https://code.google.com/p/chromium/issues/detail?id=410868#c8 if ( chrome.runtime.lastError ) { - return; + ; } + // Caller must be prepared to deal with nil tab value callback(tab); }; if ( tabId !== null ) { + if ( typeof tabId === 'string' ) { + tabId = parseInt(tabId, 10); + } chrome.tabs.get(tabId, onTabReady); return; } var onTabReceived = function(tabs) { // https://code.google.com/p/chromium/issues/detail?id=410868#c8 if ( chrome.runtime.lastError ) { - return; + ; } callback(tabs[0]); }; diff --git a/src/js/tab.js b/src/js/tab.js index 3b3a2f791..c9bdf4f35 100644 --- a/src/js/tab.js +++ b/src/js/tab.js @@ -19,18 +19,29 @@ Home: https://github.com/gorhill/uBlock */ -/* global µBlock */ +/* global vAPI, µBlock */ + +/******************************************************************************/ +/******************************************************************************/ + +(function() { + 'use strict'; /******************************************************************************/ +var µb = µBlock; + +/******************************************************************************/ +/******************************************************************************/ + // When the DOM content of root frame is loaded, this means the tab // content has changed. vAPI.tabs.onNavigation = function(details) { if ( details.frameId !== 0 ) { return; } - µBlock.bindTabToPageStats(details.tabId, details.url); + µb.bindTabToPageStats(details.tabId, details.url); }; // It may happen the URL in the tab changes, while the page's document @@ -43,19 +54,19 @@ vAPI.tabs.onUpdated = function(tabId, changeInfo, tab) { if ( !changeInfo.url ) { return; } - µBlock.bindTabToPageStats(tabId, changeInfo.url, 'tabUpdated'); + µb.bindTabToPageStats(tabId, changeInfo.url, 'tabUpdated'); }; vAPI.tabs.onClosed = function(tabId) { if ( tabId < 0 ) { return; } - µBlock.unbindTabFromPageStats(tabId); + µb.unbindTabFromPageStats(tabId); }; // https://github.com/gorhill/uBlock/issues/297 vAPI.tabs.onPopup = function(details) { - var pageStore = µBlock.pageStoreFromTabId(details.sourceTabId); + var pageStore = µb.pageStoreFromTabId(details.sourceTabId); if ( !pageStore ) { return; } @@ -64,8 +75,8 @@ vAPI.tabs.onPopup = function(details) { // https://github.com/gorhill/uBlock/issues/323 // If popup URL is whitelisted, do not block it - if ( µBlock.getNetFilteringSwitch(requestURL) ) { - result = µBlock.netFilteringEngine.matchStringExactType(pageStore, requestURL, 'popup'); + if ( µb.getNetFilteringSwitch(requestURL) ) { + result = µb.netFilteringEngine.matchStringExactType(pageStore, requestURL, 'popup'); } // https://github.com/gorhill/uBlock/issues/91 @@ -81,7 +92,7 @@ vAPI.tabs.onPopup = function(details) { // Blocked // It is a popup, block and remove the tab. - µBlock.unbindTabFromPageStats(details.tabId); + µb.unbindTabFromPageStats(details.tabId); vAPI.tabs.remove(details.tabId); // for Safari @@ -90,7 +101,6 @@ vAPI.tabs.onPopup = function(details) { vAPI.tabs.registerListeners(); - /******************************************************************************/ /******************************************************************************/ @@ -104,7 +114,7 @@ vAPI.tabs.registerListeners(); // hostname. This way, for a specific scheme you can create scope with // rules which will apply only to that scheme. -µBlock.normalizePageURL = function(pageURL) { +µb.normalizePageURL = function(pageURL) { var uri = this.URI.set(pageURL); if ( uri.scheme === 'https' || uri.scheme === 'http' ) { return uri.normalizedURI(); @@ -116,7 +126,7 @@ vAPI.tabs.registerListeners(); // Create an entry for the tab if it doesn't exist. -µBlock.bindTabToPageStats = function(tabId, pageURL, context) { +µb.bindTabToPageStats = function(tabId, pageURL, context) { this.updateBadgeAsync(tabId); // https://github.com/gorhill/httpswitchboard/issues/303 @@ -144,7 +154,7 @@ vAPI.tabs.registerListeners(); return pageStore; }; -µBlock.unbindTabFromPageStats = function(tabId) { +µb.unbindTabFromPageStats = function(tabId) { //console.debug('µBlock> unbindTabFromPageStats(%d)', tabId); var pageStore = this.pageStores[tabId]; if ( pageStore !== undefined ) { @@ -155,27 +165,60 @@ vAPI.tabs.registerListeners(); /******************************************************************************/ -µBlock.pageUrlFromTabId = function(tabId) { +µb.pageUrlFromTabId = function(tabId) { var pageStore = this.pageStores[tabId]; return pageStore ? pageStore.pageURL : ''; }; -µBlock.pageUrlFromPageStats = function(pageStats) { +µb.pageUrlFromPageStats = function(pageStats) { if ( pageStats ) { return pageStats.pageURL; } return ''; }; -µBlock.pageStoreFromTabId = function(tabId) { +µb.pageStoreFromTabId = function(tabId) { return this.pageStores[tabId]; }; +/******************************************************************************/ /******************************************************************************/ -// µBlock.forceReload = function(pageURL) { -// var tabId = this.tabIdFromPageUrl(pageURL); -// if ( tabId ) { -// chrome.tabs.reload(tabId, { bypassCache: true }); -// } -// }; +// Stale page store entries janitor +// https://github.com/gorhill/uBlock/issues/455 + +var pageStoreJanitorPeriod = 15 * 60 * 1000; +var pageStoreJanitorSampleAt = 0; +var pageStoreJanitorSampleSize = 10; + +var pageStoreJanitor = function() { + var vapiTabs = vAPI.tabs; + var tabIds = Object.keys(µb.pageStores).sort(); + var checkTab = function(tabId) { + vapiTabs.get(tabId, function(tab) { + if ( !tab ) { + //console.error('tab.js> pageStoreJanitor(): stale page store found:', µb.pageUrlFromTabId(tabId)); + µb.unbindTabFromPageStats(tabId); + } + }); + }; + if ( pageStoreJanitorSampleAt >= tabIds.length ) { + pageStoreJanitorSampleAt = 0; + } + var n = Math.min(pageStoreJanitorSampleAt + pageStoreJanitorSampleSize, tabIds.length); + for ( var i = pageStoreJanitorSampleAt; i < n; i++ ) { + checkTab(tabIds[i]); + } + pageStoreJanitorSampleAt = n; + + setTimeout(pageStoreJanitor, pageStoreJanitorPeriod); +}; + +setTimeout(pageStoreJanitor, pageStoreJanitorPeriod); + +/******************************************************************************/ +/******************************************************************************/ + +})(); + +/******************************************************************************/ From f5ec54f497c892283bc8f45fee609db0101e98fe Mon Sep 17 00:00:00 2001 From: gorhill Date: Fri, 2 Jan 2015 13:45:54 -0500 Subject: [PATCH 9/9] new revision --- platform/chromium/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/chromium/manifest.json b/platform/chromium/manifest.json index bbdb6e0d8..dd9cf785d 100644 --- a/platform/chromium/manifest.json +++ b/platform/chromium/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "µBlock", - "version": "0.8.2.6", + "version": "0.8.2.7", "default_locale": "en", "description": "__MSG_extShortDesc__",