From 86297bbff3d8d0a2bb142ea8dcc727fac246808f Mon Sep 17 00:00:00 2001 From: "YUKI \"Piro\" Hiroshi" Date: Mon, 28 Oct 2019 18:17:50 +0900 Subject: [PATCH] Detect search result tabs opened from about:addons #2397 --- webextensions/background/handle-new-tabs.js | 14 ++++++++++++++ webextensions/common/constants.js | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/webextensions/background/handle-new-tabs.js b/webextensions/background/handle-new-tabs.js index 7d165683e..af53dd5b3 100644 --- a/webextensions/background/handle-new-tabs.js +++ b/webextensions/background/handle-new-tabs.js @@ -245,6 +245,20 @@ Tab.onUpdated.addListener((tab, changeInfo) => { }); return; } + + log('checking special openers (delayed)', { opener: possibleOpenerTab.url, child: tab.url }); + for (const rule of Constants.kAGGRESSIVE_OPENER_TAB_DETECTION_RULES_WITH_URL) { + if (rule.opener.test(possibleOpenerTab.url) && + rule.child.test(tab.url)) { + log('behave as a tab opened from special opener (delayed)', { rule }); + handleNewTabFromActiveTab(tab, { + url: tab.url, + activeTab: possibleOpenerTab, + autoAttachBehavior: Constants.kNEWTAB_OPEN_AS_CHILD + }); + return; + } + } } }); diff --git a/webextensions/common/constants.js b/webextensions/common/constants.js index 5db0c3d81..fa5af81ed 100644 --- a/webextensions/common/constants.js +++ b/webextensions/common/constants.js @@ -309,4 +309,9 @@ export const kSHORTHAND_URIS = { 'test-runner': browser.extension.getURL('tests/runner.html') }; +export const kAGGRESSIVE_OPENER_TAB_DETECTION_RULES_WITH_URL = [ + { opener: /^about:addons/, + child: /^https:\/\/addons.mozilla.org\/([^\/]+\/)?[^\/]+\/search\// } +]; + export const kNOTIFICATION_DEFAULT_ICON = '/resources/icon64.png';