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

Unified Diff: chrome/ext/background.js

Issue 29374674: Issue 4864 - Start using ESLint for adblockpluschrome (Closed)
Patch Set: Use var for ext declarations again Created Feb. 8, 2017, 9:02 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: chrome/ext/background.js
diff --git a/chrome/ext/background.js b/chrome/ext/background.js
index 8cec8296408b0cafb5452c7eb0afb6e67d59035b..e7aa10cb8e54fda1fc6c4f87c15c54386a67306a 100644
--- a/chrome/ext/background.js
+++ b/chrome/ext/background.js
@@ -57,24 +57,24 @@
function afterTabLoaded(callback)
{
- return openedTab =>
- {
- let onUpdated = (tabId, changeInfo, tab) =>
- {
- if (tabId == openedTab.id && changeInfo.status == "complete")
- {
- chrome.tabs.onUpdated.removeListener(onUpdated);
- callback(new Page(openedTab));
- }
- };
- chrome.tabs.onUpdated.addListener(onUpdated);
- };
+ return openedTab =>
+ {
+ let onUpdated = (tabId, changeInfo, tab) =>
+ {
+ if (tabId == openedTab.id && changeInfo.status == "complete")
+ {
+ chrome.tabs.onUpdated.removeListener(onUpdated);
+ callback(new Page(openedTab));
+ }
+ };
+ chrome.tabs.onUpdated.addListener(onUpdated);
+ };
}
ext.pages = {
open(url, callback)
{
- chrome.tabs.create({url: url}, callback && afterTabLoaded(callback));
+ chrome.tabs.create({url}, callback && afterTabLoaded(callback));
},
query(info, callback)
{
@@ -131,7 +131,7 @@
{
if (frameId == 0)
{
- let page = new Page({id: tabId, url: url});
+ let page = new Page({id: tabId, url});
if (eagerlyUpdatedPages.get(page) != url)
{
@@ -147,11 +147,13 @@
chrome.tabs.get(tabId, () =>
{
// If the tab is prerendered, chrome.tabs.get() sets
- // chrome.runtime.lastError and we have to dispatch the onLoading event,
- // since the onUpdated event isn't dispatched for prerendered tabs.
- // However, we have to keep relying on the unUpdated event for tabs that
- // are already visible. Otherwise browser action changes get overridden
- // when Chrome automatically resets them on navigation.
+ // chrome.runtime.lastError and we have to dispatch the
+ // onLoading event, since the onUpdated event isn't
+ // dispatched for prerendered tabs. However, we have to
+ // keep relying on the unUpdated event for tabs that are
+ // already visible. Otherwise browser action changes get
+ // overridden when Chrome automatically resets them on
+ // navigation.
if (chrome.runtime.lastError)
ext.pages.onLoading._dispatch(page);
});
@@ -234,7 +236,7 @@
},
_queueChanges()
{
- chrome.tabs.get(this._tabId, function()
+ chrome.tabs.get(this._tabId, () =>
{
// If the tab is prerendered, chrome.tabs.get() sets
// chrome.runtime.lastError and we have to delay our changes
@@ -256,7 +258,7 @@
{
this._applyChanges();
}
- }.bind(this));
+ });
},
_addChange(name, value)
{
@@ -378,7 +380,9 @@
return (framesOfTabs[tabId] || {})[frameId];
};
- let handlerBehaviorChangedQuota = chrome.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES;
+ let handlerBehaviorChangedQuota = (
+ chrome.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES
+ );
Sebastian Noack 2017/02/09 01:04:49 The parenthesis here seem unnecessary.
kzar 2017/02/20 10:27:29 Done.
function propagateHandlerBehaviorChange()
{
@@ -387,7 +391,9 @@
// Otherwise Chrome notifies the user that this extension is causing issues.
if (handlerBehaviorChangedQuota > 0)
{
- chrome.webNavigation.onBeforeNavigate.removeListener(propagateHandlerBehaviorChange);
+ chrome.webNavigation.onBeforeNavigate.removeListener(
+ propagateHandlerBehaviorChange
Sebastian Noack 2017/02/09 01:04:49 I wonder whether we can perhaps shorten the variab
kzar 2017/02/20 10:27:28 I don't mind the wrapping too much here and I can'
+ );
chrome.webRequest.handlerBehaviorChanged();
handlerBehaviorChangedQuota--;
@@ -403,7 +409,7 @@
// There wouldn't be any visible effect when calling it earlier,
// but it's an expensive operation and that way we avoid to call
// it multiple times, if multiple filters are added/removed.
- let onBeforeNavigate = chrome.webNavigation.onBeforeNavigate;
+ let {onBeforeNavigate} = chrome.webNavigation;
if (!onBeforeNavigate.hasListener(propagateHandlerBehaviorChange))
onBeforeNavigate.addListener(propagateHandlerBehaviorChange);
}
@@ -420,11 +426,16 @@
let frames = framesOfTabs[tab.id] = Object.create(null);
for (let i = 0; i < details.length; i++)
- frames[details[i].frameId] = {url: new URL(details[i].url), parent: null};
+ {
+ frames[details[i].frameId] = {
+ url: new URL(details[i].url),
+ parent: null
+ };
+ }
for (let i = 0; i < details.length; i++)
{
- let parentFrameId = details[i].parentFrameId;
+ let {parentFrameId} = details[i];
if (parentFrameId != -1)
frames[details[i].frameId].parent = frames[parentFrameId];
@@ -446,17 +457,11 @@
// 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;
- let requestType;
- if (details.type == "sub_frame")
+ let {frameId, type} = details;
+ if (type == "sub_frame")
{
frameId = details.parentFrameId;
- requestType = "SUBDOCUMENT";
- }
- else
- {
- frameId = details.frameId;
- requestType = details.type.toUpperCase();
+ type = "SUBDOCUMENT";
}
let frame = ext.getFrame(details.tabId, frameId);
@@ -464,7 +469,7 @@
{
let results = ext.webRequest.onBeforeRequest._dispatch(
new URL(details.url),
- requestType,
+ type.toUpperCase(),
new Page({id: details.tabId}),
frame
);
@@ -504,7 +509,8 @@
};
}
- return ext.onMessage._dispatch(message, sender, sendResponse).indexOf(true) != -1;
+ let results = ext.onMessage._dispatch(message, sender, sendResponse);
+ return results.indexOf(true) != -1;
Sebastian Noack 2017/02/09 01:04:48 This would be another way to wrap the code here, w
kzar 2017/02/20 10:27:29 I've wrapped it in a similar way which I preferred
});

Powered by Google App Engine
This is Rietveld