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

Unified Diff: lib/requestBlocker.js

Issue 29752559: Issue 6586 - Fixed WebRTC wrapper after removing ext.webRequest.onBeforeRequest (Closed)
Patch Set: Created April 14, 2018, 11:54 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/requestBlocker.js
===================================================================
--- a/lib/requestBlocker.js
+++ b/lib/requestBlocker.js
@@ -76,6 +76,29 @@
yield "CSP";
}());
+function getDocumentInfo(page, frame, originUrl)
+{
+ return [
+ extractHostFromFrame(frame, originUrl),
+ getKey(page, frame, originUrl),
+ !!checkWhitelisted(page, frame, originUrl,
+ RegExpFilter.typeMap.GENERICBLOCK)
+ ];
+}
+
+function matchRequest(url, type, docDomain, sitekey, specificOnly)
+{
+ let urlString = stringifyURL(url);
+ let thirdParty = isThirdParty(url, docDomain);
+
+ return [
+ defaultMatcher.matchesAny(urlString, RegExpFilter.typeMap[type],
+ docDomain, thirdParty, sitekey, specificOnly),
+ urlString,
+ thirdParty
+ ];
+}
+
function getRelatedTabIds(details)
{
// This is the common case, the request is associated with a single tab.
@@ -99,20 +122,17 @@
return browser.tabs.query({url}).then(tabs => tabs.map(tab => tab.id));
}
-function logRequest(details, url, type, docDomain, thirdParty,
+function logRequest(tabIds, url, type, docDomain, thirdParty,
sitekey, specificOnly, filter)
{
- getRelatedTabIds(details).then(tabIds =>
- {
- if (filter)
- FilterNotifier.emit("filter.hitCount", filter, 0, 0, tabIds);
+ if (filter)
+ FilterNotifier.emit("filter.hitCount", filter, 0, 0, tabIds);
- devtools.logRequest(
- tabIds, url, type, docDomain,
- thirdParty, sitekey,
- specificOnly, filter
- );
- });
+ devtools.logRequest(
+ tabIds, url, type, docDomain,
+ thirdParty, sitekey,
+ specificOnly, filter
+ );
}
browser.webRequest.onBeforeRequest.addListener(details =>
@@ -174,21 +194,17 @@
if (checkWhitelisted(page, frame, originUrl))
return;
- let urlString = stringifyURL(url);
let type = resourceTypes.get(details.type) || "OTHER";
- let docDomain = extractHostFromFrame(frame, originUrl);
- let thirdParty = isThirdParty(url, docDomain);
- let sitekey = getKey(page, frame, originUrl);
- let specificOnly = !!checkWhitelisted(page, frame, originUrl,
- RegExpFilter.typeMap.GENERICBLOCK);
+ let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame,
+ originUrl);
+ let [filter, urlString, thirdParty] = matchRequest(url, type, docDomain,
+ sitekey, specificOnly);
- let filter = defaultMatcher.matchesAny(
- urlString, RegExpFilter.typeMap[type],
- docDomain, thirdParty, sitekey, specificOnly
- );
-
- logRequest(details, urlString, type, docDomain,
- thirdParty, sitekey, specificOnly, filter);
+ getRelatedTabIds(details).then(tabIds =>
+ {
+ logRequest(tabIds, urlString, type, docDomain,
+ thirdParty, sitekey, specificOnly, filter);
+ });
if (filter instanceof BlockingFilter)
return {cancel: true};
@@ -196,28 +212,19 @@
port.on("filters.collapse", (message, sender) =>
{
- if (checkWhitelisted(sender.page, sender.frame))
+ let {page, frame} = sender;
+
+ if (checkWhitelisted(page, frame))
return false;
- let typeMask = RegExpFilter.typeMap[message.mediatype];
- let documentHost = extractHostFromFrame(sender.frame);
- let sitekey = getKey(sender.page, sender.frame);
let blocked = false;
-
- let specificOnly = checkWhitelisted(
- sender.page, sender.frame, null,
- RegExpFilter.typeMap.GENERICBLOCK
- );
+ let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame);
for (let url of message.urls)
{
- let urlObj = new URL(url, message.baseURL);
- let filter = defaultMatcher.matchesAny(
- stringifyURL(urlObj),
- typeMask, documentHost,
- isThirdParty(urlObj, documentHost),
- sitekey, specificOnly
- );
+ let [filter] = matchRequest(new URL(url, message.baseURL),
+ message.mediatype, docDomain,
+ sitekey, specificOnly);
if (filter instanceof BlockingFilter)
{
@@ -274,10 +281,18 @@
port.on("request.blockedByRTCWrapper", (msg, sender) =>
{
- return ext.webRequest.onBeforeRequest._dispatch(
- new URL(msg.url),
- "webrtc",
- sender.page,
- sender.frame
- ).includes(false);
+ let {page, frame} = sender;
+
+ if (checkWhitelisted(page, frame))
+ return false;
+
+ let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame);
+ let [filter, url, thirdParty] = matchRequest(new URL(msg.url),
+ "WEBRTC", docDomain,
+ sitekey, specificOnly);
+
+ logRequest([sender.page.id], url, "WEBRTC", docDomain,
+ thirdParty, sitekey, specificOnly, filter);
+
+ return filter instanceof BlockingFilter;
});
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld