| Left: | ||
| Right: |
| 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 // Errors that occur only when we show an interest in the response from an | |
| 47 // API call. | |
| 48 const noFulfillmentErrors = new Set([ | |
| 49 "The message port closed before a response was received.", | |
| 50 // Older versions of Chrome have a typo: | |
| 51 // https://crrev.com/c33f51726eacdcc1a487b21a13611f7eab580d6d | |
| 52 "The message port closed before a reponse was received." | |
| 53 ]); | |
|
Sebastian Noack
2017/10/20 01:26:30
Perhaps, we can just use a regexp to account for t
Manish Jethani
2017/10/20 01:45:32
Yes, using a regex now.
The commit was on June 30
| |
| 54 | |
| 46 function wrapAPI(api) | 55 function wrapAPI(api) |
| 47 { | 56 { |
| 48 let object = browser; | 57 let object = browser; |
| 49 let path = api.split("."); | 58 let path = api.split("."); |
| 50 let name = path.pop(); | 59 let name = path.pop(); |
| 51 | 60 |
| 52 for (let node of path) | 61 for (let node of path) |
| 53 { | 62 { |
| 54 object = object[node]; | 63 object = object[node]; |
| 55 | 64 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 69 // callback to the list, it won't match the signature of the function and | 78 // callback to the list, it won't match the signature of the function and |
| 70 // will cause an exception. | 79 // will cause an exception. |
| 71 if (typeof args[args.length - 1] == "undefined") | 80 if (typeof args[args.length - 1] == "undefined") |
| 72 args.pop(); | 81 args.pop(); |
| 73 | 82 |
| 74 return new Promise((resolve, reject) => | 83 return new Promise((resolve, reject) => |
| 75 { | 84 { |
| 76 func.call(object, ...args, result => | 85 func.call(object, ...args, result => |
| 77 { | 86 { |
| 78 let error = browser.runtime.lastError; | 87 let error = browser.runtime.lastError; |
| 79 if (error) | 88 if (error && !noFulfillmentErrors.has(error.message)) |
| 80 reject(error); | 89 reject(error); |
| 81 else | 90 else |
| 82 resolve(result); | 91 resolve(result); |
| 83 }); | 92 }); |
| 84 }); | 93 }); |
| 85 }; | 94 }; |
| 86 } | 95 } |
| 87 | 96 |
| 88 function shouldWrapAPIs() | 97 function shouldWrapAPIs() |
| 89 { | 98 { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 112 | 121 |
| 113 // Workaround since HTMLCollection, NodeList, StyleSheetList, and CSSRuleList | 122 // Workaround since HTMLCollection, NodeList, StyleSheetList, and CSSRuleList |
| 114 // didn't have iterator support before Chrome 51. | 123 // didn't have iterator support before Chrome 51. |
| 115 // https://bugs.chromium.org/p/chromium/issues/detail?id=401699 | 124 // https://bugs.chromium.org/p/chromium/issues/detail?id=401699 |
| 116 for (let object of [HTMLCollection, NodeList, StyleSheetList, CSSRuleList]) | 125 for (let object of [HTMLCollection, NodeList, StyleSheetList, CSSRuleList]) |
| 117 { | 126 { |
| 118 if (!(Symbol.iterator in object.prototype)) | 127 if (!(Symbol.iterator in object.prototype)) |
| 119 object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator]; | 128 object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator]; |
| 120 } | 129 } |
| 121 } | 130 } |
| OLD | NEW |