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

Delta Between Two Patch Sets: chrome/ext/background.js

Issue 29367316: Issue 4722 - Drop support for Chrome 41 - 48 (Closed)
Left Patch Set: Created Dec. 13, 2016, 10:54 a.m.
Right Patch Set: Addressed nit Created Dec. 16, 2016, 10:26 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | include.preload.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 195
196 196
197 /* Browser actions */ 197 /* Browser actions */
198 198
199 var BrowserAction = function(tabId) 199 var BrowserAction = function(tabId)
200 { 200 {
201 this._tabId = tabId; 201 this._tabId = tabId;
202 this._changes = null; 202 this._changes = null;
203 }; 203 };
204 BrowserAction.prototype = { 204 BrowserAction.prototype = {
205 _legacySetIcon: function(details)
206 {
207 var legacyDetails = {};
208 for (var key in details)
209 {
210 var value = details[key];
211 if (typeof value == "object")
212 value = {19: value[19], 38: value[38]};
213 legacyDetails[key] = value;
214 }
215 chrome.browserAction.setIcon(legacyDetails);
216 },
217 _safeSetIcon: function(details)
218 {
219 try
220 {
221 chrome.browserAction.setIcon(details);
222 }
223 catch (e)
224 {
225 // Older versions of Chrome do not allow any sizes other than 19 and 38
226 // to be present, but newer versions of Chrome (and Edge) prefer
227 // different sizes.
228 this._safeSetIcon = this._legacySetIcon;
229 this._legacySetIcon(details);
230 }
231 },
232 _applyChanges: function() 205 _applyChanges: function()
233 { 206 {
234 if ("iconPath" in this._changes) 207 if ("iconPath" in this._changes)
235 { 208 {
236 this._safeSetIcon({ 209 chrome.browserAction.setIcon({
237 tabId: this._tabId, 210 tabId: this._tabId,
238 path: { 211 path: {
239 16: this._changes.iconPath.replace("$size", "16"), 212 16: this._changes.iconPath.replace("$size", "16"),
240 19: this._changes.iconPath.replace("$size", "19"), 213 19: this._changes.iconPath.replace("$size", "19"),
241 20: this._changes.iconPath.replace("$size", "20"), 214 20: this._changes.iconPath.replace("$size", "20"),
242 32: this._changes.iconPath.replace("$size", "32"), 215 32: this._changes.iconPath.replace("$size", "32"),
243 38: this._changes.iconPath.replace("$size", "38"), 216 38: this._changes.iconPath.replace("$size", "38"),
244 40: this._changes.iconPath.replace("$size", "40") 217 40: this._changes.iconPath.replace("$size", "40")
245 } 218 }
246 }); 219 });
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 onBeforeRequest: new ext._EventTarget(), 404 onBeforeRequest: new ext._EventTarget(),
432 handlerBehaviorChanged: function() 405 handlerBehaviorChanged: function()
433 { 406 {
434 // Defer handlerBehaviorChanged() until navigation occurs. 407 // Defer handlerBehaviorChanged() until navigation occurs.
435 // There wouldn't be any visible effect when calling it earlier, 408 // There wouldn't be any visible effect when calling it earlier,
436 // but it's an expensive operation and that way we avoid to call 409 // but it's an expensive operation and that way we avoid to call
437 // it multiple times, if multiple filters are added/removed. 410 // it multiple times, if multiple filters are added/removed.
438 var onBeforeNavigate = chrome.webNavigation.onBeforeNavigate; 411 var onBeforeNavigate = chrome.webNavigation.onBeforeNavigate;
439 if (!onBeforeNavigate.hasListener(propagateHandlerBehaviorChange)) 412 if (!onBeforeNavigate.hasListener(propagateHandlerBehaviorChange))
440 onBeforeNavigate.addListener(propagateHandlerBehaviorChange); 413 onBeforeNavigate.addListener(propagateHandlerBehaviorChange);
441 },
442 getIndistinguishableTypes: function()
443 {
444 // Chrome 38-48 mistakenly reports requests of type `object`
445 // (e.g. requests initiated by Flash) with the type `other`.
446 // https://code.google.com/p/chromium/issues/detail?id=410382
447 var match = navigator.userAgent.match(/\bChrome\/(\d+)/);
448 if (match)
449 {
450 var version = parseInt(match[1], 10);
451 if (version >= 38 && version <= 48)
452 return [["OTHER", "OBJECT", "OBJECT_SUBREQUEST"]];
453 }
454
455 // Chrome <44 doesn't have ResourceType.
456 var ResourceType = chrome.webRequest.ResourceType || {};
457
458 // Before Chrome 49, requests of the type `font` and `ping`
459 // have been reported with the type `other`.
460 // https://code.google.com/p/chromium/issues/detail?id=410382
461 var otherTypes = ["OTHER", "MEDIA"];
462 if (!("FONT" in ResourceType))
463 otherTypes.push("FONT");
464 if (!("PING" in ResourceType))
465 otherTypes.push("PING");
466
467 return [["OBJECT", "OBJECT_SUBREQUEST"], otherTypes];
468 } 414 }
469 }; 415 };
470 416
471 chrome.tabs.query({}, function(tabs) 417 chrome.tabs.query({}, function(tabs)
472 { 418 {
473 tabs.forEach(function(tab) 419 tabs.forEach(function(tab)
474 { 420 {
475 chrome.webNavigation.getAllFrames({tabId: tab.id}, function(details) 421 chrome.webNavigation.getAllFrames({tabId: tab.id}, function(details)
476 { 422 {
477 if (details && details.length > 0) 423 if (details && details.length > 0)
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 sender.page = new Page(rawSender.tab); 493 sender.page = new Page(rawSender.tab);
548 sender.frame = { 494 sender.frame = {
549 url: new URL(rawSender.url), 495 url: new URL(rawSender.url),
550 get parent() 496 get parent()
551 { 497 {
552 var frames = framesOfTabs[rawSender.tab.id]; 498 var frames = framesOfTabs[rawSender.tab.id];
553 499
554 if (!frames) 500 if (!frames)
555 return null; 501 return null;
556 502
557 if ("frameId" in rawSender) 503 var frame = frames[rawSender.frameId];
558 { 504 if (frame)
559 // Chrome 41+ 505 return frame.parent;
560 var frame = frames[rawSender.frameId];
561 if (frame)
562 return frame.parent;
563 }
564 else
565 {
566 // Chrome 28-40
567 for (var frameId in frames)
568 {
569 if (frames[frameId].url.href == this.url.href)
570 return frames[frameId].parent;
571 }
572 }
573 506
574 return frames[0]; 507 return frames[0];
575 } 508 }
576 }; 509 };
577 } 510 }
578 511
579 return ext.onMessage._dispatch(message, sender, sendResponse).indexOf(true) != -1; 512 return ext.onMessage._dispatch(message, sender, sendResponse).indexOf(true) != -1;
580 }); 513 });
581 514
582 515
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 ext.windows = { 581 ext.windows = {
649 create: function(createData, callback) 582 create: function(createData, callback)
650 { 583 {
651 chrome.windows.create(createData, function(createdWindow) 584 chrome.windows.create(createData, function(createdWindow)
652 { 585 {
653 afterTabLoaded(callback)(createdWindow.tabs[0]); 586 afterTabLoaded(callback)(createdWindow.tabs[0]);
654 }); 587 });
655 } 588 }
656 }; 589 };
657 })(); 590 })();
LEFTRIGHT
« no previous file | include.preload.js » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld