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

Unified Diff: lib/devtools.js

Issue 29374674: Issue 4864 - Start using ESLint for adblockpluschrome (Closed)
Patch Set: Rebased. Created Feb. 28, 2017, 3:47 p.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 | « lib/compat.js ('k') | lib/filterComposer.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/devtools.js
diff --git a/lib/devtools.js b/lib/devtools.js
index f1b40a0bfd538441c2cd91707c3278607368b058..c44ad58935ef5912436397947b05d613be64bc74 100644
--- a/lib/devtools.js
+++ b/lib/devtools.js
@@ -44,7 +44,7 @@ function hasPanels()
function getActivePanel(page)
{
let panel = panels[page.id];
- if(panel && !panel.reload && !panel.reloading)
+ if (panel && !panel.reload && !panel.reloading)
return panel;
return null;
}
@@ -71,7 +71,7 @@ function getFilterInfo(filter)
return {
text: filter.text,
whitelisted: filter instanceof WhitelistFilter,
- userDefined: userDefined,
+ userDefined,
subscription: subscriptionTitle
};
}
@@ -79,13 +79,14 @@ function getFilterInfo(filter)
function hasRecord(panel, request, filter)
{
return panel.records.some(record =>
- record.request.url == request.url &&
+ record.request.url == request.url &&
record.request.docDomain == request.docDomain &&
// Ignore partial (e.g. ELEMHIDE) whitelisting if there is already
// a DOCUMENT exception which disables all means of blocking.
- (record.request.type == "DOCUMENT" ? nonRequestTypes.indexOf(request.type) != -1
- : record.request.type == request.type) &&
+ (record.request.type == "DOCUMENT"
+ ? nonRequestTypes.indexOf(request.type) != -1
+ : record.request.type == request.type) &&
// Matched element hiding filters don't relate to a particular request,
// so we also have to match the CSS selector in order to distinguish them.
@@ -99,14 +100,11 @@ function addRecord(panel, request, filter)
{
panel.port.postMessage({
type: "add-record",
- request: request,
+ request,
filter: getFilterInfo(filter)
});
- panel.records.push({
- request: request,
- filter: filter
- });
+ panel.records.push({request, filter});
}
}
@@ -129,10 +127,12 @@ function matchRequest(request)
* @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 {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
+ * @param {?BlockingFilter} filter The matched filter or null if there is no
+ * match
*/
exports.logRequest = function(page, url, type, docDomain,
thirdParty, sitekey,
@@ -141,16 +141,8 @@ exports.logRequest = function(page, url, type, docDomain,
let panel = getActivePanel(page);
if (panel)
{
- let request = {
- url: url,
- type: type,
- docDomain: docDomain,
- thirdParty: thirdParty,
- sitekey: sitekey,
- specificOnly: specificOnly
- };
-
- addRecord(panel, request, filter);
+ addRecord(panel, {url, type, docDomain, thirdParty, sitekey, specificOnly},
+ filter);
}
};
@@ -181,11 +173,11 @@ function logHiddenElements(page, selectors, docDomain)
if (!filter.isActiveOnDomain(docDomain))
continue;
- addRecord(panel, {type: "ELEMHIDE", docDomain: docDomain}, filter);
+ addRecord(panel, {type: "ELEMHIDE", docDomain}, filter);
}
}
}
-};
+}
/**
* Logs a whitelisting filter, that disables (some kind of)
@@ -193,11 +185,14 @@ function logHiddenElements(page, selectors, docDomain)
*
* @param {Page} page The page the whitelisting is active on
* @param {string} url The url of the whitelisted document
- * @param {number} typeMask The bit mask of whitelisting types checked for
- * @param {string} docDomain The IDN-decoded hostname of the parent document
+ * @param {number} typeMask The bit mask of whitelisting types checked
+ * for
+ * @param {string} docDomain The IDN-decoded hostname of the parent
+ * document
* @param {WhitelistFilter} filter The matched whitelisting filter
*/
-exports.logWhitelistedDocument = function(page, url, typeMask, docDomain, filter)
+exports.logWhitelistedDocument = function(page, url, typeMask, docDomain,
+ filter)
{
let panel = getActivePanel(page);
if (panel)
@@ -205,7 +200,7 @@ exports.logWhitelistedDocument = function(page, url, typeMask, docDomain, filter
for (let type of nonRequestTypes)
{
if (typeMask & filter.contentType & RegExpFilter.typeMap[type])
- addRecord(panel, {url: url, type: type, docDomain: docDomain}, filter);
+ addRecord(panel, {url, type, docDomain}, filter);
}
}
};
@@ -229,9 +224,7 @@ function onBeforeRequest(details)
// when a new request is issued. However, make sure that we don't end up
// in an infinite recursion if we already triggered a reload.
if (panel.reloading)
- {
panel.reloading = false;
- }
else
{
panel.records = [];
@@ -339,9 +332,9 @@ function onSubscriptionAdded(subscription)
updateFilters(subscription.filters, true);
}
-chrome.runtime.onConnect.addListener(port =>
+chrome.runtime.onConnect.addListener(newPort =>
{
- let match = port.name.match(/^devtools-(\d+)$/);
+ let match = newPort.name.match(/^devtools-(\d+)$/);
if (!match)
return;
@@ -351,7 +344,7 @@ chrome.runtime.onConnect.addListener(port =>
chrome.webRequest.onBeforeRequest.addListener(
localOnBeforeRequest,
{
- urls: ["<all_urls>"],
+ urls: ["<all_urls>"],
types: ["main_frame"],
tabId: inspectedTabId
}
@@ -365,7 +358,7 @@ chrome.runtime.onConnect.addListener(port =>
FilterNotifier.on("subscription.added", onSubscriptionAdded);
}
- port.onDisconnect.addListener(() =>
+ newPort.onDisconnect.addListener(() =>
{
delete panels[inspectedTabId];
chrome.webRequest.onBeforeRequest.removeListener(localOnBeforeRequest);
@@ -379,7 +372,7 @@ chrome.runtime.onConnect.addListener(port =>
}
});
- panels[inspectedTabId] = {port: port, records: []};
+ panels[inspectedTabId] = {port: newPort, records: []};
});
port.on("devtools.traceElemHide", (message, sender) =>
« no previous file with comments | « lib/compat.js ('k') | lib/filterComposer.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld