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 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 browser.runtime.sendMessage = (message, responseCallback) => | 67 browser.runtime.sendMessage = (message, responseCallback) => |
68 { | 68 { |
69 let messageId = ++maxMessageId; | 69 let messageId = ++maxMessageId; |
70 | 70 |
71 ext.backgroundPage._sendRawMessage({ | 71 ext.backgroundPage._sendRawMessage({ |
72 type: "message", | 72 type: "message", |
73 messageId, | 73 messageId, |
74 payload: message | 74 payload: message |
75 }); | 75 }); |
76 | 76 |
77 let resolvePromise = null; | |
saroyanm
2018/03/05 20:28:33
I noticed that it took me longer than needed to im
Thomas Greiner
2018/03/06 13:08:47
We're not handling errors yet so we don't need to
| |
78 let callbackWrapper = event => | |
79 { | |
80 if (event.data.type == "response" && event.data.messageId == messageId) | |
81 { | |
82 window.removeEventListener("message", callbackWrapper); | |
83 resolvePromise(event.data.payload); | |
84 } | |
85 }; | |
86 window.addEventListener("message", callbackWrapper); | |
77 if (responseCallback) | 87 if (responseCallback) |
78 { | 88 { |
79 let callbackWrapper = event => | 89 resolvePromise = responseCallback; |
90 } | |
91 else | |
92 { | |
93 return new Promise((resolve, reject) => | |
80 { | 94 { |
81 if (event.data.type == "response" && event.data.messageId == messageId) | 95 resolvePromise = resolve; |
82 { | 96 }); |
83 window.removeEventListener("message", callbackWrapper); | |
84 responseCallback(event.data.payload); | |
85 } | |
86 }; | |
87 | |
88 window.addEventListener("message", callbackWrapper); | |
89 } | 97 } |
90 }; | 98 }; |
91 }()); | 99 }()); |
LEFT | RIGHT |