| Index: chrome/ext/background.js |
| =================================================================== |
| --- a/chrome/ext/background.js |
| +++ b/chrome/ext/background.js |
| @@ -326,9 +326,58 @@ |
| return (framesOfTabs[tabId] || {})[frameId]; |
| }; |
| + var handlerBehaviorChangedQuota = chrome.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES; |
| + var handlerBehaviorChangedQuotaExceeded = false; |
| + var handlerBehaviorChangedPending = false; |
| + |
| + function handlerBehaviorChanged() |
| + { |
| + chrome.webRequest.handlerBehaviorChanged(); |
| + handlerBehaviorChangedQuota--; |
| + |
| + // 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. |
| + setTimeout(function() |
| + { |
| + handlerBehaviorChangedQuota++; |
| + |
| + // If the quota were exceeded, call handlerBehaviorChanged() |
| + // delayed, when 10 minutes since the first call within the |
| + // past 10 minutes passed. |
| + if (handlerBehaviorChangedQuotaExceeded) |
| + { |
| + handlerBehaviorChangedQuotaExceeded = false; |
| + handlerBehaviorChanged(); |
| + } |
| + }, 600000); |
| + } |
|
Wladimir Palant
2015/02/23 18:25:26
Is this really a good approach? I think that we sh
Sebastian Noack
2015/02/23 19:12:08
We call handlerBehaviorChanged() only if it did. T
Wladimir Palant
2015/02/23 19:22:42
If users are changing filters frequently (more oft
Sebastian Noack
2015/04/09 07:04:55
How about this: The new patch defers handlerBehavi
|
| + |
| ext.webRequest = { |
| onBeforeRequest: new ext._EventTarget(), |
| - handlerBehaviorChanged: chrome.webRequest.handlerBehaviorChanged |
| + handlerBehaviorChanged: function() |
| + { |
| + if (handlerBehaviorChangedQuota > 0) |
| + { |
| + // Call handlerBehaviorChanged() asynchronously, and only if it |
| + // hasn't been scheduled yet. That way we avoid to call it multiple |
| + // times, if multiple filters were added/removed simultanously. |
| + if (!handlerBehaviorChangedPending) |
| + { |
| + handlerBehaviorChangedPending = true; |
| + |
| + setTimeout(function() |
| + { |
| + handlerBehaviorChanged(); |
| + handlerBehaviorChangedPending = false; |
| + }, 0); |
| + } |
| + } |
| + else |
| + { |
| + handlerBehaviorChangedQuotaExceeded = true; |
| + } |
| + } |
| }; |
| chrome.tabs.query({}, function(tabs) |