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

Unified Diff: lib/devtools.js

Issue 29418679: Issue 5042 - Adds handling for requests which are not associated with browser tab (Closed)
Patch Set: addresses comments, nits, redundancies, white space Created May 31, 2017, 8:43 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
Index: lib/devtools.js
===================================================================
--- a/lib/devtools.js
+++ b/lib/devtools.js
@@ -29,20 +29,25 @@
const nonRequestTypes = ["DOCUMENT", "ELEMHIDE", "GENERICBLOCK", "GENERICHIDE"];
// Mapping of inspected tabs to their devpanel page
// and recorded items. We can't use a PageMap here,
// because data must persist after navigation/reload.
let panels = new Map();
+function isActivePanel(panel)
+{
+ return panel && !panel.reload && !panel.reloading;
+}
+
function getActivePanel(page)
{
let panel = panels.get(page.id);
- if (panel && !panel.reload && !panel.reloading)
+ if (isActivePanel(panel))
return panel;
return null;
}
function getFilterInfo(filter)
{
if (!filter)
return null;
@@ -111,37 +116,44 @@
request.sitekey,
request.specificOnly
);
}
/**
* Logs a request to the devtools panel.
*
- * @param {Page} page The page the request occured on
+ * @param {?Page} page The page the request occured on
Sebastian Noack 2017/06/01 17:32:21 Please describe the scenario in which Page is null
Jon Sonesen 2017/06/02 05:02:57 Acknowledged.
* @param {string} url The URL of the request
* @param {string} type The request type
* @param {string} docDomain The IDN-decoded hostname of the document
* @param {boolean} thirdParty Whether the origin of the request and
* document differs
* @param {?string} sitekey The active sitekey if there is any
* @param {?boolean} specificOnly Whether generic filters should be ignored
* @param {?BlockingFilter} filter The matched filter or null if there is no
* match
*/
exports.logRequest = function(page, url, type, docDomain,
thirdParty, sitekey,
specificOnly, filter)
{
- let panel = getActivePanel(page);
- if (panel)
+ if (panels.size == 0)
+ return;
+ let request = {url, type, docDomain, thirdParty, sitekey, specificOnly};
+ if (page)
{
- let request = {url, type, docDomain, thirdParty, sitekey, specificOnly};
- addRecord(panel, request, filter);
+ let panel = getActivePanel(page);
+ if (panel)
+ addRecord(panel, request, filter);
+ return;
}
+ for (let [tabId, panel] of panels)
Sebastian Noack 2017/06/01 17:32:21 The logic above, handling the case of page being n
Jon Sonesen 2017/06/02 05:02:57 Acknowledged.
+ if ((!page || page.id == tabId) && isActivePanel(panel))
+ addRecord(panel, request, filter);
};
/**
* Logs active element hiding filters to the devtools panel.
*
* @param {Page} page The page the elements were hidden on
* @param {string[]} selectors The selectors of applied ElemHideFilters
* @param {string[]} filters The text of applied ElemHideEmulationFilters
« no previous file with comments | « ext/background.js ('k') | lib/requestBlocker.js » ('j') | lib/requestBlocker.js » ('J')

Powered by Google App Engine
This is Rietveld