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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 { | 51 { |
52 callback(new ext.Page(optionsTab)); | 52 callback(new ext.Page(optionsTab)); |
53 } | 53 } |
54 else | 54 else |
55 { | 55 { |
56 // If we don't already have an options page, it means we've just opened | 56 // If we don't already have an options page, it means we've just opened |
57 // one, in which case we must find the tab, wait for it to be ready, and | 57 // one, in which case we must find the tab, wait for it to be ready, and |
58 // then return the call. | 58 // then return the call. |
59 findOptionsTab(tab => | 59 findOptionsTab(tab => |
60 { | 60 { |
61 if (!tab) | |
62 return; | |
63 | |
61 function onMessage(message, sender) | 64 function onMessage(message, sender) |
62 { | 65 { |
63 if (message.type == "app.listen" && | 66 if (message.type == "app.listen" && |
64 sender.page && sender.page.id == tab.id) | 67 sender.page && sender.page.id == tab.id) |
65 { | 68 { |
66 port.off("app.listen", onMessage); | 69 port.off("app.listen", onMessage); |
67 callback(new ext.Page(tab)); | 70 callback(new ext.Page(tab)); |
68 } | 71 } |
69 } | 72 } |
70 | 73 |
(...skipping 15 matching lines...) Expand all Loading... | |
86 // Edge does not yet support runtime.openOptionsPage (tested version 38) | 89 // Edge does not yet support runtime.openOptionsPage (tested version 38) |
87 if ("openOptionsPage" in chrome.runtime && | 90 if ("openOptionsPage" in chrome.runtime && |
88 // Some versions of Firefox for Android before version 57 do have a | 91 // Some versions of Firefox for Android before version 57 do have a |
89 // runtime.openOptionsPage but it doesn't do anything. | 92 // runtime.openOptionsPage but it doesn't do anything. |
90 // https://bugzilla.mozilla.org/show_bug.cgi?id=1364945 | 93 // https://bugzilla.mozilla.org/show_bug.cgi?id=1364945 |
91 (info.application != "fennec" || | 94 (info.application != "fennec" || |
92 parseInt(info.applicationVersion, 10) >= 57)) | 95 parseInt(info.applicationVersion, 10) >= 57)) |
93 { | 96 { |
94 chrome.runtime.openOptionsPage(() => | 97 chrome.runtime.openOptionsPage(() => |
95 { | 98 { |
96 if (chrome.runtime.lastError) | |
Sebastian Noack
2017/10/02 01:47:07
Nit: This logic would be slightly simpler when inv
Manish Jethani
2017/10/02 08:03:13
Yeah, I don't think we should touch runtime.lastEr
| |
97 return; | |
98 | |
99 returnShowOptionsCall(optionsTab, callback); | 99 returnShowOptionsCall(optionsTab, callback); |
100 }); | 100 }); |
101 } | 101 } |
102 else if (optionsTab) | 102 else if (optionsTab) |
103 { | 103 { |
104 // Firefox for Android before version 57 does not support | 104 // Firefox for Android before version 57 does not support |
105 // runtime.openOptionsPage, nor does it support the windows API. | 105 // runtime.openOptionsPage, nor does it support the windows API. |
106 // Since there is effectively only one window on the mobile browser, | 106 // Since there is effectively only one window on the mobile browser, |
107 // there's no need to bring it into focus. | 107 // there's no need to bring it into focus. |
108 if ("windows" in chrome) | 108 if ("windows" in chrome) |
(...skipping 18 matching lines...) Expand all Loading... | |
127 // On Firefox for Android, open the options page directly when the browser | 127 // On Firefox for Android, open the options page directly when the browser |
128 // action is clicked. | 128 // action is clicked. |
129 chrome.browserAction.onClicked.addListener(() => | 129 chrome.browserAction.onClicked.addListener(() => |
130 { | 130 { |
131 ext.pages.query({active: true, lastFocusedWindow: true}, pages => | 131 ext.pages.query({active: true, lastFocusedWindow: true}, pages => |
132 { | 132 { |
133 let currentPage = pages[0]; | 133 let currentPage = pages[0]; |
134 | 134 |
135 showOptions(optionsPage => | 135 showOptions(optionsPage => |
136 { | 136 { |
137 if (!["http:", "https:"].includes(currentPage.url.protocol)) | 137 if (!/^https?:$/.test(currentPage.url.protocol)) |
138 return; | 138 return; |
139 | 139 |
140 optionsPage.sendMessage({ | 140 optionsPage.sendMessage({ |
141 type: "app.respond", | 141 type: "app.respond", |
142 action: "showPageOptions", | 142 action: "showPageOptions", |
143 args: [ | 143 args: [ |
144 { | 144 { |
145 host: getDecodedHostname(currentPage.url).replace(/^www\./, ""), | 145 host: getDecodedHostname(currentPage.url).replace(/^www\./, ""), |
146 whitelisted: !!checkWhitelisted(currentPage) | 146 whitelisted: !!checkWhitelisted(currentPage) |
147 } | 147 } |
148 ] | 148 ] |
149 }); | 149 }); |
150 }); | 150 }); |
151 }); | 151 }); |
152 }); | 152 }); |
LEFT | RIGHT |