diff options
Diffstat (limited to 'chrome/browser/views')
-rw-r--r-- | chrome/browser/views/browser_actions_container.cc | 39 | ||||
-rw-r--r-- | chrome/browser/views/toolbar_view.cc | 45 | ||||
-rw-r--r-- | chrome/browser/views/toolbar_view.h | 1 |
3 files changed, 27 insertions, 58 deletions
diff --git a/chrome/browser/views/browser_actions_container.cc b/chrome/browser/views/browser_actions_container.cc index 1c0733f..df6d905 100644 --- a/chrome/browser/views/browser_actions_container.cc +++ b/chrome/browser/views/browser_actions_container.cc @@ -133,13 +133,14 @@ BrowserActionButton::BrowserActionButton( // Load the images this view needs asynchronously on the file thread. We'll // get a call back into OnImageLoaded if the image loads successfully. If not, // the ImageView will have no image and will not appear in the browser chrome. - DCHECK(!browser_action->icon_paths().empty()); - const std::vector<std::string>& icon_paths = browser_action->icon_paths(); - browser_action_icons_.resize(icon_paths.size()); - tracker_ = new ImageLoadingTracker(this, icon_paths.size()); - for (std::vector<std::string>::const_iterator iter = icon_paths.begin(); - iter != icon_paths.end(); ++iter) { - tracker_->PostLoadImageTask(extension->GetResource(*iter)); + if (!browser_action->icon_paths().empty()) { + const std::vector<std::string>& icon_paths = browser_action->icon_paths(); + browser_action_icons_.resize(icon_paths.size()); + tracker_ = new ImageLoadingTracker(this, icon_paths.size()); + for (std::vector<std::string>::const_iterator iter = icon_paths.begin(); + iter != icon_paths.end(); ++iter) { + tracker_->PostLoadImageTask(extension->GetResource(*iter)); + } } registrar_.Add(this, NotificationType::EXTENSION_BROWSER_ACTION_UPDATED, @@ -174,9 +175,16 @@ void BrowserActionButton::OnImageLoaded(SkBitmap* image, size_t index) { void BrowserActionButton::OnStateUpdated() { SkBitmap* image = browser_action_state_->icon(); - if (!image) - image = &browser_action_icons_[browser_action_state_->icon_index()]; - SetIcon(*image); + if (!image) { + if (static_cast<size_t>(browser_action_state_->icon_index()) < + browser_action_icons_.size()) { + image = &browser_action_icons_[browser_action_state_->icon_index()]; + } + } + + if (image) + SetIcon(*image); + SetTooltipText(ASCIIToWide(browser_action_state_->title())); panel_->OnBrowserActionVisibilityChanged(); GetParent()->SchedulePaint(); @@ -414,13 +422,10 @@ void BrowserActionsContainer::RefreshBrowserActionViews() { browser_actions[i]->extension_id()); DCHECK(extension); - // Only show browser actions that have an icon. - if (browser_actions[i]->icon_paths().size() > 0) { - BrowserActionView* view = - new BrowserActionView(browser_actions[i], extension, this); - browser_action_views_.push_back(view); - AddChildView(view); - } + BrowserActionView* view = + new BrowserActionView(browser_actions[i], extension, this); + browser_action_views_.push_back(view); + AddChildView(view); } } diff --git a/chrome/browser/views/toolbar_view.cc b/chrome/browser/views/toolbar_view.cc index ed8912a..072e6c8 100644 --- a/chrome/browser/views/toolbar_view.cc +++ b/chrome/browser/views/toolbar_view.cc @@ -1081,8 +1081,8 @@ void ToolbarView::CreateDevToolsMenuContents() { #endif void ToolbarView::CreateAppMenu() { - // We always rebuild the app menu so that we can get the current state of the - // extension system. + if (app_menu_contents_.get()) + return; app_menu_contents_.reset(new views::SimpleMenuModel(this)); app_menu_contents_->AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB); @@ -1112,47 +1112,12 @@ void ToolbarView::CreateAppMenu() { 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". + // Create the manage extensions menu item. ExtensionsService* extensions_service = browser_->profile()->GetExtensionsService(); if (extensions_service && extensions_service->extensions_enabled()) { - // Get a count of all non-popup browser actions to decide how to layout - // the Extensions menu. - std::vector<ExtensionAction*> browser_actions = - browser_->profile()->GetExtensionsService()->GetBrowserActions(false); - 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); - - // TODO(erikkay) Even though we just got the list of all browser actions, - // we have to enumerate the list of extensions in order to get the action - // state. It seems like we should find a way to combine these. - const ExtensionList* extensions = extensions_service->extensions(); - for (size_t i = 0; i < extensions->size(); ++i) { - Extension* extension = extensions->at(i); - if (!extension->browser_action()) { - continue; - } else if (extension->browser_action()->command_id() > - IDC_BROWSER_ACTION_LAST) { - NOTREACHED() << "Too many browser actions."; - } else if (!extension->browser_action()->is_popup()) { - extension_menu_contents_->AddItem( - extension->browser_action()->command_id(), - UTF8ToUTF16(extension->browser_action_state()->title())); - } - } - } + app_menu_contents_->AddItemWithStringId(IDC_MANAGE_EXTENSIONS, + IDS_SHOW_EXTENSIONS); } app_menu_contents_->AddSeparator(); diff --git a/chrome/browser/views/toolbar_view.h b/chrome/browser/views/toolbar_view.h index 514265a..97fba3b 100644 --- a/chrome/browser/views/toolbar_view.h +++ b/chrome/browser/views/toolbar_view.h @@ -247,7 +247,6 @@ class ToolbarView : public views::View, scoped_ptr<EncodingMenuModel> encoding_menu_contents_; scoped_ptr<views::SimpleMenuModel> devtools_menu_contents_; scoped_ptr<views::SimpleMenuModel> app_menu_contents_; - scoped_ptr<views::SimpleMenuModel> extension_menu_contents_; // TODO(beng): build these into MenuButton. scoped_ptr<views::Menu2> page_menu_menu_; |