Skip to content

Commit

Permalink
Don't reopen unopenable URL tab for container inheritance by default #…
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Nov 20, 2023
1 parent 48f43e9 commit 4ad0b62
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions webextensions/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@
"config_inheritContextualIdentityToTabsFromAnyOtherTriggerMode_parent": { "message": "Inherit from the parent tab on the tree" },
"config_inheritContextualIdentityToTabsFromAnyOtherTriggerMode_lastActive": { "message": "Inherit from the current tab" },

"config_inheritContextualIdentityToUnopenableURLTabs_label": { "message": "Reopen tab with inherited container anyway, even if it has a URL unable to open by addon's permission" },

"config_groupTab_caption": { "message": "Auto-grouping of tabs" },

"config_tabBunchesDetectionTimeout_before": { "message": "Detect tabs opened from a bookmark folder within" },
Expand Down
2 changes: 2 additions & 0 deletions webextensions/_locales/ja/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,8 @@
"config_inheritContextualIdentityToTabsFromAnyOtherTriggerMode_parent": { "message": "ツリー上での親から継承" },
"config_inheritContextualIdentityToTabsFromAnyOtherTriggerMode_lastActive": { "message": "現在のタブから継承" },

"config_inheritContextualIdentityToUnopenableURLTabs_label": { "message": "アドオンの権限で開けないURLのタブを、コンテナーを継承するために安全なURLで強制的に開き直す" },

"config_groupTab_caption": { "message": "タブを自動的にグループ化する" },

"config_tabBunchesDetectionTimeout_before": { "message": "1つのブックマークフォルダーから" },
Expand Down
6 changes: 6 additions & 0 deletions webextensions/background/handle-new-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ async function handleNewTabFromActiveTab(tab, { url, activeTab, autoAttachBehavi
return moved;
}

if (!configs.inheritContextualIdentityToUnopenableURLTabs &&
!TabsOpen.isOpenable(url)) {
log('handleNewTabFromActiveTab: not openable URL, skip reopening ', cookieStoreId, url);
return moved;
}

log('handleNewTabFromActiveTab: reopen with inherited contextual identity ', cookieStoreId);
// We need to prevent grouping of this original tab and the reopened tab
// by the "multiple tab opened in XXX msec" feature.
Expand Down
2 changes: 2 additions & 0 deletions webextensions/background/tab-context-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import * as TSTAPI from '/common/tst-api.js';
import Tab from '/common/Tab.js';

import * as Commands from './commands.js';
import * as TabsOpen from './tabs-open.js';

function log(...args) {
internalLogger('background/tab-context-menu', ...args);
Expand Down Expand Up @@ -694,6 +695,7 @@ async function onShown(info, contextTab) {
}
updateItem('context_reopenInContainer', {
visible: emulate && contextTab && showContextualIdentities && !contextTab.incognito,
enabled: TabsOpen.isOpenable(contextTab.url),
multiselected
}) && modifiedItemsCount++;

Expand Down
4 changes: 4 additions & 0 deletions webextensions/background/tabs-open.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ function sanitizeURL(url) {
return url;
}

export function isOpenable(url) {
return !url || url == sanitizeURL(url);
}


function onMessage(message, openerTab) {
switch (message.type) {
Expand Down
1 change: 1 addition & 0 deletions webextensions/common/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ export const configs = new Configs({
inheritContextualIdentityToSameSiteOrphanMode: Constants.kCONTEXTUAL_IDENTITY_FROM_LAST_ACTIVE,
inheritContextualIdentityToTabsFromExternalMode: Constants.kCONTEXTUAL_IDENTITY_DEFAULT,
inheritContextualIdentityToTabsFromAnyOtherTriggerMode: Constants.kCONTEXTUAL_IDENTITY_DEFAULT,
inheritContextualIdentityToUnopenableURLTabs: false,


// behavior around closed tab
Expand Down
3 changes: 3 additions & 0 deletions webextensions/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,9 @@ <h1>__MSG_config_newTab_caption__</h1>
<option value="2">__MSG_config_inheritContextualIdentityToTabsFromExternalMode_lastActive__</option>
</select></label></p>
<div class="expert">
<p><label><input id="inheritContextualIdentityToUnopenableURLTabs"
type="checkbox">
__MSG_config_inheritContextualIdentityToUnopenableURLTabs_label__</label></p>
<hr>
<p><label>__MSG_config_anyOtherTrigger_caption__: __MSG_config_autoAttachOnAnyOtherTrigger_before__
<select id="autoAttachOnAnyOtherTrigger">
Expand Down

0 comments on commit 4ad0b62

Please sign in to comment.