summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/ui')
-rw-r--r--chrome/browser/ui/browser_command_controller.cc27
-rw-r--r--chrome/browser/ui/browser_command_controller.h7
-rw-r--r--chrome/browser/ui/browser_command_controller_unittest.cc35
-rw-r--r--chrome/browser/ui/cocoa/browser_window_controller.mm8
-rw-r--r--chrome/browser/ui/cocoa/panels/panel_cocoa_unittest.mm7
-rw-r--r--chrome/browser/ui/toolbar/wrench_menu_model.cc71
-rw-r--r--chrome/browser/ui/toolbar/wrench_menu_model.h1
-rw-r--r--chrome/browser/ui/views/toolbar/toolbar_view.cc8
8 files changed, 160 insertions, 4 deletions
diff --git a/chrome/browser/ui/browser_command_controller.cc b/chrome/browser/ui/browser_command_controller.cc
index c007a8e..abb1233 100644
--- a/chrome/browser/ui/browser_command_controller.cc
+++ b/chrome/browser/ui/browser_command_controller.cc
@@ -229,6 +229,11 @@ BrowserCommandController::BrowserCommandController(Browser* browser)
base::Bind(&BrowserCommandController::UpdateCommandsForFullscreenMode,
base::Unretained(this)));
#endif
+ pref_signin_allowed_.Init(
+ prefs::kSigninAllowed,
+ profile()->GetOriginalProfile()->GetPrefs(),
+ base::Bind(&BrowserCommandController::OnSigninAllowedPrefChange,
+ base::Unretained(this)));
InitCommandState();
@@ -759,6 +764,9 @@ void BrowserCommandController::ExecuteCommandWithDisposition(
case IDC_HELP_PAGE_VIA_MENU:
ShowHelp(browser_, HELP_SOURCE_MENU);
break;
+ case IDC_SHOW_SIGNIN:
+ ShowBrowserSigninOrSettings(browser_, signin_metrics::SOURCE_MENU);
+ break;
case IDC_TOGGLE_SPEECH_INPUT:
ToggleSpeechInput(browser_);
break;
@@ -777,6 +785,16 @@ void BrowserCommandController::ExecuteCommandWithDisposition(
}
}
+////////////////////////////////////////////////////////////////////////////////
+// BrowserCommandController, SigninPrefObserver implementation:
+
+void BrowserCommandController::OnSigninAllowedPrefChange() {
+ // For unit tests, we don't have a window.
+ if (!window())
+ return;
+ UpdateShowSyncState(IsShowingMainUI());
+}
+
// BrowserCommandController, TabStripModelObserver implementation:
void BrowserCommandController::TabInsertedAt(WebContents* contents,
@@ -966,6 +984,8 @@ void BrowserCommandController::InitCommandState() {
}
#endif
+ UpdateShowSyncState(true);
+
// Navigation commands
command_updater_.UpdateCommandEnabled(
IDC_HOME,
@@ -1050,6 +1070,7 @@ void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito);
command_updater->UpdateCommandEnabled(IDC_OPTIONS,
!forced_incognito || guest_session);
+ command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito);
}
void BrowserCommandController::UpdateCommandsForIncognitoAvailability() {
@@ -1228,6 +1249,7 @@ void BrowserCommandController::UpdateCommandsForFullscreenMode() {
#if defined(GOOGLE_CHROME_BUILD)
command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui);
#endif
+ UpdateShowSyncState(show_main_ui);
// Settings page/subpages are forced to open in normal mode. We disable these
// commands for guest sessions and when incognito is forced.
@@ -1277,6 +1299,11 @@ void BrowserCommandController::UpdateSaveAsState() {
command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_));
}
+void BrowserCommandController::UpdateShowSyncState(bool show_main_ui) {
+ command_updater_.UpdateCommandEnabled(
+ IDC_SHOW_SYNC_SETUP, show_main_ui && pref_signin_allowed_.GetValue());
+}
+
// static
void BrowserCommandController::UpdateOpenFileState(
CommandUpdater* command_updater) {
diff --git a/chrome/browser/ui/browser_command_controller.h b/chrome/browser/ui/browser_command_controller.h
index 0e564c0..05ec35a 100644
--- a/chrome/browser/ui/browser_command_controller.h
+++ b/chrome/browser/ui/browser_command_controller.h
@@ -140,9 +140,15 @@ class BrowserCommandController : public CommandUpdaterDelegate,
// Updates the printing command state.
void UpdatePrintingState();
+ // Updates the SHOW_SYNC_SETUP menu entry.
+ void OnSigninAllowedPrefChange();
+
// Updates the save-page-as command state.
void UpdateSaveAsState();
+ // Updates the show-sync command state.
+ void UpdateShowSyncState(bool show_main_ui);
+
// Ask the Reload/Stop button to change its icon, and update the Stop command
// state. |is_loading| is true if the current WebContents is loading.
// |force| is true if the button should change its icon immediately.
@@ -179,6 +185,7 @@ class BrowserCommandController : public CommandUpdaterDelegate,
PrefChangeRegistrar profile_pref_registrar_;
PrefChangeRegistrar local_pref_registrar_;
+ BooleanPrefMember pref_signin_allowed_;
DISALLOW_COPY_AND_ASSIGN(BrowserCommandController);
};
diff --git a/chrome/browser/ui/browser_command_controller_unittest.cc b/chrome/browser/ui/browser_command_controller_unittest.cc
index 4629624..a80c758 100644
--- a/chrome/browser/ui/browser_command_controller_unittest.cc
+++ b/chrome/browser/ui/browser_command_controller_unittest.cc
@@ -139,6 +139,7 @@ TEST_F(BrowserCommandControllerTest, IsReservedCommandOrKeyIsApp) {
TEST_F(BrowserCommandControllerTest, IncognitoCommands) {
EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS));
EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS));
+ EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_SHOW_SIGNIN));
TestingProfile* testprofile = browser()->profile()->AsTestingProfile();
EXPECT_TRUE(testprofile);
@@ -148,6 +149,7 @@ TEST_F(BrowserCommandControllerTest, IncognitoCommands) {
browser()->command_controller()->command_updater(), testprofile);
EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS));
EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS));
+ EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_SHOW_SIGNIN));
testprofile->SetGuestSession(false);
IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(),
@@ -157,6 +159,7 @@ TEST_F(BrowserCommandControllerTest, IncognitoCommands) {
browser()->command_controller()->command_updater(), testprofile);
EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS));
EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS));
+ EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_SHOW_SIGNIN));
}
TEST_F(BrowserCommandControllerTest, AppFullScreen) {
@@ -418,3 +421,35 @@ TEST_F(BrowserCommandControllerFullscreenTest,
EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS));
EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS));
}
+
+TEST_F(BrowserCommandControllerTest, IncognitoModeOnSigninAllowedPrefChange) {
+ // Set up a profile with an off the record profile.
+ scoped_ptr<TestingProfile> profile1 = TestingProfile::Builder().Build();
+ Profile* profile2 = profile1->GetOffTheRecordProfile();
+
+ EXPECT_EQ(profile2->GetOriginalProfile(), profile1.get());
+
+ // Create a new browser based on the off the record profile.
+ Browser::CreateParams profile_params(profile1->GetOffTheRecordProfile(),
+ chrome::GetActiveDesktop());
+ scoped_ptr<Browser> browser2(
+ chrome::CreateBrowserWithTestWindowForParams(&profile_params));
+
+ chrome::BrowserCommandController command_controller(browser2.get());
+ const CommandUpdater* command_updater = command_controller.command_updater();
+
+ // Check that the SYNC_SETUP command is updated on preference change.
+ EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP));
+ profile1->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false);
+ EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP));
+}
+
+TEST_F(BrowserCommandControllerTest, OnSigninAllowedPrefChange) {
+ chrome::BrowserCommandController command_controller(browser());
+ const CommandUpdater* command_updater = command_controller.command_updater();
+
+ // Check that the SYNC_SETUP command is updated on preference change.
+ EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP));
+ profile()->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false);
+ EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP));
+}
diff --git a/chrome/browser/ui/cocoa/browser_window_controller.mm b/chrome/browser/ui/cocoa/browser_window_controller.mm
index 4598c96..b86492f 100644
--- a/chrome/browser/ui/cocoa/browser_window_controller.mm
+++ b/chrome/browser/ui/cocoa/browser_window_controller.mm
@@ -1148,6 +1148,14 @@ using content::WebContents;
}
break;
}
+ case IDC_SHOW_SIGNIN: {
+ Profile* original_profile =
+ browser_->profile()->GetOriginalProfile();
+ [AppController updateSigninItem:item
+ shouldShow:enable
+ currentProfile:original_profile];
+ break;
+ }
case IDC_BOOKMARK_PAGE: {
// Extensions have the ability to hide the bookmark page menu item.
// This only affects the bookmark page menu item under the main menu.
diff --git a/chrome/browser/ui/cocoa/panels/panel_cocoa_unittest.mm b/chrome/browser/ui/cocoa/panels/panel_cocoa_unittest.mm
index a11e498..1e3f17f 100644
--- a/chrome/browser/ui/cocoa/panels/panel_cocoa_unittest.mm
+++ b/chrome/browser/ui/cocoa/panels/panel_cocoa_unittest.mm
@@ -308,6 +308,7 @@ TEST_F(PanelCocoaTest, MenuItems) {
NSMenuItem* fullscreen_menu_item = CreateMenuItem(menu, IDC_FULLSCREEN);
NSMenuItem* presentation_menu_item =
CreateMenuItem(menu, IDC_PRESENTATION_MODE);
+ NSMenuItem* sync_menu_item = CreateMenuItem(menu, IDC_SHOW_SYNC_SETUP);
NSMenuItem* dev_tools_item = CreateMenuItem(menu, IDC_DEV_TOOLS);
NSMenuItem* dev_tools_console_item =
CreateMenuItem(menu, IDC_DEV_TOOLS_CONSOLE);
@@ -326,6 +327,7 @@ TEST_F(PanelCocoaTest, MenuItems) {
EXPECT_FALSE([find_next_menu_item isEnabled]);
EXPECT_FALSE([fullscreen_menu_item isEnabled]);
EXPECT_FALSE([presentation_menu_item isEnabled]);
+ EXPECT_FALSE([sync_menu_item isEnabled]);
// These are not enabled by Panel, so they are expected to be disabled for
// this unit_test. In real Chrome app, they are enabled by Chrome NSApp
// controller. PanelCocoaBrowsertest.MenuItems verifies that.
@@ -336,6 +338,11 @@ TEST_F(PanelCocoaTest, MenuItems) {
EXPECT_TRUE([dev_tools_item isEnabled]);
EXPECT_TRUE([dev_tools_console_item isEnabled]);
+ // Verify that commandDispatch on an invalid menu item does not crash.
+ [NSApp sendAction:[sync_menu_item action]
+ to:[sync_menu_item target]
+ from:sync_menu_item];
+
ClosePanelAndWait(panel);
}
diff --git a/chrome/browser/ui/toolbar/wrench_menu_model.cc b/chrome/browser/ui/toolbar/wrench_menu_model.cc
index b3ffec0..5f9ca12 100644
--- a/chrome/browser/ui/toolbar/wrench_menu_model.cc
+++ b/chrome/browser/ui/toolbar/wrench_menu_model.cc
@@ -366,7 +366,8 @@ bool WrenchMenuModel::IsItemForCommandIdDynamic(int command_id) const {
#elif defined(OS_WIN)
command_id == IDC_PIN_TO_START_SCREEN ||
#endif
- command_id == IDC_UPGRADE_DIALOG;
+ command_id == IDC_UPGRADE_DIALOG ||
+ (!switches::IsNewAvatarMenu() && command_id == IDC_SHOW_SIGNIN);
}
base::string16 WrenchMenuModel::GetLabelForCommandId(int command_id) const {
@@ -396,6 +397,10 @@ base::string16 WrenchMenuModel::GetLabelForCommandId(int command_id) const {
#endif
case IDC_UPGRADE_DIALOG:
return GetUpgradeDialogMenuItemName();
+ case IDC_SHOW_SIGNIN:
+ DCHECK(!switches::IsNewAvatarMenu());
+ return signin_ui_util::GetSigninMenuLabel(
+ browser_->profile()->GetOriginalProfile());
default:
NOTREACHED();
return base::string16();
@@ -414,6 +419,19 @@ bool WrenchMenuModel::GetIconForCommandId(int command_id,
}
return false;
}
+ case IDC_SHOW_SIGNIN: {
+ DCHECK(!switches::IsNewAvatarMenu());
+ GlobalError* error = signin_ui_util::GetSignedInServiceError(
+ browser_->profile()->GetOriginalProfile());
+ if (error) {
+ int icon_id = error->MenuItemIconResourceID();
+ if (icon_id) {
+ *icon = rb.GetNativeImageNamed(icon_id);
+ return true;
+ }
+ }
+ return false;
+ }
default:
break;
}
@@ -428,6 +446,16 @@ void WrenchMenuModel::ExecuteCommand(int command_id, int event_flags) {
return;
}
+ if (!switches::IsNewAvatarMenu() && command_id == IDC_SHOW_SIGNIN) {
+ // If a custom error message is being shown, handle it.
+ GlobalError* error = signin_ui_util::GetSignedInServiceError(
+ browser_->profile()->GetOriginalProfile());
+ if (error) {
+ error->ExecuteMenuItem(browser_);
+ return;
+ }
+ }
+
LogMenuMetrics(command_id);
chrome::ExecuteCommand(browser_, command_id);
}
@@ -672,6 +700,13 @@ void WrenchMenuModel::LogMenuMetrics(int command_id) {
}
LogMenuAction(MENU_ACTION_SHOW_DOWNLOADS);
break;
+ case IDC_SHOW_SYNC_SETUP:
+ if (!uma_action_recorded_) {
+ UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction.ShowSyncSetup",
+ delta);
+ }
+ LogMenuAction(MENU_ACTION_SHOW_SYNC_SETUP);
+ break;
case IDC_OPTIONS:
if (!uma_action_recorded_)
UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction.Settings", delta);
@@ -895,7 +930,21 @@ void WrenchMenuModel::Build() {
CreateCutCopyPasteMenu();
AddItemWithStringId(IDC_OPTIONS, IDS_SETTINGS);
-
+#if !defined(OS_CHROMEOS)
+ if (!switches::IsNewAvatarMenu()) {
+ // No "Sign in to Chromium..." menu item on ChromeOS.
+ SigninManager* signin = SigninManagerFactory::GetForProfile(
+ browser_->profile()->GetOriginalProfile());
+ if (signin && signin->IsSigninAllowed() &&
+ signin_ui_util::GetSignedInServiceErrors(
+ browser_->profile()->GetOriginalProfile()).empty()) {
+ AddItem(IDC_SHOW_SYNC_SETUP,
+ l10n_util::GetStringFUTF16(
+ IDS_SYNC_MENU_PRE_SYNCED_LABEL,
+ l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)));
+ }
+ }
+#endif
// The help submenu is only displayed on official Chrome builds. As the
// 'About' item has been moved to this submenu, it's reinstated here for
// Chromium builds.
@@ -941,6 +990,11 @@ bool WrenchMenuModel::AddGlobalErrorMenuItems() {
// it won't show in the existing wrench menu. To fix this we need to some
// how update the menu if new errors are added.
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ // GetSignedInServiceErrors() can modify the global error list, so call it
+ // before iterating through that list below.
+ std::vector<GlobalError*> signin_errors;
+ signin_errors = signin_ui_util::GetSignedInServiceErrors(
+ browser_->profile()->GetOriginalProfile());
const GlobalErrorService::GlobalErrorList& errors =
GlobalErrorServiceFactory::GetForProfile(browser_->profile())->errors();
bool menu_items_added = false;
@@ -949,6 +1003,19 @@ bool WrenchMenuModel::AddGlobalErrorMenuItems() {
GlobalError* error = *it;
DCHECK(error);
if (error->HasMenuItem()) {
+#if !defined(OS_CHROMEOS)
+ // Don't add a signin error if it's already being displayed elsewhere.
+ if (std::find(signin_errors.begin(), signin_errors.end(), error) !=
+ signin_errors.end()) {
+ MenuModel* model = this;
+ int index = 0;
+ if (MenuModel::GetModelAndIndexForCommandId(
+ IDC_SHOW_SIGNIN, &model, &index)) {
+ continue;
+ }
+ }
+#endif
+
AddItem(error->MenuItemCommandID(), error->MenuItemLabel());
int icon_id = error->MenuItemIconResourceID();
if (icon_id) {
diff --git a/chrome/browser/ui/toolbar/wrench_menu_model.h b/chrome/browser/ui/toolbar/wrench_menu_model.h
index 1753e66..525f47d 100644
--- a/chrome/browser/ui/toolbar/wrench_menu_model.h
+++ b/chrome/browser/ui/toolbar/wrench_menu_model.h
@@ -62,6 +62,7 @@ enum WrenchMenuAction {
MENU_ACTION_FULLSCREEN,
MENU_ACTION_SHOW_HISTORY,
MENU_ACTION_SHOW_DOWNLOADS,
+ MENU_ACTION_SHOW_SYNC_SETUP,
MENU_ACTION_OPTIONS,
MENU_ACTION_ABOUT,
MENU_ACTION_HELP_PAGE_VIA_MENU,
diff --git a/chrome/browser/ui/views/toolbar/toolbar_view.cc b/chrome/browser/ui/views/toolbar/toolbar_view.cc
index 14fa652..5f1b2a6 100644
--- a/chrome/browser/ui/views/toolbar/toolbar_view.cc
+++ b/chrome/browser/ui/views/toolbar/toolbar_view.cc
@@ -79,6 +79,7 @@
#endif
#if !defined(OS_CHROMEOS)
+#include "chrome/browser/signin/signin_global_error_factory.h"
#include "chrome/browser/sync/sync_global_error_factory.h"
#endif
@@ -219,15 +220,18 @@ void ToolbarView::Init() {
LoadImages();
// Start global error services now so we badge the menu correctly.
-#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
+#if !defined(OS_CHROMEOS)
if (!HasAshShell()) {
+ SigninGlobalErrorFactory::GetForProfile(browser_->profile());
+#if !defined(OS_ANDROID)
SyncGlobalErrorFactory::GetForProfile(browser_->profile());
- }
#endif
+ }
#if defined(OS_WIN)
RecoveryInstallGlobalErrorFactory::GetForProfile(browser_->profile());
#endif
+#endif // OS_CHROMEOS
// Add any necessary badges to the menu item based on the system state.
// Do this after |app_menu_| has been added as a bubble may be shown that