| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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) | 61 if (!tab) |
| 62 { | |
| 63 // This likely means that there was an error. Let the callback deal | |
| 64 // with it. | |
| 65 callback(); | |
|
Manish Jethani
2017/10/02 08:03:14
I think it's better to call the callback anyway wi
Sebastian Noack
2017/10/04 01:22:32
I can think of two scenarios here:
1. chrome.runt
Manish Jethani
2017/10/04 03:46:49
In general I think that a callback should be calle
Sebastian Noack
2017/10/04 05:33:14
This would rather be an argument to return a Promi
Manish Jethani
2017/10/04 13:02:45
Acknowledged.
| |
| 66 return; | 62 return; |
| 67 } | |
| 68 | 63 |
| 69 function onMessage(message, sender) | 64 function onMessage(message, sender) |
| 70 { | 65 { |
| 71 if (message.type == "app.listen" && | 66 if (message.type == "app.listen" && |
| 72 sender.page && sender.page.id == tab.id) | 67 sender.page && sender.page.id == tab.id) |
| 73 { | 68 { |
| 74 port.off("app.listen", onMessage); | 69 port.off("app.listen", onMessage); |
| 75 callback(new ext.Page(tab)); | 70 callback(new ext.Page(tab)); |
| 76 } | 71 } |
| 77 } | 72 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 // 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 |
| 133 // action is clicked. | 128 // action is clicked. |
| 134 chrome.browserAction.onClicked.addListener(() => | 129 chrome.browserAction.onClicked.addListener(() => |
| 135 { | 130 { |
| 136 ext.pages.query({active: true, lastFocusedWindow: true}, pages => | 131 ext.pages.query({active: true, lastFocusedWindow: true}, pages => |
| 137 { | 132 { |
| 138 let currentPage = pages[0]; | 133 let currentPage = pages[0]; |
| 139 | 134 |
| 140 showOptions(optionsPage => | 135 showOptions(optionsPage => |
| 141 { | 136 { |
| 142 if (!["http:", "https:"].includes(currentPage.url.protocol)) | 137 if (!/^https?:$/.test(currentPage.url.protocol)) |
|
Sebastian Noack
2017/10/04 01:22:33
You could just use a regular expression here (if y
Manish Jethani
2017/10/04 03:46:49
Done.
| |
| 143 return; | 138 return; |
| 144 | 139 |
| 145 optionsPage.sendMessage({ | 140 optionsPage.sendMessage({ |
| 146 type: "app.respond", | 141 type: "app.respond", |
| 147 action: "showPageOptions", | 142 action: "showPageOptions", |
| 148 args: [ | 143 args: [ |
| 149 { | 144 { |
| 150 host: getDecodedHostname(currentPage.url).replace(/^www\./, ""), | 145 host: getDecodedHostname(currentPage.url).replace(/^www\./, ""), |
| 151 whitelisted: !!checkWhitelisted(currentPage) | 146 whitelisted: !!checkWhitelisted(currentPage) |
| 152 } | 147 } |
| 153 ] | 148 ] |
| 154 }); | 149 }); |
| 155 }); | 150 }); |
| 156 }); | 151 }); |
| 157 }); | 152 }); |
| LEFT | RIGHT |