| OLD | NEW |
| 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 Loading... |
| 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, | 85 getWindow: function() |
| 77 getWindow: chrome.extension.getBackgroundPage | 86 { |
| 87 return chrome.extension.getBackgroundPage(); |
| 88 } |
| 78 }, | 89 }, |
| 79 getURL: chrome.extension.getURL, | 90 getURL: chrome.extension.getURL, |
| 80 onMessage: new MessageEventTarget(), | 91 onMessage: new MessageEventTarget(), |
| 81 i18n: chrome.i18n | 92 i18n: chrome.i18n |
| 82 }; | 93 }; |
| 94 |
| 95 if ("runtime" in chrome && "sendMessage" in chrome.runtime) |
| 96 ext.backgroundPage.sendMessage = chrome.runtime.sendMessage; |
| 97 else if ("sendMessage" in chrome.extension) |
| 98 ext.backgroundPage.sendMessage = chrome.extension.sendMessage; |
| 99 else |
| 100 ext.backgroundPage.sendMessage = chrome.extension.sendRequest; |
| 83 })(); | 101 })(); |
| OLD | NEW |