Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/toolbar/action_box_menu_model.h" | 5 #include "chrome/browser/ui/toolbar/action_box_menu_model.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/app/chrome_command_ids.h" | |
| 8 #include "chrome/browser/extensions/extension_toolbar_model.h" | 9 #include "chrome/browser/extensions/extension_toolbar_model.h" |
| 10 #include "grit/generated_resources.h" | |
| 11 #include "grit/theme_resources.h" | |
| 12 #include "ui/base/resource/resource_bundle.h" | |
| 9 | 13 |
| 10 // Arbitrary number just to leave enough space for menu IDs | 14 namespace { |
| 11 // that show before extensions. Like "Bookmark this page", "Send tab to device" | 15 |
| 12 // and so on. They could have any IDs < kFirstExtensionCommandId. | 16 // Extensions get command IDs that are beyond the maximal valid extension ID |
| 13 static const int kFirstExtensionCommandId = 1000; | 17 // (0xDFFF) so that they are not confused with actual commands that appear in |
| 18 // the menu. For more details see: chrome/app/chrome_command_ids.h | |
| 19 // | |
| 20 static const int kFirstExtensionCommandId = 0xE000; | |
|
Scott Hess - ex-Googler
2012/08/13 18:54:43
No need for static in anonymous namespace.
beaudoin
2012/08/17 20:04:21
Done.
| |
| 21 | |
| 22 } // namespace | |
| 14 | 23 |
| 15 //////////////////////////////////////////////////////////////////////////////// | 24 //////////////////////////////////////////////////////////////////////////////// |
| 16 // ActionBoxMenuModel | 25 // ActionBoxMenuModel |
| 17 | 26 |
| 18 ActionBoxMenuModel::ActionBoxMenuModel(ExtensionService* extension_service) | 27 ActionBoxMenuModel::ActionBoxMenuModel(Browser* browser, |
| 19 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(NULL)), | 28 ExtensionService* extension_service) |
| 29 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), | |
| 30 browser_(browser), | |
| 20 extension_service_(extension_service) { | 31 extension_service_(extension_service) { |
| 32 | |
|
Scott Hess - ex-Googler
2012/08/13 18:54:43
No need for this empty line.
beaudoin
2012/08/17 20:04:21
Done.
| |
| 33 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 34 InsertItemWithStringIdAt(0, IDC_CHROME_TO_MOBILE_PAGE, | |
| 35 IDS_CHROME_TO_MOBILE_BUBBLE_TOOLTIP); | |
| 36 SetIcon(0, *rb.GetImageSkiaNamed(IDR_MOBILE)); | |
| 37 InsertItemWithStringIdAt(1, IDC_BOOKMARK_PAGE, IDS_BOOKMARK_STAR); | |
| 38 SetIcon(1, *rb.GetImageSkiaNamed(IDR_STAR)); | |
| 39 | |
| 21 // Adds extensions to the model. | 40 // Adds extensions to the model. |
| 22 int command_id = kFirstExtensionCommandId; | 41 int command_id = kFirstExtensionCommandId; |
| 23 const extensions::ExtensionList& action_box_items = action_box_menu_items(); | 42 const extensions::ExtensionList& action_box_items = action_box_menu_items(); |
| 43 if (action_box_items.size() > 0) | |
|
Scott Hess - ex-Googler
2012/08/13 18:54:43
Might as well put the for() loop in here at this p
beaudoin
2012/08/17 20:04:21
Done.
| |
| 44 InsertSeparatorAt(2); | |
|
Scott Hess - ex-Googler
2012/08/13 18:54:43
Could this be coded as "Insert separator at the en
beaudoin
2012/08/17 20:04:21
Done.
| |
| 24 for (size_t i = 0; i < action_box_items.size(); ++i) { | 45 for (size_t i = 0; i < action_box_items.size(); ++i) { |
| 25 const extensions::Extension* extension = action_box_items[i]; | 46 const extensions::Extension* extension = action_box_items[i]; |
| 26 AddItem(command_id, UTF8ToUTF16(extension->name())); | 47 AddItem(command_id, UTF8ToUTF16(extension->name())); |
| 27 id_to_extension_id_map_[command_id++] = extension->id(); | 48 id_to_extension_id_map_[command_id++] = extension->id(); |
| 28 } | 49 } |
| 29 } | 50 } |
| 30 | 51 |
| 31 ActionBoxMenuModel::~ActionBoxMenuModel() { | 52 ActionBoxMenuModel::~ActionBoxMenuModel() { |
| 32 } | 53 } |
|
Scott Hess - ex-Googler
2012/08/13 18:54:43
Does SimpleMenuModel() support clearing the delega
beaudoin
2012/08/17 20:04:21
Done.
| |
| 33 | 54 |
| 55 bool ActionBoxMenuModel::IsCommandIdChecked(int command_id) const { | |
| 56 return false; | |
| 57 } | |
| 58 | |
| 59 bool ActionBoxMenuModel::IsCommandIdEnabled(int command_id) const { | |
| 60 return true; | |
| 61 } | |
| 62 | |
| 63 bool ActionBoxMenuModel::GetAcceleratorForCommandId( | |
| 64 int command_id, | |
| 65 ui::Accelerator* accelerator) { | |
| 66 return false; | |
| 67 } | |
| 68 | |
| 69 void ActionBoxMenuModel::ExecuteCommand(int command_id) { | |
| 70 if (command_id < kFirstExtensionCommandId) | |
| 71 chrome::ExecuteCommand(browser_, command_id); | |
| 72 } | |
| 73 | |
| 34 void ActionBoxMenuModel::Observe(int type, | 74 void ActionBoxMenuModel::Observe(int type, |
| 35 const content::NotificationSource& source, | 75 const content::NotificationSource& source, |
| 36 const content::NotificationDetails& details) { | 76 const content::NotificationDetails& details) { |
| 37 } | 77 } |
| OLD | NEW |