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

Unified Diff: ext/background.js

Issue 29418679: Issue 5042 - Adds handling for requests which are not associated with browser tab (Closed)
Patch Set: rebase Created May 30, 2017, 9:04 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 | lib/devtools.js » ('j') | lib/devtools.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ext/background.js
===================================================================
--- a/ext/background.js
+++ b/ext/background.js
@@ -563,17 +563,17 @@
});
});
chrome.webRequest.onBeforeRequest.addListener(details =>
{
// The high-level code isn't interested in requests that aren't
// related to a tab or requests loading a top-level document,
// those should never be blocked.
- if (details.tabId == -1 || details.type == "main_frame")
+ if (details.type == "main_frame")
return;
// Filter out requests from non web protocols. Ideally, we'd explicitly
// specify the protocols we are interested in (i.e. http://, https://,
// ws:// and wss://) with the url patterns, given below, when adding this
// listener. But unfortunately, Chrome <=57 doesn't support the WebSocket
// protocol and is causing an error if it is given.
let url = new URL(details.url);
@@ -582,28 +582,34 @@
return;
// We are looking for the frame that contains the element which
// has triggered this request. For most requests (e.g. images) we
// can just use the request's frame ID, but for subdocument requests
// (e.g. iframes) we must instead use the request's parent frame ID.
let {frameId, type} = details;
if (type == "sub_frame")
- frameId = details.parentFrameId;
-
- let frame = ext.getFrame(details.tabId, frameId);
- if (frame)
{
- let results = ext.webRequest.onBeforeRequest._dispatch(
- url, type, new Page({id: details.tabId}), frame
- );
+ frameId = details.parentFrameId;
+ type = "SUBDOCUMENT";
Sebastian Noack 2017/05/30 11:10:48 We no longer map "sub_frame" to "SUBDOCUMENT" here
Jon Sonesen 2017/05/31 08:28:17 Acknowledged.
+ }
- if (results.indexOf(false) != -1)
- return {cancel: true};
+ // Sometimes requests are not associated with a browser tab and
+ // in this case we want to still be able to view the url being called.
+ let frame = null;
+ let page = null;
+ if (details.tabId != -1)
+ {
+ frame = ext.getFrame(details.tabId, frameId);
+ page = new Page({id: details.tabId});
}
+
+ if (ext.webRequest.onBeforeRequest._dispatch(
+ url, type.toUpperCase(), page, frame).includes(false))
Sebastian Noack 2017/05/30 11:10:48 We no longer convert the type to upper case here.
Jon Sonesen 2017/05/31 08:28:17 Acknowledged.
+ return {cancel: true};
}, {urls: ["<all_urls>"]}, ["blocking"]);
/* Message passing */
chrome.runtime.onMessage.addListener((message, rawSender, sendResponse) =>
{
let sender = {};
« no previous file with comments | « no previous file | lib/devtools.js » ('j') | lib/devtools.js » ('J')

Powered by Google App Engine
This is Rietveld