| 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 20 matching lines...) Expand all Loading... | |
| 31 browser.tabs.query({}, tabs => | 31 browser.tabs.query({}, tabs => |
| 32 { | 32 { |
| 33 // We find a tab ourselves because Edge has a bug when quering tabs with | 33 // We find a tab ourselves because Edge has a bug when quering tabs with |
| 34 // extension URL protocol: | 34 // extension URL protocol: |
| 35 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8094 141/ | 35 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8094 141/ |
| 36 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8604 703/ | 36 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8604 703/ |
| 37 // Firefox won't let us query for moz-extension:// pages either, though | 37 // Firefox won't let us query for moz-extension:// pages either, though |
| 38 // starting with Firefox 56 an extension can query for its own URLs: | 38 // starting with Firefox 56 an extension can query for its own URLs: |
| 39 // https://bugzilla.mozilla.org/show_bug.cgi?id=1271354 | 39 // https://bugzilla.mozilla.org/show_bug.cgi?id=1271354 |
| 40 let fullOptionsUrl = browser.extension.getURL(optionsUrl); | 40 let fullOptionsUrl = browser.extension.getURL(optionsUrl); |
| 41 callback(tabs.find(element => element.url == fullOptionsUrl)); | 41 let optionsTab = tabs.find(tab => tab.url == fullOptionsUrl); |
| 42 if (optionsTab) | |
| 43 { | |
| 44 callback(optionsTab); | |
| 45 return; | |
| 46 } | |
| 47 | |
| 48 // Newly created tabs might have about:blank as their URL in Firefox rather | |
| 49 // than the final options page URL, we need to wait for those to finish | |
| 50 // loading. | |
| 51 let potentialOptionTabIds = new Set( | |
| 52 tabs.filter(tab => tab.url == "about:blank" && tab.status == "loading") | |
| 53 .map(tab => tab.id) | |
| 54 ); | |
| 55 if (potentialOptionTabIds.size == 0) | |
| 56 { | |
| 57 callback(); | |
| 58 return; | |
| 59 } | |
| 60 let removeListener; | |
| 61 let updateListener = (tabId, changeInfo, tab) => | |
| 62 { | |
| 63 if (potentialOptionTabIds.has(tabId) && | |
| 64 changeInfo.status == "complete") | |
| 65 { | |
| 66 potentialOptionTabIds.delete(tabId); | |
| 67 let urlMatches = tab.url == fullOptionsUrl; | |
|
Wladimir Palant
2017/11/23 11:37:12
Nit: Variable names are supposed to be nouns, not
kzar
2017/11/23 11:51:08
Done. (It's quite nice in Clojure you can use symb
| |
| 68 if (urlMatches || potentialOptionTabIds.size == 0) | |
| 69 { | |
| 70 browser.tabs.onUpdated.removeListener(updateListener); | |
| 71 browser.tabs.onRemoved.removeListener(removeListener); | |
| 72 callback(urlMatches ? tab : undefined); | |
| 73 } | |
| 74 } | |
| 75 }; | |
| 76 browser.tabs.onUpdated.addListener(updateListener); | |
| 77 removeListener = removedTabId => | |
| 78 { | |
| 79 potentialOptionTabIds.delete(removedTabId); | |
| 80 if (potentialOptionTabIds.size == 0) | |
| 81 { | |
| 82 browser.tabs.onUpdated.removeListener(updateListener); | |
| 83 browser.tabs.onRemoved.removeListener(removeListener); | |
| 84 callback(); | |
| 85 } | |
| 86 }; | |
| 87 browser.tabs.onRemoved.addListener(removeListener); | |
| 42 }); | 88 }); |
| 43 } | 89 } |
| 44 | 90 |
| 45 function returnShowOptionsCall(optionsTab, callback) | 91 function returnShowOptionsCall(optionsTab, callback) |
| 46 { | 92 { |
| 47 if (!callback) | 93 if (!callback) |
| 48 return; | 94 return; |
| 49 | 95 |
| 50 if (optionsTab) | 96 if (optionsTab) |
| 51 { | 97 { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 args: [ | 189 args: [ |
| 144 { | 190 { |
| 145 host: getDecodedHostname(currentPage.url).replace(/^www\./, ""), | 191 host: getDecodedHostname(currentPage.url).replace(/^www\./, ""), |
| 146 whitelisted: !!checkWhitelisted(currentPage) | 192 whitelisted: !!checkWhitelisted(currentPage) |
| 147 } | 193 } |
| 148 ] | 194 ] |
| 149 }); | 195 }); |
| 150 }); | 196 }); |
| 151 }); | 197 }); |
| 152 }); | 198 }); |
| OLD | NEW |