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" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "chrome/app/chrome_command_ids.h" | 16 #include "chrome/app/chrome_command_ids.h" |
17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/defaults.h" | 18 #include "chrome/browser/defaults.h" |
19 #include "chrome/browser/extensions/extension_toolbar_model.h" | |
20 #include "chrome/browser/extensions/extension_util.h" | 19 #include "chrome/browser/extensions/extension_util.h" |
21 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 20 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
22 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/profiles/profile_manager.h" | 22 #include "chrome/browser/profiles/profile_manager.h" |
24 #include "chrome/browser/search/search.h" | 23 #include "chrome/browser/search/search.h" |
25 #include "chrome/browser/signin/signin_manager_factory.h" | 24 #include "chrome/browser/signin/signin_manager_factory.h" |
26 #include "chrome/browser/signin/signin_ui_util.h" | 25 #include "chrome/browser/signin/signin_ui_util.h" |
27 #include "chrome/browser/task_manager/task_manager.h" | 26 #include "chrome/browser/task_manager/task_manager.h" |
28 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" | 27 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" |
29 #include "chrome/browser/ui/browser.h" | 28 #include "chrome/browser/ui/browser.h" |
30 #include "chrome/browser/ui/browser_commands.h" | 29 #include "chrome/browser/ui/browser_commands.h" |
31 #include "chrome/browser/ui/browser_finder.h" | 30 #include "chrome/browser/ui/browser_finder.h" |
32 #include "chrome/browser/ui/browser_window.h" | 31 #include "chrome/browser/ui/browser_window.h" |
33 #include "chrome/browser/ui/global_error/global_error.h" | 32 #include "chrome/browser/ui/global_error/global_error.h" |
34 #include "chrome/browser/ui/global_error/global_error_service.h" | 33 #include "chrome/browser/ui/global_error/global_error_service.h" |
35 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 34 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
36 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 35 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
37 #include "chrome/browser/ui/toolbar/bookmark_sub_menu_model.h" | 36 #include "chrome/browser/ui/toolbar/bookmark_sub_menu_model.h" |
38 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" | |
39 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" | 37 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" |
40 #include "chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h" | 38 #include "chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h" |
39 #include "chrome/browser/ui/toolbar/toolbar_actions_model.h" | |
41 #include "chrome/browser/upgrade_detector.h" | 40 #include "chrome/browser/upgrade_detector.h" |
42 #include "chrome/common/chrome_paths.h" | 41 #include "chrome/common/chrome_paths.h" |
43 #include "chrome/common/chrome_switches.h" | 42 #include "chrome/common/chrome_switches.h" |
44 #include "chrome/common/pref_names.h" | 43 #include "chrome/common/pref_names.h" |
45 #include "chrome/common/profiling.h" | 44 #include "chrome/common/profiling.h" |
46 #include "chrome/grit/chromium_strings.h" | 45 #include "chrome/grit/chromium_strings.h" |
47 #include "chrome/grit/generated_resources.h" | 46 #include "chrome/grit/generated_resources.h" |
48 #include "components/dom_distiller/core/dom_distiller_switches.h" | 47 #include "components/dom_distiller/core/dom_distiller_switches.h" |
49 #include "components/signin/core/browser/signin_manager.h" | 48 #include "components/signin/core/browser/signin_manager.h" |
50 #include "components/signin/core/common/profile_management_switches.h" | 49 #include "components/signin/core/common/profile_management_switches.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 #include "ash/shell.h" | 81 #include "ash/shell.h" |
83 #endif | 82 #endif |
84 | 83 |
85 using base::UserMetricsAction; | 84 using base::UserMetricsAction; |
86 using content::WebContents; | 85 using content::WebContents; |
87 | 86 |
88 namespace { | 87 namespace { |
89 | 88 |
90 #if defined(OS_MACOSX) | 89 #if defined(OS_MACOSX) |
91 // An empty command used because of a bug in AppKit menus. | 90 // An empty command used because of a bug in AppKit menus. |
92 // See comment in CreateExtensionToolbarOverflowMenu(). | 91 // See comment in CreateActionToolbarOverflowMenu(). |
93 const int kEmptyMenuItemCommand = 0; | 92 const int kEmptyMenuItemCommand = 0; |
94 #endif | 93 #endif |
95 | 94 |
96 // Conditionally return the update app menu item title based on upgrade detector | 95 // Conditionally return the update app menu item title based on upgrade detector |
97 // state. | 96 // state. |
98 base::string16 GetUpgradeDialogMenuItemName() { | 97 base::string16 GetUpgradeDialogMenuItemName() { |
99 if (UpgradeDetector::GetInstance()->is_outdated_install() || | 98 if (UpgradeDetector::GetInstance()->is_outdated_install() || |
100 UpgradeDetector::GetInstance()->is_outdated_install_no_au()) { | 99 UpgradeDetector::GetInstance()->is_outdated_install_no_au()) { |
101 return l10n_util::GetStringUTF16(IDS_UPGRADE_BUBBLE_MENU_ITEM); | 100 return l10n_util::GetStringUTF16(IDS_UPGRADE_BUBBLE_MENU_ITEM); |
102 } else { | 101 } else { |
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
779 if (error) | 778 if (error) |
780 return true; | 779 return true; |
781 | 780 |
782 return chrome::IsCommandEnabled(browser_, command_id); | 781 return chrome::IsCommandEnabled(browser_, command_id); |
783 } | 782 } |
784 | 783 |
785 bool WrenchMenuModel::IsCommandIdVisible(int command_id) const { | 784 bool WrenchMenuModel::IsCommandIdVisible(int command_id) const { |
786 switch (command_id) { | 785 switch (command_id) { |
787 #if defined(OS_MACOSX) | 786 #if defined(OS_MACOSX) |
788 case kEmptyMenuItemCommand: | 787 case kEmptyMenuItemCommand: |
789 return false; // Always hidden (see CreateExtensionToolbarOverflowMenu). | 788 return false; // Always hidden (see CreateActionToolbarOverflowMenu). |
790 #endif | 789 #endif |
791 #if defined(OS_WIN) | 790 #if defined(OS_WIN) |
792 case IDC_VIEW_INCOMPATIBILITIES: { | 791 case IDC_VIEW_INCOMPATIBILITIES: { |
793 EnumerateModulesModel* loaded_modules = | 792 EnumerateModulesModel* loaded_modules = |
794 EnumerateModulesModel::GetInstance(); | 793 EnumerateModulesModel::GetInstance(); |
795 if (loaded_modules->confirmed_bad_modules_detected() <= 0) | 794 if (loaded_modules->confirmed_bad_modules_detected() <= 0) |
796 return false; | 795 return false; |
797 // We'll leave the wrench adornment on until the user clicks the link. | 796 // We'll leave the wrench adornment on until the user clicks the link. |
798 if (loaded_modules->modules_to_notify_about() <= 0) | 797 if (loaded_modules->modules_to_notify_about() <= 0) |
799 loaded_modules->AcknowledgeConflictNotification(); | 798 loaded_modules->AcknowledgeConflictNotification(); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
876 // Menu is organised as follows: | 875 // Menu is organised as follows: |
877 // - Extension toolbar overflow. | 876 // - Extension toolbar overflow. |
878 // - Global browser errors and warnings. | 877 // - Global browser errors and warnings. |
879 // - Tabs and windows. | 878 // - Tabs and windows. |
880 // - Places previously been e.g. History, bookmarks, recent tabs. | 879 // - Places previously been e.g. History, bookmarks, recent tabs. |
881 // - Page actions e.g. zoom, edit, find, print. | 880 // - Page actions e.g. zoom, edit, find, print. |
882 // - Learn about the browser and global customisation e.g. settings, help. | 881 // - Learn about the browser and global customisation e.g. settings, help. |
883 // - Browser relaunch, quit. | 882 // - Browser relaunch, quit. |
884 void WrenchMenuModel::Build() { | 883 void WrenchMenuModel::Build() { |
885 if (extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) | 884 if (extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) |
886 CreateExtensionToolbarOverflowMenu(); | 885 CreateActionToolbarOverflowMenu(); |
887 | 886 |
888 AddItem(IDC_VIEW_INCOMPATIBILITIES, | 887 AddItem(IDC_VIEW_INCOMPATIBILITIES, |
889 l10n_util::GetStringUTF16(IDS_VIEW_INCOMPATIBILITIES)); | 888 l10n_util::GetStringUTF16(IDS_VIEW_INCOMPATIBILITIES)); |
890 SetIcon(GetIndexOfCommandId(IDC_VIEW_INCOMPATIBILITIES), | 889 SetIcon(GetIndexOfCommandId(IDC_VIEW_INCOMPATIBILITIES), |
891 ui::ResourceBundle::GetSharedInstance(). | 890 ui::ResourceBundle::GetSharedInstance(). |
892 GetNativeImageNamed(IDR_INPUT_ALERT_MENU)); | 891 GetNativeImageNamed(IDR_INPUT_ALERT_MENU)); |
893 if (IsCommandIdVisible(IDC_UPGRADE_DIALOG)) | 892 if (IsCommandIdVisible(IDC_UPGRADE_DIALOG)) |
894 AddItem(IDC_UPGRADE_DIALOG, GetUpgradeDialogMenuItemName()); | 893 AddItem(IDC_UPGRADE_DIALOG, GetUpgradeDialogMenuItemName()); |
895 if (AddGlobalErrorMenuItems() || | 894 if (AddGlobalErrorMenuItems() || |
896 IsCommandIdVisible(IDC_VIEW_INCOMPATIBILITIES) || | 895 IsCommandIdVisible(IDC_VIEW_INCOMPATIBILITIES) || |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1023 const gfx::Image& image = rb.GetNativeImageNamed(icon_id); | 1022 const gfx::Image& image = rb.GetNativeImageNamed(icon_id); |
1024 SetIcon(GetIndexOfCommandId(error->MenuItemCommandID()), | 1023 SetIcon(GetIndexOfCommandId(error->MenuItemCommandID()), |
1025 image); | 1024 image); |
1026 } | 1025 } |
1027 menu_items_added = true; | 1026 menu_items_added = true; |
1028 } | 1027 } |
1029 } | 1028 } |
1030 return menu_items_added; | 1029 return menu_items_added; |
1031 } | 1030 } |
1032 | 1031 |
1033 void WrenchMenuModel::CreateExtensionToolbarOverflowMenu() { | 1032 void WrenchMenuModel::CreateActionToolbarOverflowMenu() { |
1034 // We only add the extensions overflow container if there are any icons that | 1033 // We only add the extensions overflow container if there are any icons that |
1035 // aren't shown in the main container or if there are component actions. | 1034 // aren't shown in the main container or if there are component actions. |
Peter Kasting
2015/08/06 20:15:18
Nit: I think this comment needs updating?
apacible
2015/08/10 22:38:11
Done.
| |
1036 // TODO(apacible): Remove check for component actions when | 1035 if (!ToolbarActionsModel::Get(browser_->profile())->all_icons_visible()) { |
1037 // ExtensionToolbarModel can support them. | |
1038 if (!extensions::ExtensionToolbarModel::Get(browser_->profile())-> | |
1039 all_icons_visible() || | |
1040 ComponentToolbarActionsFactory::GetInstance()-> | |
1041 GetNumComponentActions(browser_) > 0) { | |
1042 #if defined(OS_MACOSX) | 1036 #if defined(OS_MACOSX) |
1043 // There's a bug in AppKit menus, where if a menu item with a custom view | 1037 // There's a bug in AppKit menus, where if a menu item with a custom view |
1044 // (like the extensions overflow menu) is the first menu item, it is not | 1038 // (like the extensions overflow menu) is the first menu item, it is not |
1045 // highlightable or keyboard-selectable. | 1039 // highlightable or keyboard-selectable. |
1046 // Adding any menu item before it (even one which is never visible) prevents | 1040 // Adding any menu item before it (even one which is never visible) prevents |
1047 // it, so add a bogus item here that will always be hidden. | 1041 // it, so add a bogus item here that will always be hidden. |
1048 AddItem(kEmptyMenuItemCommand, base::string16()); | 1042 AddItem(kEmptyMenuItemCommand, base::string16()); |
1049 #endif | 1043 #endif |
1050 AddItem(IDC_EXTENSIONS_OVERFLOW_MENU, base::string16()); | 1044 AddItem(IDC_EXTENSIONS_OVERFLOW_MENU, base::string16()); |
1051 AddSeparator(ui::UPPER_SEPARATOR); | 1045 AddSeparator(ui::UPPER_SEPARATOR); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1096 ->GetZoomPercent(); | 1090 ->GetZoomPercent(); |
1097 } | 1091 } |
1098 zoom_label_ = l10n_util::GetStringFUTF16( | 1092 zoom_label_ = l10n_util::GetStringFUTF16( |
1099 IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent)); | 1093 IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent)); |
1100 } | 1094 } |
1101 | 1095 |
1102 void WrenchMenuModel::OnZoomLevelChanged( | 1096 void WrenchMenuModel::OnZoomLevelChanged( |
1103 const content::HostZoomMap::ZoomLevelChange& change) { | 1097 const content::HostZoomMap::ZoomLevelChange& change) { |
1104 UpdateZoomControls(); | 1098 UpdateZoomControls(); |
1105 } | 1099 } |
OLD | NEW |