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

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

Issue 240453006: Fix sign-in error strings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Put error in button Created 6 years, 7 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/wrench_menu_model.h" 5 #include "chrome/browser/ui/toolbar/wrench_menu_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 return command_id != IDC_ZOOM_MINUS && command_id != IDC_ZOOM_PLUS; 270 return command_id != IDC_ZOOM_MINUS && command_id != IDC_ZOOM_PLUS;
271 } 271 }
272 272
273 bool WrenchMenuModel::IsItemForCommandIdDynamic(int command_id) const { 273 bool WrenchMenuModel::IsItemForCommandIdDynamic(int command_id) const {
274 return command_id == IDC_ZOOM_PERCENT_DISPLAY || 274 return command_id == IDC_ZOOM_PERCENT_DISPLAY ||
275 #if defined(OS_MACOSX) 275 #if defined(OS_MACOSX)
276 command_id == IDC_FULLSCREEN || 276 command_id == IDC_FULLSCREEN ||
277 #elif defined(OS_WIN) 277 #elif defined(OS_WIN)
278 command_id == IDC_PIN_TO_START_SCREEN || 278 command_id == IDC_PIN_TO_START_SCREEN ||
279 #endif 279 #endif
280 command_id == IDC_UPGRADE_DIALOG || 280 command_id == IDC_UPGRADE_DIALOG;
281 command_id == IDC_SHOW_SIGNIN;
noms (inactive) 2014/05/11 19:21:25 Hmm, can we delete this already? Shouldn't we stil
Roger Tawa OOO till Jul 10th 2014/05/13 21:23:54 Nope. All changes in this file must be kept for p
noms (inactive) 2014/05/13 22:57:00 I guess what I was trying to say was: it looks lik
Roger Tawa OOO till Jul 10th 2014/05/14 14:02:13 Correct, with mirror auth errors are shown differe
282 } 281 }
283 282
284 base::string16 WrenchMenuModel::GetLabelForCommandId(int command_id) const { 283 base::string16 WrenchMenuModel::GetLabelForCommandId(int command_id) const {
285 switch (command_id) { 284 switch (command_id) {
286 case IDC_ZOOM_PERCENT_DISPLAY: 285 case IDC_ZOOM_PERCENT_DISPLAY:
287 return zoom_label_; 286 return zoom_label_;
288 #if defined(OS_MACOSX) 287 #if defined(OS_MACOSX)
289 case IDC_FULLSCREEN: { 288 case IDC_FULLSCREEN: {
290 int string_id = IDS_ENTER_FULLSCREEN_MAC; // Default to Enter. 289 int string_id = IDS_ENTER_FULLSCREEN_MAC; // Default to Enter.
291 // Note: On startup, |window()| may be NULL. 290 // Note: On startup, |window()| may be NULL.
292 if (browser_->window() && browser_->window()->IsFullscreen()) 291 if (browser_->window() && browser_->window()->IsFullscreen())
293 string_id = IDS_EXIT_FULLSCREEN_MAC; 292 string_id = IDS_EXIT_FULLSCREEN_MAC;
294 return l10n_util::GetStringUTF16(string_id); 293 return l10n_util::GetStringUTF16(string_id);
295 } 294 }
296 #elif defined(OS_WIN) 295 #elif defined(OS_WIN)
297 case IDC_PIN_TO_START_SCREEN: { 296 case IDC_PIN_TO_START_SCREEN: {
298 int string_id = IDS_PIN_TO_START_SCREEN; 297 int string_id = IDS_PIN_TO_START_SCREEN;
299 WebContents* web_contents = 298 WebContents* web_contents =
300 browser_->tab_strip_model()->GetActiveWebContents(); 299 browser_->tab_strip_model()->GetActiveWebContents();
301 MetroPinTabHelper* tab_helper = 300 MetroPinTabHelper* tab_helper =
302 web_contents ? MetroPinTabHelper::FromWebContents(web_contents) 301 web_contents ? MetroPinTabHelper::FromWebContents(web_contents)
303 : NULL; 302 : NULL;
304 if (tab_helper && tab_helper->IsPinned()) 303 if (tab_helper && tab_helper->IsPinned())
305 string_id = IDS_UNPIN_FROM_START_SCREEN; 304 string_id = IDS_UNPIN_FROM_START_SCREEN;
306 return l10n_util::GetStringUTF16(string_id); 305 return l10n_util::GetStringUTF16(string_id);
307 } 306 }
308 #endif 307 #endif
309 case IDC_UPGRADE_DIALOG: 308 case IDC_UPGRADE_DIALOG:
310 return GetUpgradeDialogMenuItemName(); 309 return GetUpgradeDialogMenuItemName();
311 case IDC_SHOW_SIGNIN:
312 return signin_ui_util::GetSigninMenuLabel(
313 browser_->profile()->GetOriginalProfile());
314 default: 310 default:
315 NOTREACHED(); 311 NOTREACHED();
316 return base::string16(); 312 return base::string16();
317 } 313 }
318 } 314 }
319 315
320 bool WrenchMenuModel::GetIconForCommandId(int command_id, 316 bool WrenchMenuModel::GetIconForCommandId(int command_id,
321 gfx::Image* icon) const { 317 gfx::Image* icon) const {
322 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 318 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
323 switch (command_id) { 319 switch (command_id) {
324 case IDC_UPGRADE_DIALOG: { 320 case IDC_UPGRADE_DIALOG: {
325 if (UpgradeDetector::GetInstance()->notify_upgrade()) { 321 if (UpgradeDetector::GetInstance()->notify_upgrade()) {
326 *icon = rb.GetNativeImageNamed( 322 *icon = rb.GetNativeImageNamed(
327 UpgradeDetector::GetInstance()->GetIconResourceID( 323 UpgradeDetector::GetInstance()->GetIconResourceID(
328 UpgradeDetector::UPGRADE_ICON_TYPE_MENU_ICON)); 324 UpgradeDetector::UPGRADE_ICON_TYPE_MENU_ICON));
329 return true; 325 return true;
330 } 326 }
331 return false; 327 return false;
332 } 328 }
333 case IDC_SHOW_SIGNIN: {
334 GlobalError* error = signin_ui_util::GetSignedInServiceError(
335 browser_->profile()->GetOriginalProfile());
336 if (error) {
337 int icon_id = error->MenuItemIconResourceID();
338 if (icon_id) {
339 *icon = rb.GetNativeImageNamed(icon_id);
340 return true;
341 }
342 }
343 return false;
344 }
345 default: 329 default:
346 break; 330 break;
347 } 331 }
348 return false; 332 return false;
349 } 333 }
350 334
351 void WrenchMenuModel::ExecuteCommand(int command_id, int event_flags) { 335 void WrenchMenuModel::ExecuteCommand(int command_id, int event_flags) {
352 GlobalError* error = GlobalErrorServiceFactory::GetForProfile( 336 GlobalError* error = GlobalErrorServiceFactory::GetForProfile(
353 browser_->profile())->GetGlobalErrorByMenuItemCommandID(command_id); 337 browser_->profile())->GetGlobalErrorByMenuItemCommandID(command_id);
354 if (error) { 338 if (error) {
355 error->ExecuteMenuItem(browser_); 339 error->ExecuteMenuItem(browser_);
356 return; 340 return;
357 } 341 }
358 342
359 if (command_id == IDC_SHOW_SIGNIN) {
360 // If a custom error message is being shown, handle it.
361 GlobalError* error = signin_ui_util::GetSignedInServiceError(
362 browser_->profile()->GetOriginalProfile());
363 if (error) {
364 error->ExecuteMenuItem(browser_);
365 return;
366 }
367 }
368
369 if (command_id == IDC_HELP_PAGE_VIA_MENU) 343 if (command_id == IDC_HELP_PAGE_VIA_MENU)
370 content::RecordAction(UserMetricsAction("ShowHelpTabViaWrenchMenu")); 344 content::RecordAction(UserMetricsAction("ShowHelpTabViaWrenchMenu"));
371 345
372 if (command_id == IDC_FULLSCREEN) { 346 if (command_id == IDC_FULLSCREEN) {
373 // We issue the UMA command here and not in BrowserCommandController or even 347 // We issue the UMA command here and not in BrowserCommandController or even
374 // FullscreenController since we want to be able to distinguish this event 348 // FullscreenController since we want to be able to distinguish this event
375 // and a menu which is under development. 349 // and a menu which is under development.
376 content::RecordAction(UserMetricsAction("EnterFullScreenWithWrenchMenu")); 350 content::RecordAction(UserMetricsAction("EnterFullScreenWithWrenchMenu"));
377 } 351 }
378 352
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 545
572 if (is_new_menu) 546 if (is_new_menu)
573 CreateZoomMenu(is_new_menu); 547 CreateZoomMenu(is_new_menu);
574 else 548 else
575 AddSeparator(ui::NORMAL_SEPARATOR); 549 AddSeparator(ui::NORMAL_SEPARATOR);
576 550
577 AddItemWithStringId(IDC_SHOW_HISTORY, IDS_SHOW_HISTORY); 551 AddItemWithStringId(IDC_SHOW_HISTORY, IDS_SHOW_HISTORY);
578 AddItemWithStringId(IDC_SHOW_DOWNLOADS, IDS_SHOW_DOWNLOADS); 552 AddItemWithStringId(IDC_SHOW_DOWNLOADS, IDS_SHOW_DOWNLOADS);
579 AddSeparator(ui::NORMAL_SEPARATOR); 553 AddSeparator(ui::NORMAL_SEPARATOR);
580 554
581 #if !defined(OS_CHROMEOS)
582 // No "Sign in to Chromium..." menu item on ChromeOS.
583 SigninManager* signin = SigninManagerFactory::GetForProfile(
584 browser_->profile()->GetOriginalProfile());
585 if (signin && signin->IsSigninAllowed()) {
586 const base::string16 short_product_name =
587 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME);
588 AddItem(IDC_SHOW_SYNC_SETUP, l10n_util::GetStringFUTF16(
589 IDS_SYNC_MENU_PRE_SYNCED_LABEL, short_product_name));
590 AddSeparator(ui::NORMAL_SEPARATOR);
591 }
592 #endif
593
594 AddItemWithStringId(IDC_OPTIONS, IDS_SETTINGS); 555 AddItemWithStringId(IDC_OPTIONS, IDS_SETTINGS);
595 556
596 #if defined(OS_CHROMEOS) 557 #if defined(OS_CHROMEOS)
597 if (CommandLine::ForCurrentProcess()->HasSwitch( 558 if (CommandLine::ForCurrentProcess()->HasSwitch(
598 chromeos::switches::kEnableRequestTabletSite)) 559 chromeos::switches::kEnableRequestTabletSite))
599 AddCheckItemWithStringId(IDC_TOGGLE_REQUEST_TABLET_SITE, 560 AddCheckItemWithStringId(IDC_TOGGLE_REQUEST_TABLET_SITE,
600 IDS_TOGGLE_REQUEST_TABLET_SITE); 561 IDS_TOGGLE_REQUEST_TABLET_SITE);
601 #endif 562 #endif
602 563
603 // On ChromeOS-Touch, we don't want the about menu option. 564 // On ChromeOS-Touch, we don't want the about menu option.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 AddItemWithStringId(IDC_EXIT, IDS_EXIT); 612 AddItemWithStringId(IDC_EXIT, IDS_EXIT);
652 } 613 }
653 } 614 }
654 615
655 void WrenchMenuModel::AddGlobalErrorMenuItems() { 616 void WrenchMenuModel::AddGlobalErrorMenuItems() {
656 // TODO(sail): Currently we only build the wrench menu once per browser 617 // TODO(sail): Currently we only build the wrench menu once per browser
657 // window. This means that if a new error is added after the menu is built 618 // window. This means that if a new error is added after the menu is built
658 // it won't show in the existing wrench menu. To fix this we need to some 619 // it won't show in the existing wrench menu. To fix this we need to some
659 // how update the menu if new errors are added. 620 // how update the menu if new errors are added.
660 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 621 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
661 // GetSignedInServiceErrors() can modify the global error list, so call it
662 // before iterating through that list below.
663 std::vector<GlobalError*> signin_errors =
664 signin_ui_util::GetSignedInServiceErrors(
665 browser_->profile()->GetOriginalProfile());
666 const GlobalErrorService::GlobalErrorList& errors = 622 const GlobalErrorService::GlobalErrorList& errors =
667 GlobalErrorServiceFactory::GetForProfile(browser_->profile())->errors(); 623 GlobalErrorServiceFactory::GetForProfile(browser_->profile())->errors();
668 for (GlobalErrorService::GlobalErrorList::const_iterator 624 for (GlobalErrorService::GlobalErrorList::const_iterator
669 it = errors.begin(); it != errors.end(); ++it) { 625 it = errors.begin(); it != errors.end(); ++it) {
670 GlobalError* error = *it; 626 GlobalError* error = *it;
671 DCHECK(error); 627 DCHECK(error);
672 if (error->HasMenuItem()) { 628 if (error->HasMenuItem()) {
673 #if !defined(OS_CHROMEOS)
674 // Don't add a signin error if it's already being displayed elsewhere.
675 if (std::find(signin_errors.begin(), signin_errors.end(), error) !=
676 signin_errors.end()) {
677 MenuModel* model = this;
678 int index = 0;
679 if (MenuModel::GetModelAndIndexForCommandId(
680 IDC_SHOW_SIGNIN, &model, &index)) {
681 continue;
682 }
683 }
684 #endif
685 629
686 AddItem(error->MenuItemCommandID(), error->MenuItemLabel()); 630 AddItem(error->MenuItemCommandID(), error->MenuItemLabel());
687 int icon_id = error->MenuItemIconResourceID(); 631 int icon_id = error->MenuItemIconResourceID();
688 if (icon_id) { 632 if (icon_id) {
689 const gfx::Image& image = rb.GetNativeImageNamed(icon_id); 633 const gfx::Image& image = rb.GetNativeImageNamed(icon_id);
690 SetIcon(GetIndexOfCommandId(error->MenuItemCommandID()), 634 SetIcon(GetIndexOfCommandId(error->MenuItemCommandID()),
691 image); 635 image);
692 } 636 }
693 } 637 }
694 } 638 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 &enable_increment, &enable_decrement); 703 &enable_increment, &enable_decrement);
760 } 704 }
761 zoom_label_ = l10n_util::GetStringFUTF16( 705 zoom_label_ = l10n_util::GetStringFUTF16(
762 IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent)); 706 IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent));
763 } 707 }
764 708
765 void WrenchMenuModel::OnZoomLevelChanged( 709 void WrenchMenuModel::OnZoomLevelChanged(
766 const content::HostZoomMap::ZoomLevelChange& change) { 710 const content::HostZoomMap::ZoomLevelChange& change) {
767 UpdateZoomControls(); 711 UpdateZoomControls();
768 } 712 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698