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

Unified Diff: chrome/ext/background.js

Issue 6615790883176448: Issue 2034 - Respect chrome.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES (Closed)
Patch Set: Renamed overlooked variable name Created April 10, 2015, 7: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
« no previous file with comments | « no previous file | webrequest.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/ext/background.js
===================================================================
--- a/chrome/ext/background.js
+++ b/chrome/ext/background.js
@@ -326,9 +326,35 @@
return (framesOfTabs[tabId] || {})[frameId];
};
+ var handlerBehaviorChangedQuota = chrome.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES;
+
+ function propagateHandlerBehaviorChange()
+ {
+ // Make sure to not call handlerBehaviorChanged() more often than allowed
+ // by chrome.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES.
+ // Otherwise Chrome notifies the user that this extension is causing issues.
+ if (handlerBehaviorChangedQuota > 0)
+ {
+ chrome.webNavigation.onBeforeNavigate.removeListener(propagateHandlerBehaviorChange);
+ chrome.webRequest.handlerBehaviorChanged();
+
+ handlerBehaviorChangedQuota--;
+ setTimeout(function() { handlerBehaviorChangedQuota++; }, 600000);
+ }
+ }
+
ext.webRequest = {
onBeforeRequest: new ext._EventTarget(),
- handlerBehaviorChanged: chrome.webRequest.handlerBehaviorChanged
+ handlerBehaviorChanged: function()
+ {
+ // 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.
+ var onBeforeNavigate = chrome.webNavigation.onBeforeNavigate;
+ if (!onBeforeNavigate.hasListener(propagateHandlerBehaviorChange))
+ onBeforeNavigate.addListener(propagateHandlerBehaviorChange);
+ }
};
// Since Chrome 38 requests of type 'object' (e.g. requests
« no previous file with comments | « no previous file | webrequest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld