| 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 21 matching lines...) Expand all Loading... | |
| 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 let optionsTab = tabs.find(tab => tab.url == fullOptionsUrl); | 41 let optionsTab = tabs.find(tab => tab.url == fullOptionsUrl); |
| 42 if (optionsTab) | |
| 43 { | |
| 44 callback(optionsTab); | |
| 45 return; | |
| 46 } | |
| 42 | 47 |
| 43 if (optionsTab) | 48 // Newly created tabs might have about:blank as their URL in Firefox rather |
| 44 callback(optionsTab); | 49 // than the final options page URL, we need to wait for those to finish |
|
Wladimir Palant
2017/11/11 18:34:14
Maybe reduce the indentation level here:
if (op
kzar
2017/11/13 12:32:57
Done.
| |
| 45 else | 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) | |
| 46 { | 56 { |
| 47 // It seems that the url property isn't always set for the tab with | 57 callback(); |
| 48 // Firefox 57 on Windows 10 until the tab has finished loading. Until | 58 return; |
| 49 // then the url is given as "about:blank", but the title is the URL | 59 } |
| 50 // we expect (minus the protocol part). | 60 let removeListener; |
|
Wladimir Palant
2017/11/11 18:34:14
That's too many details IMHO. We don't really know
kzar
2017/11/13 12:32:57
Done.
| |
| 51 let {hostname, pathname} = new URL(fullOptionsUrl); | 61 let updateListener = (tabId, changeInfo, tab) => |
| 52 let potentialOptionsTab = tabs.find( | 62 { |
| 53 tab => tab.url == "about:blank" && | 63 if (potentialOptionTabIds.has(tabId) && |
| 54 tab.title == hostname + pathname && | 64 changeInfo.status == "complete") |
|
Wladimir Palant
2017/11/11 18:34:14
I don't think that we should rely on the tab title
kzar
2017/11/13 12:32:57
Done.
| |
| 55 tab.status == "loading" | |
| 56 ); | |
| 57 | |
| 58 if (potentialOptionsTab) | |
|
Wladimir Palant
2017/11/11 18:34:14
Maybe reduce indentation level here as well:
if
kzar
2017/11/13 12:32:57
Done.
| |
| 59 { | 65 { |
| 60 let onRemoved; | 66 potentialOptionTabIds.delete(tabId); |
| 61 let updateListener = (tabId, changeInfo, tab) => | 67 let urlMatch = tab.url == fullOptionsUrl; |
|
Wladimir Palant
2017/11/11 18:34:14
What about consistent naming? Meaning either remov
kzar
2017/11/13 12:32:57
Done.
| |
| 68 if (urlMatch || potentialOptionTabIds.size == 0) | |
| 62 { | 69 { |
| 63 if (tabId == potentialOptionsTab.id && | 70 browser.tabs.onUpdated.removeListener(updateListener); |
| 64 changeInfo.status == "complete") | 71 browser.tabs.onRemoved.removeListener(removeListener); |
| 65 { | 72 callback(urlMatch ? tab : undefined); |
| 66 browser.tabs.onUpdated.removeListener(updateListener); | 73 } |
| 67 browser.tabs.onRemoved.removeListener(onRemoved); | |
| 68 callback(tab.url == fullOptionsUrl ? tab : undefined); | |
| 69 } | |
| 70 }; | |
| 71 browser.tabs.onUpdated.addListener(updateListener); | |
| 72 onRemoved = removedTabId => | |
| 73 { | |
| 74 if (removedTabId == potentialOptionsTab.id) | |
| 75 { | |
| 76 browser.tabs.onUpdated.removeListener(updateListener); | |
| 77 browser.tabs.onRemoved.removeListener(onRemoved); | |
| 78 callback(); | |
| 79 } | |
| 80 }; | |
| 81 browser.tabs.onRemoved.addListener(onRemoved); | |
| 82 } | 74 } |
| 83 else | 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(); | 84 callback(); |
| 85 } | 85 } |
| 86 }; | |
| 87 browser.tabs.onRemoved.addListener(removeListener); | |
| 86 }); | 88 }); |
| 87 } | 89 } |
| 88 | 90 |
| 89 function returnShowOptionsCall(optionsTab, callback) | 91 function returnShowOptionsCall(optionsTab, callback) |
| 90 { | 92 { |
| 91 if (!callback) | 93 if (!callback) |
| 92 return; | 94 return; |
| 93 | 95 |
| 94 if (optionsTab) | 96 if (optionsTab) |
| 95 { | 97 { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 args: [ | 189 args: [ |
| 188 { | 190 { |
| 189 host: getDecodedHostname(currentPage.url).replace(/^www\./, ""), | 191 host: getDecodedHostname(currentPage.url).replace(/^www\./, ""), |
| 190 whitelisted: !!checkWhitelisted(currentPage) | 192 whitelisted: !!checkWhitelisted(currentPage) |
| 191 } | 193 } |
| 192 ] | 194 ] |
| 193 }); | 195 }); |
| 194 }); | 196 }); |
| 195 }); | 197 }); |
| 196 }); | 198 }); |
| LEFT | RIGHT |