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

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"
9 #include "chrome/browser/extensions/extension_toolbar_model.h" 12 #include "chrome/browser/extensions/extension_toolbar_model.h"
13 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" 14 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
11 #include "chrome/browser/ui/browser_tabstrip.h" 15 #include "chrome/browser/ui/browser_tabstrip.h"
12 #include "chrome/browser/ui/tab_contents/tab_contents.h" 16 #include "chrome/browser/ui/tab_contents/tab_contents.h"
13 #include "grit/generated_resources.h" 17 #include "grit/generated_resources.h"
14 #include "grit/theme_resources.h" 18 #include "grit/theme_resources.h"
15 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
16 20
17 namespace { 21 namespace {
18 22
19 // Extensions get command IDs that are beyond the maximal valid extension ID 23 // 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 24 // (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 25 // the menu. For more details see: chrome/app/chrome_command_ids.h
22 // 26 //
23 const int kFirstExtensionCommandId = 0xE000; 27 const int kFirstExtensionCommandId = 0xE000;
24 28
25 } // namespace 29 } // namespace
26 30
27 //////////////////////////////////////////////////////////////////////////////// 31 ////////////////////////////////////////////////////////////////////////////////
28 // ActionBoxMenuModel 32 // ActionBoxMenuModel
29 33
30 ActionBoxMenuModel::ActionBoxMenuModel(Browser* browser, 34 ActionBoxMenuModel::ActionBoxMenuModel(Browser* browser)
31 ExtensionService* extension_service)
32 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), 35 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)),
33 browser_(browser), 36 browser_(browser) {
34 extension_service_(extension_service) {
35 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 37 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
36 InsertItemWithStringIdAt(0, IDC_CHROME_TO_MOBILE_PAGE, 38 if (ChromeToMobileService::IsChromeToMobileEnabled() &&
37 IDS_CHROME_TO_MOBILE_BUBBLE_TOOLTIP); 39 ChromeToMobileServiceFactory::GetForProfile(browser_->profile())->
38 SetIcon(0, rb.GetNativeImageNamed(IDR_MOBILE)); 40 HasMobiles()) {
39 41 AddItemWithStringId(IDC_CHROME_TO_MOBILE_PAGE,
40 TabContents* current_tab_contents = chrome::GetActiveTabContents(browser); 42 IDS_CHROME_TO_MOBILE_BUBBLE_TOOLTIP);
43 SetIcon(GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE),
44 rb.GetNativeImageNamed(IDR_MOBILE));
45 }
46 TabContents* current_tab_contents = chrome::GetActiveTabContents(browser_);
41 bool starred = current_tab_contents->bookmark_tab_helper()->is_starred(); 47 bool starred = current_tab_contents->bookmark_tab_helper()->is_starred();
42 InsertItemWithStringIdAt(1, IDC_BOOKMARK_PAGE, 48 AddItemWithStringId(IDC_BOOKMARK_PAGE,
43 starred ? IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR); 49 starred ? IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR);
44 SetIcon(1, rb.GetNativeImageNamed(starred ? IDR_STAR_LIT : IDR_STAR)); 50 SetIcon(GetIndexOfCommandId(IDC_BOOKMARK_PAGE),
51 rb.GetNativeImageNamed(starred ? IDR_STAR_LIT : IDR_STAR));
45 52
46 // Adds extensions to the model. 53 // Adds extensions to the model.
47 int command_id = kFirstExtensionCommandId; 54 int command_id = kFirstExtensionCommandId;
48 const extensions::ExtensionList& action_box_items = action_box_menu_items(); 55 const extensions::ExtensionList& action_box_items = action_box_menu_items();
49 if (!action_box_items.empty()) { 56 if (!action_box_items.empty()) {
50 AddSeparator(ui::NORMAL_SEPARATOR); 57 AddSeparator(ui::NORMAL_SEPARATOR);
51 for (size_t i = 0; i < action_box_items.size(); ++i) { 58 for (size_t i = 0; i < action_box_items.size(); ++i) {
52 const extensions::Extension* extension = action_box_items[i]; 59 const extensions::Extension* extension = action_box_items[i];
53 AddItem(command_id, UTF8ToUTF16(extension->name())); 60 AddItem(command_id, UTF8ToUTF16(extension->name()));
54 id_to_extension_id_map_[command_id++] = extension->id(); 61 id_to_extension_id_map_[command_id++] = extension->id();
(...skipping 13 matching lines...) Expand all
68 const extensions::Extension* ActionBoxMenuModel::GetExtensionAt(int index) { 75 const extensions::Extension* ActionBoxMenuModel::GetExtensionAt(int index) {
69 if (!IsItemExtension(index)) 76 if (!IsItemExtension(index))
70 return NULL; 77 return NULL;
71 78
72 // ExtensionList is mutable, so need to get up-to-date extension. 79 // ExtensionList is mutable, so need to get up-to-date extension.
73 int command_id = GetCommandIdAt(index); 80 int command_id = GetCommandIdAt(index);
74 IdToEntensionIdMap::const_iterator it = 81 IdToEntensionIdMap::const_iterator it =
75 id_to_extension_id_map_.find(command_id); 82 id_to_extension_id_map_.find(command_id);
76 if (it == id_to_extension_id_map_.end()) 83 if (it == id_to_extension_id_map_.end())
77 return NULL; 84 return NULL;
78 85 ExtensionService* extension_service =
79 return extension_service_->GetExtensionById(it->second, false); 86 extensions::ExtensionSystem::Get(browser_->profile())->
87 extension_service();
88 return extension_service->GetExtensionById(it->second, false);
80 } 89 }
81 90
82 bool ActionBoxMenuModel::IsCommandIdChecked(int command_id) const { 91 bool ActionBoxMenuModel::IsCommandIdChecked(int command_id) const {
83 return false; 92 return false;
84 } 93 }
85 94
86 bool ActionBoxMenuModel::IsCommandIdEnabled(int command_id) const { 95 bool ActionBoxMenuModel::IsCommandIdEnabled(int command_id) const {
87 return true; 96 return true;
88 } 97 }
89 98
90 bool ActionBoxMenuModel::GetAcceleratorForCommandId( 99 bool ActionBoxMenuModel::GetAcceleratorForCommandId(
91 int command_id, 100 int command_id,
92 ui::Accelerator* accelerator) { 101 ui::Accelerator* accelerator) {
93 return false; 102 return false;
94 } 103 }
95 104
96 void ActionBoxMenuModel::ExecuteCommand(int command_id) { 105 void ActionBoxMenuModel::ExecuteCommand(int command_id) {
97 if (command_id < kFirstExtensionCommandId) 106 if (command_id < kFirstExtensionCommandId)
98 chrome::ExecuteCommand(browser_, command_id); 107 chrome::ExecuteCommand(browser_, command_id);
99 } 108 }
100 109
101 void ActionBoxMenuModel::Observe(int type, 110 void ActionBoxMenuModel::Observe(int type,
102 const content::NotificationSource& source, 111 const content::NotificationSource& source,
103 const content::NotificationDetails& details) { 112 const content::NotificationDetails& details) {
104 } 113 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698