Skip to content

Commit e055dee

Browse files
committed
Control new tabs form other applications more correctly
1 parent da04b05 commit e055dee

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

webextensions/background/api-tabs-listener.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ async function onNewTabTracked(tab, info) {
330330
const duplicatedInternally = window.duplicatingTabsCount > 0;
331331
const maybeOrphan = window.toBeOpenedOrphanTabs > 0;
332332
const activeTab = Tab.getActiveTab(window.id);
333-
const fromExternalApplication = !mAppIsActive;
333+
const fromExternal = !mAppIsActive;
334334

335335
// New tab's index can become invalid because the value of "index" is same to
336336
// the one given to browser.tabs.create() (new tab) or the original index
@@ -362,7 +362,7 @@ async function onNewTabTracked(tab, info) {
362362
mayBeReplacedWithContainer,
363363
maybeOrphan,
364364
activeTab,
365-
fromExternalApplication
365+
fromExternal
366366
});
367367

368368
if (Tab.needToWaitTracked(tab.windowId, { exceptionTabId: tab.id }))
@@ -471,7 +471,7 @@ async function onNewTabTracked(tab, info) {
471471
duplicated,
472472
duplicatedInternally,
473473
activeTab,
474-
fromExternalApplication
474+
fromExternal
475475
});
476476
// don't do await if not needed, to process things synchronously
477477
if (moved instanceof Promise)
@@ -516,7 +516,7 @@ async function onNewTabTracked(tab, info) {
516516
duplicatedInternally,
517517
originalTab: duplicated && Tab.get(uniqueId.originalTabId),
518518
treeForActionDetection,
519-
fromExternalApplication
519+
fromExternal
520520
});
521521
tab.$TST.resolveOpened();
522522

webextensions/background/handle-new-tabs.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ Tab.onCreating.addListener((tab, info = {}) => {
4141
TabsStore.addToBeGroupedTab(tab);
4242
}
4343
else {
44+
let dontMove = false;
4445
if (!info.maybeOrphan &&
4546
possibleOpenerTab &&
4647
!info.restored) {
4748
let autoAttachBehavior = configs.autoAttachOnNewTabCommand;
48-
let dontMove = false;
4949
if (tab.$TST.nextTab &&
5050
possibleOpenerTab == tab.$TST.previousTab) {
5151
// New tab opened with browser.tabs.insertAfterCurrent=true may have
@@ -85,7 +85,17 @@ Tab.onCreating.addListener((tab, info = {}) => {
8585
else if (possibleOpenerTab != tab) {
8686
tab.$TST.possibleOpenerTab = possibleOpenerTab.id;
8787
}
88-
tab.$TST.isNewTab = true;
88+
tab.$TST.isNewTab = !info.fromExternal;
89+
}
90+
if (info.fromExternal) {
91+
log('behave as a tab opened from external application');
92+
return Tree.behaveAutoAttachedTab(tab, {
93+
baseTab: possibleOpenerTab,
94+
behavior: configs.autoAttachOnOpenedFromExternal,
95+
dontMove,
96+
inheritContextualIdentity: configs.inheritContextualIdentityToTabsFromExternal,
97+
broadcast: true
98+
}).then(moved => !moved);
8999
}
90100
log('behave as a tab opened with any URL');
91101
tab.$TST.positionedBySelf = info.positionedBySelf;
@@ -111,8 +121,9 @@ Tab.onCreating.addListener((tab, info = {}) => {
111121
else if (!info.maybeOrphan && configs.autoAttach) {
112122
return Tree.behaveAutoAttachedTab(tab, {
113123
baseTab: opener,
114-
behavior: configs.autoAttachOnOpenedWithOwner,
124+
behavior: info.fromExternal ? configs.autoAttachOnOpenedFromExternal : configs.autoAttachOnOpenedWithOwner,
115125
dontMove: info.positionedBySelf || info.mayBeReplacedWithContainer,
126+
inheritContextualIdentity: info.fromExternal ? configs.inheritContextualIdentityToTabsFromExternal : false,
116127
broadcast: true
117128
}).then(moved => !moved);
118129
}

webextensions/common/common.js

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ export const configs = new Configs({
144144
autoAttachOnNewTabButtonMiddleClick: Constants.kNEWTAB_OPEN_AS_CHILD,
145145
autoAttachOnDuplicated: Constants.kNEWTAB_OPEN_AS_NEXT_SIBLING,
146146
autoAttachSameSiteOrphan: Constants.kNEWTAB_OPEN_AS_CHILD,
147+
autoAttachOnOpenedFromExternal: Constants.kNEWTAB_DO_NOTHING,
147148
guessNewOrphanTabAsOpenedByNewTabCommand: true,
148149
guessNewOrphanTabAsOpenedByNewTabCommandUrl: 'about:newtab',
149150
inheritContextualIdentityToNewChildTab: false,

0 commit comments

Comments
 (0)