summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/toolbar_view.cc
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-30 07:32:01 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-30 07:32:01 +0000
commit9fd542df08cfbff0743b2553d3855a87ce16cbfc (patch)
tree32332f42daf9ed425c198f831033a39a1c5ae2a1 /chrome/browser/views/toolbar_view.cc
parentfa9a7b41ccbf11213d2264cec8e6ff2dbd142fcc (diff)
downloadchromium_src-9fd542df08cfbff0743b2553d3855a87ce16cbfc.zip
chromium_src-9fd542df08cfbff0743b2553d3855a87ce16cbfc.tar.gz
chromium_src-9fd542df08cfbff0743b2553d3855a87ce16cbfc.tar.bz2
Integrate browser actions with the wrench menu. Browser
actions always show up in a submenu of the wrench menu, and if they have an icon, they also show up in the toolbar area. BUG=23380,22883 TEST=Added new automated tests for the command handling, but we need to test that the menu items show up manually. To do that, run with no extension installed, you should see "extensions" in the wrench menu. Add an extension that adds a browser action, you should now see an "extensions" submenu with "manage extensions" and the browser action(s) in the submenu. Review URL: http://codereview.chromium.org/246037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27599 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/toolbar_view.cc')
-rw-r--r--chrome/browser/views/toolbar_view.cc40
1 files changed, 37 insertions, 3 deletions
diff --git a/chrome/browser/views/toolbar_view.cc b/chrome/browser/views/toolbar_view.cc
index 430bfef..7e08acf 100644
--- a/chrome/browser/views/toolbar_view.cc
+++ b/chrome/browser/views/toolbar_view.cc
@@ -1044,8 +1044,8 @@ void ToolbarView::CreateDevToolsMenuContents() {
#endif
void ToolbarView::CreateAppMenu() {
- if (app_menu_contents_.get())
- return;
+ // We always rebuild the app menu so that we can get the current state of the
+ // extension system.
app_menu_contents_.reset(new views::SimpleMenuModel(this));
app_menu_contents_->AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB);
@@ -1056,7 +1056,8 @@ void ToolbarView::CreateAppMenu() {
// We will create the child menu items for this once the asynchronous call is
// done. See OnGetProfilesDone().
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
- if (command_line.HasSwitch(switches::kEnableUserDataDirProfiles)) {
+ if (command_line.HasSwitch(switches::kEnableUserDataDirProfiles) &&
+ !profiles_menu_contents_.get()) {
profiles_helper_->GetProfiles(NULL);
profiles_menu_contents_.reset(new views::SimpleMenuModel(this));
app_menu_contents_->AddSubMenuWithStringId(IDS_PROFILE_MENU,
@@ -1073,6 +1074,39 @@ void ToolbarView::CreateAppMenu() {
IDS_BOOKMARK_MANAGER);
app_menu_contents_->AddItemWithStringId(IDC_SHOW_DOWNLOADS,
IDS_SHOW_DOWNLOADS);
+
+ // Create the extensions item or submenu.
+ // If there are any browser actions, we create an "Extensions" submenu, of
+ // which "Manage extensions" is the first entry. If there are no browser
+ // actions, we just create an "Extensions" menu item which does the same thing
+ // as "Manage extensions".
+ ExtensionsService* extensions_service =
+ browser_->profile()->GetExtensionsService();
+ if (extensions_service && extensions_service->extensions_enabled()) {
+ std::vector<ExtensionAction*> browser_actions =
+ browser_->profile()->GetExtensionsService()->GetBrowserActions();
+ if (browser_actions.size() == 0) {
+ app_menu_contents_->AddItemWithStringId(IDC_MANAGE_EXTENSIONS,
+ IDS_SHOW_EXTENSIONS);
+ } else {
+ extension_menu_contents_.reset(new views::SimpleMenuModel(this));
+ app_menu_contents_->AddSubMenuWithStringId(
+ IDS_SHOW_EXTENSIONS, extension_menu_contents_.get());
+
+ extension_menu_contents_->AddItemWithStringId(IDC_MANAGE_EXTENSIONS,
+ IDS_MANAGE_EXTENSIONS);
+ for (size_t i = 0; i < browser_actions.size(); ++i) {
+ if (browser_actions[i]->command_id() > IDC_BROWSER_ACTION_LAST) {
+ NOTREACHED() << "Too many browser actions.";
+ } else {
+ extension_menu_contents_->AddItem(
+ browser_actions[i]->command_id(),
+ UTF8ToUTF16(browser_actions[i]->name()));
+ }
+ }
+ }
+ }
+
app_menu_contents_->AddSeparator();
#ifdef CHROME_PERSONALIZATION
if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableSync)) {