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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 ext.backgroundPage = { | 52 ext.backgroundPage = { |
53 _sendRawMessage(message) | 53 _sendRawMessage(message) |
54 { | 54 { |
55 if (messageQueue) | 55 if (messageQueue) |
56 messageQueue.push(message); | 56 messageQueue.push(message); |
57 else | 57 else |
58 backgroundFrame.contentWindow.postMessage(message, "*"); | 58 backgroundFrame.contentWindow.postMessage(message, "*"); |
59 } | 59 } |
60 }; | 60 }; |
61 | 61 |
62 /* Polyfills */ | 62 /* Message passing */ |
63 | 63 |
64 if (!("runtime" in browser)) | 64 if (!("runtime" in browser)) |
65 browser.runtime = {}; | 65 browser.runtime = {}; |
66 | 66 |
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", |
(...skipping 16 matching lines...) Expand all Loading... |
89 resolvePromise = responseCallback; | 89 resolvePromise = responseCallback; |
90 } | 90 } |
91 else | 91 else |
92 { | 92 { |
93 return new Promise((resolve, reject) => | 93 return new Promise((resolve, reject) => |
94 { | 94 { |
95 resolvePromise = resolve; | 95 resolvePromise = resolve; |
96 }); | 96 }); |
97 } | 97 } |
98 }; | 98 }; |
| 99 |
| 100 function postMessage(msg) |
| 101 { |
| 102 ext.backgroundPage._sendRawMessage({ |
| 103 type: "port", |
| 104 name: this._name, |
| 105 payload: msg |
| 106 }); |
| 107 } |
| 108 ext._Port.prototype.postMessage = postMessage; |
| 109 |
| 110 function connect({name}) |
| 111 { |
| 112 ext.backgroundPage._sendRawMessage({type: "connect", name}); |
| 113 return new ext._Port(name); |
| 114 } |
| 115 browser.runtime.connect = connect; |
99 }()); | 116 }()); |
LEFT | RIGHT |