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-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 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/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 (function() | 18 (function() |
19 { | 19 { |
20 /* Message passing */ | 20 /* Message passing */ |
21 | 21 |
22 var sendMessage; | |
23 if ("runtime" in chrome && "sendMessage" in chrome.runtime) | |
24 sendMessage = chrome.runtime.sendMessage; | |
25 else if ("sendMessage" in chrome.extension) | |
26 sendMessage = chrome.extension.sendMessage; | |
27 else | |
28 sendMessage = chrome.extension.sendRequest; | |
29 | |
30 ext._setupMessageListener = function(wrapSender) | |
31 { | |
32 var onMessage; | |
33 if ("runtime" in chrome && "onMessage" in chrome.runtime) | |
34 onMessage = chrome.runtime.onMessage; | |
35 else if ("onMessage" in chrome.extension) | |
36 onMessage = chrome.extension.onMessage; | |
37 else | |
38 onMessage = chrome.extension.onRequest; | |
39 | |
40 onMessage.addListener(function(message, sender, sendResponse) | |
41 { | |
42 return ext.onMessage._dispatch(message, wrapSender(sender), sendResponse); | |
43 }); | |
44 }; | |
45 | |
46 ext.onMessage = new ext._EventTarget(); | 22 ext.onMessage = new ext._EventTarget(); |
47 | 23 |
48 | 24 |
49 /* Background page */ | 25 /* Background page */ |
50 | 26 |
51 ext.backgroundPage = { | 27 ext.backgroundPage = { |
52 sendMessage: sendMessage, | 28 sendMessage: chrome.runtime.sendMessage, |
53 getWindow: function() | 29 getWindow: function() |
54 { | 30 { |
55 return chrome.extension.getBackgroundPage(); | 31 return chrome.extension.getBackgroundPage(); |
56 } | 32 } |
57 }; | 33 }; |
58 | 34 |
59 | 35 |
60 /* Utils */ | 36 /* Utils */ |
61 | 37 |
62 ext.getURL = chrome.extension.getURL; | 38 ext.getURL = chrome.extension.getURL; |
63 ext.i18n = chrome.i18n; | 39 ext.i18n = chrome.i18n; |
64 })(); | 40 })(); |
OLD | NEW |