| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | |
| 3 * Copyright (C) 2006-2013 Eyeo GmbH | |
| 4 * | |
| 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 | |
| 7 * published by the Free Software Foundation. | |
| 8 * | |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 12 * GNU General Public License for more details. | |
| 13 * | |
| 14 * You should have received a copy of the GNU General Public License | |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | |
| 16 */ | |
| 17 | |
| 18 (function() { | |
| 19 /* Events */ | |
|
Felix Dahlke
2013/10/24 16:30:34
As in other places, opening braces should go on th
| |
| 20 | |
| 21 WrappedEventTarget = function(target) { | |
| 22 this._listeners = []; | |
| 23 this._wrappedListeners = []; | |
| 24 this._target = target; | |
| 25 }; | |
| 26 WrappedEventTarget.prototype = { | |
| 27 _prepareExtraArguments: function() { | |
| 28 return []; | |
| 29 }, | |
| 30 addListener: function(listener) { | |
| 31 var extaArgs = Array.prototype.slice.call(arguments, 1); | |
|
Felix Dahlke
2013/10/24 16:30:34
s/extaArgs/extraArgs/?
| |
| 32 extaArgs = this._prepareExtraArguments.apply(this, extaArgs); | |
| 33 | |
| 34 var wrappedListener = this._wrapListener(listener); | |
| 35 this._listeners.push(listener); | |
| 36 this._wrappedListeners.push(wrappedListener); | |
| 37 | |
| 38 this._target.addListener.apply(this._target, [wrappedListener].concat(exta Args)); | |
| 39 }, | |
| 40 removeListener: function(listener) { | |
| 41 var idx = this._listeners.indexOf(listener); | |
| 42 | |
| 43 if (idx != -1) { | |
| 44 this._target.removeListener(this._wrappedListeners[idx]); | |
| 45 | |
| 46 this._listeners.splice(idx, 1); | |
| 47 this._wrappedListeners.splice(idx, 1); | |
| 48 } | |
| 49 } | |
| 50 }; | |
| 51 | |
| 52 var MessageEventTarget = function() { | |
| 53 WrappedEventTarget.call(this, chrome.runtime.onMessage); | |
| 54 }; | |
| 55 MessageEventTarget.prototype = { | |
| 56 __proto__: WrappedEventTarget.prototype, | |
| 57 _wrapListener: function(listener) { | |
| 58 return function(message, sender, sendResponse) { | |
| 59 listener(message, {tab: sender.tab && new Tab(sender.tab)}, sendResponse ); | |
| 60 }; | |
| 61 } | |
| 62 }; | |
| 63 | |
| 64 /* API */ | |
| 65 | |
| 66 ext = { | |
| 67 backgroundPage: { | |
| 68 sendMessage: function(message, responseCallback) { | |
| 69 chrome.runtime.sendMessage(message, responseCallback); | |
| 70 }, | |
| 71 getDOMWindow: function() { | |
| 72 return chrome.extension.getBackgroundPage(); | |
| 73 } | |
| 74 }, | |
| 75 getURL: chrome.extension.getURL, | |
| 76 onMessage: new MessageEventTarget(), | |
| 77 i18n: chrome.i18n | |
| 78 }; | |
| 79 })(); | |
| OLD | NEW |