| OLD | NEW |
| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 /* Polyfills */ | 62 /* Polyfills */ |
| 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 | |
| 71 ext.backgroundPage._sendRawMessage({ | 70 ext.backgroundPage._sendRawMessage({ |
| 72 type: "message", | 71 type: "message", |
| 73 messageId, | 72 messageId, |
| 74 payload: message | 73 payload: message |
| 75 }); | 74 }); |
| 76 | 75 |
| 77 let resolvePromise = null; | 76 let resolvePromise = null; |
| 78 let callbackWrapper = event => | 77 let callbackWrapper = event => |
| 79 { | 78 { |
| 80 if (event.data.type == "response" && event.data.messageId == messageId) | 79 if (event.data.type == "response" && event.data.messageId == messageId) |
| 81 { | 80 { |
| 82 window.removeEventListener("message", callbackWrapper); | 81 window.removeEventListener("message", callbackWrapper); |
| 83 resolvePromise(event.data.payload); | 82 resolvePromise(event.data.payload); |
| 84 } | 83 } |
| 85 }; | 84 }; |
| 86 window.addEventListener("message", callbackWrapper); | 85 window.addEventListener("message", callbackWrapper); |
| 87 if (responseCallback) | 86 if (responseCallback) |
| 88 { | 87 { |
| 89 resolvePromise = responseCallback; | 88 resolvePromise = responseCallback; |
| 90 } | 89 } |
| 91 else | 90 else |
| 92 { | 91 { |
| 93 return new Promise((resolve, reject) => | 92 return new Promise((resolve, reject) => |
| 94 { | 93 { |
| 95 resolvePromise = resolve; | 94 resolvePromise = resolve; |
| 96 }); | 95 }); |
| 97 } | 96 } |
| 98 }; | 97 }; |
| 98 |
| 99 if (!("tabs" in browser)) |
| 100 browser.tabs = new Map([[0, {url: "example.com"}]]); |
| 101 |
| 102 browser.tabs.get = (...args) => |
| 103 { |
| 104 // Extend browser.tabs.get() |
| 105 const result = Map.prototype.get.apply(browser.tabs, args); |
| 106 return (result ? Promise.resolve(result) : |
| 107 Promise.reject(new Error("Tab cannot be found"))); |
| 108 }; |
| 99 }()); | 109 }()); |
| OLD | NEW |