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

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

Issue 29367316: Issue 4722 - Drop support for Chrome 41 - 48 (Closed)
Patch Set: Brought back http CSP comment + indistinguishableTypes Created Dec. 13, 2016, 3:04 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 | include.preload.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-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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }, 414 },
442 getIndistinguishableTypes: function() 415 getIndistinguishableTypes: function()
443 { 416 {
444 // Chrome 38-48 mistakenly reports requests of type `object` 417 return [["OBJECT", "OBJECT_SUBREQUEST"]];
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 } 418 }
469 }; 419 };
470 420
471 chrome.tabs.query({}, function(tabs) 421 chrome.tabs.query({}, function(tabs)
472 { 422 {
473 tabs.forEach(function(tab) 423 tabs.forEach(function(tab)
474 { 424 {
475 chrome.webNavigation.getAllFrames({tabId: tab.id}, function(details) 425 chrome.webNavigation.getAllFrames({tabId: tab.id}, function(details)
476 { 426 {
477 if (details && details.length > 0) 427 if (details && details.length > 0)
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 sender.page = new Page(rawSender.tab); 497 sender.page = new Page(rawSender.tab);
548 sender.frame = { 498 sender.frame = {
549 url: new URL(rawSender.url), 499 url: new URL(rawSender.url),
550 get parent() 500 get parent()
551 { 501 {
552 var frames = framesOfTabs[rawSender.tab.id]; 502 var frames = framesOfTabs[rawSender.tab.id];
553 503
554 if (!frames) 504 if (!frames)
555 return null; 505 return null;
556 506
557 if ("frameId" in rawSender) 507 var frame = frames[rawSender.frameId];
558 { 508 if (frame)
559 // Chrome 41+ 509 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 510
574 return frames[0]; 511 return frames[0];
575 } 512 }
576 }; 513 };
577 } 514 }
578 515
579 return ext.onMessage._dispatch(message, sender, sendResponse).indexOf(true) != -1; 516 return ext.onMessage._dispatch(message, sender, sendResponse).indexOf(true) != -1;
580 }); 517 });
581 518
582 519
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 ext.windows = { 585 ext.windows = {
649 create: function(createData, callback) 586 create: function(createData, callback)
650 { 587 {
651 chrome.windows.create(createData, function(createdWindow) 588 chrome.windows.create(createData, function(createdWindow)
652 { 589 {
653 afterTabLoaded(callback)(createdWindow.tabs[0]); 590 afterTabLoaded(callback)(createdWindow.tabs[0]);
654 }); 591 });
655 } 592 }
656 }; 593 };
657 })(); 594 })();
OLDNEW
« no previous file with comments | « no previous file | include.preload.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld