Index: lib/popupBlocker.js |
=================================================================== |
rename from popupBlocker.js |
rename to lib/popupBlocker.js |
--- a/popupBlocker.js |
+++ b/lib/popupBlocker.js |
@@ -15,62 +15,25 @@ |
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
*/ |
-if (require("info").platform == "chromium") |
-{ |
- var logRequest = require("devtools").logRequest; |
- var tabsLoading = {}; |
+/** @module popupBlocker */ |
- chrome.webNavigation.onCreatedNavigationTarget.addListener(function(details) |
- { |
- var sourcePage = new ext.Page({id: details.sourceTabId}); |
- var sourceFrame = ext.getFrame(details.sourceTabId, details.sourceFrameId); |
+"use strict"; |
- if (checkWhitelisted(sourcePage, sourceFrame)) |
- return; |
+let {defaultMatcher} = require("matcher"); |
+let {BlockingFilter} = require("filterClasses"); |
+let {stringifyURL, isThirdParty, extractHostFromFrame} = require("url"); |
+let {checkWhitelisted} = require("whitelisting"); |
+let {logRequest} = require("devtools"); |
- var documentHost = extractHostFromFrame(sourceFrame); |
- if (!documentHost) |
- return; |
- |
- var specificOnly = checkWhitelisted(sourcePage, sourceFrame, |
- RegExpFilter.typeMap.GENERICBLOCK); |
- |
- tabsLoading[details.tabId] = { |
- page: sourcePage, |
- documentHost: documentHost, |
- specificOnly: specificOnly |
- }; |
- checkPotentialPopup(details.tabId, details.url, sourcePage, documentHost, specificOnly); |
- }); |
- |
- chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) |
- { |
- if (!(tabId in tabsLoading)) |
- { |
- // Not a pop-up we've previously seen |
- return; |
- } |
- |
- if ("url" in changeInfo) |
- { |
- var source = tabsLoading[tabId]; |
- checkPotentialPopup(tabId, tab.url, source.page, |
- source.documentHost, |
- source.specificOnly); |
- } |
- |
- if ("status" in changeInfo && changeInfo.status == "complete" && tab.url != "about:blank") |
- delete tabsLoading[tabId]; |
- }); |
-} |
+let tabsLoading = {}; |
function checkPotentialPopup(tabId, url, sourcePage, documentHost, specificOnly) |
{ |
- var urlObj = new URL(url || "about:blank"); |
- var urlString = stringifyURL(urlObj); |
- var thirdParty = isThirdParty(urlObj, documentHost); |
+ let urlObj = new URL(url || "about:blank"); |
+ let urlString = stringifyURL(urlObj); |
+ let thirdParty = isThirdParty(urlObj, documentHost); |
- var filter = defaultMatcher.matchesAny( |
+ let filter = defaultMatcher.matchesAny( |
urlString, RegExpFilter.typeMap.POPUP, |
documentHost, thirdParty, null, specificOnly |
); |
@@ -83,3 +46,43 @@ |
thirdParty, null, specificOnly, filter |
); |
} |
+ |
+chrome.webNavigation.onCreatedNavigationTarget.addListener(details => |
+{ |
+ let sourcePage = new ext.Page({id: details.sourceTabId}); |
+ let sourceFrame = ext.getFrame(details.sourceTabId, details.sourceFrameId); |
+ |
+ if (checkWhitelisted(sourcePage, sourceFrame)) |
+ return; |
+ |
+ let documentHost = extractHostFromFrame(sourceFrame); |
+ if (!documentHost) |
+ return; |
+ |
+ let specificOnly = checkWhitelisted(sourcePage, sourceFrame, |
+ RegExpFilter.typeMap.GENERICBLOCK); |
+ |
+ tabsLoading[details.tabId] = { |
+ page: sourcePage, |
+ documentHost: documentHost, |
+ specificOnly: specificOnly |
+ }; |
+ checkPotentialPopup(details.tabId, details.url, sourcePage, documentHost, specificOnly); |
kzar
2016/02/03 10:18:14
Nit: Mind fixing the long lines too?
|
+}); |
+ |
+chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => |
+{ |
+ if (!(tabId in tabsLoading)) |
+ return; |
+ |
+ if ("url" in changeInfo) |
+ { |
+ let source = tabsLoading[tabId]; |
+ checkPotentialPopup(tabId, tab.url, source.page, |
+ source.documentHost, |
+ source.specificOnly); |
+ } |
+ |
+ if ("status" in changeInfo && changeInfo.status == "complete" && tab.url != "about:blank") |
+ delete tabsLoading[tabId]; |
+}); |