| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/ash/launcher/launcher_context_menu.h" | 5 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "ash/desktop_background/user_wallpaper_delegate.h" | 9 #include "ash/desktop_background/user_wallpaper_delegate.h" |
| 10 #include "ash/metrics/user_metrics_recorder.h" | 10 #include "ash/metrics/user_metrics_recorder.h" |
| 11 #include "ash/root_window_controller.h" | |
| 12 #include "ash/session/session_state_delegate.h" | 11 #include "ash/session/session_state_delegate.h" |
| 12 #include "ash/shelf/shelf.h" |
| 13 #include "ash/shelf/shelf_item_delegate.h" | 13 #include "ash/shelf/shelf_item_delegate.h" |
| 14 #include "ash/shelf/shelf_widget.h" | 14 #include "ash/shelf/shelf_widget.h" |
| 15 #include "ash/shell.h" | 15 #include "ash/shell.h" |
| 16 #include "base/bind.h" | 16 #include "base/bind.h" |
| 17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 18 #include "chrome/browser/extensions/context_menu_matcher.h" | 18 #include "chrome/browser/extensions/context_menu_matcher.h" |
| 19 #include "chrome/browser/extensions/extension_util.h" | 19 #include "chrome/browser/extensions/extension_util.h" |
| 20 #include "chrome/browser/fullscreen.h" | 20 #include "chrome/browser/fullscreen.h" |
| 21 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 21 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/ui/ash/chrome_shell_delegate.h" | 23 #include "chrome/browser/ui/ash/chrome_shell_delegate.h" |
| 24 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 24 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 25 #include "chrome/common/extensions/extension_constants.h" | 25 #include "chrome/common/extensions/extension_constants.h" |
| 26 #include "chrome/common/pref_names.h" |
| 26 #include "chrome/grit/generated_resources.h" | 27 #include "chrome/grit/generated_resources.h" |
| 27 #include "components/prefs/pref_service.h" | 28 #include "components/prefs/pref_service.h" |
| 28 #include "content/public/common/context_menu_params.h" | 29 #include "content/public/common/context_menu_params.h" |
| 29 #include "grit/ash_strings.h" | 30 #include "grit/ash_strings.h" |
| 30 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 34 bool MenuItemHasLauncherContext(const extensions::MenuItem* item) { | 35 bool MenuItemHasLauncherContext(const extensions::MenuItem* item) { |
| 35 return item->contexts().Contains(extensions::MenuItem::LAUNCHER); | 36 return item->contexts().Contains(extensions::MenuItem::LAUNCHER); |
| 36 } | 37 } |
| 37 | 38 |
| 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 |
| 38 } // namespace | 45 } // namespace |
| 39 | 46 |
| 40 LauncherContextMenu::LauncherContextMenu(ChromeLauncherController* controller, | 47 LauncherContextMenu::LauncherContextMenu(ChromeLauncherController* controller, |
| 41 const ash::ShelfItem* item, | 48 const ash::ShelfItem* item, |
| 42 aura::Window* root_window) | 49 ash::Shelf* shelf) |
| 43 : ui::SimpleMenuModel(nullptr), | 50 : ui::SimpleMenuModel(nullptr), |
| 44 controller_(controller), | 51 controller_(controller), |
| 45 item_(item ? *item : ash::ShelfItem()), | 52 item_(item ? *item : ash::ShelfItem()), |
| 46 shelf_alignment_menu_(root_window), | 53 shelf_alignment_menu_(shelf), |
| 47 root_window_(root_window) { | 54 shelf_(shelf) { |
| 48 DCHECK(root_window_); | 55 DCHECK(shelf_); |
| 49 Init(); | 56 Init(); |
| 50 } | 57 } |
| 51 | 58 |
| 52 void LauncherContextMenu::Init() { | 59 void LauncherContextMenu::Init() { |
| 53 set_delegate(this); | 60 set_delegate(this); |
| 54 | 61 |
| 55 if (is_valid_item()) { | 62 if (item_.id != 0) { |
| 56 extension_items_.reset(new extensions::ContextMenuMatcher( | 63 extension_items_.reset(new extensions::ContextMenuMatcher( |
| 57 controller_->profile(), this, this, | 64 controller_->profile(), this, this, |
| 58 base::Bind(MenuItemHasLauncherContext))); | 65 base::Bind(MenuItemHasLauncherContext))); |
| 59 if (item_.type == ash::TYPE_APP_SHORTCUT || | 66 if (item_.type == ash::TYPE_APP_SHORTCUT || |
| 60 item_.type == ash::TYPE_WINDOWED_APP) { | 67 item_.type == ash::TYPE_WINDOWED_APP) { |
| 61 // V1 apps can be started from the menu - but V2 apps should not. | 68 // V1 apps can be started from the menu - but V2 apps should not. |
| 62 if (!controller_->IsPlatformApp(item_.id)) { | 69 if (!controller_->IsPlatformApp(item_.id)) { |
| 63 AddItem(MENU_OPEN_NEW, base::string16()); | 70 AddItem(MENU_OPEN_NEW, base::string16()); |
| 64 AddSeparator(ui::NORMAL_SEPARATOR); | 71 AddSeparator(ui::NORMAL_SEPARATOR); |
| 65 } | 72 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 &index, | 150 &index, |
| 144 false); // is_action_menu | 151 false); // is_action_menu |
| 145 AddSeparator(ui::NORMAL_SEPARATOR); | 152 AddSeparator(ui::NORMAL_SEPARATOR); |
| 146 } | 153 } |
| 147 } | 154 } |
| 148 } | 155 } |
| 149 // In fullscreen, the launcher is either hidden or autohidden depending on the | 156 // In fullscreen, the launcher is either hidden or autohidden depending on the |
| 150 // type of fullscreen. Do not show the auto-hide menu item while in fullscreen | 157 // type of fullscreen. Do not show the auto-hide menu item while in fullscreen |
| 151 // because it is confusing when the preference appears not to apply. | 158 // because it is confusing when the preference appears not to apply. |
| 152 if (!IsFullScreenMode() && | 159 if (!IsFullScreenMode() && |
| 153 controller_->CanUserModifyShelfAutoHideBehavior(root_window_)) { | 160 CanUserModifyShelfAutoHideBehavior(controller_->profile())) { |
| 154 AddCheckItemWithStringId(MENU_AUTO_HIDE, | 161 AddCheckItemWithStringId(MENU_AUTO_HIDE, |
| 155 IDS_ASH_SHELF_CONTEXT_MENU_AUTO_HIDE); | 162 IDS_ASH_SHELF_CONTEXT_MENU_AUTO_HIDE); |
| 156 } | 163 } |
| 157 if (ash::ShelfWidget::ShelfAlignmentAllowed() && | 164 if (ash::ShelfWidget::ShelfAlignmentAllowed() && |
| 158 !ash::Shell::GetInstance()->session_state_delegate()->IsScreenLocked()) { | 165 !ash::Shell::GetInstance()->session_state_delegate()->IsScreenLocked()) { |
| 159 AddSubMenuWithStringId(MENU_ALIGNMENT_MENU, | 166 AddSubMenuWithStringId(MENU_ALIGNMENT_MENU, |
| 160 IDS_ASH_SHELF_CONTEXT_MENU_POSITION, | 167 IDS_ASH_SHELF_CONTEXT_MENU_POSITION, |
| 161 &shelf_alignment_menu_); | 168 &shelf_alignment_menu_); |
| 162 } | 169 } |
| 163 if (!controller_->IsLoggedInAsGuest()) { | 170 if (!controller_->IsLoggedInAsGuest()) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 case LAUNCH_TYPE_REGULAR_TAB: | 209 case LAUNCH_TYPE_REGULAR_TAB: |
| 203 return controller_->GetLaunchType(item_.id) == | 210 return controller_->GetLaunchType(item_.id) == |
| 204 extensions::LAUNCH_TYPE_REGULAR; | 211 extensions::LAUNCH_TYPE_REGULAR; |
| 205 case LAUNCH_TYPE_WINDOW: | 212 case LAUNCH_TYPE_WINDOW: |
| 206 return controller_->GetLaunchType(item_.id) == | 213 return controller_->GetLaunchType(item_.id) == |
| 207 extensions::LAUNCH_TYPE_WINDOW; | 214 extensions::LAUNCH_TYPE_WINDOW; |
| 208 case LAUNCH_TYPE_FULLSCREEN: | 215 case LAUNCH_TYPE_FULLSCREEN: |
| 209 return controller_->GetLaunchType(item_.id) == | 216 return controller_->GetLaunchType(item_.id) == |
| 210 extensions::LAUNCH_TYPE_FULLSCREEN; | 217 extensions::LAUNCH_TYPE_FULLSCREEN; |
| 211 case MENU_AUTO_HIDE: | 218 case MENU_AUTO_HIDE: |
| 212 return controller_->GetShelfAutoHideBehavior(root_window_) == | 219 return shelf_->GetAutoHideBehavior() == |
| 213 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; | 220 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; |
| 214 default: | 221 default: |
| 215 if (command_id < MENU_ITEM_COUNT) | 222 if (command_id < MENU_ITEM_COUNT) |
| 216 return false; | 223 return false; |
| 217 return (extension_items_ && | 224 return (extension_items_ && |
| 218 extension_items_->IsCommandIdChecked(command_id)); | 225 extension_items_->IsCommandIdChecked(command_id)); |
| 219 } | 226 } |
| 220 } | 227 } |
| 221 | 228 |
| 222 bool LauncherContextMenu::IsCommandIdEnabled(int command_id) const { | 229 bool LauncherContextMenu::IsCommandIdEnabled(int command_id) const { |
| 223 switch (command_id) { | 230 switch (command_id) { |
| 224 case MENU_PIN: | 231 case MENU_PIN: |
| 225 return controller_->IsPinnable(item_.id); | 232 return controller_->IsPinnable(item_.id); |
| 226 case MENU_CHANGE_WALLPAPER: | 233 case MENU_CHANGE_WALLPAPER: |
| 227 return ash::Shell::GetInstance()->user_wallpaper_delegate()-> | 234 return ash::Shell::GetInstance()->user_wallpaper_delegate()-> |
| 228 CanOpenSetWallpaperPage(); | 235 CanOpenSetWallpaperPage(); |
| 229 case MENU_NEW_WINDOW: | 236 case MENU_NEW_WINDOW: |
| 230 // "Normal" windows are not allowed when incognito is enforced. | 237 // "Normal" windows are not allowed when incognito is enforced. |
| 231 return IncognitoModePrefs::GetAvailability( | 238 return IncognitoModePrefs::GetAvailability( |
| 232 controller_->profile()->GetPrefs()) != IncognitoModePrefs::FORCED; | 239 controller_->profile()->GetPrefs()) != IncognitoModePrefs::FORCED; |
| 233 case MENU_AUTO_HIDE: | 240 case MENU_AUTO_HIDE: |
| 234 return controller_->CanUserModifyShelfAutoHideBehavior(root_window_); | 241 return CanUserModifyShelfAutoHideBehavior(controller_->profile()); |
| 235 case MENU_NEW_INCOGNITO_WINDOW: | 242 case MENU_NEW_INCOGNITO_WINDOW: |
| 236 // Incognito windows are not allowed when incognito is disabled. | 243 // Incognito windows are not allowed when incognito is disabled. |
| 237 return IncognitoModePrefs::GetAvailability( | 244 return IncognitoModePrefs::GetAvailability( |
| 238 controller_->profile()->GetPrefs()) != IncognitoModePrefs::DISABLED; | 245 controller_->profile()->GetPrefs()) != IncognitoModePrefs::DISABLED; |
| 239 default: | 246 default: |
| 240 if (command_id < MENU_ITEM_COUNT) | 247 if (command_id < MENU_ITEM_COUNT) |
| 241 return true; | 248 return true; |
| 242 return (extension_items_ && | 249 return (extension_items_ && |
| 243 extension_items_->IsCommandIdEnabled(command_id)); | 250 extension_items_->IsCommandIdEnabled(command_id)); |
| 244 } | 251 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 ? extensions::LAUNCH_TYPE_REGULAR | 296 ? extensions::LAUNCH_TYPE_REGULAR |
| 290 : extensions::LAUNCH_TYPE_WINDOW; | 297 : extensions::LAUNCH_TYPE_WINDOW; |
| 291 } | 298 } |
| 292 controller_->SetLaunchType(item_.id, launch_type); | 299 controller_->SetLaunchType(item_.id, launch_type); |
| 293 break; | 300 break; |
| 294 } | 301 } |
| 295 case LAUNCH_TYPE_FULLSCREEN: | 302 case LAUNCH_TYPE_FULLSCREEN: |
| 296 controller_->SetLaunchType(item_.id, extensions::LAUNCH_TYPE_FULLSCREEN); | 303 controller_->SetLaunchType(item_.id, extensions::LAUNCH_TYPE_FULLSCREEN); |
| 297 break; | 304 break; |
| 298 case MENU_AUTO_HIDE: | 305 case MENU_AUTO_HIDE: |
| 299 controller_->ToggleShelfAutoHideBehavior(root_window_); | 306 shelf_->SetAutoHideBehavior(shelf_->GetAutoHideBehavior() == |
| 307 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS |
| 308 ? ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER |
| 309 : ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
| 300 break; | 310 break; |
| 301 case MENU_NEW_WINDOW: | 311 case MENU_NEW_WINDOW: |
| 302 controller_->CreateNewWindow(); | 312 controller_->CreateNewWindow(); |
| 303 break; | 313 break; |
| 304 case MENU_NEW_INCOGNITO_WINDOW: | 314 case MENU_NEW_INCOGNITO_WINDOW: |
| 305 controller_->CreateNewIncognitoWindow(); | 315 controller_->CreateNewIncognitoWindow(); |
| 306 break; | 316 break; |
| 307 case MENU_ALIGNMENT_MENU: | 317 case MENU_ALIGNMENT_MENU: |
| 308 break; | 318 break; |
| 309 case MENU_CHANGE_WALLPAPER: | 319 case MENU_CHANGE_WALLPAPER: |
| 310 ash::Shell::GetInstance()->user_wallpaper_delegate()-> | 320 ash::Shell::GetInstance()->user_wallpaper_delegate()-> |
| 311 OpenSetWallpaperPage(); | 321 OpenSetWallpaperPage(); |
| 312 break; | 322 break; |
| 313 default: | 323 default: |
| 314 if (extension_items_) { | 324 if (extension_items_) { |
| 315 extension_items_->ExecuteCommand(command_id, nullptr, nullptr, | 325 extension_items_->ExecuteCommand(command_id, nullptr, nullptr, |
| 316 content::ContextMenuParams()); | 326 content::ContextMenuParams()); |
| 317 } | 327 } |
| 318 } | 328 } |
| 319 } | 329 } |
| OLD | NEW |