Chromium Code Reviews| 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/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" | 11 #include "ash/root_window_controller.h" |
| 12 #include "ash/shelf/shelf_item_delegate.h" | |
| 12 #include "ash/shelf/shelf_widget.h" | 13 #include "ash/shelf/shelf_widget.h" |
| 13 #include "ash/shell.h" | 14 #include "ash/shell.h" |
| 14 #include "base/bind.h" | 15 #include "base/bind.h" |
| 15 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 16 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
| 17 #include "chrome/browser/extensions/context_menu_matcher.h" | 18 #include "chrome/browser/extensions/context_menu_matcher.h" |
| 18 #include "chrome/browser/fullscreen.h" | 19 #include "chrome/browser/fullscreen.h" |
| 19 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 20 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/ui/ash/chrome_shell_delegate.h" | 22 #include "chrome/browser/ui/ash/chrome_shell_delegate.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 35 | 36 |
| 36 } // namespace | 37 } // namespace |
| 37 | 38 |
| 38 LauncherContextMenu::LauncherContextMenu(ChromeLauncherController* controller, | 39 LauncherContextMenu::LauncherContextMenu(ChromeLauncherController* controller, |
| 39 const ash::LauncherItem* item, | 40 const ash::LauncherItem* item, |
| 40 aura::Window* root) | 41 aura::Window* root) |
| 41 : ui::SimpleMenuModel(NULL), | 42 : ui::SimpleMenuModel(NULL), |
| 42 controller_(controller), | 43 controller_(controller), |
| 43 item_(*item), | 44 item_(*item), |
| 44 shelf_alignment_menu_(root), | 45 shelf_alignment_menu_(root), |
| 45 root_window_(root) { | 46 root_window_(root), |
| 47 item_delegate_(NULL) { | |
| 46 DCHECK(item); | 48 DCHECK(item); |
| 47 DCHECK(root_window_); | 49 DCHECK(root_window_); |
| 48 Init(); | 50 Init(); |
| 51 } | |
| 52 | |
| 53 LauncherContextMenu::LauncherContextMenu( | |
| 54 ChromeLauncherController* controller, | |
| 55 ash::ShelfItemDelegate* item_delegate, | |
| 56 ash::LauncherItem* item, | |
| 57 aura::Window* root) | |
| 58 : ui::SimpleMenuModel(NULL), | |
| 59 controller_(controller), | |
| 60 item_(*item), | |
| 61 shelf_alignment_menu_(root), | |
| 62 root_window_(root), | |
| 63 item_delegate_(item_delegate) { | |
| 64 DCHECK(item); | |
| 65 DCHECK(root_window_); | |
| 66 Init(); | |
| 49 } | 67 } |
| 50 | 68 |
| 51 LauncherContextMenu::LauncherContextMenu(ChromeLauncherController* controller, | 69 LauncherContextMenu::LauncherContextMenu(ChromeLauncherController* controller, |
| 52 aura::Window* root) | 70 aura::Window* root) |
| 53 : ui::SimpleMenuModel(NULL), | 71 : ui::SimpleMenuModel(NULL), |
| 54 controller_(controller), | 72 controller_(controller), |
| 55 item_(ash::LauncherItem()), | 73 item_(ash::LauncherItem()), |
| 56 shelf_alignment_menu_(root), | 74 shelf_alignment_menu_(root), |
| 57 extension_items_(new extensions::ContextMenuMatcher( | 75 extension_items_(new extensions::ContextMenuMatcher( |
| 58 controller->profile(), this, this, | 76 controller->profile(), this, this, |
| 59 base::Bind(MenuItemHasLauncherContext))), | 77 base::Bind(MenuItemHasLauncherContext))), |
| 60 root_window_(root) { | 78 root_window_(root), |
| 79 item_delegate_(NULL) { | |
| 61 DCHECK(root_window_); | 80 DCHECK(root_window_); |
| 62 Init(); | 81 Init(); |
| 63 } | 82 } |
| 64 | 83 |
| 65 void LauncherContextMenu::Init() { | 84 void LauncherContextMenu::Init() { |
| 66 extension_items_.reset(new extensions::ContextMenuMatcher( | 85 extension_items_.reset(new extensions::ContextMenuMatcher( |
| 67 controller_->profile(), this, this, | 86 controller_->profile(), this, this, |
| 68 base::Bind(MenuItemHasLauncherContext))); | 87 base::Bind(MenuItemHasLauncherContext))); |
| 69 set_delegate(this); | 88 set_delegate(this); |
| 70 | 89 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 IDS_APP_CONTEXT_MENU_OPEN_MAXIMIZED); | 132 IDS_APP_CONTEXT_MENU_OPEN_MAXIMIZED); |
| 114 } | 133 } |
| 115 } | 134 } |
| 116 } else if (item_.type == ash::TYPE_BROWSER_SHORTCUT) { | 135 } else if (item_.type == ash::TYPE_BROWSER_SHORTCUT) { |
| 117 AddItem(MENU_NEW_WINDOW, | 136 AddItem(MENU_NEW_WINDOW, |
| 118 l10n_util::GetStringUTF16(IDS_LAUNCHER_NEW_WINDOW)); | 137 l10n_util::GetStringUTF16(IDS_LAUNCHER_NEW_WINDOW)); |
| 119 if (!controller_->IsLoggedInAsGuest()) { | 138 if (!controller_->IsLoggedInAsGuest()) { |
| 120 AddItem(MENU_NEW_INCOGNITO_WINDOW, | 139 AddItem(MENU_NEW_INCOGNITO_WINDOW, |
| 121 l10n_util::GetStringUTF16(IDS_LAUNCHER_NEW_INCOGNITO_WINDOW)); | 140 l10n_util::GetStringUTF16(IDS_LAUNCHER_NEW_INCOGNITO_WINDOW)); |
| 122 } | 141 } |
| 142 } else if (item_.type == ash::TYPE_DIALOG) { | |
| 143 AddItem(MENU_CLOSE, | |
| 144 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_CLOSE)); | |
| 123 } else { | 145 } else { |
| 124 if (item_.type == ash::TYPE_PLATFORM_APP) { | 146 if (item_.type == ash::TYPE_PLATFORM_APP) { |
| 125 AddItem( | 147 AddItem( |
| 126 MENU_PIN, | 148 MENU_PIN, |
| 127 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_PIN)); | 149 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_PIN)); |
| 128 } | 150 } |
| 129 if (controller_->IsOpen(item_.id)) { | 151 if (controller_->IsOpen(item_.id)) { |
| 130 AddItem(MENU_CLOSE, | 152 AddItem(MENU_CLOSE, |
| 131 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_CLOSE)); | 153 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_CLOSE)); |
| 132 } | 154 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 ui::Accelerator* accelerator) { | 261 ui::Accelerator* accelerator) { |
| 240 return false; | 262 return false; |
| 241 } | 263 } |
| 242 | 264 |
| 243 void LauncherContextMenu::ExecuteCommand(int command_id, int event_flags) { | 265 void LauncherContextMenu::ExecuteCommand(int command_id, int event_flags) { |
| 244 switch (static_cast<MenuItem>(command_id)) { | 266 switch (static_cast<MenuItem>(command_id)) { |
| 245 case MENU_OPEN_NEW: | 267 case MENU_OPEN_NEW: |
| 246 controller_->Launch(item_.id, ui::EF_NONE); | 268 controller_->Launch(item_.id, ui::EF_NONE); |
| 247 break; | 269 break; |
| 248 case MENU_CLOSE: | 270 case MENU_CLOSE: |
| 249 controller_->Close(item_.id); | 271 if (item_.type == ash::TYPE_DIALOG) { |
| 272 DCHECK(item_delegate_); | |
| 273 item_delegate_->Close(); | |
| 274 } else { | |
| 275 controller_->Close(item_.id); | |
|
sky
2014/01/08 14:39:14
Why can'
t controller_->Close(item_.id); do the ri
simonhong
2014/01/09 00:38:24
Yes, TYPE_DIALOG is not managed by controller_.
I
| |
| 276 } | |
| 250 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction( | 277 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
| 251 ash::UMA_CLOSE_THROUGH_CONTEXT_MENU); | 278 ash::UMA_CLOSE_THROUGH_CONTEXT_MENU); |
| 252 break; | 279 break; |
| 253 case MENU_PIN: | 280 case MENU_PIN: |
| 254 controller_->TogglePinned(item_.id); | 281 controller_->TogglePinned(item_.id); |
| 255 break; | 282 break; |
| 256 case LAUNCH_TYPE_PINNED_TAB: | 283 case LAUNCH_TYPE_PINNED_TAB: |
| 257 controller_->SetLaunchType(item_.id, extensions::LAUNCH_TYPE_PINNED); | 284 controller_->SetLaunchType(item_.id, extensions::LAUNCH_TYPE_PINNED); |
| 258 break; | 285 break; |
| 259 case LAUNCH_TYPE_REGULAR_TAB: { | 286 case LAUNCH_TYPE_REGULAR_TAB: { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 case MENU_CHANGE_WALLPAPER: | 319 case MENU_CHANGE_WALLPAPER: |
| 293 ash::Shell::GetInstance()->user_wallpaper_delegate()-> | 320 ash::Shell::GetInstance()->user_wallpaper_delegate()-> |
| 294 OpenSetWallpaperPage(); | 321 OpenSetWallpaperPage(); |
| 295 break; | 322 break; |
| 296 #endif | 323 #endif |
| 297 default: | 324 default: |
| 298 extension_items_->ExecuteCommand(command_id, NULL, | 325 extension_items_->ExecuteCommand(command_id, NULL, |
| 299 content::ContextMenuParams()); | 326 content::ContextMenuParams()); |
| 300 } | 327 } |
| 301 } | 328 } |
| OLD | NEW |