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

Side by Side Diff: chrome/browser/ui/toolbar/action_box_menu_model.cc

Issue 10887029: Only show chrome2mobile in action box if it is enabled (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/app/chrome_command_ids.h"
9 #include "chrome/browser/chrome_to_mobile_service.h"
10 #include "chrome/browser/chrome_to_mobile_service_factory.h"
11 #include "chrome/browser/command_updater.h"
12 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/extensions/extension_system.h"
9 #include "chrome/browser/extensions/extension_toolbar_model.h" 14 #include "chrome/browser/extensions/extension_toolbar_model.h"
15 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" 16 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
17 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/browser_commands.h"
11 #include "chrome/browser/ui/browser_tabstrip.h" 19 #include "chrome/browser/ui/browser_tabstrip.h"
12 #include "chrome/browser/ui/tab_contents/tab_contents.h" 20 #include "chrome/browser/ui/tab_contents/tab_contents.h"
13 #include "grit/generated_resources.h" 21 #include "grit/generated_resources.h"
14 #include "grit/theme_resources.h" 22 #include "grit/theme_resources.h"
15 #include "ui/base/resource/resource_bundle.h" 23 #include "ui/base/resource/resource_bundle.h"
16 24
17 namespace { 25 namespace {
18 26
19 // Extensions get command IDs that are beyond the maximal valid extension ID 27 // Extensions get command IDs that are beyond the maximal valid extension ID
20 // (0xDFFF) so that they are not confused with actual commands that appear in 28 // (0xDFFF) so that they are not confused with actual commands that appear in
21 // the menu. For more details see: chrome/app/chrome_command_ids.h 29 // the menu. For more details see: chrome/app/chrome_command_ids.h
22 // 30 //
23 const int kFirstExtensionCommandId = 0xE000; 31 const int kFirstExtensionCommandId = 0xE000;
24 32
25 } // namespace 33 } // namespace
26 34
27 //////////////////////////////////////////////////////////////////////////////// 35 ////////////////////////////////////////////////////////////////////////////////
28 // ActionBoxMenuModel 36 // ActionBoxMenuModel
29 37
30 ActionBoxMenuModel::ActionBoxMenuModel(Browser* browser, 38 ActionBoxMenuModel::ActionBoxMenuModel(Browser* browser)
31 ExtensionService* extension_service)
32 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), 39 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)),
33 browser_(browser), 40 browser_(browser) {
34 extension_service_(extension_service) {
35 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 41 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
36 InsertItemWithStringIdAt(0, IDC_CHROME_TO_MOBILE_PAGE, 42 if (ChromeToMobileService::IsChromeToMobileEnabled() &&
37 IDS_CHROME_TO_MOBILE_BUBBLE_TOOLTIP); 43 ChromeToMobileServiceFactory::GetForProfile(browser_->profile())->
38 SetIcon(0, rb.GetNativeImageNamed(IDR_MOBILE)); 44 HasMobiles()) {
39 45 AddItemWithStringId(IDC_CHROME_TO_MOBILE_PAGE,
40 TabContents* current_tab_contents = chrome::GetActiveTabContents(browser); 46 IDS_CHROME_TO_MOBILE_BUBBLE_TOOLTIP);
47 SetIcon(GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE),
48 rb.GetNativeImageNamed(IDR_MOBILE));
49 }
50 TabContents* current_tab_contents = chrome::GetActiveTabContents(browser_);
41 bool starred = current_tab_contents->bookmark_tab_helper()->is_starred(); 51 bool starred = current_tab_contents->bookmark_tab_helper()->is_starred();
42 InsertItemWithStringIdAt(1, IDC_BOOKMARK_PAGE, 52 AddItemWithStringId(IDC_BOOKMARK_PAGE,
43 starred ? IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR); 53 starred ? IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR);
44 SetIcon(1, rb.GetNativeImageNamed(starred ? IDR_STAR_LIT : IDR_STAR)); 54 SetIcon(GetIndexOfCommandId(IDC_BOOKMARK_PAGE),
55 rb.GetNativeImageNamed(starred ? IDR_STAR_LIT : IDR_STAR));
45 56
46 // Adds extensions to the model. 57 // Adds extensions to the model.
47 int command_id = kFirstExtensionCommandId; 58 int command_id = kFirstExtensionCommandId;
48 const extensions::ExtensionList& action_box_items = action_box_menu_items(); 59 const extensions::ExtensionList& action_box_items = GetActionBoxMenuItems();
49 if (!action_box_items.empty()) { 60 if (!action_box_items.empty()) {
50 AddSeparator(ui::NORMAL_SEPARATOR); 61 AddSeparator(ui::NORMAL_SEPARATOR);
51 for (size_t i = 0; i < action_box_items.size(); ++i) { 62 for (size_t i = 0; i < action_box_items.size(); ++i) {
52 const extensions::Extension* extension = action_box_items[i]; 63 const extensions::Extension* extension = action_box_items[i];
53 AddItem(command_id, UTF8ToUTF16(extension->name())); 64 AddItem(command_id, UTF8ToUTF16(extension->name()));
54 id_to_extension_id_map_[command_id++] = extension->id(); 65 id_to_extension_id_map_[command_id++] = extension->id();
55 } 66 }
56 } 67 }
57 } 68 }
58 69
59 ActionBoxMenuModel::~ActionBoxMenuModel() { 70 ActionBoxMenuModel::~ActionBoxMenuModel() {
60 // Ensures parent destructor does not use a partially destroyed delegate. 71 // Ensures parent destructor does not use a partially destroyed delegate.
61 set_delegate(NULL); 72 set_delegate(NULL);
62 } 73 }
63 74
64 bool ActionBoxMenuModel::IsItemExtension(int index) { 75 bool ActionBoxMenuModel::IsItemExtension(int index) {
65 return GetCommandIdAt(index) >= kFirstExtensionCommandId; 76 return GetCommandIdAt(index) >= kFirstExtensionCommandId;
66 } 77 }
67 78
68 const extensions::Extension* ActionBoxMenuModel::GetExtensionAt(int index) { 79 const extensions::Extension* ActionBoxMenuModel::GetExtensionAt(int index) {
69 if (!IsItemExtension(index)) 80 if (!IsItemExtension(index))
70 return NULL; 81 return NULL;
71 82
72 // ExtensionList is mutable, so need to get up-to-date extension. 83 // ExtensionList is mutable, so need to get up-to-date extension.
73 int command_id = GetCommandIdAt(index); 84 int command_id = GetCommandIdAt(index);
74 IdToEntensionIdMap::const_iterator it = 85 IdToEntensionIdMap::const_iterator it =
75 id_to_extension_id_map_.find(command_id); 86 id_to_extension_id_map_.find(command_id);
76 if (it == id_to_extension_id_map_.end()) 87 if (it == id_to_extension_id_map_.end())
77 return NULL; 88 return NULL;
89 ExtensionService* extension_service =
90 extensions::ExtensionSystem::Get(browser_->profile())->
91 extension_service();
92 return extension_service->GetExtensionById(it->second, false);
93 }
78 94
79 return extension_service_->GetExtensionById(it->second, false); 95 const extensions::ExtensionList& ActionBoxMenuModel::GetActionBoxMenuItems() {
msw 2012/08/30 01:47:01 This belongs below ExecuteCommand to match declara
Cait (Slow) 2012/08/30 21:46:03 Done.
96 ExtensionService* extension_service =
97 extensions::ExtensionSystem::Get(browser_->profile())->
98 extension_service();
99 return extension_service->toolbar_model()->action_box_menu_items();
80 } 100 }
81 101
82 bool ActionBoxMenuModel::IsCommandIdChecked(int command_id) const { 102 bool ActionBoxMenuModel::IsCommandIdChecked(int command_id) const {
83 return false; 103 return false;
84 } 104 }
85 105
86 bool ActionBoxMenuModel::IsCommandIdEnabled(int command_id) const { 106 bool ActionBoxMenuModel::IsCommandIdEnabled(int command_id) const {
87 return true; 107 return true;
88 } 108 }
89 109
90 bool ActionBoxMenuModel::GetAcceleratorForCommandId( 110 bool ActionBoxMenuModel::GetAcceleratorForCommandId(
91 int command_id, 111 int command_id,
92 ui::Accelerator* accelerator) { 112 ui::Accelerator* accelerator) {
93 return false; 113 return false;
94 } 114 }
95 115
96 void ActionBoxMenuModel::ExecuteCommand(int command_id) { 116 void ActionBoxMenuModel::ExecuteCommand(int command_id) {
97 if (command_id < kFirstExtensionCommandId) 117 if (command_id < kFirstExtensionCommandId)
98 chrome::ExecuteCommand(browser_, command_id); 118 chrome::ExecuteCommand(browser_, command_id);
99 } 119 }
100 120
101 void ActionBoxMenuModel::Observe(int type, 121 void ActionBoxMenuModel::Observe(int type,
102 const content::NotificationSource& source, 122 const content::NotificationSource& source,
103 const content::NotificationDetails& details) { 123 const content::NotificationDetails& details) {
104 } 124 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698