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

Side by Side Diff: chrome/common.js

Issue 5867629902299136: Fixed various issues in older Chrome versions (Closed)
Patch Set: Created Dec. 19, 2013, 10:24 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 | « chrome/background.js ('k') | popup.html » ('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 <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 this._target.removeListener(this._wrappedListeners[idx]); 49 this._target.removeListener(this._wrappedListeners[idx]);
50 50
51 this._listeners.splice(idx, 1); 51 this._listeners.splice(idx, 1);
52 this._wrappedListeners.splice(idx, 1); 52 this._wrappedListeners.splice(idx, 1);
53 } 53 }
54 } 54 }
55 }; 55 };
56 56
57 var MessageEventTarget = function() 57 var MessageEventTarget = function()
58 { 58 {
59 WrappedEventTarget.call(this, (chrome.runtime || {}).onMessage || chrome.ext ension.onRequest); 59 var target;
60 if ("runtime" in chrome && "onMessage" in chrome.runtime)
61 target = chrome.runtime.onMessage;
62 else if ("onMessage" in chrome.extension)
63 target = chrome.extension.onMessage;
64 else
65 target = chrome.extension.onRequest;
66 WrappedEventTarget.call(this, target);
60 }; 67 };
61 MessageEventTarget.prototype = { 68 MessageEventTarget.prototype = {
62 __proto__: WrappedEventTarget.prototype, 69 __proto__: WrappedEventTarget.prototype,
63 _wrapListener: function(listener) { 70 _wrapListener: function(listener) {
64 return function(message, sender, sendResponse) 71 return function(message, sender, sendResponse)
65 { 72 {
66 return listener(message, {tab: sender.tab && new Tab(sender.tab)}, sendR esponse); 73 if (sender.tab && sender.tab.id >= 0)
74 sender.tab = new Tab(sender.tab);
75 return listener(message, sender, sendResponse);
67 }; 76 };
68 } 77 }
69 }; 78 };
70 79
71 80
72 /* API */ 81 /* API */
73 82
74 ext = { 83 ext = {
75 backgroundPage: { 84 backgroundPage: {},
76 sendMessage: (chrome.runtime || {}).sendMessage || chrome.extension.sendRe quest,
77 getWindow: chrome.extension.getBackgroundPage
78 },
79 getURL: chrome.extension.getURL, 85 getURL: chrome.extension.getURL,
80 onMessage: new MessageEventTarget(), 86 onMessage: new MessageEventTarget(),
81 i18n: chrome.i18n 87 i18n: chrome.i18n
82 }; 88 };
89
90 if ("runtime" in chrome && "sendMessage" in chrome.runtime)
91 ext.backgroundPage.sendMessage = chrome.runtime.sendMessage;
92 else if ("sendMessage" in chrome.extension)
93 ext.backgroundPage.sendMessage = chrome.extension.sendMessage;
94 else
95 ext.backgroundPage.sendMessage = chrome.extension.sendRequest;
96
97 try
Sebastian Noack 2013/12/19 10:38:59 I would prefer to wrap chrome.extension.getBackgro
Wladimir Palant 2013/12/19 10:47:17 True, that's a better solution - done.
98 {
99 ext.backgroundPage.getWindow = chrome.extension.getBackgroundPage;
100 }
101 catch (e)
102 {
103 // This exception is expected in content scripts in older Chrome versions.
104 }
83 })(); 105 })();
OLDNEW
« no previous file with comments | « chrome/background.js ('k') | popup.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld