Skip to content

Commit

Permalink
Control new tabs form other applications more correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Oct 28, 2019
1 parent da04b05 commit e055dee
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
8 changes: 4 additions & 4 deletions webextensions/background/api-tabs-listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ async function onNewTabTracked(tab, info) {
const duplicatedInternally = window.duplicatingTabsCount > 0;
const maybeOrphan = window.toBeOpenedOrphanTabs > 0;
const activeTab = Tab.getActiveTab(window.id);
const fromExternalApplication = !mAppIsActive;
const fromExternal = !mAppIsActive;

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

if (Tab.needToWaitTracked(tab.windowId, { exceptionTabId: tab.id }))
Expand Down Expand Up @@ -471,7 +471,7 @@ async function onNewTabTracked(tab, info) {
duplicated,
duplicatedInternally,
activeTab,
fromExternalApplication
fromExternal
});
// don't do await if not needed, to process things synchronously
if (moved instanceof Promise)
Expand Down Expand Up @@ -516,7 +516,7 @@ async function onNewTabTracked(tab, info) {
duplicatedInternally,
originalTab: duplicated && Tab.get(uniqueId.originalTabId),
treeForActionDetection,
fromExternalApplication
fromExternal
});
tab.$TST.resolveOpened();

Expand Down
17 changes: 14 additions & 3 deletions webextensions/background/handle-new-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ Tab.onCreating.addListener((tab, info = {}) => {
TabsStore.addToBeGroupedTab(tab);
}
else {
let dontMove = false;
if (!info.maybeOrphan &&
possibleOpenerTab &&
!info.restored) {
let autoAttachBehavior = configs.autoAttachOnNewTabCommand;
let dontMove = false;
if (tab.$TST.nextTab &&
possibleOpenerTab == tab.$TST.previousTab) {
// New tab opened with browser.tabs.insertAfterCurrent=true may have
Expand Down Expand Up @@ -85,7 +85,17 @@ Tab.onCreating.addListener((tab, info = {}) => {
else if (possibleOpenerTab != tab) {
tab.$TST.possibleOpenerTab = possibleOpenerTab.id;
}
tab.$TST.isNewTab = true;
tab.$TST.isNewTab = !info.fromExternal;
}
if (info.fromExternal) {
log('behave as a tab opened from external application');
return Tree.behaveAutoAttachedTab(tab, {
baseTab: possibleOpenerTab,
behavior: configs.autoAttachOnOpenedFromExternal,
dontMove,
inheritContextualIdentity: configs.inheritContextualIdentityToTabsFromExternal,
broadcast: true
}).then(moved => !moved);
}
log('behave as a tab opened with any URL');
tab.$TST.positionedBySelf = info.positionedBySelf;
Expand All @@ -111,8 +121,9 @@ Tab.onCreating.addListener((tab, info = {}) => {
else if (!info.maybeOrphan && configs.autoAttach) {
return Tree.behaveAutoAttachedTab(tab, {
baseTab: opener,
behavior: configs.autoAttachOnOpenedWithOwner,
behavior: info.fromExternal ? configs.autoAttachOnOpenedFromExternal : configs.autoAttachOnOpenedWithOwner,
dontMove: info.positionedBySelf || info.mayBeReplacedWithContainer,
inheritContextualIdentity: info.fromExternal ? configs.inheritContextualIdentityToTabsFromExternal : false,
broadcast: true
}).then(moved => !moved);
}
Expand Down
1 change: 1 addition & 0 deletions webextensions/common/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export const configs = new Configs({
autoAttachOnNewTabButtonMiddleClick: Constants.kNEWTAB_OPEN_AS_CHILD,
autoAttachOnDuplicated: Constants.kNEWTAB_OPEN_AS_NEXT_SIBLING,
autoAttachSameSiteOrphan: Constants.kNEWTAB_OPEN_AS_CHILD,
autoAttachOnOpenedFromExternal: Constants.kNEWTAB_DO_NOTHING,
guessNewOrphanTabAsOpenedByNewTabCommand: true,
guessNewOrphanTabAsOpenedByNewTabCommandUrl: 'about:newtab',
inheritContextualIdentityToNewChildTab: false,
Expand Down

0 comments on commit e055dee

Please sign in to comment.