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 84af1e16ced4e9832bf9d18019a14123a8aac744..188fce7d0937f32be983f867e4719ec3d832eca4 100644 |
--- a/chrome/browser/ui/toolbar/action_box_menu_model.cc |
+++ b/chrome/browser/ui/toolbar/action_box_menu_model.cc |
@@ -6,8 +6,13 @@ |
#include "base/utf_string_conversions.h" |
#include "chrome/app/chrome_command_ids.h" |
+#include "chrome/browser/chrome_to_mobile_service.h" |
+#include "chrome/browser/chrome_to_mobile_service_factory.h" |
+#include "chrome/browser/command_updater.h" |
#include "chrome/browser/extensions/extension_toolbar_model.h" |
+#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
+#include "chrome/browser/ui/browser.h" |
#include "chrome/browser/ui/browser_tabstrip.h" |
#include "chrome/browser/ui/tab_contents/tab_contents.h" |
#include "grit/generated_resources.h" |
@@ -28,37 +33,26 @@ const int kFirstExtensionCommandId = 0xE000; |
// ActionBoxMenuModel |
ActionBoxMenuModel::ActionBoxMenuModel(Browser* browser, |
- ExtensionService* extension_service) |
+ ExtensionService* extension_service, |
+ CommandUpdater* command_updater) |
: 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.GetNativeImageNamed(IDR_MOBILE)); |
- |
- TabContents* current_tab_contents = chrome::GetActiveTabContents(browser); |
- bool starred = current_tab_contents->bookmark_tab_helper()->is_starred(); |
- InsertItemWithStringIdAt(1, IDC_BOOKMARK_PAGE, |
- starred ? IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR); |
- SetIcon(1, rb.GetNativeImageNamed(starred ? IDR_STAR_LIT : IDR_STAR)); |
- |
- // Adds extensions to the model. |
- int command_id = kFirstExtensionCommandId; |
- const extensions::ExtensionList& action_box_items = action_box_menu_items(); |
- if (!action_box_items.empty()) { |
- AddSeparator(ui::NORMAL_SEPARATOR); |
- 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(); |
- } |
+ extension_service_(extension_service), |
+ command_updater_(command_updater) { |
+ // Disable Chrome To Mobile for off-the-record and non-synced profiles, |
+ // or if the feature is disabled by a command line flag or chrome://flags. |
+ if (!browser_->profile()->IsOffTheRecord() && |
msw
2012/08/29 22:05:42
I think this should just always observe; sorry for
Cait (Slow)
2012/08/29 23:03:47
Done.
|
+ ChromeToMobileService::IsChromeToMobileEnabled()) { |
+ command_updater_->AddCommandObserver(IDC_CHROME_TO_MOBILE_PAGE, this); |
} |
+ UpdateMenu(); |
} |
ActionBoxMenuModel::~ActionBoxMenuModel() { |
// Ensures parent destructor does not use a partially destroyed delegate. |
set_delegate(NULL); |
+ // Remove command observer. |
+ command_updater_->RemoveCommandObserver(this); |
} |
bool ActionBoxMenuModel::IsItemExtension(int index) { |
@@ -102,3 +96,38 @@ void ActionBoxMenuModel::Observe(int type, |
const content::NotificationSource& source, |
const content::NotificationDetails& details) { |
} |
+ |
+void ActionBoxMenuModel::EnabledStateChangedForCommand(int id, bool enabled) { |
+ DCHECK_EQ(id, IDC_CHROME_TO_MOBILE_PAGE); |
+ UpdateMenu(); |
+} |
+ |
+void ActionBoxMenuModel::UpdateMenu() { |
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
+ if (ChromeToMobileService::IsChromeToMobileEnabled() && |
+ ChromeToMobileServiceFactory::GetForProfile(browser_->profile())-> |
+ HasMobiles()) { |
+ AddItemWithStringId(IDC_CHROME_TO_MOBILE_PAGE, |
+ IDS_CHROME_TO_MOBILE_BUBBLE_TOOLTIP); |
+ SetIcon(GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE), |
msw
2012/08/29 22:05:42
Ah, sorry my advice necessitated this roundabout w
|
+ rb.GetNativeImageNamed(IDR_MOBILE)); |
+ } |
+ TabContents* current_tab_contents = chrome::GetActiveTabContents(browser_); |
+ bool starred = current_tab_contents->bookmark_tab_helper()->is_starred(); |
+ AddItemWithStringId(IDC_BOOKMARK_PAGE, |
+ starred ? IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR); |
+ SetIcon(GetIndexOfCommandId(IDC_BOOKMARK_PAGE), |
+ rb.GetNativeImageNamed(starred ? IDR_STAR_LIT : IDR_STAR)); |
+ |
+ // Adds extensions to the model. |
+ int command_id = kFirstExtensionCommandId; |
+ const extensions::ExtensionList& action_box_items = action_box_menu_items(); |
+ if (!action_box_items.empty()) { |
+ AddSeparator(ui::NORMAL_SEPARATOR); |
+ 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(); |
+ } |
+ } |
+} |