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

Delta Between Two Patch Sets: lib/requestBlocker.js

Issue 29760707: Issue 6622 - Implement $rewrite filter option (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Left Patch Set: Rename rewrittenTo to rewrittenUrl. Adjust some comments. Created May 15, 2018, 4:31 p.m.
Right Patch Set: Updated proper revision for adblockpluscore. No dependency change for ui Created May 18, 2018, 3:27 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « dependencies ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 // If tabId is -1, its not (e.g. the request was sent by 101 // If tabId is -1, its not (e.g. the request was sent by
102 // a Service/Shared Worker) and we have to identify the related tabs. 102 // a Service/Shared Worker) and we have to identify the related tabs.
103 if (details.tabId != -1) 103 if (details.tabId != -1)
104 return Promise.resolve([details.tabId]); 104 return Promise.resolve([details.tabId]);
105 105
106 let url; // Firefox provides "originUrl" indicating the 106 let url; // Firefox provides "originUrl" indicating the
107 if (details.originUrl) // URL of the tab that caused this request. 107 if (details.originUrl) // URL of the tab that caused this request.
108 url = details.originUrl; // In case of Service/Shared Worker, this is the 108 url = details.originUrl; // In case of Service/Shared Worker, this is the
109 // URL of the tab that caused the worker to spawn. 109 // URL of the tab that caused the worker to spawn.
110 110
111 else if (details.initiator) // Chromium >=63 provides "intiator" which 111 else if (details.initiator && details.initiator != "null")
112 url = details.initiator + "/*"; // is equivalent to "originUrl" on Firefox 112 url = details.initiator + "/*"; // Chromium >=63 provides "intiator" which
113 // is equivalent to "originUrl" on Firefox
113 // except that its not a full URL but just 114 // except that its not a full URL but just
114 // an origin (proto + host). 115 // an origin (proto + host).
115 else 116 else
116 return Promise.resolve([]); 117 return Promise.resolve([]);
117 118
118 return browser.tabs.query({url}).then(tabs => tabs.map(tab => tab.id)); 119 return browser.tabs.query({url}).then(tabs => tabs.map(tab => tab.id));
119 } 120 }
120 121
121 function logRequest(tabIds, request, filter) 122 function logRequest(tabIds, request, filter)
122 { 123 {
(...skipping 15 matching lines...) Expand all
138 // listener. But unfortunately, Chrome <=57 doesn't support the WebSocket 139 // listener. But unfortunately, Chrome <=57 doesn't support the WebSocket
139 // protocol and is causing an error if it is given. 140 // protocol and is causing an error if it is given.
140 let url = new URL(details.url); 141 let url = new URL(details.url);
141 if (url.protocol != "http:" && url.protocol != "https:" && 142 if (url.protocol != "http:" && url.protocol != "https:" &&
142 url.protocol != "ws:" && url.protocol != "wss:") 143 url.protocol != "ws:" && url.protocol != "wss:")
143 return; 144 return;
144 145
145 // Firefox provides us with the full origin URL, while Chromium (>=63) 146 // Firefox provides us with the full origin URL, while Chromium (>=63)
146 // provides only the protocol + host of the (top-level) document which 147 // provides only the protocol + host of the (top-level) document which
147 // the request originates from through the "initiator" property. 148 // the request originates from through the "initiator" property.
148 let originUrl = details.originUrl ? new URL(details.originUrl) : 149 let originUrl = null;
149 details.initiator ? new URL(details.initiator) : null; 150 if (details.originUrl)
151 originUrl = new URL(details.originUrl);
152 else if (details.initiator && details.initiator != "null")
153 originUrl = new URL(details.initiator);
150 154
151 // Ignore requests sent by extensions or by Firefox itself: 155 // Ignore requests sent by extensions or by Firefox itself:
152 // * Firefox intercepts requests sent by any extensions, indicated with 156 // * Firefox intercepts requests sent by any extensions, indicated with
153 // an "originURL" starting with "moz-extension:". 157 // an "originURL" starting with "moz-extension:".
154 // * Chromium intercepts requests sent by this extension only, indicated 158 // * Chromium intercepts requests sent by this extension only, indicated
155 // on Chromium >=63 with an "initiator" starting with "chrome-extension:". 159 // on Chromium >=63 with an "initiator" starting with "chrome-extension:".
156 // * On Firefox, requests that don't relate to any document or extension are 160 // * On Firefox, requests that don't relate to any document or extension are
157 // indicated with an "originUrl" starting with "chrome:". 161 // indicated with an "originUrl" starting with "chrome:".
158 if (originUrl && (originUrl.protocol == extensionProtocol || 162 if (originUrl && (originUrl.protocol == extensionProtocol ||
159 originUrl.protocol == "chrome:")) 163 originUrl.protocol == "chrome:"))
160 return; 164 return;
161 165
162 let page = new ext.Page({id: details.tabId}); 166 let page = new ext.Page({id: details.tabId});
163 let frame = ext.getFrame( 167 let frame = ext.getFrame(
164 details.tabId, 168 details.tabId,
165 // We are looking for the frame that contains the element which 169 // We are looking for the frame that contains the element which
166 // has triggered this request. For most requests (e.g. images) we 170 // has triggered this request. For most requests (e.g. images) we
167 // can just use the request's frame ID, but for subdocument requests 171 // can just use the request's frame ID, but for subdocument requests
168 // (e.g. iframes) we must instead use the request's parent frame ID. 172 // (e.g. iframes) we must instead use the request's parent frame ID.
169 details.type == "sub_frame" ? details.parentFrameId : details.frameId 173 details.type == "sub_frame" ? details.parentFrameId : details.frameId
170 ); 174 );
171 175
172 // On Chromium >= 63, if both the frame is unknown and we haven't get 176 // On Chromium >= 63, if both the frame is unknown and we haven't get
173 // an "initator", this implies a request sent by the browser itself 177 // an "initiator", this implies a request sent by the browser itself
174 // (on older versions of Chromium, due to the lack of "initator", 178 // (on older versions of Chromium, due to the lack of "initiator",
175 // this can also indicate a request sent by a Shared/Service Worker). 179 // this can also indicate a request sent by a Shared/Service Worker).
176 if (!frame && !originUrl) 180 if (!frame && !originUrl)
177 return; 181 return;
178 182
179 if (checkWhitelisted(page, frame, originUrl)) 183 if (checkWhitelisted(page, frame, originUrl))
180 return; 184 return;
181 185
182 let type = resourceTypes.get(details.type) || "OTHER"; 186 let type = resourceTypes.get(details.type) || "OTHER";
183 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame, 187 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame,
184 originUrl); 188 originUrl);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 } 328 }
325 329
326 FilterNotifier.on("subscription.added", onFilterChange); 330 FilterNotifier.on("subscription.added", onFilterChange);
327 FilterNotifier.on("subscription.removed", onFilterChange); 331 FilterNotifier.on("subscription.removed", onFilterChange);
328 FilterNotifier.on("subscription.updated", onFilterChange); 332 FilterNotifier.on("subscription.updated", onFilterChange);
329 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); 333 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true));
330 FilterNotifier.on("filter.added", onFilterChange); 334 FilterNotifier.on("filter.added", onFilterChange);
331 FilterNotifier.on("filter.removed", onFilterChange); 335 FilterNotifier.on("filter.removed", onFilterChange);
332 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); 336 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true));
333 FilterNotifier.on("load", onFilterChange); 337 FilterNotifier.on("load", onFilterChange);
LEFTRIGHT
« dependencies ('k') | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld