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 ]); |
| 51 |
46 function wrapAPI(api) | 52 function wrapAPI(api) |
47 { | 53 { |
48 let object = browser; | 54 let object = browser; |
49 let path = api.split("."); | 55 let path = api.split("."); |
50 let name = path.pop(); | 56 let name = path.pop(); |
51 | 57 |
52 for (let node of path) | 58 for (let node of path) |
53 { | 59 { |
54 object = object[node]; | 60 object = object[node]; |
55 | 61 |
(...skipping 13 matching lines...) Expand all Loading... |
69 // callback to the list, it won't match the signature of the function and | 75 // callback to the list, it won't match the signature of the function and |
70 // will cause an exception. | 76 // will cause an exception. |
71 if (typeof args[args.length - 1] == "undefined") | 77 if (typeof args[args.length - 1] == "undefined") |
72 args.pop(); | 78 args.pop(); |
73 | 79 |
74 return new Promise((resolve, reject) => | 80 return new Promise((resolve, reject) => |
75 { | 81 { |
76 func.call(object, ...args, result => | 82 func.call(object, ...args, result => |
77 { | 83 { |
78 let error = browser.runtime.lastError; | 84 let error = browser.runtime.lastError; |
79 if (error) | 85 if (error && !noFulfillmentErrors.has(error.message)) |
80 reject(error); | 86 reject(error); |
81 else | 87 else |
82 resolve(result); | 88 resolve(result); |
83 }); | 89 }); |
84 }); | 90 }); |
85 }; | 91 }; |
86 } | 92 } |
87 | 93 |
88 function shouldWrapAPIs() | 94 function shouldWrapAPIs() |
89 { | 95 { |
(...skipping 22 matching lines...) Expand all Loading... |
112 | 118 |
113 // Workaround since HTMLCollection, NodeList, StyleSheetList, and CSSRuleList | 119 // Workaround since HTMLCollection, NodeList, StyleSheetList, and CSSRuleList |
114 // didn't have iterator support before Chrome 51. | 120 // didn't have iterator support before Chrome 51. |
115 // https://bugs.chromium.org/p/chromium/issues/detail?id=401699 | 121 // https://bugs.chromium.org/p/chromium/issues/detail?id=401699 |
116 for (let object of [HTMLCollection, NodeList, StyleSheetList, CSSRuleList]) | 122 for (let object of [HTMLCollection, NodeList, StyleSheetList, CSSRuleList]) |
117 { | 123 { |
118 if (!(Symbol.iterator in object.prototype)) | 124 if (!(Symbol.iterator in object.prototype)) |
119 object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator]; | 125 object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator]; |
120 } | 126 } |
121 } | 127 } |
OLD | NEW |