Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/popupBlocker.js

Issue 29570614: Issue 5028 - Use browser namespace (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Update adblockplusui dependency Created Oct. 17, 2017, 1:02 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/options.js ('k') | lib/prefs.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 15 matching lines...) Expand all
26 const {logRequest} = require("devtools"); 26 const {logRequest} = require("devtools");
27 27
28 let loadingPopups = new Map(); 28 let loadingPopups = new Map();
29 29
30 function forgetPopup(tabId) 30 function forgetPopup(tabId)
31 { 31 {
32 loadingPopups.delete(tabId); 32 loadingPopups.delete(tabId);
33 33
34 if (loadingPopups.size == 0) 34 if (loadingPopups.size == 0)
35 { 35 {
36 chrome.webRequest.onBeforeRequest.removeListener(onPopupURLChanged); 36 browser.webRequest.onBeforeRequest.removeListener(onPopupURLChanged);
37 chrome.webNavigation.onCommitted.removeListener(onPopupURLChanged); 37 browser.webNavigation.onCommitted.removeListener(onPopupURLChanged);
38 chrome.webNavigation.onCompleted.removeListener(onCompleted); 38 browser.webNavigation.onCompleted.removeListener(onCompleted);
39 chrome.tabs.onRemoved.removeListener(forgetPopup); 39 browser.tabs.onRemoved.removeListener(forgetPopup);
40 } 40 }
41 } 41 }
42 42
43 function checkPotentialPopup(tabId, popup) 43 function checkPotentialPopup(tabId, popup)
44 { 44 {
45 let urlObj = new URL(popup.url || "about:blank"); 45 let urlObj = new URL(popup.url || "about:blank");
46 let urlString = stringifyURL(urlObj); 46 let urlString = stringifyURL(urlObj);
47 let documentHost = extractHostFromFrame(popup.sourceFrame); 47 let documentHost = extractHostFromFrame(popup.sourceFrame);
48 let thirdParty = isThirdParty(urlObj, documentHost); 48 let thirdParty = isThirdParty(urlObj, documentHost);
49 49
50 let specificOnly = !!checkWhitelisted( 50 let specificOnly = !!checkWhitelisted(
51 popup.sourcePage, popup.sourceFrame, 51 popup.sourcePage, popup.sourceFrame,
52 RegExpFilter.typeMap.GENERICBLOCK 52 RegExpFilter.typeMap.GENERICBLOCK
53 ); 53 );
54 54
55 let filter = defaultMatcher.matchesAny( 55 let filter = defaultMatcher.matchesAny(
56 urlString, RegExpFilter.typeMap.POPUP, 56 urlString, RegExpFilter.typeMap.POPUP,
57 documentHost, thirdParty, null, specificOnly 57 documentHost, thirdParty, null, specificOnly
58 ); 58 );
59 59
60 if (filter instanceof BlockingFilter) 60 if (filter instanceof BlockingFilter)
61 chrome.tabs.remove(tabId); 61 browser.tabs.remove(tabId);
62 62
63 logRequest( 63 logRequest(
64 popup.sourcePage, urlString, "POPUP", 64 popup.sourcePage, urlString, "POPUP",
65 documentHost, thirdParty, null, 65 documentHost, thirdParty, null,
66 specificOnly, filter 66 specificOnly, filter
67 ); 67 );
68 } 68 }
69 69
70 function onPopupURLChanged(details) 70 function onPopupURLChanged(details)
71 { 71 {
(...skipping 12 matching lines...) Expand all
84 84
85 function onCompleted(details) 85 function onCompleted(details)
86 { 86 {
87 if (details.frameId == 0 && details.url != "about:blank") 87 if (details.frameId == 0 && details.url != "about:blank")
88 forgetPopup(details.tabId); 88 forgetPopup(details.tabId);
89 } 89 }
90 90
91 // Versions of Firefox before 54 do not support 91 // Versions of Firefox before 54 do not support
92 // webNavigation.onCreatedNavigationTarget 92 // webNavigation.onCreatedNavigationTarget
93 // https://bugzilla.mozilla.org/show_bug.cgi?id=1190687 93 // https://bugzilla.mozilla.org/show_bug.cgi?id=1190687
94 if ("onCreatedNavigationTarget" in chrome.webNavigation) 94 if ("onCreatedNavigationTarget" in browser.webNavigation)
95 { 95 {
96 chrome.webNavigation.onCreatedNavigationTarget.addListener(details => 96 browser.webNavigation.onCreatedNavigationTarget.addListener(details =>
97 { 97 {
98 if (loadingPopups.size == 0) 98 if (loadingPopups.size == 0)
99 { 99 {
100 chrome.webRequest.onBeforeRequest.addListener( 100 browser.webRequest.onBeforeRequest.addListener(
101 onPopupURLChanged, 101 onPopupURLChanged,
102 { 102 {
103 urls: ["http://*/*", "https://*/*"], 103 urls: ["http://*/*", "https://*/*"],
104 types: ["main_frame"] 104 types: ["main_frame"]
105 } 105 }
106 ); 106 );
107 chrome.webNavigation.onCommitted.addListener(onPopupURLChanged); 107 browser.webNavigation.onCommitted.addListener(onPopupURLChanged);
108 chrome.webNavigation.onCompleted.addListener(onCompleted); 108 browser.webNavigation.onCompleted.addListener(onCompleted);
109 chrome.tabs.onRemoved.addListener(forgetPopup); 109 browser.tabs.onRemoved.addListener(forgetPopup);
110 } 110 }
111 111
112 let popup = { 112 let popup = {
113 url: details.url, 113 url: details.url,
114 sourcePage: new ext.Page({id: details.sourceTabId}), 114 sourcePage: new ext.Page({id: details.sourceTabId}),
115 sourceFrame: null 115 sourceFrame: null
116 }; 116 };
117 117
118 loadingPopups.set(details.tabId, popup); 118 loadingPopups.set(details.tabId, popup);
119 119
120 let frame = ext.getFrame(details.sourceTabId, details.sourceFrameId); 120 let frame = ext.getFrame(details.sourceTabId, details.sourceFrameId);
121 121
122 if (checkWhitelisted(popup.sourcePage, frame)) 122 if (checkWhitelisted(popup.sourcePage, frame))
123 { 123 {
124 forgetPopup(details.tabId); 124 forgetPopup(details.tabId);
125 } 125 }
126 else 126 else
127 { 127 {
128 popup.sourceFrame = frame; 128 popup.sourceFrame = frame;
129 checkPotentialPopup(details.tabId, popup); 129 checkPotentialPopup(details.tabId, popup);
130 } 130 }
131 }); 131 });
132 } 132 }
OLDNEW
« no previous file with comments | « lib/options.js ('k') | lib/prefs.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld