Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(550)

Unified Diff: chrome/browser/ui/toolbar/action_box_menu_model.cc

Issue 10823289: Adding "send to mobile" and "add bookmark" to the action box menu and wiring to their respective ac… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Applied review comments. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/toolbar/action_box_menu_model.cc
diff --git a/chrome/browser/ui/toolbar/action_box_menu_model.cc b/chrome/browser/ui/toolbar/action_box_menu_model.cc
index 8148598dc8974f8d53d889a42e3654e9892e40e3..afca65abb1789e512058ef195c948ebe980afde0 100644
--- a/chrome/browser/ui/toolbar/action_box_menu_model.cc
+++ b/chrome/browser/ui/toolbar/action_box_menu_model.cc
@@ -5,30 +5,72 @@
#include "chrome/browser/ui/toolbar/action_box_menu_model.h"
#include "base/utf_string_conversions.h"
+#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/extensions/extension_toolbar_model.h"
+#include "grit/generated_resources.h"
+#include "grit/theme_resources.h"
+#include "ui/base/resource/resource_bundle.h"
-// Arbitrary number just to leave enough space for menu IDs
-// that show before extensions. Like "Bookmark this page", "Send tab to device"
-// and so on. They could have any IDs < kFirstExtensionCommandId.
-static const int kFirstExtensionCommandId = 1000;
+namespace {
+
+// Extensions get command IDs that are beyond the maximal valid extension ID
+// (0xDFFF) so that they are not confused with actual commands that appear in
+// the menu. For more details see: chrome/app/chrome_command_ids.h
+//
+const int kFirstExtensionCommandId = 0xE000;
+
+} // namespace
////////////////////////////////////////////////////////////////////////////////
// ActionBoxMenuModel
-ActionBoxMenuModel::ActionBoxMenuModel(ExtensionService* extension_service)
- : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(NULL)),
+ActionBoxMenuModel::ActionBoxMenuModel(Browser* browser,
+ ExtensionService* extension_service)
+ : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)),
+ browser_(browser),
extension_service_(extension_service) {
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ InsertItemWithStringIdAt(0, IDC_CHROME_TO_MOBILE_PAGE,
+ IDS_CHROME_TO_MOBILE_BUBBLE_TOOLTIP);
+ SetIcon(0, *rb.GetImageSkiaNamed(IDR_MOBILE));
+ InsertItemWithStringIdAt(1, IDC_BOOKMARK_PAGE, IDS_BOOKMARK_STAR);
+ SetIcon(1, *rb.GetImageSkiaNamed(IDR_STAR));
+
// Adds extensions to the model.
int command_id = kFirstExtensionCommandId;
const extensions::ExtensionList& action_box_items = action_box_menu_items();
- for (size_t i = 0; i < action_box_items.size(); ++i) {
- const extensions::Extension* extension = action_box_items[i];
- AddItem(command_id, UTF8ToUTF16(extension->name()));
- id_to_extension_id_map_[command_id++] = extension->id();
+ if (!action_box_items.empty()) {
+ AddSeparator();
+ for (size_t i = 0; i < action_box_items.size(); ++i) {
+ const extensions::Extension* extension = action_box_items[i];
+ AddItem(command_id, UTF8ToUTF16(extension->name()));
+ id_to_extension_id_map_[command_id++] = extension->id();
+ }
}
}
ActionBoxMenuModel::~ActionBoxMenuModel() {
+ // Ensures parent destructor does not use a partially destroyed delegate.
+ set_delegate(NULL);
+}
+
+bool ActionBoxMenuModel::IsCommandIdChecked(int command_id) const {
+ return false;
+}
+
+bool ActionBoxMenuModel::IsCommandIdEnabled(int command_id) const {
+ return true;
+}
+
+bool ActionBoxMenuModel::GetAcceleratorForCommandId(
+ int command_id,
+ ui::Accelerator* accelerator) {
+ return false;
+}
+
+void ActionBoxMenuModel::ExecuteCommand(int command_id) {
+ if (command_id < kFirstExtensionCommandId)
+ chrome::ExecuteCommand(browser_, command_id);
}
void ActionBoxMenuModel::Observe(int type,
« no previous file with comments | « chrome/browser/ui/toolbar/action_box_menu_model.h ('k') | chrome/browser/ui/views/location_bar/action_box_button_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698