Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 let wrapAPI = api => | 46 function wrapAPI(api) |
47 { | 47 { |
48 let object = browser; | 48 let object = browser; |
49 let path = api.split("."); | 49 let path = api.split("."); |
50 let name = path.pop(); | 50 let name = path.pop(); |
51 | 51 |
52 for (let node of path) | 52 for (let node of path) |
53 { | 53 { |
54 object = object[node]; | 54 object = object[node]; |
55 | 55 |
56 if (!object) | 56 if (!object) |
(...skipping 19 matching lines...) Expand all Loading... | |
76 func.call(object, ...args, result => | 76 func.call(object, ...args, result => |
77 { | 77 { |
78 let error = browser.runtime.lastError; | 78 let error = browser.runtime.lastError; |
79 if (error) | 79 if (error) |
80 reject(error); | 80 reject(error); |
81 else | 81 else |
82 resolve(result); | 82 resolve(result); |
83 }); | 83 }); |
84 }); | 84 }); |
85 }; | 85 }; |
86 }; | 86 } |
87 | 87 |
88 let shouldWrapAPIs = () => | 88 function shouldWrapAPIs() |
89 { | 89 { |
90 try | 90 try |
91 { | 91 { |
92 return !(browser.storage.local.get([]) instanceof Promise); | 92 return !(browser.storage.local.get([]) instanceof Promise); |
93 } | 93 } |
94 catch (error) | 94 catch (error) |
95 { | 95 { |
96 } | 96 } |
97 | 97 |
98 return true; | 98 return true; |
Wladimir Palant
2017/10/18 08:59:11
Nit: I would put that return inside the catch bloc
Manish Jethani
2017/10/18 11:00:26
Acknowledged.
| |
99 }; | 99 } |
100 | 100 |
101 if (shouldWrapAPIs()) | 101 if (shouldWrapAPIs()) |
102 { | 102 { |
103 // Unlike Firefox and Microsoft Edge, Chrome doesn't have a "browser" object , | 103 // Unlike Firefox and Microsoft Edge, Chrome doesn't have a "browser" object , |
104 // but provides the extension API through the "chrome" namespace | 104 // but provides the extension API through the "chrome" namespace |
105 // (non-standard). | 105 // (non-standard). |
106 if (typeof browser == "undefined") | 106 if (typeof browser == "undefined") |
107 window.browser = chrome; | 107 window.browser = chrome; |
108 | 108 |
109 for (let api of asyncAPIs) | 109 for (let api of asyncAPIs) |
110 wrapAPI(api); | 110 wrapAPI(api); |
111 } | 111 } |
112 | 112 |
113 // Workaround since HTMLCollection, NodeList, StyleSheetList, and CSSRuleList | 113 // Workaround since HTMLCollection, NodeList, StyleSheetList, and CSSRuleList |
114 // didn't have iterator support before Chrome 51. | 114 // didn't have iterator support before Chrome 51. |
115 // https://bugs.chromium.org/p/chromium/issues/detail?id=401699 | 115 // https://bugs.chromium.org/p/chromium/issues/detail?id=401699 |
116 for (let object of [HTMLCollection, NodeList, StyleSheetList, CSSRuleList]) | 116 for (let object of [HTMLCollection, NodeList, StyleSheetList, CSSRuleList]) |
117 { | 117 { |
118 if (!(Symbol.iterator in object.prototype)) | 118 if (!(Symbol.iterator in object.prototype)) |
119 object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator]; | 119 object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator]; |
120 } | 120 } |
121 } | 121 } |
LEFT | RIGHT |