OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/app_list/app_context_menu.h" | 5 #include "chrome/browser/ui/app_list/app_context_menu.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
10 #include "chrome/browser/extensions/context_menu_matcher.h" | 10 #include "chrome/browser/extensions/context_menu_matcher.h" |
11 #include "chrome/browser/extensions/launch_util.h" | |
12 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 11 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
13 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/app_list/app_context_menu_delegate.h" | 13 #include "chrome/browser/ui/app_list/app_context_menu_delegate.h" |
15 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" | 14 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
16 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/common/extensions/extension_constants.h" | 16 #include "chrome/common/extensions/extension_constants.h" |
18 #include "chrome/common/extensions/manifest_url_handler.h" | 17 #include "chrome/common/extensions/manifest_url_handler.h" |
19 #include "content/public/common/context_menu_params.h" | 18 #include "content/public/common/context_menu_params.h" |
20 #include "grit/chromium_strings.h" | 19 #include "grit/chromium_strings.h" |
21 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
22 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
23 | 22 |
24 #if defined(USE_ASH) | 23 #if defined(USE_ASH) |
25 #include "ash/shell.h" | 24 #include "ash/shell.h" |
26 #endif | 25 #endif |
27 | 26 |
28 namespace app_list { | 27 namespace app_list { |
29 | 28 |
30 namespace { | 29 namespace { |
31 | 30 |
32 enum CommandId { | 31 enum CommandId { |
33 LAUNCH_NEW = 100, | 32 LAUNCH_NEW = 100, |
34 TOGGLE_PIN, | 33 TOGGLE_PIN, |
35 CREATE_SHORTCUTS, | 34 CREATE_SHORTCUTS, |
36 OPTIONS, | 35 OPTIONS, |
37 UNINSTALL, | 36 UNINSTALL, |
38 DETAILS, | 37 DETAILS, |
39 MENU_NEW_WINDOW, | 38 MENU_NEW_WINDOW, |
40 MENU_NEW_INCOGNITO_WINDOW, | 39 MENU_NEW_INCOGNITO_WINDOW, |
41 // Order matters in LAUNCHER_TYPE_xxxx and must match LaunchType. | 40 // Order matters in USE_LAUNCH_TYPE_* and must match the LaunchType enum. |
42 LAUNCH_TYPE_START = 200, | 41 USE_LAUNCH_TYPE_COMMAND_START = 200, |
43 LAUNCH_TYPE_PINNED_TAB = LAUNCH_TYPE_START, | 42 USE_LAUNCH_TYPE_PINNED = USE_LAUNCH_TYPE_COMMAND_START, |
44 LAUNCH_TYPE_REGULAR_TAB, | 43 USE_LAUNCH_TYPE_REGULAR, |
45 LAUNCH_TYPE_FULLSCREEN, | 44 USE_LAUNCH_TYPE_FULLSCREEN, |
46 LAUNCH_TYPE_WINDOW, | 45 USE_LAUNCH_TYPE_WINDOW, |
47 LAUNCH_TYPE_LAST, | 46 USE_LAUNCH_TYPE_COMMAND_END, |
48 }; | 47 }; |
49 | 48 |
50 bool MenuItemHasLauncherContext(const extensions::MenuItem* item) { | 49 bool MenuItemHasLauncherContext(const extensions::MenuItem* item) { |
51 return item->contexts().Contains(extensions::MenuItem::LAUNCHER); | 50 return item->contexts().Contains(extensions::MenuItem::LAUNCHER); |
52 } | 51 } |
53 | 52 |
54 } // namespace | 53 } // namespace |
55 | 54 |
56 AppContextMenu::AppContextMenu(AppContextMenuDelegate* delegate, | 55 AppContextMenu::AppContextMenu(AppContextMenuDelegate* delegate, |
57 Profile* profile, | 56 Profile* profile, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 IDS_APP_LIST_CONTEXT_MENU_PIN); | 108 IDS_APP_LIST_CONTEXT_MENU_PIN); |
110 } | 109 } |
111 | 110 |
112 if (controller_->CanDoCreateShortcutsFlow()) { | 111 if (controller_->CanDoCreateShortcutsFlow()) { |
113 menu_model_->AddItemWithStringId(CREATE_SHORTCUTS, | 112 menu_model_->AddItemWithStringId(CREATE_SHORTCUTS, |
114 IDS_NEW_TAB_APP_CREATE_SHORTCUT); | 113 IDS_NEW_TAB_APP_CREATE_SHORTCUT); |
115 } | 114 } |
116 | 115 |
117 if (!is_platform_app_) { | 116 if (!is_platform_app_) { |
118 menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); | 117 menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); |
119 // Streamlined hosted apps can only toggle between LAUNCH_WINDOW and | 118 // Streamlined hosted apps can only toggle between USE_LAUNCH_TYPE_WINDOW |
120 // LAUNCH_REGULAR. | 119 // and USE_LAUNCH_TYPE_REGULAR. |
121 if (CommandLine::ForCurrentProcess()->HasSwitch( | 120 if (CommandLine::ForCurrentProcess()->HasSwitch( |
122 switches::kEnableStreamlinedHostedApps)) { | 121 switches::kEnableStreamlinedHostedApps)) { |
123 menu_model_->AddCheckItemWithStringId( | 122 menu_model_->AddCheckItemWithStringId( |
124 LAUNCH_TYPE_REGULAR_TAB, | 123 USE_LAUNCH_TYPE_REGULAR, |
125 IDS_APP_CONTEXT_MENU_OPEN_TAB); | 124 IDS_APP_CONTEXT_MENU_OPEN_TAB); |
126 } else { | 125 } else { |
127 menu_model_->AddCheckItemWithStringId( | 126 menu_model_->AddCheckItemWithStringId( |
128 LAUNCH_TYPE_REGULAR_TAB, | 127 USE_LAUNCH_TYPE_REGULAR, |
129 IDS_APP_CONTEXT_MENU_OPEN_REGULAR); | 128 IDS_APP_CONTEXT_MENU_OPEN_REGULAR); |
130 menu_model_->AddCheckItemWithStringId( | 129 menu_model_->AddCheckItemWithStringId( |
131 LAUNCH_TYPE_PINNED_TAB, | 130 USE_LAUNCH_TYPE_PINNED, |
132 IDS_APP_CONTEXT_MENU_OPEN_PINNED); | 131 IDS_APP_CONTEXT_MENU_OPEN_PINNED); |
133 #if defined(OS_MACOSX) | 132 #if defined(OS_MACOSX) |
134 // Mac does not support standalone web app browser windows or maximize. | 133 // Mac does not support standalone web app browser windows or maximize. |
135 menu_model_->AddCheckItemWithStringId( | 134 menu_model_->AddCheckItemWithStringId( |
136 LAUNCH_TYPE_FULLSCREEN, | 135 USE_LAUNCH_TYPE_FULLSCREEN, |
137 IDS_APP_CONTEXT_MENU_OPEN_FULLSCREEN); | 136 IDS_APP_CONTEXT_MENU_OPEN_FULLSCREEN); |
138 #else | 137 #else |
139 menu_model_->AddCheckItemWithStringId( | 138 menu_model_->AddCheckItemWithStringId( |
140 LAUNCH_TYPE_WINDOW, | 139 USE_LAUNCH_TYPE_WINDOW, |
141 IDS_APP_CONTEXT_MENU_OPEN_WINDOW); | 140 IDS_APP_CONTEXT_MENU_OPEN_WINDOW); |
142 // Even though the launch type is Full Screen it is more accurately | 141 // Even though the launch type is Full Screen it is more accurately |
143 // described as Maximized in Ash. | 142 // described as Maximized in Ash. |
144 menu_model_->AddCheckItemWithStringId( | 143 menu_model_->AddCheckItemWithStringId( |
145 LAUNCH_TYPE_FULLSCREEN, | 144 USE_LAUNCH_TYPE_FULLSCREEN, |
146 IDS_APP_CONTEXT_MENU_OPEN_MAXIMIZED); | 145 IDS_APP_CONTEXT_MENU_OPEN_MAXIMIZED); |
147 #endif | 146 #endif |
148 } | 147 } |
149 menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); | 148 menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); |
150 menu_model_->AddItemWithStringId(OPTIONS, IDS_NEW_TAB_APP_OPTIONS); | 149 menu_model_->AddItemWithStringId(OPTIONS, IDS_NEW_TAB_APP_OPTIONS); |
151 } | 150 } |
152 | 151 |
153 menu_model_->AddItemWithStringId(DETAILS, IDS_NEW_TAB_APP_DETAILS); | 152 menu_model_->AddItemWithStringId(DETAILS, IDS_NEW_TAB_APP_DETAILS); |
154 menu_model_->AddItemWithStringId( | 153 menu_model_->AddItemWithStringId( |
155 UNINSTALL, | 154 UNINSTALL, |
(...skipping 11 matching lines...) Expand all Loading... |
167 string16 AppContextMenu::GetLabelForCommandId(int command_id) const { | 166 string16 AppContextMenu::GetLabelForCommandId(int command_id) const { |
168 if (command_id == TOGGLE_PIN) { | 167 if (command_id == TOGGLE_PIN) { |
169 return controller_->IsAppPinned(app_id_) ? | 168 return controller_->IsAppPinned(app_id_) ? |
170 l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_UNPIN) : | 169 l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_UNPIN) : |
171 l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_PIN); | 170 l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_PIN); |
172 } else if (command_id == LAUNCH_NEW) { | 171 } else if (command_id == LAUNCH_NEW) { |
173 #if defined(OS_MACOSX) | 172 #if defined(OS_MACOSX) |
174 // Even fullscreen windows launch in a browser tab on Mac. | 173 // Even fullscreen windows launch in a browser tab on Mac. |
175 const bool launches_in_tab = true; | 174 const bool launches_in_tab = true; |
176 #else | 175 #else |
177 const bool launches_in_tab = IsCommandIdChecked(LAUNCH_TYPE_PINNED_TAB) || | 176 const bool launches_in_tab = IsCommandIdChecked(USE_LAUNCH_TYPE_PINNED) || |
178 IsCommandIdChecked(LAUNCH_TYPE_REGULAR_TAB); | 177 IsCommandIdChecked(USE_LAUNCH_TYPE_REGULAR); |
179 #endif | 178 #endif |
180 return launches_in_tab ? | 179 return launches_in_tab ? |
181 l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_NEW_TAB) : | 180 l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_NEW_TAB) : |
182 l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_NEW_WINDOW); | 181 l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_NEW_WINDOW); |
183 } else { | 182 } else { |
184 NOTREACHED(); | 183 NOTREACHED(); |
185 return string16(); | 184 return string16(); |
186 } | 185 } |
187 } | 186 } |
188 | 187 |
189 bool AppContextMenu::IsCommandIdChecked(int command_id) const { | 188 bool AppContextMenu::IsCommandIdChecked(int command_id) const { |
190 if (command_id >= LAUNCH_TYPE_START && command_id < LAUNCH_TYPE_LAST) { | 189 if (command_id >= USE_LAUNCH_TYPE_COMMAND_START && |
| 190 command_id < USE_LAUNCH_TYPE_COMMAND_END) { |
191 return static_cast<int>(controller_->GetExtensionLaunchType( | 191 return static_cast<int>(controller_->GetExtensionLaunchType( |
192 profile_, app_id_)) + LAUNCH_TYPE_START == command_id; | 192 profile_, app_id_)) + USE_LAUNCH_TYPE_COMMAND_START == command_id; |
193 } else if (command_id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && | 193 } else if (command_id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && |
194 command_id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { | 194 command_id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { |
195 return extension_menu_items_->IsCommandIdChecked(command_id); | 195 return extension_menu_items_->IsCommandIdChecked(command_id); |
196 } | 196 } |
197 return false; | 197 return false; |
198 } | 198 } |
199 | 199 |
200 bool AppContextMenu::IsCommandIdEnabled(int command_id) const { | 200 bool AppContextMenu::IsCommandIdEnabled(int command_id) const { |
201 if (command_id == TOGGLE_PIN) { | 201 if (command_id == TOGGLE_PIN) { |
202 return controller_->GetPinnable() == | 202 return controller_->GetPinnable() == |
(...skipping 29 matching lines...) Expand all Loading... |
232 if (command_id == LAUNCH_NEW) { | 232 if (command_id == LAUNCH_NEW) { |
233 delegate_->ExecuteLaunchCommand(event_flags); | 233 delegate_->ExecuteLaunchCommand(event_flags); |
234 } else if (command_id == TOGGLE_PIN && controller_->GetPinnable() == | 234 } else if (command_id == TOGGLE_PIN && controller_->GetPinnable() == |
235 AppListControllerDelegate::PIN_EDITABLE) { | 235 AppListControllerDelegate::PIN_EDITABLE) { |
236 if (controller_->IsAppPinned(app_id_)) | 236 if (controller_->IsAppPinned(app_id_)) |
237 controller_->UnpinApp(app_id_); | 237 controller_->UnpinApp(app_id_); |
238 else | 238 else |
239 controller_->PinApp(app_id_); | 239 controller_->PinApp(app_id_); |
240 } else if (command_id == CREATE_SHORTCUTS) { | 240 } else if (command_id == CREATE_SHORTCUTS) { |
241 controller_->DoCreateShortcutsFlow(profile_, app_id_); | 241 controller_->DoCreateShortcutsFlow(profile_, app_id_); |
242 } else if (command_id >= LAUNCH_TYPE_START && | 242 } else if (command_id >= USE_LAUNCH_TYPE_COMMAND_START && |
243 command_id < LAUNCH_TYPE_LAST) { | 243 command_id < USE_LAUNCH_TYPE_COMMAND_END) { |
244 extensions::LaunchType launch_type = | 244 extensions::LaunchType launch_type = static_cast<extensions::LaunchType>( |
245 static_cast<extensions::LaunchType>(command_id - LAUNCH_TYPE_START); | 245 command_id - USE_LAUNCH_TYPE_COMMAND_START); |
246 // Streamlined hosted apps can only toggle between LAUNCH_WINDOW and | 246 // Streamlined hosted apps can only toggle between LAUNCH_TYPE_WINDOW and |
247 // LAUNCH_REGULAR. | 247 // LAUNCH_TYPE_REGULAR. |
248 if (CommandLine::ForCurrentProcess()->HasSwitch( | 248 if (CommandLine::ForCurrentProcess()->HasSwitch( |
249 switches::kEnableStreamlinedHostedApps)) { | 249 switches::kEnableStreamlinedHostedApps)) { |
250 launch_type = (controller_->GetExtensionLaunchType(profile_, app_id_) == | 250 launch_type = (controller_->GetExtensionLaunchType(profile_, app_id_) == |
251 extensions::LAUNCH_TYPE_REGULAR) ? | 251 extensions::LAUNCH_TYPE_REGULAR) ? |
252 extensions::LAUNCH_TYPE_WINDOW : | 252 extensions::LAUNCH_TYPE_WINDOW : |
253 extensions::LAUNCH_TYPE_REGULAR; | 253 extensions::LAUNCH_TYPE_REGULAR; |
254 } | 254 } |
255 controller_->SetExtensionLaunchType(profile_, app_id_, launch_type); | 255 controller_->SetExtensionLaunchType(profile_, app_id_, launch_type); |
256 } else if (command_id == OPTIONS) { | 256 } else if (command_id == OPTIONS) { |
257 controller_->ShowOptionsPage(profile_, app_id_); | 257 controller_->ShowOptionsPage(profile_, app_id_); |
258 } else if (command_id == UNINSTALL) { | 258 } else if (command_id == UNINSTALL) { |
259 controller_->UninstallApp(profile_, app_id_); | 259 controller_->UninstallApp(profile_, app_id_); |
260 } else if (command_id == DETAILS) { | 260 } else if (command_id == DETAILS) { |
261 controller_->ShowAppInWebStore(profile_, app_id_, is_search_result_); | 261 controller_->ShowAppInWebStore(profile_, app_id_, is_search_result_); |
262 } else if (command_id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && | 262 } else if (command_id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && |
263 command_id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { | 263 command_id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { |
264 extension_menu_items_->ExecuteCommand(command_id, NULL, | 264 extension_menu_items_->ExecuteCommand(command_id, NULL, |
265 content::ContextMenuParams()); | 265 content::ContextMenuParams()); |
266 } else if (command_id == MENU_NEW_WINDOW) { | 266 } else if (command_id == MENU_NEW_WINDOW) { |
267 controller_->CreateNewWindow(profile_, false); | 267 controller_->CreateNewWindow(profile_, false); |
268 } else if (command_id == MENU_NEW_INCOGNITO_WINDOW) { | 268 } else if (command_id == MENU_NEW_INCOGNITO_WINDOW) { |
269 controller_->CreateNewWindow(profile_, true); | 269 controller_->CreateNewWindow(profile_, true); |
270 } | 270 } |
271 } | 271 } |
272 | 272 |
273 } // namespace app_list | 273 } // namespace app_list |
OLD | NEW |