summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/app/generated_resources.grd18
-rw-r--r--chrome/browser/about_flags.cc7
-rw-r--r--chrome/browser/tabs/tab_strip_model.cc53
-rw-r--r--chrome/browser/tabs/tab_strip_model.h12
-rw-r--r--chrome/browser/ui/tabs/tab_menu_model.cc8
-rw-r--r--chrome/common/chrome_switches.cc3
-rw-r--r--chrome/common/chrome_switches.h1
7 files changed, 99 insertions, 3 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index cb6e00b..f24b325 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -4185,6 +4185,12 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_FLAGS_NEW_TAB_PAGE_4_DESCRIPTION" desc="Description of the new tab page 4 lab.">
Enables an in-development redesign of the new tab page.
</message>
+ <message name="IDS_FLAGS_TAB_GROUPS_CONTEXT_MENU_NAME" desc="Name of the context menu for enabling tab grouping in the context menu">
+ Add grouping to tab context menu
+ </message>
+ <message name="IDS_FLAGS_TAB_GROUPS_CONTEXT_MENU_DESCRIPTION" desc="Description of the context menu for enabling tab grouping in the context menu lab.">
+ Adds items to the tab context menu for grouping tabs.
+ </message>
<!-- Crashes -->
<message name="IDS_CRASHES_TITLE" desc="Title for the chrome://crashes page.">
@@ -5548,6 +5554,12 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_TAB_CXMENU_USE_VERTICAL_TABS" desc="Use the vertical tab strip">
Use side tabs
</message>
+ <message name="IDS_TAB_CXMENU_SELECT_BY_DOMAIN" desc="The label of the tab context menu item for selecting tabs with the same domain">
+ Select by domain
+ </message>
+ <message name="IDS_TAB_CXMENU_SELECT_BY_OPENER" desc="The label of the tab context menu item for selecting tabs with the same opener">
+ Select by opener
+ </message>
</if>
<if expr="pp_ifdef('use_titlecase')">
<message name="IDS_TAB_CXMENU_NEWTAB" desc="In Title Case: The label of the 'New Tab' Tab context menu item.">
@@ -5589,6 +5601,12 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_TAB_CXMENU_USE_VERTICAL_TABS" desc="In Title Case: Use the vertical tab strip">
Use Side Tabs
</message>
+ <message name="IDS_TAB_CXMENU_SELECT_BY_DOMAIN" desc="The label of the tab context menu item for selecting tabs with the same domain">
+ Select by Domain
+ </message>
+ <message name="IDS_TAB_CXMENU_SELECT_BY_OPENER" desc="The label of the tab context menu item for selecting tabs with the same opener">
+ Select by Opener
+ </message>
</if>
<!-- Bookmarks bar -->
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
index fc8f0d8..c59d072 100644
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
@@ -295,6 +295,13 @@ const Experiment kExperiments[] = {
kOsAll,
SINGLE_VALUE_TYPE(switches::kNewTabPage4)
},
+ {
+ "tab-groups-context-menu",
+ IDS_FLAGS_TAB_GROUPS_CONTEXT_MENU_NAME,
+ IDS_FLAGS_TAB_GROUPS_CONTEXT_MENU_DESCRIPTION,
+ kOsWin,
+ SINGLE_VALUE_TYPE(switches::kEnableTabGroupsContextMenu)
+ },
};
const Experiment* experiments = kExperiments;
diff --git a/chrome/browser/tabs/tab_strip_model.cc b/chrome/browser/tabs/tab_strip_model.cc
index 6f87482..2925e53 100644
--- a/chrome/browser/tabs/tab_strip_model.cc
+++ b/chrome/browser/tabs/tab_strip_model.cc
@@ -756,6 +756,10 @@ bool TabStripModel::IsContextMenuCommandEnabled(
case CommandUseVerticalTabs:
return true;
+ case CommandSelectByDomain:
+ case CommandSelectByOpener:
+ return true;
+
default:
NOTREACHED();
}
@@ -899,6 +903,22 @@ void TabStripModel::ExecuteContextMenuCommand(
delegate()->ToggleUseVerticalTabs();
break;
}
+
+ case CommandSelectByDomain:
+ case CommandSelectByOpener: {
+ std::vector<int> indices;
+ if (command_id == CommandSelectByDomain)
+ GetIndicesWithSameDomain(context_index, &indices);
+ else
+ GetIndicesWithSameOpener(context_index, &indices);
+ TabStripSelectionModel selection_model;
+ selection_model.SetSelectedIndex(context_index);
+ for (size_t i = 0; i < indices.size(); ++i)
+ selection_model.AddIndexToSelection(indices[i]);
+ SetSelectionFromModel(selection_model);
+ break;
+ }
+
default:
NOTREACHED();
}
@@ -1020,6 +1040,39 @@ bool TabStripModel::ContextMenuCommandToBrowserCommand(int cmd_id,
///////////////////////////////////////////////////////////////////////////////
// TabStripModel, private:
+void TabStripModel::GetIndicesWithSameDomain(int index,
+ std::vector<int>* indices) {
+ TabContentsWrapper* tab = GetTabContentsAt(index);
+ std::string domain = tab->tab_contents()->GetURL().host();
+ if (domain.empty())
+ return;
+ for (int i = 0; i < count(); ++i) {
+ if (i == index)
+ continue;
+ if (GetTabContentsAt(i)->tab_contents()->GetURL().host() == domain)
+ indices->push_back(i);
+ }
+}
+
+void TabStripModel::GetIndicesWithSameOpener(int index,
+ std::vector<int>* indices) {
+ NavigationController* opener = contents_data_[index]->group;
+ if (!opener) {
+ // If there is no group, find all tabs with the selected tab as the opener.
+ opener = &(GetTabContentsAt(index)->controller());
+ if (!opener)
+ return;
+ }
+ for (int i = 0; i < count(); ++i) {
+ if (i == index)
+ continue;
+ if (contents_data_[i]->group == opener ||
+ &(GetTabContentsAt(i)->controller()) == opener) {
+ indices->push_back(i);
+ }
+ }
+}
+
std::vector<int> TabStripModel::GetIndicesForCommand(int index) const {
if (!IsTabSelected(index)) {
std::vector<int> indices;
diff --git a/chrome/browser/tabs/tab_strip_model.h b/chrome/browser/tabs/tab_strip_model.h
index 9c481b2..df0c545 100644
--- a/chrome/browser/tabs/tab_strip_model.h
+++ b/chrome/browser/tabs/tab_strip_model.h
@@ -429,6 +429,8 @@ class TabStripModel : public NotificationObserver {
CommandTogglePinned,
CommandBookmarkAllTabs,
CommandUseVerticalTabs,
+ CommandSelectByDomain,
+ CommandSelectByOpener,
CommandLast
};
@@ -467,8 +469,12 @@ class TabStripModel : public NotificationObserver {
static bool ContextMenuCommandToBrowserCommand(int cmd_id, int* browser_cmd);
private:
- // We cannot be constructed without a delegate.
- TabStripModel();
+ // Gets the set of tab indices whose domain matches the tab at |index|.
+ void GetIndicesWithSameDomain(int index, std::vector<int>* indices);
+
+ // Gets the set of tab indices that have the same opener as the tab at
+ // |index|.
+ void GetIndicesWithSameOpener(int index, std::vector<int>* indices);
// If |index| is selected all the selected indices are returned, otherwise a
// vector with |index| is returned. This is used when executing commands to
@@ -628,7 +634,7 @@ class TabStripModel : public NotificationObserver {
TabStripSelectionModel selection_model_;
- DISALLOW_COPY_AND_ASSIGN(TabStripModel);
+ DISALLOW_IMPLICIT_CONSTRUCTORS(TabStripModel);
};
#endif // CHROME_BROWSER_TABS_TAB_STRIP_MODEL_H_
diff --git a/chrome/browser/ui/tabs/tab_menu_model.cc b/chrome/browser/ui/tabs/tab_menu_model.cc
index 38b1e78..070507e 100644
--- a/chrome/browser/ui/tabs/tab_menu_model.cc
+++ b/chrome/browser/ui/tabs/tab_menu_model.cc
@@ -99,4 +99,12 @@ void TabMenuModel::Build(TabStripModel* tab_strip, int index) {
AddCheckItemWithStringId(TabStripModel::CommandUseVerticalTabs,
IDS_TAB_CXMENU_USE_VERTICAL_TABS);
}
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableTabGroupsContextMenu)) {
+ AddSeparator();
+ AddItemWithStringId(TabStripModel::CommandSelectByDomain,
+ IDS_TAB_CXMENU_SELECT_BY_DOMAIN);
+ AddItemWithStringId(TabStripModel::CommandSelectByOpener,
+ IDS_TAB_CXMENU_SELECT_BY_OPENER);
+ }
}
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index 9e1d759..113adaf 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -539,6 +539,9 @@ const char kEnableSyncAutofill[] = "enable-sync-autofill";
// Enable syncing browser sessions.
const char kEnableSyncSessions[] = "enable-sync-sessions";
+// Enables context menu for selecting groups of tabs.
+const char kEnableTabGroupsContextMenu[] = "enable-tab-groups-context-menu";
+
// Enable syncing browser typed urls.
const char kEnableSyncTypedUrls[] = "enable-sync-typed-urls";
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index fb26713..5670337 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -164,6 +164,7 @@ extern const char kEnableSyncAutofill[];
extern const char kEnableSyncPreferences[];
extern const char kEnableSyncSessions[];
extern const char kEnableSyncTypedUrls[];
+extern const char kEnableTabGroupsContextMenu[];
extern const char kEnableTcpFastOpen[];
extern const char kEnableTopSites[];
extern const char kEnableVerticalTabs[];