Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 function init(message) | 50 function init(message) |
51 { | 51 { |
52 removeMessageListener("AdblockPlus:Info", init); | 52 removeMessageListener("AdblockPlus:Info", init); |
53 | 53 |
54 let callbackPrefix = Services.appinfo.processID + " "; | 54 let callbackPrefix = Services.appinfo.processID + " "; |
55 let maxCallbackID = 0; | 55 let maxCallbackID = 0; |
56 let callbacks = new Map(); | 56 let callbacks = new Map(); |
57 | 57 |
58 function sendSyncMessageSingleResponse(messageName, data) | 58 function sendSyncMessageSingleResponse(messageName, data) |
59 { | 59 { |
60 let response = sendSyncMessage(messageName, {data})[0]; | 60 return sendSyncMessage(messageName, {data})[0]; |
61 return typeof response == "string" ? JSON.parse(response) : response; | |
62 } | 61 } |
63 | 62 |
64 function sendAsyncMessageWithResponse(messageName, data, callback) | 63 function sendAsyncMessageWithResponse(messageName, data, callback) |
Wladimir Palant
2015/11/04 15:04:09
Note that normally the third parameter for both se
| |
65 { | 64 { |
66 data = {data}; | 65 data = {data}; |
67 if (callback) | 66 if (callback) |
68 { | 67 { |
69 let callbackID = callbackPrefix + (++maxCallbackID); | 68 let callbackID = callbackPrefix + (++maxCallbackID); |
70 callbacks.set(callbackID, callback); | 69 callbacks.set(callbackID, callback); |
71 data.callbackID = callbackID; | 70 data.callbackID = callbackID; |
72 } | 71 } |
73 sendAsyncMessage(messageName, data); | 72 sendAsyncMessage(messageName, data); |
74 } | 73 } |
(...skipping 12 matching lines...) Expand all Loading... | |
87 onShutdown.add(() => removeMessageListener("AdblockPlus:Response", onRespons e)); | 86 onShutdown.add(() => removeMessageListener("AdblockPlus:Response", onRespons e)); |
88 | 87 |
89 let info = message.data; | 88 let info = message.data; |
90 loader = Loader({ | 89 loader = Loader({ |
91 paths: { | 90 paths: { |
92 "": info.addonRoot + "lib/" | 91 "": info.addonRoot + "lib/" |
93 }, | 92 }, |
94 globals: { | 93 globals: { |
95 Components, Cc, Ci, Cu, Cr, atob, btoa, onShutdown, | 94 Components, Cc, Ci, Cu, Cr, atob, btoa, onShutdown, |
96 addMessageListener, removeMessageListener, | 95 addMessageListener, removeMessageListener, |
97 sendAsyncMessage: sendAsyncMessageWithResponse, | 96 sendAsyncMessage: sendAsyncMessageWithResponse, |
tschuster
2015/11/14 21:26:07
I don't think it's great that we use the same name
Wladimir Palant
2015/11/16 12:54:24
I don't think these will stay like that. My idea i
| |
98 sendSyncMessage: sendSyncMessageSingleResponse | 97 sendSyncMessage: sendSyncMessageSingleResponse |
99 }, | 98 }, |
100 modules: {"info": info}, | 99 modules: {"info": info}, |
101 id: info.addonID | 100 id: info.addonID |
102 }); | 101 }); |
103 onShutdown.add(() => unload(loader, "disable")) | 102 onShutdown.add(() => unload(loader, "disable")) |
104 | 103 |
105 main(loader, "child/main"); | 104 main(loader, "child/main"); |
106 } | 105 } |
107 | 106 |
(...skipping 13 matching lines...) Expand all Loading... | |
121 catch (e) | 120 catch (e) |
122 { | 121 { |
123 Cu.reportError(e); | 122 Cu.reportError(e); |
124 } | 123 } |
125 } | 124 } |
126 shutdownHandlers = null; | 125 shutdownHandlers = null; |
127 } | 126 } |
128 } | 127 } |
129 })(); | 128 })(); |
130 | 129 |
LEFT | RIGHT |