Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ash/launcher/launcher_context_menu.h" | 5 #include "chrome/browser/ui/ash/launcher/extension_launcher_context_menu.h" |
| 6 | 6 |
| 7 #include <string> | |
| 8 | |
| 9 #include "ash/desktop_background/user_wallpaper_delegate.h" | |
| 10 #include "ash/metrics/user_metrics_recorder.h" | |
| 11 #include "ash/session/session_state_delegate.h" | |
| 12 #include "ash/shelf/shelf.h" | 7 #include "ash/shelf/shelf.h" |
| 13 #include "ash/shelf/shelf_item_delegate.h" | 8 #include "ash/shelf/shelf_item_delegate.h" |
| 14 #include "ash/shelf/shelf_widget.h" | |
| 15 #include "ash/shell.h" | |
| 16 #include "base/bind.h" | 9 #include "base/bind.h" |
| 17 #include "build/build_config.h" | |
| 18 #include "chrome/browser/extensions/context_menu_matcher.h" | 10 #include "chrome/browser/extensions/context_menu_matcher.h" |
| 19 #include "chrome/browser/extensions/extension_util.h" | 11 #include "chrome/browser/extensions/extension_util.h" |
| 20 #include "chrome/browser/fullscreen.h" | |
| 21 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 12 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/ui/ash/chrome_shell_delegate.h" | |
| 24 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 25 #include "chrome/common/extensions/extension_constants.h" | 15 #include "chrome/common/extensions/extension_constants.h" |
| 26 #include "chrome/common/pref_names.h" | |
| 27 #include "chrome/grit/generated_resources.h" | 16 #include "chrome/grit/generated_resources.h" |
| 28 #include "components/prefs/pref_service.h" | |
| 29 #include "content/public/common/context_menu_params.h" | 17 #include "content/public/common/context_menu_params.h" |
| 30 #include "grit/ash_strings.h" | 18 #include "grit/ash_strings.h" |
| 31 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 32 | 20 |
| 33 namespace { | 21 namespace { |
| 34 | 22 |
| 35 bool MenuItemHasLauncherContext(const extensions::MenuItem* item) { | 23 bool MenuItemHasLauncherContext(const extensions::MenuItem* item) { |
| 36 return item->contexts().Contains(extensions::MenuItem::LAUNCHER); | 24 return item->contexts().Contains(extensions::MenuItem::LAUNCHER); |
| 37 } | 25 } |
| 38 | 26 |
| 39 // Returns true if the user can modify the |shelf|'s auto-hide behavior. | |
| 40 bool CanUserModifyShelfAutoHideBehavior(const Profile* profile) { | |
| 41 const std::string& pref = prefs::kShelfAutoHideBehaviorLocal; | |
| 42 return profile->GetPrefs()->FindPreference(pref)->IsUserModifiable(); | |
| 43 } | |
| 44 | |
| 45 } // namespace | 27 } // namespace |
| 46 | 28 |
| 47 LauncherContextMenu::LauncherContextMenu(ChromeLauncherController* controller, | 29 ExtensionLauncherContextMenu::ExtensionLauncherContextMenu( |
| 48 const ash::ShelfItem* item, | 30 ChromeLauncherController* controller, |
| 49 ash::Shelf* shelf) | 31 const ash::ShelfItem* item, |
| 50 : ui::SimpleMenuModel(nullptr), | 32 ash::Shelf* shelf) |
| 51 controller_(controller), | 33 : LauncherContextMenu(controller, item, shelf) { |
| 52 item_(item ? *item : ash::ShelfItem()), | |
| 53 shelf_alignment_menu_(shelf), | |
| 54 shelf_(shelf) { | |
| 55 DCHECK(shelf_); | |
| 56 Init(); | 34 Init(); |
| 57 } | 35 } |
| 58 | 36 |
| 59 void LauncherContextMenu::Init() { | 37 ExtensionLauncherContextMenu::~ExtensionLauncherContextMenu() {} |
| 60 set_delegate(this); | |
| 61 | 38 |
| 62 if (item_.id != 0) { | 39 void ExtensionLauncherContextMenu::Init() { |
| 63 extension_items_.reset(new extensions::ContextMenuMatcher( | 40 extension_items_.reset(new extensions::ContextMenuMatcher( |
| 64 controller_->profile(), this, this, | 41 controller()->profile(), this, this, |
| 65 base::Bind(MenuItemHasLauncherContext))); | 42 base::Bind(MenuItemHasLauncherContext))); |
| 66 if (item_.type == ash::TYPE_APP_SHORTCUT || | 43 if (item().type == ash::TYPE_APP_SHORTCUT || |
| 67 item_.type == ash::TYPE_WINDOWED_APP) { | 44 item().type == ash::TYPE_WINDOWED_APP) { |
| 68 // V1 apps can be started from the menu - but V2 apps should not. | 45 // V1 apps can be started from the menu - but V2 apps should not. |
| 69 if (!controller_->IsPlatformApp(item_.id)) { | 46 if (!controller()->IsPlatformApp(item().id)) { |
| 70 AddItem(MENU_OPEN_NEW, base::string16()); | 47 AddItem(MENU_OPEN_NEW, base::string16()); |
| 71 AddSeparator(ui::NORMAL_SEPARATOR); | 48 AddSeparator(ui::NORMAL_SEPARATOR); |
| 72 } | 49 } |
| 73 const std::string app_id = controller_->GetAppIDForShelfID(item_.id); | 50 AddPinMenu(); |
| 74 int menu_pin_string_id; | 51 if (controller()->IsOpen(item().id)) |
| 75 if (!controller_->CanPin(app_id)) | 52 AddItemWithStringId(MENU_CLOSE, IDS_LAUNCHER_CONTEXT_MENU_CLOSE); |
| 76 menu_pin_string_id = IDS_LAUNCHER_CONTEXT_MENU_PIN_ENFORCED_BY_POLICY; | 53 |
| 77 else if (controller_->IsPinned(item_.id)) | 54 if (!controller()->IsPlatformApp(item().id) && |
| 78 menu_pin_string_id = IDS_LAUNCHER_CONTEXT_MENU_UNPIN; | 55 item().type != ash::TYPE_WINDOWED_APP) { |
| 79 else | 56 AddSeparator(ui::NORMAL_SEPARATOR); |
| 80 menu_pin_string_id = IDS_LAUNCHER_CONTEXT_MENU_PIN; | 57 if (extensions::util::IsNewBookmarkAppsEnabled()) { |
| 81 AddItem(MENU_PIN, l10n_util::GetStringUTF16(menu_pin_string_id)); | 58 // With bookmark apps enabled, hosted apps launch in a window by |
| 82 if (controller_->IsOpen(item_.id)) { | 59 // default. This menu item is re-interpreted as a single, toggle-able |
| 83 AddItem(MENU_CLOSE, | 60 // option to launch the hosted app as a tab. |
| 84 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_CLOSE)); | 61 AddCheckItemWithStringId(LAUNCH_TYPE_WINDOW, |
| 85 } | 62 IDS_APP_CONTEXT_MENU_OPEN_WINDOW); |
| 86 if (!controller_->IsPlatformApp(item_.id) && | 63 } else { |
| 87 item_.type != ash::TYPE_WINDOWED_APP) { | 64 AddCheckItemWithStringId(LAUNCH_TYPE_REGULAR_TAB, |
| 88 AddSeparator(ui::NORMAL_SEPARATOR); | 65 IDS_APP_CONTEXT_MENU_OPEN_REGULAR); |
| 89 if (extensions::util::IsNewBookmarkAppsEnabled()) { | 66 AddCheckItemWithStringId(LAUNCH_TYPE_PINNED_TAB, |
| 90 // With bookmark apps enabled, hosted apps launch in a window by | 67 IDS_APP_CONTEXT_MENU_OPEN_PINNED); |
| 91 // default. This menu item is re-interpreted as a single, toggle-able | 68 AddCheckItemWithStringId(LAUNCH_TYPE_WINDOW, |
| 92 // option to launch the hosted app as a tab. | 69 IDS_APP_CONTEXT_MENU_OPEN_WINDOW); |
| 93 AddCheckItemWithStringId(LAUNCH_TYPE_WINDOW, | 70 // Even though the launch type is Full Screen it is more accurately |
| 94 IDS_APP_CONTEXT_MENU_OPEN_WINDOW); | 71 // described as Maximized in Ash. |
| 95 } else { | 72 AddCheckItemWithStringId(LAUNCH_TYPE_FULLSCREEN, |
| 96 AddCheckItemWithStringId( | 73 IDS_APP_CONTEXT_MENU_OPEN_MAXIMIZED); |
| 97 LAUNCH_TYPE_REGULAR_TAB, | |
| 98 IDS_APP_CONTEXT_MENU_OPEN_REGULAR); | |
| 99 AddCheckItemWithStringId( | |
| 100 LAUNCH_TYPE_PINNED_TAB, | |
| 101 IDS_APP_CONTEXT_MENU_OPEN_PINNED); | |
| 102 AddCheckItemWithStringId( | |
| 103 LAUNCH_TYPE_WINDOW, | |
| 104 IDS_APP_CONTEXT_MENU_OPEN_WINDOW); | |
| 105 // Even though the launch type is Full Screen it is more accurately | |
| 106 // described as Maximized in Ash. | |
| 107 AddCheckItemWithStringId( | |
| 108 LAUNCH_TYPE_FULLSCREEN, | |
| 109 IDS_APP_CONTEXT_MENU_OPEN_MAXIMIZED); | |
| 110 } | |
| 111 } | |
| 112 } else if (item_.type == ash::TYPE_BROWSER_SHORTCUT) { | |
| 113 AddItem(MENU_NEW_WINDOW, | |
| 114 l10n_util::GetStringUTF16(IDS_APP_LIST_NEW_WINDOW)); | |
| 115 if (!controller_->IsLoggedInAsGuest()) { | |
| 116 AddItem(MENU_NEW_INCOGNITO_WINDOW, | |
| 117 l10n_util::GetStringUTF16(IDS_APP_LIST_NEW_INCOGNITO_WINDOW)); | |
| 118 } | |
| 119 } else if (item_.type == ash::TYPE_DIALOG) { | |
| 120 AddItem(MENU_CLOSE, | |
| 121 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_CLOSE)); | |
| 122 } else { | |
| 123 if (item_.type == ash::TYPE_PLATFORM_APP) { | |
| 124 AddItem( | |
| 125 MENU_PIN, | |
| 126 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_PIN)); | |
| 127 } | |
| 128 bool show_close_button = controller_->IsOpen(item_.id); | |
| 129 #if defined(OS_CHROMEOS) | |
| 130 if (extension_misc::IsImeMenuExtensionId( | |
| 131 controller_->GetAppIDForShelfID(item_.id))) { | |
| 132 show_close_button = false; | |
| 133 } | |
| 134 #endif | |
| 135 if (show_close_button) { | |
| 136 AddItem(MENU_CLOSE, | |
| 137 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_CLOSE)); | |
| 138 } | 74 } |
| 139 } | 75 } |
| 140 AddSeparator(ui::NORMAL_SEPARATOR); | 76 } else if (item().type == ash::TYPE_BROWSER_SHORTCUT) { |
| 141 if (item_.type == ash::TYPE_APP_SHORTCUT || | 77 AddItemWithStringId(MENU_NEW_WINDOW, IDS_APP_LIST_NEW_WINDOW); |
| 142 item_.type == ash::TYPE_WINDOWED_APP || | 78 if (!controller()->IsLoggedInAsGuest()) { |
| 143 item_.type == ash::TYPE_PLATFORM_APP) { | 79 AddItemWithStringId(MENU_NEW_INCOGNITO_WINDOW, |
| 144 const extensions::MenuItem::ExtensionKey app_key( | 80 IDS_APP_LIST_NEW_INCOGNITO_WINDOW); |
| 145 controller_->GetAppIDForShelfID(item_.id)); | 81 } |
| 146 if (!app_key.empty()) { | 82 } else if (item().type == ash::TYPE_DIALOG) { |
| 147 int index = 0; | 83 AddItemWithStringId(MENU_CLOSE, IDS_LAUNCHER_CONTEXT_MENU_CLOSE); |
| 148 extension_items_->AppendExtensionItems(app_key, | 84 } else { |
| 149 base::string16(), | 85 if (item().type == ash::TYPE_PLATFORM_APP) |
| 150 &index, | 86 AddItemWithStringId(MENU_PIN, IDS_LAUNCHER_CONTEXT_MENU_PIN); |
| 151 false); // is_action_menu | 87 bool show_close_button = controller()->IsOpen(item().id); |
| 152 AddSeparator(ui::NORMAL_SEPARATOR); | 88 #if defined(OS_CHROMEOS) |
| 153 } | 89 if (extension_misc::IsImeMenuExtensionId( |
| 90 controller()->GetAppIDForShelfID(item().id))) | |
| 91 show_close_button = false; | |
| 92 #endif | |
| 93 if (show_close_button) | |
| 94 AddItemWithStringId(MENU_CLOSE, IDS_LAUNCHER_CONTEXT_MENU_CLOSE); | |
| 95 } | |
| 96 AddSeparator(ui::NORMAL_SEPARATOR); | |
| 97 if (item().type == ash::TYPE_APP_SHORTCUT || | |
| 98 item().type == ash::TYPE_WINDOWED_APP || | |
| 99 item().type == ash::TYPE_PLATFORM_APP) { | |
| 100 const extensions::MenuItem::ExtensionKey app_key( | |
| 101 controller()->GetAppIDForShelfID(item().id)); | |
| 102 if (!app_key.empty()) { | |
| 103 int index = 0; | |
| 104 extension_items_->AppendExtensionItems(app_key, base::string16(), &index, | |
| 105 false); // is_action_menu | |
| 106 AddSeparator(ui::NORMAL_SEPARATOR); | |
| 154 } | 107 } |
| 155 } | 108 } |
| 156 // In fullscreen, the launcher is either hidden or autohidden depending on the | 109 AddAutohideAlignmentWallpaperMenu(); |
| 157 // type of fullscreen. Do not show the auto-hide menu item while in fullscreen | |
| 158 // because it is confusing when the preference appears not to apply. | |
| 159 if (!IsFullScreenMode() && | |
| 160 CanUserModifyShelfAutoHideBehavior(controller_->profile())) { | |
| 161 AddCheckItemWithStringId(MENU_AUTO_HIDE, | |
| 162 IDS_ASH_SHELF_CONTEXT_MENU_AUTO_HIDE); | |
| 163 } | |
| 164 if (ash::ShelfWidget::ShelfAlignmentAllowed() && | |
| 165 !ash::Shell::GetInstance()->session_state_delegate()->IsScreenLocked()) { | |
| 166 AddSubMenuWithStringId(MENU_ALIGNMENT_MENU, | |
| 167 IDS_ASH_SHELF_CONTEXT_MENU_POSITION, | |
| 168 &shelf_alignment_menu_); | |
| 169 } | |
| 170 #if defined(OS_CHROMEOS) | |
| 171 if (!controller_->IsLoggedInAsGuest()) { | |
| 172 AddItem(MENU_CHANGE_WALLPAPER, | |
| 173 l10n_util::GetStringUTF16(IDS_AURA_SET_DESKTOP_WALLPAPER)); | |
| 174 } | |
| 175 #endif | |
| 176 } | 110 } |
| 177 | 111 |
| 178 LauncherContextMenu::~LauncherContextMenu() { | 112 bool ExtensionLauncherContextMenu::IsItemForCommandIdDynamic( |
| 179 } | 113 int command_id) const { |
| 180 | |
| 181 bool LauncherContextMenu::IsItemForCommandIdDynamic(int command_id) const { | |
| 182 return command_id == MENU_OPEN_NEW; | 114 return command_id == MENU_OPEN_NEW; |
| 183 } | 115 } |
| 184 | 116 |
| 185 base::string16 LauncherContextMenu::GetLabelForCommandId(int command_id) const { | 117 base::string16 ExtensionLauncherContextMenu::GetLabelForCommandId( |
| 118 int command_id) const { | |
| 186 if (command_id == MENU_OPEN_NEW) { | 119 if (command_id == MENU_OPEN_NEW) { |
| 187 if (item_.type == ash::TYPE_PLATFORM_APP) { | 120 if (item().type == ash::TYPE_PLATFORM_APP) |
| 188 return l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_NEW_WINDOW); | 121 return l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_NEW_WINDOW); |
| 189 } | 122 switch (controller()->GetLaunchType(item().id)) { |
| 190 switch (controller_->GetLaunchType(item_.id)) { | |
| 191 case extensions::LAUNCH_TYPE_PINNED: | 123 case extensions::LAUNCH_TYPE_PINNED: |
| 192 case extensions::LAUNCH_TYPE_REGULAR: | 124 case extensions::LAUNCH_TYPE_REGULAR: |
| 193 return l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_NEW_TAB); | 125 return l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_NEW_TAB); |
| 194 case extensions::LAUNCH_TYPE_FULLSCREEN: | 126 case extensions::LAUNCH_TYPE_FULLSCREEN: |
| 195 case extensions::LAUNCH_TYPE_WINDOW: | 127 case extensions::LAUNCH_TYPE_WINDOW: |
| 196 return l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_NEW_WINDOW); | 128 return l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_NEW_WINDOW); |
| 197 default: | 129 default: |
| 198 NOTREACHED(); | 130 NOTREACHED(); |
| 199 return base::string16(); | 131 return base::string16(); |
| 200 } | 132 } |
| 201 } | 133 } |
| 202 NOTREACHED(); | 134 NOTREACHED(); |
| 203 return base::string16(); | 135 return base::string16(); |
| 204 } | 136 } |
| 205 | 137 |
| 206 bool LauncherContextMenu::IsCommandIdChecked(int command_id) const { | 138 bool ExtensionLauncherContextMenu::IsCommandIdChecked(int command_id) const { |
| 207 switch (command_id) { | 139 switch (command_id) { |
| 208 case LAUNCH_TYPE_PINNED_TAB: | 140 case LAUNCH_TYPE_PINNED_TAB: |
| 209 return controller_->GetLaunchType(item_.id) == | 141 return controller()->GetLaunchType(item().id) == |
| 210 extensions::LAUNCH_TYPE_PINNED; | 142 extensions::LAUNCH_TYPE_PINNED; |
| 211 case LAUNCH_TYPE_REGULAR_TAB: | 143 case LAUNCH_TYPE_REGULAR_TAB: |
| 212 return controller_->GetLaunchType(item_.id) == | 144 return controller()->GetLaunchType(item().id) == |
| 213 extensions::LAUNCH_TYPE_REGULAR; | 145 extensions::LAUNCH_TYPE_REGULAR; |
| 214 case LAUNCH_TYPE_WINDOW: | 146 case LAUNCH_TYPE_WINDOW: |
| 215 return controller_->GetLaunchType(item_.id) == | 147 return controller()->GetLaunchType(item().id) == |
| 216 extensions::LAUNCH_TYPE_WINDOW; | 148 extensions::LAUNCH_TYPE_WINDOW; |
| 217 case LAUNCH_TYPE_FULLSCREEN: | 149 case LAUNCH_TYPE_FULLSCREEN: |
| 218 return controller_->GetLaunchType(item_.id) == | 150 return controller()->GetLaunchType(item().id) == |
| 219 extensions::LAUNCH_TYPE_FULLSCREEN; | 151 extensions::LAUNCH_TYPE_FULLSCREEN; |
| 220 case MENU_AUTO_HIDE: | |
| 221 return shelf_->GetAutoHideBehavior() == | |
| 222 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; | |
| 223 default: | 152 default: |
| 224 if (command_id < MENU_ITEM_COUNT) | 153 if (command_id < MENU_ITEM_COUNT) |
| 225 return false; | 154 return LauncherContextMenu::IsCommandIdChecked(command_id); |
| 226 return (extension_items_ && | 155 return (extension_items_ && |
| 227 extension_items_->IsCommandIdChecked(command_id)); | 156 extension_items_->IsCommandIdChecked(command_id)); |
| 228 } | 157 } |
| 229 } | 158 } |
| 230 | 159 |
| 231 bool LauncherContextMenu::IsCommandIdEnabled(int command_id) const { | 160 bool ExtensionLauncherContextMenu::IsCommandIdEnabled(int command_id) const { |
| 232 switch (command_id) { | 161 switch (command_id) { |
| 233 case MENU_PIN: | |
| 234 return controller_->IsPinnable(item_.id); | |
| 235 case MENU_CHANGE_WALLPAPER: | |
| 236 return ash::Shell::GetInstance()->user_wallpaper_delegate()-> | |
| 237 CanOpenSetWallpaperPage(); | |
| 238 case MENU_NEW_WINDOW: | 162 case MENU_NEW_WINDOW: |
| 239 // "Normal" windows are not allowed when incognito is enforced. | 163 // "Normal" windows are not allowed when incognito is enforced. |
| 240 return IncognitoModePrefs::GetAvailability( | 164 return IncognitoModePrefs::GetAvailability( |
| 241 controller_->profile()->GetPrefs()) != IncognitoModePrefs::FORCED; | 165 controller()->profile()->GetPrefs()) != |
| 242 case MENU_AUTO_HIDE: | 166 IncognitoModePrefs::FORCED; |
| 243 return CanUserModifyShelfAutoHideBehavior(controller_->profile()); | |
| 244 case MENU_NEW_INCOGNITO_WINDOW: | 167 case MENU_NEW_INCOGNITO_WINDOW: |
| 245 // Incognito windows are not allowed when incognito is disabled. | 168 // Incognito windows are not allowed when incognito is disabled. |
| 246 return IncognitoModePrefs::GetAvailability( | 169 return IncognitoModePrefs::GetAvailability( |
| 247 controller_->profile()->GetPrefs()) != IncognitoModePrefs::DISABLED; | 170 controller()->profile()->GetPrefs()) != |
| 171 IncognitoModePrefs::DISABLED; | |
| 248 default: | 172 default: |
| 249 if (command_id < MENU_ITEM_COUNT) | 173 if (command_id < MENU_ITEM_COUNT) |
| 250 return true; | 174 return LauncherContextMenu::IsCommandIdEnabled(command_id); |
| 251 return (extension_items_ && | 175 return (extension_items_ && |
| 252 extension_items_->IsCommandIdEnabled(command_id)); | 176 extension_items_->IsCommandIdEnabled(command_id)); |
| 253 } | 177 } |
| 254 } | 178 } |
| 255 | 179 |
| 256 bool LauncherContextMenu::GetAcceleratorForCommandId( | 180 void ExtensionLauncherContextMenu::ExecuteCommand(int command_id, |
| 257 int command_id, | 181 int event_flags) { |
| 258 ui::Accelerator* accelerator) { | 182 if (IsCommonCommandId(command_id)) |
| 259 return false; | 183 return LauncherContextMenu::ExecuteCommand(command_id, event_flags); |
|
stevenjb
2016/04/06 22:19:23
Instead of adding a separate method here, have Exe
lgcheng
2016/04/06 22:59:54
Done. This is better implementation.
lgcheng
2016/04/06 23:14:25
Done. ExecuteComand is an overridden function. I c
| |
| 260 } | |
| 261 | |
| 262 void LauncherContextMenu::ExecuteCommand(int command_id, int event_flags) { | |
| 263 switch (static_cast<MenuItem>(command_id)) { | 184 switch (static_cast<MenuItem>(command_id)) { |
| 264 case MENU_OPEN_NEW: | |
| 265 controller_->Launch(item_.id, ui::EF_NONE); | |
| 266 break; | |
| 267 case MENU_CLOSE: | |
| 268 if (item_.type == ash::TYPE_DIALOG) { | |
| 269 ash::ShelfItemDelegate* item_delegate = | |
| 270 ash::Shell::GetInstance() | |
| 271 ->shelf_item_delegate_manager() | |
| 272 ->GetShelfItemDelegate(item_.id); | |
| 273 DCHECK(item_delegate); | |
| 274 item_delegate->Close(); | |
| 275 } else { | |
| 276 // TODO(simonhong): Use ShelfItemDelegate::Close(). | |
| 277 controller_->Close(item_.id); | |
| 278 } | |
| 279 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction( | |
| 280 ash::UMA_CLOSE_THROUGH_CONTEXT_MENU); | |
| 281 break; | |
| 282 case MENU_PIN: | |
| 283 controller_->TogglePinned(item_.id); | |
| 284 break; | |
| 285 case LAUNCH_TYPE_PINNED_TAB: | 185 case LAUNCH_TYPE_PINNED_TAB: |
| 286 controller_->SetLaunchType(item_.id, extensions::LAUNCH_TYPE_PINNED); | 186 controller()->SetLaunchType(item().id, extensions::LAUNCH_TYPE_PINNED); |
| 287 break; | 187 break; |
| 288 case LAUNCH_TYPE_REGULAR_TAB: | 188 case LAUNCH_TYPE_REGULAR_TAB: |
| 289 controller_->SetLaunchType(item_.id, extensions::LAUNCH_TYPE_REGULAR); | 189 controller()->SetLaunchType(item().id, extensions::LAUNCH_TYPE_REGULAR); |
| 290 break; | 190 break; |
| 291 case LAUNCH_TYPE_WINDOW: { | 191 case LAUNCH_TYPE_WINDOW: { |
| 292 extensions::LaunchType launch_type = extensions::LAUNCH_TYPE_WINDOW; | 192 extensions::LaunchType launch_type = extensions::LAUNCH_TYPE_WINDOW; |
| 293 // With bookmark apps enabled, hosted apps can only toggle between | 193 // With bookmark apps enabled, hosted apps can only toggle between |
| 294 // LAUNCH_WINDOW and LAUNCH_REGULAR. | 194 // LAUNCH_WINDOW and LAUNCH_REGULAR. |
| 295 if (extensions::util::IsNewBookmarkAppsEnabled()) { | 195 if (extensions::util::IsNewBookmarkAppsEnabled()) { |
| 296 launch_type = controller_->GetLaunchType(item_.id) == | 196 launch_type = controller()->GetLaunchType(item().id) == |
| 297 extensions::LAUNCH_TYPE_WINDOW | 197 extensions::LAUNCH_TYPE_WINDOW |
| 298 ? extensions::LAUNCH_TYPE_REGULAR | 198 ? extensions::LAUNCH_TYPE_REGULAR |
| 299 : extensions::LAUNCH_TYPE_WINDOW; | 199 : extensions::LAUNCH_TYPE_WINDOW; |
| 300 } | 200 } |
| 301 controller_->SetLaunchType(item_.id, launch_type); | 201 controller()->SetLaunchType(item().id, launch_type); |
| 302 break; | 202 break; |
| 303 } | 203 } |
| 304 case LAUNCH_TYPE_FULLSCREEN: | 204 case LAUNCH_TYPE_FULLSCREEN: |
| 305 controller_->SetLaunchType(item_.id, extensions::LAUNCH_TYPE_FULLSCREEN); | 205 controller()->SetLaunchType(item().id, |
| 306 break; | 206 extensions::LAUNCH_TYPE_FULLSCREEN); |
| 307 case MENU_AUTO_HIDE: | |
| 308 shelf_->SetAutoHideBehavior(shelf_->GetAutoHideBehavior() == | |
| 309 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS | |
| 310 ? ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER | |
| 311 : ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | |
| 312 break; | 207 break; |
| 313 case MENU_NEW_WINDOW: | 208 case MENU_NEW_WINDOW: |
| 314 controller_->CreateNewWindow(); | 209 controller()->CreateNewWindow(); |
| 315 break; | 210 break; |
| 316 case MENU_NEW_INCOGNITO_WINDOW: | 211 case MENU_NEW_INCOGNITO_WINDOW: |
| 317 controller_->CreateNewIncognitoWindow(); | 212 controller()->CreateNewIncognitoWindow(); |
| 318 break; | |
| 319 case MENU_ALIGNMENT_MENU: | |
| 320 break; | |
| 321 case MENU_CHANGE_WALLPAPER: | |
| 322 ash::Shell::GetInstance()->user_wallpaper_delegate()-> | |
| 323 OpenSetWallpaperPage(); | |
| 324 break; | 213 break; |
| 325 default: | 214 default: |
| 326 if (extension_items_) { | 215 if (extension_items_) { |
| 327 extension_items_->ExecuteCommand(command_id, nullptr, nullptr, | 216 extension_items_->ExecuteCommand(command_id, nullptr, nullptr, |
| 328 content::ContextMenuParams()); | 217 content::ContextMenuParams()); |
| 329 } | 218 } |
| 330 } | 219 } |
| 331 } | 220 } |
| OLD | NEW |