| 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 25 matching lines...) Expand all Loading... |
| 36 "tabs.query", | 36 "tabs.query", |
| 37 "tabs.reload", | 37 "tabs.reload", |
| 38 "tabs.sendMessage", | 38 "tabs.sendMessage", |
| 39 "tabs.update", | 39 "tabs.update", |
| 40 "webNavigation.getAllFrames", | 40 "webNavigation.getAllFrames", |
| 41 "webRequest.handlerBehaviorChanged", | 41 "webRequest.handlerBehaviorChanged", |
| 42 "windows.create", | 42 "windows.create", |
| 43 "windows.update" | 43 "windows.update" |
| 44 ]; | 44 ]; |
| 45 | 45 |
| 46 // Since we add a callback for all messaging API calls in our wrappers, |
| 47 // Chrome assumes we're interested in the response; when there's no response, |
| 48 // it sets runtime.lastError |
| 49 const portClosedBeforeResponseError = |
| 50 // Older versions of Chrome have a typo: |
| 51 // https://crrev.com/c33f51726eacdcc1a487b21a13611f7eab580d6d |
| 52 /^The message port closed before a res?ponse was received\.$/; |
| 53 |
| 46 function wrapAPI(api) | 54 function wrapAPI(api) |
| 47 { | 55 { |
| 48 let object = browser; | 56 let object = browser; |
| 49 let path = api.split("."); | 57 let path = api.split("."); |
| 50 let name = path.pop(); | 58 let name = path.pop(); |
| 51 | 59 |
| 52 for (let node of path) | 60 for (let node of path) |
| 53 { | 61 { |
| 54 object = object[node]; | 62 object = object[node]; |
| 55 | 63 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 71 // callback to the list, it won't match the signature of the function and | 79 // callback to the list, it won't match the signature of the function and |
| 72 // will cause an exception. | 80 // will cause an exception. |
| 73 if (typeof args[args.length - 1] == "undefined") | 81 if (typeof args[args.length - 1] == "undefined") |
| 74 args.pop(); | 82 args.pop(); |
| 75 | 83 |
| 76 return new Promise((resolve, reject) => | 84 return new Promise((resolve, reject) => |
| 77 { | 85 { |
| 78 func.call(object, ...args, result => | 86 func.call(object, ...args, result => |
| 79 { | 87 { |
| 80 let error = browser.runtime.lastError; | 88 let error = browser.runtime.lastError; |
| 81 if (error) | 89 if (error && !portClosedBeforeResponseError.test(error.message)) |
| 82 { | 90 { |
| 83 // runtime.lastError is already an Error instance on Edge, while on | 91 // runtime.lastError is already an Error instance on Edge, while on |
| 84 // Chrome it is a plain object with only a message property. | 92 // Chrome it is a plain object with only a message property. |
| 85 if (!(error instanceof Error)) | 93 if (!(error instanceof Error)) |
| 86 { | 94 { |
| 87 error = new Error(error.message); | 95 error = new Error(error.message); |
| 88 | 96 |
| 89 // Add a more helpful stack trace. | 97 // Add a more helpful stack trace. |
| 90 error.stack = callStack; | 98 error.stack = callStack; |
| 91 } | 99 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 136 |
| 129 // Workaround since HTMLCollection, NodeList, StyleSheetList, and CSSRuleList | 137 // Workaround since HTMLCollection, NodeList, StyleSheetList, and CSSRuleList |
| 130 // didn't have iterator support before Chrome 51. | 138 // didn't have iterator support before Chrome 51. |
| 131 // https://bugs.chromium.org/p/chromium/issues/detail?id=401699 | 139 // https://bugs.chromium.org/p/chromium/issues/detail?id=401699 |
| 132 for (let object of [HTMLCollection, NodeList, StyleSheetList, CSSRuleList]) | 140 for (let object of [HTMLCollection, NodeList, StyleSheetList, CSSRuleList]) |
| 133 { | 141 { |
| 134 if (!(Symbol.iterator in object.prototype)) | 142 if (!(Symbol.iterator in object.prototype)) |
| 135 object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator]; | 143 object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator]; |
| 136 } | 144 } |
| 137 } | 145 } |
| OLD | NEW |