Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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; | 329 var handlerBehaviorChangedQuota = chrome.webRequest.MAX_HANDLER_BEHAVIOR_CHANG ED_CALLS_PER_10_MINUTES; |
330 | 330 |
331 function handlerBehaviorChanged() | 331 function propagateHandlerBehaviorChange() |
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
| |
332 { | 332 { |
333 // Make sure to not call handlerBehaviorChanged() more often than allowed | 333 // Make sure to not call handlerBehaviorChanged() more often than allowed |
334 // by chrome.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES. | 334 // by chrome.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES. |
335 // Otherwise Chrome notifies the user that this extension is causing issues. | 335 // Otherwise Chrome notifies the user that this extension is causing issues. |
336 if (handlerBehaviorChangedQuota > 0) | 336 if (handlerBehaviorChangedQuota > 0) |
337 { | 337 { |
338 chrome.webNavigation.onBeforeNavigate.removeListener(handlerBehaviorChange d); | 338 chrome.webNavigation.onBeforeNavigate.removeListener(propagateHandlerBehav iorChange); |
339 chrome.webRequest.handlerBehaviorChanged(); | 339 chrome.webRequest.handlerBehaviorChanged(); |
340 | 340 |
341 handlerBehaviorChangedQuota--; | 341 handlerBehaviorChangedQuota--; |
342 setTimeout(function() { handlerBehaviorChangedQuota++; }, 600000); | 342 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.
| |
343 } | 343 } |
344 } | 344 } |
345 | 345 |
346 ext.webRequest = { | 346 ext.webRequest = { |
347 onBeforeRequest: new ext._EventTarget(), | 347 onBeforeRequest: new ext._EventTarget(), |
348 handlerBehaviorChanged: function() | 348 handlerBehaviorChanged: function() |
349 { | 349 { |
350 // Defer handlerBehaviorChanged() until navigation occurs. | 350 // Defer handlerBehaviorChanged() until navigation occurs. |
351 // There wouldn't be any visible effect when calling it earlier, | 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 | 352 // but it's an expensive operation and that way we avoid to call |
353 // it multiple times, if multiple filters are added/removed. | 353 // it multiple times, if multiple filters are added/removed. |
354 var onBeforeNavigate = chrome.webNavigation.onBeforeNavigate; | 354 var onBeforeNavigate = chrome.webNavigation.onBeforeNavigate; |
355 if (!onBeforeNavigate.hasListener(handlerBehaviorChanged)) | 355 if (!onBeforeNavigate.hasListener(propagateHandlerBehaviorChange)) |
356 onBeforeNavigate.addListener(handlerBehaviorChanged); | 356 onBeforeNavigate.addListener(propagateHandlerBehaviorChange); |
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. ;)
| |
357 } | 357 } |
358 }; | 358 }; |
359 | 359 |
360 // Since Chrome 38 requests of type 'object' (e.g. requests | 360 // Since Chrome 38 requests of type 'object' (e.g. requests |
361 // initiated by Flash) are mistakenly reported with the type 'other'. | 361 // initiated by Flash) are mistakenly reported with the type 'other'. |
362 // https://code.google.com/p/chromium/issues/detail?id=410382 | 362 // https://code.google.com/p/chromium/issues/detail?id=410382 |
363 if (parseInt(navigator.userAgent.match(/\bChrome\/(\d+)/)[1], 10) >= 38) | 363 if (parseInt(navigator.userAgent.match(/\bChrome\/(\d+)/)[1], 10) >= 38) |
364 { | 364 { |
365 ext.webRequest.indistinguishableTypes = [ | 365 ext.webRequest.indistinguishableTypes = [ |
366 ["OTHER", "OBJECT", "OBJECT_SUBREQUEST"] | 366 ["OTHER", "OBJECT", "OBJECT_SUBREQUEST"] |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
556 callback(new Page(tab)); | 556 callback(new Page(tab)); |
557 } | 557 } |
558 else | 558 else |
559 { | 559 { |
560 ext.pages.open(optionsUrl, callback); | 560 ext.pages.open(optionsUrl, callback); |
561 } | 561 } |
562 }); | 562 }); |
563 }); | 563 }); |
564 }; | 564 }; |
565 })(); | 565 })(); |
LEFT | RIGHT |