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