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

Unified Diff: lib/requestBlocker.js

Issue 29752564: Issue 4580 - Removed ext.webRequest.handlerBehaviorChanged() (Closed)
Patch Set: Created April 14, 2018, 12:22 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 | « ext/background.js ('k') | 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
@@ -256,6 +256,24 @@
});
let ignoreFilterNotifications = false;
+let handlerBehaviorChangedQuota =
+ browser.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES;
+
+function propagateHandlerBehaviorChange()
+{
+ // Make sure to not call handlerBehaviorChanged() more often than allowed
+ // by browser.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES.
+ // Otherwise Chrome notifies the user that this extension is causing issues.
+ if (handlerBehaviorChangedQuota > 0)
+ {
+ browser.webNavigation.onBeforeNavigate.removeListener(
+ propagateHandlerBehaviorChange
+ );
+ browser.webRequest.handlerBehaviorChanged();
+ handlerBehaviorChangedQuota--;
+ setTimeout(() => { handlerBehaviorChangedQuota++; }, 600000);
+ }
+}
function onFilterChange(arg, isDisabledAction)
{
@@ -282,8 +300,16 @@
ignoreFilterNotifications = true;
setTimeout(() =>
{
+ // Defer handlerBehaviorChanged() until navigation occurs.
+ // 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.
+ if (!browser.webNavigation.onBeforeNavigate
+ .hasListener(propagateHandlerBehaviorChange))
+ browser.webNavigation.onBeforeNavigate
+ .addListener(propagateHandlerBehaviorChange);
+
ignoreFilterNotifications = false;
- ext.webRequest.handlerBehaviorChanged();
FilterNotifier.emit("filter.behaviorChanged");
});
}
« no previous file with comments | « ext/background.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld