OLD | NEW |
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 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 return command_id != IDC_ZOOM_MINUS && command_id != IDC_ZOOM_PLUS; | 359 return command_id != IDC_ZOOM_MINUS && command_id != IDC_ZOOM_PLUS; |
360 } | 360 } |
361 | 361 |
362 bool WrenchMenuModel::IsItemForCommandIdDynamic(int command_id) const { | 362 bool WrenchMenuModel::IsItemForCommandIdDynamic(int command_id) const { |
363 return command_id == IDC_ZOOM_PERCENT_DISPLAY || | 363 return command_id == IDC_ZOOM_PERCENT_DISPLAY || |
364 #if defined(OS_MACOSX) | 364 #if defined(OS_MACOSX) |
365 command_id == IDC_FULLSCREEN || | 365 command_id == IDC_FULLSCREEN || |
366 #elif defined(OS_WIN) | 366 #elif defined(OS_WIN) |
367 command_id == IDC_PIN_TO_START_SCREEN || | 367 command_id == IDC_PIN_TO_START_SCREEN || |
368 #endif | 368 #endif |
369 command_id == IDC_UPGRADE_DIALOG; | 369 command_id == IDC_UPGRADE_DIALOG || |
| 370 (!switches::IsNewAvatarMenu() && command_id == IDC_SHOW_SIGNIN); |
370 } | 371 } |
371 | 372 |
372 base::string16 WrenchMenuModel::GetLabelForCommandId(int command_id) const { | 373 base::string16 WrenchMenuModel::GetLabelForCommandId(int command_id) const { |
373 switch (command_id) { | 374 switch (command_id) { |
374 case IDC_ZOOM_PERCENT_DISPLAY: | 375 case IDC_ZOOM_PERCENT_DISPLAY: |
375 return zoom_label_; | 376 return zoom_label_; |
376 #if defined(OS_MACOSX) | 377 #if defined(OS_MACOSX) |
377 case IDC_FULLSCREEN: { | 378 case IDC_FULLSCREEN: { |
378 int string_id = IDS_ENTER_FULLSCREEN_MAC; // Default to Enter. | 379 int string_id = IDS_ENTER_FULLSCREEN_MAC; // Default to Enter. |
379 // Note: On startup, |window()| may be NULL. | 380 // Note: On startup, |window()| may be NULL. |
380 if (browser_->window() && browser_->window()->IsFullscreen()) | 381 if (browser_->window() && browser_->window()->IsFullscreen()) |
381 string_id = IDS_EXIT_FULLSCREEN_MAC; | 382 string_id = IDS_EXIT_FULLSCREEN_MAC; |
382 return l10n_util::GetStringUTF16(string_id); | 383 return l10n_util::GetStringUTF16(string_id); |
383 } | 384 } |
384 #elif defined(OS_WIN) | 385 #elif defined(OS_WIN) |
385 case IDC_PIN_TO_START_SCREEN: { | 386 case IDC_PIN_TO_START_SCREEN: { |
386 int string_id = IDS_PIN_TO_START_SCREEN; | 387 int string_id = IDS_PIN_TO_START_SCREEN; |
387 WebContents* web_contents = | 388 WebContents* web_contents = |
388 browser_->tab_strip_model()->GetActiveWebContents(); | 389 browser_->tab_strip_model()->GetActiveWebContents(); |
389 MetroPinTabHelper* tab_helper = | 390 MetroPinTabHelper* tab_helper = |
390 web_contents ? MetroPinTabHelper::FromWebContents(web_contents) | 391 web_contents ? MetroPinTabHelper::FromWebContents(web_contents) |
391 : NULL; | 392 : NULL; |
392 if (tab_helper && tab_helper->IsPinned()) | 393 if (tab_helper && tab_helper->IsPinned()) |
393 string_id = IDS_UNPIN_FROM_START_SCREEN; | 394 string_id = IDS_UNPIN_FROM_START_SCREEN; |
394 return l10n_util::GetStringUTF16(string_id); | 395 return l10n_util::GetStringUTF16(string_id); |
395 } | 396 } |
396 #endif | 397 #endif |
397 case IDC_UPGRADE_DIALOG: | 398 case IDC_UPGRADE_DIALOG: |
398 return GetUpgradeDialogMenuItemName(); | 399 return GetUpgradeDialogMenuItemName(); |
| 400 case IDC_SHOW_SIGNIN: |
| 401 DCHECK(!switches::IsNewAvatarMenu()); |
| 402 return signin_ui_util::GetSigninMenuLabel( |
| 403 browser_->profile()->GetOriginalProfile()); |
399 default: | 404 default: |
400 NOTREACHED(); | 405 NOTREACHED(); |
401 return base::string16(); | 406 return base::string16(); |
402 } | 407 } |
403 } | 408 } |
404 | 409 |
405 bool WrenchMenuModel::GetIconForCommandId(int command_id, | 410 bool WrenchMenuModel::GetIconForCommandId(int command_id, |
406 gfx::Image* icon) const { | 411 gfx::Image* icon) const { |
407 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 412 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
408 switch (command_id) { | 413 switch (command_id) { |
409 case IDC_UPGRADE_DIALOG: { | 414 case IDC_UPGRADE_DIALOG: { |
410 if (UpgradeDetector::GetInstance()->notify_upgrade()) { | 415 if (UpgradeDetector::GetInstance()->notify_upgrade()) { |
411 *icon = rb.GetNativeImageNamed( | 416 *icon = rb.GetNativeImageNamed( |
412 UpgradeDetector::GetInstance()->GetIconResourceID()); | 417 UpgradeDetector::GetInstance()->GetIconResourceID()); |
413 return true; | 418 return true; |
414 } | 419 } |
415 return false; | 420 return false; |
416 } | 421 } |
| 422 case IDC_SHOW_SIGNIN: { |
| 423 DCHECK(!switches::IsNewAvatarMenu()); |
| 424 GlobalError* error = signin_ui_util::GetSignedInServiceError( |
| 425 browser_->profile()->GetOriginalProfile()); |
| 426 if (error) { |
| 427 int icon_id = error->MenuItemIconResourceID(); |
| 428 if (icon_id) { |
| 429 *icon = rb.GetNativeImageNamed(icon_id); |
| 430 return true; |
| 431 } |
| 432 } |
| 433 return false; |
| 434 } |
417 default: | 435 default: |
418 break; | 436 break; |
419 } | 437 } |
420 return false; | 438 return false; |
421 } | 439 } |
422 | 440 |
423 void WrenchMenuModel::ExecuteCommand(int command_id, int event_flags) { | 441 void WrenchMenuModel::ExecuteCommand(int command_id, int event_flags) { |
424 GlobalError* error = GlobalErrorServiceFactory::GetForProfile( | 442 GlobalError* error = GlobalErrorServiceFactory::GetForProfile( |
425 browser_->profile())->GetGlobalErrorByMenuItemCommandID(command_id); | 443 browser_->profile())->GetGlobalErrorByMenuItemCommandID(command_id); |
426 if (error) { | 444 if (error) { |
427 error->ExecuteMenuItem(browser_); | 445 error->ExecuteMenuItem(browser_); |
428 return; | 446 return; |
429 } | 447 } |
430 | 448 |
| 449 if (!switches::IsNewAvatarMenu() && command_id == IDC_SHOW_SIGNIN) { |
| 450 // If a custom error message is being shown, handle it. |
| 451 GlobalError* error = signin_ui_util::GetSignedInServiceError( |
| 452 browser_->profile()->GetOriginalProfile()); |
| 453 if (error) { |
| 454 error->ExecuteMenuItem(browser_); |
| 455 return; |
| 456 } |
| 457 } |
| 458 |
431 LogMenuMetrics(command_id); | 459 LogMenuMetrics(command_id); |
432 chrome::ExecuteCommand(browser_, command_id); | 460 chrome::ExecuteCommand(browser_, command_id); |
433 } | 461 } |
434 | 462 |
435 void WrenchMenuModel::LogMenuMetrics(int command_id) { | 463 void WrenchMenuModel::LogMenuMetrics(int command_id) { |
436 base::TimeDelta delta = timer_.Elapsed(); | 464 base::TimeDelta delta = timer_.Elapsed(); |
437 | 465 |
438 switch (command_id) { | 466 switch (command_id) { |
439 case IDC_NEW_TAB: | 467 case IDC_NEW_TAB: |
440 if (!uma_action_recorded_) | 468 if (!uma_action_recorded_) |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 } | 693 } |
666 LogMenuAction(MENU_ACTION_SHOW_HISTORY); | 694 LogMenuAction(MENU_ACTION_SHOW_HISTORY); |
667 break; | 695 break; |
668 case IDC_SHOW_DOWNLOADS: | 696 case IDC_SHOW_DOWNLOADS: |
669 if (!uma_action_recorded_) { | 697 if (!uma_action_recorded_) { |
670 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction.ShowDownloads", | 698 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction.ShowDownloads", |
671 delta); | 699 delta); |
672 } | 700 } |
673 LogMenuAction(MENU_ACTION_SHOW_DOWNLOADS); | 701 LogMenuAction(MENU_ACTION_SHOW_DOWNLOADS); |
674 break; | 702 break; |
| 703 case IDC_SHOW_SYNC_SETUP: |
| 704 if (!uma_action_recorded_) { |
| 705 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction.ShowSyncSetup", |
| 706 delta); |
| 707 } |
| 708 LogMenuAction(MENU_ACTION_SHOW_SYNC_SETUP); |
| 709 break; |
675 case IDC_OPTIONS: | 710 case IDC_OPTIONS: |
676 if (!uma_action_recorded_) | 711 if (!uma_action_recorded_) |
677 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction.Settings", delta); | 712 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction.Settings", delta); |
678 LogMenuAction(MENU_ACTION_OPTIONS); | 713 LogMenuAction(MENU_ACTION_OPTIONS); |
679 break; | 714 break; |
680 case IDC_ABOUT: | 715 case IDC_ABOUT: |
681 if (!uma_action_recorded_) | 716 if (!uma_action_recorded_) |
682 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction.About", delta); | 717 UMA_HISTOGRAM_MEDIUM_TIMES("WrenchMenu.TimeToAction.About", delta); |
683 LogMenuAction(MENU_ACTION_ABOUT); | 718 LogMenuAction(MENU_ACTION_ABOUT); |
684 break; | 719 break; |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 switches::kEnableDomDistiller)) | 923 switches::kEnableDomDistiller)) |
889 AddItemWithStringId(IDC_DISTILL_PAGE, IDS_DISTILL_PAGE); | 924 AddItemWithStringId(IDC_DISTILL_PAGE, IDS_DISTILL_PAGE); |
890 tools_menu_model_.reset(new ToolsMenuModel(this, browser_)); | 925 tools_menu_model_.reset(new ToolsMenuModel(this, browser_)); |
891 AddSubMenuWithStringId( | 926 AddSubMenuWithStringId( |
892 IDC_MORE_TOOLS_MENU, IDS_MORE_TOOLS_MENU, tools_menu_model_.get()); | 927 IDC_MORE_TOOLS_MENU, IDS_MORE_TOOLS_MENU, tools_menu_model_.get()); |
893 // Append the full menu including separators. The final separator only gets | 928 // Append the full menu including separators. The final separator only gets |
894 // appended when this is a touch menu - otherwise it would get added twice. | 929 // appended when this is a touch menu - otherwise it would get added twice. |
895 CreateCutCopyPasteMenu(); | 930 CreateCutCopyPasteMenu(); |
896 | 931 |
897 AddItemWithStringId(IDC_OPTIONS, IDS_SETTINGS); | 932 AddItemWithStringId(IDC_OPTIONS, IDS_SETTINGS); |
898 | 933 #if !defined(OS_CHROMEOS) |
| 934 if (!switches::IsNewAvatarMenu()) { |
| 935 // No "Sign in to Chromium..." menu item on ChromeOS. |
| 936 SigninManager* signin = SigninManagerFactory::GetForProfile( |
| 937 browser_->profile()->GetOriginalProfile()); |
| 938 if (signin && signin->IsSigninAllowed() && |
| 939 signin_ui_util::GetSignedInServiceErrors( |
| 940 browser_->profile()->GetOriginalProfile()).empty()) { |
| 941 AddItem(IDC_SHOW_SYNC_SETUP, |
| 942 l10n_util::GetStringFUTF16( |
| 943 IDS_SYNC_MENU_PRE_SYNCED_LABEL, |
| 944 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); |
| 945 } |
| 946 } |
| 947 #endif |
899 // The help submenu is only displayed on official Chrome builds. As the | 948 // The help submenu is only displayed on official Chrome builds. As the |
900 // 'About' item has been moved to this submenu, it's reinstated here for | 949 // 'About' item has been moved to this submenu, it's reinstated here for |
901 // Chromium builds. | 950 // Chromium builds. |
902 #if defined(GOOGLE_CHROME_BUILD) | 951 #if defined(GOOGLE_CHROME_BUILD) |
903 help_menu_model_.reset(new HelpMenuModel(this, browser_)); | 952 help_menu_model_.reset(new HelpMenuModel(this, browser_)); |
904 AddSubMenuWithStringId(IDC_HELP_MENU, IDS_HELP_MENU, | 953 AddSubMenuWithStringId(IDC_HELP_MENU, IDS_HELP_MENU, |
905 help_menu_model_.get()); | 954 help_menu_model_.get()); |
906 #else | 955 #else |
907 AddItem(IDC_ABOUT, l10n_util::GetStringUTF16(IDS_ABOUT)); | 956 AddItem(IDC_ABOUT, l10n_util::GetStringUTF16(IDS_ABOUT)); |
908 #endif | 957 #endif |
(...skipping 25 matching lines...) Expand all Loading... |
934 } | 983 } |
935 uma_action_recorded_ = false; | 984 uma_action_recorded_ = false; |
936 } | 985 } |
937 | 986 |
938 bool WrenchMenuModel::AddGlobalErrorMenuItems() { | 987 bool WrenchMenuModel::AddGlobalErrorMenuItems() { |
939 // TODO(sail): Currently we only build the wrench menu once per browser | 988 // TODO(sail): Currently we only build the wrench menu once per browser |
940 // window. This means that if a new error is added after the menu is built | 989 // window. This means that if a new error is added after the menu is built |
941 // it won't show in the existing wrench menu. To fix this we need to some | 990 // it won't show in the existing wrench menu. To fix this we need to some |
942 // how update the menu if new errors are added. | 991 // how update the menu if new errors are added. |
943 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 992 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 993 // GetSignedInServiceErrors() can modify the global error list, so call it |
| 994 // before iterating through that list below. |
| 995 std::vector<GlobalError*> signin_errors; |
| 996 signin_errors = signin_ui_util::GetSignedInServiceErrors( |
| 997 browser_->profile()->GetOriginalProfile()); |
944 const GlobalErrorService::GlobalErrorList& errors = | 998 const GlobalErrorService::GlobalErrorList& errors = |
945 GlobalErrorServiceFactory::GetForProfile(browser_->profile())->errors(); | 999 GlobalErrorServiceFactory::GetForProfile(browser_->profile())->errors(); |
946 bool menu_items_added = false; | 1000 bool menu_items_added = false; |
947 for (GlobalErrorService::GlobalErrorList::const_iterator | 1001 for (GlobalErrorService::GlobalErrorList::const_iterator |
948 it = errors.begin(); it != errors.end(); ++it) { | 1002 it = errors.begin(); it != errors.end(); ++it) { |
949 GlobalError* error = *it; | 1003 GlobalError* error = *it; |
950 DCHECK(error); | 1004 DCHECK(error); |
951 if (error->HasMenuItem()) { | 1005 if (error->HasMenuItem()) { |
| 1006 #if !defined(OS_CHROMEOS) |
| 1007 // Don't add a signin error if it's already being displayed elsewhere. |
| 1008 if (std::find(signin_errors.begin(), signin_errors.end(), error) != |
| 1009 signin_errors.end()) { |
| 1010 MenuModel* model = this; |
| 1011 int index = 0; |
| 1012 if (MenuModel::GetModelAndIndexForCommandId( |
| 1013 IDC_SHOW_SIGNIN, &model, &index)) { |
| 1014 continue; |
| 1015 } |
| 1016 } |
| 1017 #endif |
| 1018 |
952 AddItem(error->MenuItemCommandID(), error->MenuItemLabel()); | 1019 AddItem(error->MenuItemCommandID(), error->MenuItemLabel()); |
953 int icon_id = error->MenuItemIconResourceID(); | 1020 int icon_id = error->MenuItemIconResourceID(); |
954 if (icon_id) { | 1021 if (icon_id) { |
955 const gfx::Image& image = rb.GetNativeImageNamed(icon_id); | 1022 const gfx::Image& image = rb.GetNativeImageNamed(icon_id); |
956 SetIcon(GetIndexOfCommandId(error->MenuItemCommandID()), | 1023 SetIcon(GetIndexOfCommandId(error->MenuItemCommandID()), |
957 image); | 1024 image); |
958 } | 1025 } |
959 menu_items_added = true; | 1026 menu_items_added = true; |
960 } | 1027 } |
961 } | 1028 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1023 ->GetZoomPercent(); | 1090 ->GetZoomPercent(); |
1024 } | 1091 } |
1025 zoom_label_ = l10n_util::GetStringFUTF16( | 1092 zoom_label_ = l10n_util::GetStringFUTF16( |
1026 IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent)); | 1093 IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent)); |
1027 } | 1094 } |
1028 | 1095 |
1029 void WrenchMenuModel::OnZoomLevelChanged( | 1096 void WrenchMenuModel::OnZoomLevelChanged( |
1030 const content::HostZoomMap::ZoomLevelChange& change) { | 1097 const content::HostZoomMap::ZoomLevelChange& change) { |
1031 UpdateZoomControls(); | 1098 UpdateZoomControls(); |
1032 } | 1099 } |
OLD | NEW |