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: Renamed function to propagateHandlerBehaviorChange Created April 10, 2015, 6:45 a.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
331 function propagateHandlerBehaviorChange()
332 {
333 // Make sure to not call handlerBehaviorChanged() more often than allowed
334 // by chrome.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES.
335 // Otherwise Chrome notifies the user that this extension is causing issues.
336 if (handlerBehaviorChangedQuota > 0)
337 {
338 chrome.webNavigation.onBeforeNavigate.removeListener(handlerBehaviorChange d);
Wladimir Palant 2015/04/10 06:58:14 Feel free to change the name here as well. Please
Sebastian Noack 2015/04/10 07:03:21 Done.
339 chrome.webRequest.handlerBehaviorChanged();
340
341 handlerBehaviorChangedQuota--;
342 setTimeout(function() { handlerBehaviorChangedQuota++; }, 600000);
343 }
344 }
345
329 ext.webRequest = { 346 ext.webRequest = {
330 onBeforeRequest: new ext._EventTarget(), 347 onBeforeRequest: new ext._EventTarget(),
331 handlerBehaviorChanged: chrome.webRequest.handlerBehaviorChanged 348 handlerBehaviorChanged: function()
349 {
350 // Defer handlerBehaviorChanged() until navigation occurs.
351 // There wouldn't be any visible effect when calling it earlier,
352 // but it's an expensive operation and that way we avoid to call
353 // it multiple times, if multiple filters are added/removed.
354 var onBeforeNavigate = chrome.webNavigation.onBeforeNavigate;
355 if (!onBeforeNavigate.hasListener(propagateHandlerBehaviorChange))
356 onBeforeNavigate.addListener(propagateHandlerBehaviorChange);
357 }
332 }; 358 };
333 359
334 // Since Chrome 38 requests of type 'object' (e.g. requests 360 // Since Chrome 38 requests of type 'object' (e.g. requests
335 // initiated by Flash) are mistakenly reported with the type 'other'. 361 // initiated by Flash) are mistakenly reported with the type 'other'.
336 // https://code.google.com/p/chromium/issues/detail?id=410382 362 // https://code.google.com/p/chromium/issues/detail?id=410382
337 if (parseInt(navigator.userAgent.match(/\bChrome\/(\d+)/)[1], 10) >= 38) 363 if (parseInt(navigator.userAgent.match(/\bChrome\/(\d+)/)[1], 10) >= 38)
338 { 364 {
339 ext.webRequest.indistinguishableTypes = [ 365 ext.webRequest.indistinguishableTypes = [
340 ["OTHER", "OBJECT", "OBJECT_SUBREQUEST"] 366 ["OTHER", "OBJECT", "OBJECT_SUBREQUEST"]
341 ]; 367 ];
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 callback(new Page(tab)); 556 callback(new Page(tab));
531 } 557 }
532 else 558 else
533 { 559 {
534 ext.pages.open(optionsUrl, callback); 560 ext.pages.open(optionsUrl, callback);
535 } 561 }
536 }); 562 });
537 }); 563 });
538 }; 564 };
539 })(); 565 })();
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