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

Side by Side Diff: chrome/ext/background.js

Issue 6615790883176448: Issue 2034 - Respect chrome.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES (Closed)
Patch Set: Created Feb. 23, 2015, 5:18 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | webrequest.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 319
320 /* Web requests */ 320 /* Web requests */
321 321
322 var framesOfTabs = Object.create(null); 322 var framesOfTabs = Object.create(null);
323 323
324 ext.getFrame = function(tabId, frameId) 324 ext.getFrame = function(tabId, frameId)
325 { 325 {
326 return (framesOfTabs[tabId] || {})[frameId]; 326 return (framesOfTabs[tabId] || {})[frameId];
327 }; 327 };
328 328
329 var handlerBehaviorChangedQuota = chrome.webRequest.MAX_HANDLER_BEHAVIOR_CHANG ED_CALLS_PER_10_MINUTES;
330 var handlerBehaviorChangedQuotaExceeded = false;
331 var handlerBehaviorChangedPending = false;
332
333 function handlerBehaviorChanged()
334 {
335 chrome.webRequest.handlerBehaviorChanged();
336 handlerBehaviorChangedQuota--;
337
338 // Make sure to not call handlerBehaviorChanged() more often than allowed
339 // by chrome.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES.
340 // Otherwise Chrome notifies the user that this extension is causing issues.
341 setTimeout(function()
342 {
343 handlerBehaviorChangedQuota++;
344
345 // If the quota were exceeded, call handlerBehaviorChanged()
346 // delayed, when 10 minutes since the first call within the
347 // past 10 minutes passed.
348 if (handlerBehaviorChangedQuotaExceeded)
349 {
350 handlerBehaviorChangedQuotaExceeded = false;
351 handlerBehaviorChanged();
352 }
353 }, 600000);
354 }
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
355
329 ext.webRequest = { 356 ext.webRequest = {
330 onBeforeRequest: new ext._EventTarget(), 357 onBeforeRequest: new ext._EventTarget(),
331 handlerBehaviorChanged: chrome.webRequest.handlerBehaviorChanged 358 handlerBehaviorChanged: function()
359 {
360 if (handlerBehaviorChangedQuota > 0)
361 {
362 // Call handlerBehaviorChanged() asynchronously, and only if it
363 // hasn't been scheduled yet. That way we avoid to call it multiple
364 // times, if multiple filters were added/removed simultanously.
365 if (!handlerBehaviorChangedPending)
366 {
367 handlerBehaviorChangedPending = true;
368
369 setTimeout(function()
370 {
371 handlerBehaviorChanged();
372 handlerBehaviorChangedPending = false;
373 }, 0);
374 }
375 }
376 else
377 {
378 handlerBehaviorChangedQuotaExceeded = true;
379 }
380 }
332 }; 381 };
333 382
334 chrome.tabs.query({}, function(tabs) 383 chrome.tabs.query({}, function(tabs)
335 { 384 {
336 tabs.forEach(function(tab) 385 tabs.forEach(function(tab)
337 { 386 {
338 chrome.webNavigation.getAllFrames({tabId: tab.id}, function(details) 387 chrome.webNavigation.getAllFrames({tabId: tab.id}, function(details)
339 { 388 {
340 if (details && details.length > 0) 389 if (details && details.length > 0)
341 { 390 {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 callback(new Page(tab)); 563 callback(new Page(tab));
515 } 564 }
516 else 565 else
517 { 566 {
518 ext.pages.open(optionsUrl, callback); 567 ext.pages.open(optionsUrl, callback);
519 } 568 }
520 }); 569 });
521 }); 570 });
522 }; 571 };
523 })(); 572 })();
OLDNEW
« no previous file with comments | « no previous file | webrequest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld