Left: | ||
Right: |
LEFT | RIGHT |
---|---|
(no file at all) | |
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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 "use strict"; | 18 "use strict"; |
19 | 19 |
20 (function() | |
21 { | 20 { |
22 window.browser = {}; | 21 window.browser = {}; |
23 | 22 |
24 /* I18n */ | 23 /* runtime */ |
24 | |
25 let messageQueue = []; | |
26 let maxMessageId = -1; | |
27 let backgroundWindow = null; | |
Manish Jethani
2017/10/18 01:41:31
We have to maintain a reference to the background
| |
28 | |
29 function backgroundPageLoadedHandler(event) | |
30 { | |
31 if (event.data.type == "backgroundPageLoaded") | |
32 { | |
33 window.removeEventListener("message", backgroundPageLoadedHandler); | |
Manish Jethani
2017/10/18 01:41:31
Removing the listener first, I hope it's OK.
| |
34 | |
35 backgroundWindow = event.source; | |
36 | |
37 let queue = messageQueue || []; | |
38 messageQueue = null; | |
39 for (let message of queue) | |
40 backgroundWindow.postMessage(message, "*"); | |
41 } | |
42 } | |
43 | |
44 window.addEventListener("message", backgroundPageLoadedHandler); | |
45 | |
46 function sendRawMessage(message) | |
47 { | |
48 if (messageQueue) | |
49 messageQueue.push(message); | |
50 else | |
51 backgroundWindow.postMessage(message, "*"); | |
52 } | |
53 | |
54 browser.runtime = { | |
55 connect() | |
56 { | |
57 sendRawMessage({type: "connect"}); | |
58 return {onMessage: ext.onMessage}; | |
59 }, | |
60 | |
61 sendMessage(message, responseCallback) | |
62 { | |
63 let messageId = ++maxMessageId; | |
64 | |
65 sendRawMessage({type: "message", messageId, payload: message}); | |
66 | |
67 if (responseCallback) | |
68 { | |
69 let callbackWrapper = event => | |
70 { | |
71 if (event.data.type == "response" && | |
72 event.data.messageId == messageId) | |
73 { | |
74 window.removeEventListener("message", callbackWrapper); | |
75 responseCallback(event.data.payload); | |
76 } | |
77 }; | |
78 | |
79 window.addEventListener("message", callbackWrapper); | |
80 } | |
81 }, | |
82 | |
83 onConnect: { | |
84 addListener(callback) | |
85 { | |
86 window.addEventListener("message", event => | |
87 { | |
88 if (event.data.type == "connect") | |
89 { | |
90 callback({ | |
91 postMessage(message) | |
92 { | |
93 event.source.postMessage({ | |
94 type: "message", | |
95 messageId: -1, | |
96 payload: message | |
97 }, "*"); | |
98 } | |
99 }); | |
100 } | |
101 }); | |
102 } | |
103 } | |
104 }; | |
105 | |
106 /* devtools */ | |
107 | |
108 if (top.location.pathname == "/devtools-panel.html") | |
109 { | |
110 browser.devtools = { | |
111 panels: { | |
112 openResource() {} | |
113 }, | |
114 | |
115 inspectedWindow: { | |
116 reload() {} | |
117 } | |
118 }; | |
119 } | |
120 | |
121 /* i18n */ | |
25 | 122 |
26 let getLocaleCandidates = function(selectedLocale) | 123 let getLocaleCandidates = function(selectedLocale) |
27 { | 124 { |
28 let candidates = []; | 125 let candidates = []; |
29 let defaultLocale = "en_US"; | 126 let defaultLocale = "en_US"; |
30 | 127 |
31 // e.g. "ja-jp-mac" -> "ja_JP", note that the part after the second | 128 // e.g. "ja-jp-mac" -> "ja_JP", note that the part after the second |
32 // dash is dropped, since we only support language and region | 129 // dash is dropped, since we only support language and region |
33 let parts = selectedLocale.split("-"); | 130 let parts = selectedLocale.split("-"); |
34 let language = parts[0]; | 131 let language = parts[0]; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 | 227 |
131 if (locales.length == 0) | 228 if (locales.length == 0) |
132 return ""; | 229 return ""; |
133 | 230 |
134 let locale = locales.shift(); | 231 let locale = locales.shift(); |
135 readCatalog(locale, "common.json"); | 232 readCatalog(locale, "common.json"); |
136 readCatalog(locale, catalogFile); | 233 readCatalog(locale, catalogFile); |
137 } | 234 } |
138 } | 235 } |
139 }; | 236 }; |
140 }()); | 237 } |
LEFT | RIGHT |