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: Rebased and deferred handlerBehaviorChanged() until navigation occurs Created April 9, 2015, 7 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 handlerBehaviorChanged()
Wladimir Palant 2015/04/09 18:45:02 That's a confusing name. We have three things all
Sebastian Noack 2015/04/10 06:45:26 Good point. I went for propagateHandlerBehaviorCha
+ {
+ // 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(handlerBehaviorChanged);
+ chrome.webRequest.handlerBehaviorChanged();
+
+ handlerBehaviorChangedQuota--;
+ setTimeout(function() { handlerBehaviorChangedQuota++; }, 600000);
Wladimir Palant 2015/04/09 18:45:02 This will "recover" the quota way too slowly. I gu
Sebastian Noack 2015/04/10 06:45:26 I think it is correct. This makes sure to not call
Wladimir Palant 2015/04/10 06:58:14 You are right, the current approach is correct.
+ }
+ }
+
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(handlerBehaviorChanged))
+ onBeforeNavigate.addListener(handlerBehaviorChanged);
Wladimir Palant 2015/04/09 18:45:02 My initial reaction was: "cannot be that the same
Sebastian Noack 2015/04/10 06:45:26 Yep, it can. ;)
+ }
};
// 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