Skip to content

Commit

Permalink
Guess new tab command tab more certainly with its title #3291
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Jan 17, 2024
1 parent 88839f7 commit c72d94e
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 19 deletions.
8 changes: 6 additions & 2 deletions webextensions/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@
"api_requestedPermissions_type_cookies": { "message": "Detect container of browser tabs" },


"guessNewOrphanTabAsOpenedByNewTabCommandTitle": { "message": "New Tab|New Private Tab" },


"context_menu_label": { "message": "Tree of tabs" },

"context_reloadTree_label": { "message": "&Reload this Tree" },
Expand Down Expand Up @@ -455,8 +458,9 @@
"config_autoAttachOnNewTabCommand_sibling": { "message": "Sibling of the current tab" },
"config_autoAttachOnNewTabCommand_nextSibling": { "message": "Next Sibling of the current tab" },
"config_autoAttachOnNewTabCommand_after": { "message": "\u200b" },
"config_guessNewOrphanTabAsOpenedByNewTabCommandUrl_before": { "message": "Guess a newly opened tab as opened by \"New Blank Tab\" action, when it is opened with URL(s) " },
"config_guessNewOrphanTabAsOpenedByNewTabCommandUrl_after": { "message": "(*You can list multiple URLs with a separator \"|\")" },
"config_guessNewOrphanTabAsOpenedByNewTabCommandTitle_before": { "message": "Guess a newly opened tab as opened by \"New Blank Tab\" action, when it is opened with title(s) " },
"config_guessNewOrphanTabAsOpenedByNewTabCommandUrl_before": { "message": " or URL(s) " },
"config_guessNewOrphanTabAsOpenedByNewTabCommandUrl_after": { "message": "(*You can list multiple values with a separator \"|\")" },

"config_autoAttachOnNewTabButtonMiddleClick_before": { "message": "For middle click, open new blank tab as" },
"config_autoAttachOnNewTabButtonMiddleClick_noControl": { "message": "(no control)" },
Expand Down
9 changes: 7 additions & 2 deletions webextensions/_locales/ja/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@
"api_requestedPermissions_type_tabs": { "message": "ブラウザーのタブへのアクセス" },
"api_requestedPermissions_type_cookies": { "message": "ブラウザーのタブのコンテナーの識別" },


"guessNewOrphanTabAsOpenedByNewTabCommandTitle": { "message": "新しいタブ|新しいプライベートタブ" },


"context_menu_label": { "message": "タブのツリーを操作" },

"context_reloadTree_label": { "message": "このツリーを再読み込み(&R)" },
Expand Down Expand Up @@ -451,8 +455,9 @@
"config_autoAttachOnNewTabCommand_sibling": { "message": "現在のタブと同階層に" },
"config_autoAttachOnNewTabCommand_nextSibling": { "message": "現在のタブと同階層で隣に" },
"config_autoAttachOnNewTabCommand_after": { "message": "開く" },
"config_guessNewOrphanTabAsOpenedByNewTabCommandUrl_before": { "message": "URLが" },
"config_guessNewOrphanTabAsOpenedByNewTabCommandUrl_after": { "message": "であるタブが開かれた場合、新しい空のタブが開かれたとみなす(※「|」で区切って複数URLを列挙可能)" },
"config_guessNewOrphanTabAsOpenedByNewTabCommandTitle_before": { "message": "タイトルが" },
"config_guessNewOrphanTabAsOpenedByNewTabCommandUrl_before": { "message": "またはURLが" },
"config_guessNewOrphanTabAsOpenedByNewTabCommandUrl_after": { "message": "であるタブが開かれた場合、新しい空のタブが開かれたとみなす(※「|」で区切って複数の値を列挙可能)" },

"config_autoAttachOnNewTabButtonMiddleClick_before": { "message": "中クリックした時、新しい空のタブを" },
"config_autoAttachOnNewTabButtonMiddleClick_noControl": { "message": "(制御せず既定の位置に)" },
Expand Down
2 changes: 1 addition & 1 deletion webextensions/background/api-tabs-listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* The Original Code is the Tree Style Tab.
*
* The Initial Developer of the Original Code is YUKI "Piro" Hiroshi.
* Portions created by the Initial Developer are Copyright (C) 2011-2021
* Portions created by the Initial Developer are Copyright (C) 2011-2024
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): YUKI "Piro" Hiroshi <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion webextensions/background/handle-new-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Tab.onCreating.addListener((tab, info = {}) => {
}).then(moved => !moved);
});
}
log('behave as a tab opened with any URL');
log('behave as a tab opened with any URL ', tab.title, tab.url);
if (!info.restored &&
!info.positionedBySelf &&
!info.bypassTabControl &&
Expand Down
6 changes: 3 additions & 3 deletions webextensions/common/Tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
mapAndFilterUniq,
toLines,
sanitizeForRegExpSource,
isNewTabCommandURL,
isNewTabCommandTab,
configs,
} from './common.js';

Expand Down Expand Up @@ -302,8 +302,8 @@ export default class Tab {
!configs.guessNewOrphanTabAsOpenedByNewTabCommand)
return false;

if (!isNewTabCommandURL(this.tab.url))
return false;
if (isNewTabCommandTab(this.tab))
return true;

// Firefox always opens a blank tab as the placeholder, when trying to
// open a bookmark in a new tab. So, we cannot determine is the tab
Expand Down
8 changes: 5 additions & 3 deletions webextensions/common/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ export const configs = new Configs({
autoAttachOnOpenedFromExternal: Constants.kNEWTAB_DO_NOTHING,
autoAttachOnAnyOtherTrigger: Constants.kNEWTAB_DO_NOTHING,
guessNewOrphanTabAsOpenedByNewTabCommand: true,
guessNewOrphanTabAsOpenedByNewTabCommandTitle: browser.i18n.getMessage('guessNewOrphanTabAsOpenedByNewTabCommandTitle'),
guessNewOrphanTabAsOpenedByNewTabCommandUrl: 'about:newtab|about:privatebrowsing',
inheritContextualIdentityToChildTabMode: Constants.kCONTEXTUAL_IDENTITY_DEFAULT,
inheritContextualIdentityToSameSiteOrphanMode: Constants.kCONTEXTUAL_IDENTITY_FROM_LAST_ACTIVE,
Expand Down Expand Up @@ -949,9 +950,10 @@ export function getWindowParamsFromSource(sourceWindow, { left, top, width, heig
return params;
}

export function isNewTabCommandURL(url) {
const newTabUrls = new Set(configs.guessNewOrphanTabAsOpenedByNewTabCommandUrl.split('|'));
return newTabUrls.has(url);
export function isNewTabCommandTab(tab) {
const newTabTitles = new Set(configs.guessNewOrphanTabAsOpenedByNewTabCommandTitle.split('|'));
const newTabUrls = new Set(configs.guessNewOrphanTabAsOpenedByNewTabCommandUrl.split('|'));
return newTabTitles.has(tab.title) || newTabUrls.has(tab.url);
}


Expand Down
3 changes: 3 additions & 0 deletions webextensions/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,9 @@ <h1>__MSG_config_newTab_caption__</h1>
<p class="sub"><label class="has-checkbox"
><input id="guessNewOrphanTabAsOpenedByNewTabCommand"
type="checkbox">
__MSG_config_guessNewOrphanTabAsOpenedByNewTabCommandTitle_before__
<input id="guessNewOrphanTabAsOpenedByNewTabCommandTitle"
size="40">
__MSG_config_guessNewOrphanTabAsOpenedByNewTabCommandUrl_before__
<input id="guessNewOrphanTabAsOpenedByNewTabCommandUrl"
size="40">
Expand Down
19 changes: 12 additions & 7 deletions webextensions/sidebar/gap-canceller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import {
log as internalLogger,
configs,
isNewTabCommandURL,
isNewTabCommandTab,
} from '/common/common.js';
import * as Constants from '/common/constants.js';
import * as TabsStore from '/common/tabs-store.js';
Expand Down Expand Up @@ -38,14 +38,14 @@ export function init() {
browser.tabs.query({ active: true, windowId: mWindowId }).then(async tabs => {
if (tabs.length == 0)
tabs = await browser.tabs.query({ windowId: mWindowId });
onLocationChange(tabs[0].url);
onLocationChange(tabs[0]);
});
BackgroundConnection.onMessage.addListener(async message => {
switch (message.type) {
case Constants.kCOMMAND_NOTIFY_TAB_ACTIVATING:
const tab = Tab.get(message.tabId);
if (tab) {
onLocationChange(tab.url, { byMouseOperation: message.byMouseOperation });
onLocationChange(tab, { byMouseOperation: message.byMouseOperation });
if (!message.byMouseOperation)
updateOffset();
}
Expand All @@ -54,7 +54,7 @@ export function init() {
});
browser.tabs.onUpdated.addListener((_tabId, changeInfo, tab) => {
if (tab.active && changeInfo.status == 'complete')
onLocationChange(tab.url);
onLocationChange(tab);
}, { windowId: mWindowId, properties: ['status'] });

if (shouldWatchVisualGap())
Expand Down Expand Up @@ -88,7 +88,10 @@ function getWindowDimension() {
function updateOffset() {
const dimension = getWindowDimension();

const isNewTab = isNewTabCommandURL(mDataset.activeTabUrl);
const isNewTab = isNewTabCommandTab({
title: mDataset.activeTabTitle,
url: mDataset.activeTabUrl,
});
const isFullScreen = mDataset.ownerWindowState == 'fullscreen'
const shouldSuppressGapOnNewTab = (
configs.suppressGapFromShownOrHiddenToolbarOnNewTab &&
Expand All @@ -104,6 +107,7 @@ function updateOffset() {
(mByMouseOperation || !configs.suppressGapFromShownOrHiddenToolbarOnlyOnMouseOperation)
);
log('updateOffset: ', {
title: mDataset.activeTabTitle,
url: mDataset.activeTabUrl,
isNewTab,
state: mDataset.ownerWindowState,
Expand Down Expand Up @@ -186,8 +190,9 @@ function cancelUpdateOffset() {
}
}

function onLocationChange(url, { byMouseOperation } = {}) {
mDataset.activeTabUrl = url;
function onLocationChange(tab, { byMouseOperation } = {}) {
mDataset.activeTabTitle = tab.title;
mDataset.activeTabUrl = tab.url;
if (byMouseOperation)
mByMouseOperation = true;
}
Expand Down

0 comments on commit c72d94e

Please sign in to comment.