Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1451)

Side by Side Diff: chrome/browser/ui/ash/launcher/extension_launcher_context_menu.cc

Issue 2052013002: Adding ChromeLauncherController interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@chrome_launcher_smaller_api
Patch Set: Rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 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/extension_launcher_context_menu.h" 5 #include "chrome/browser/ui/ash/launcher/extension_launcher_context_menu.h"
6 6
7 #include "ash/common/shelf/shelf_item_delegate.h" 7 #include "ash/common/shelf/shelf_item_delegate.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "chrome/browser/extensions/context_menu_matcher.h" 10 #include "chrome/browser/extensions/context_menu_matcher.h"
11 #include "chrome/browser/extensions/extension_util.h" 11 #include "chrome/browser/extensions/extension_util.h"
12 #include "chrome/browser/prefs/incognito_mode_prefs.h" 12 #include "chrome/browser/prefs/incognito_mode_prefs.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h" 14 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h"
15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h"
16 #include "chrome/browser/ui/browser_commands.h" 16 #include "chrome/browser/ui/browser_commands.h"
17 #include "chrome/common/extensions/extension_constants.h" 17 #include "chrome/common/extensions/extension_constants.h"
18 #include "chrome/grit/generated_resources.h" 18 #include "chrome/grit/generated_resources.h"
19 #include "content/public/common/context_menu_params.h" 19 #include "content/public/common/context_menu_params.h"
20 #include "grit/ash_strings.h" 20 #include "grit/ash_strings.h"
21 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
22 22
23 namespace { 23 namespace {
24 24
25 bool MenuItemHasLauncherContext(const extensions::MenuItem* item) { 25 bool MenuItemHasLauncherContext(const extensions::MenuItem* item) {
26 return item->contexts().Contains(extensions::MenuItem::LAUNCHER); 26 return item->contexts().Contains(extensions::MenuItem::LAUNCHER);
27 } 27 }
28 28
29 } // namespace 29 } // namespace
30 30
31 ExtensionLauncherContextMenu::ExtensionLauncherContextMenu( 31 ExtensionLauncherContextMenu::ExtensionLauncherContextMenu(
32 ChromeLauncherController* controller, 32 ChromeLauncherControllerImpl* controller,
33 const ash::ShelfItem* item, 33 const ash::ShelfItem* item,
34 ash::WmShelf* wm_shelf) 34 ash::WmShelf* wm_shelf)
35 : LauncherContextMenu(controller, item, wm_shelf) { 35 : LauncherContextMenu(controller, item, wm_shelf) {
36 Init(); 36 Init();
37 } 37 }
38 38
39 ExtensionLauncherContextMenu::~ExtensionLauncherContextMenu() {} 39 ExtensionLauncherContextMenu::~ExtensionLauncherContextMenu() {}
40 40
41 void ExtensionLauncherContextMenu::Init() { 41 void ExtensionLauncherContextMenu::Init() {
42 extension_items_.reset(new extensions::ContextMenuMatcher( 42 extension_items_.reset(new extensions::ContextMenuMatcher(
43 controller()->profile(), this, this, 43 controller()->GetProfile(), this, this,
44 base::Bind(MenuItemHasLauncherContext))); 44 base::Bind(MenuItemHasLauncherContext)));
45 if (item().type == ash::TYPE_APP_SHORTCUT || 45 if (item().type == ash::TYPE_APP_SHORTCUT ||
46 item().type == ash::TYPE_WINDOWED_APP) { 46 item().type == ash::TYPE_WINDOWED_APP) {
47 // V1 apps can be started from the menu - but V2 apps should not. 47 // V1 apps can be started from the menu - but V2 apps should not.
48 if (!controller()->IsPlatformApp(item().id)) { 48 if (!controller()->IsPlatformApp(item().id)) {
49 AddItem(MENU_OPEN_NEW, base::string16()); 49 AddItem(MENU_OPEN_NEW, base::string16());
50 AddSeparator(ui::NORMAL_SEPARATOR); 50 AddSeparator(ui::NORMAL_SEPARATOR);
51 } 51 }
52 AddPinMenu(); 52 AddPinMenu();
53 if (controller()->IsOpen(item().id)) 53 if (controller()->IsOpen(item().id))
(...skipping 16 matching lines...) Expand all
70 AddCheckItemWithStringId(LAUNCH_TYPE_WINDOW, 70 AddCheckItemWithStringId(LAUNCH_TYPE_WINDOW,
71 IDS_APP_CONTEXT_MENU_OPEN_WINDOW); 71 IDS_APP_CONTEXT_MENU_OPEN_WINDOW);
72 // Even though the launch type is Full Screen it is more accurately 72 // Even though the launch type is Full Screen it is more accurately
73 // described as Maximized in Ash. 73 // described as Maximized in Ash.
74 AddCheckItemWithStringId(LAUNCH_TYPE_FULLSCREEN, 74 AddCheckItemWithStringId(LAUNCH_TYPE_FULLSCREEN,
75 IDS_APP_CONTEXT_MENU_OPEN_MAXIMIZED); 75 IDS_APP_CONTEXT_MENU_OPEN_MAXIMIZED);
76 } 76 }
77 } 77 }
78 } else if (item().type == ash::TYPE_BROWSER_SHORTCUT) { 78 } else if (item().type == ash::TYPE_BROWSER_SHORTCUT) {
79 AddItemWithStringId(MENU_NEW_WINDOW, IDS_APP_LIST_NEW_WINDOW); 79 AddItemWithStringId(MENU_NEW_WINDOW, IDS_APP_LIST_NEW_WINDOW);
80 if (!controller()->profile()->IsGuestSession()) { 80 if (!controller()->GetProfile()->IsGuestSession()) {
81 AddItemWithStringId(MENU_NEW_INCOGNITO_WINDOW, 81 AddItemWithStringId(MENU_NEW_INCOGNITO_WINDOW,
82 IDS_APP_LIST_NEW_INCOGNITO_WINDOW); 82 IDS_APP_LIST_NEW_INCOGNITO_WINDOW);
83 } 83 }
84 if (!BrowserShortcutLauncherItemController( 84 if (!BrowserShortcutLauncherItemController(
85 controller(), ash::Shell::GetInstance()->shelf_model()) 85 controller(), ash::Shell::GetInstance()->shelf_model())
86 .IsListOfActiveBrowserEmpty()) { 86 .IsListOfActiveBrowserEmpty()) {
87 AddItem(MENU_CLOSE, 87 AddItem(MENU_CLOSE,
88 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_CLOSE)); 88 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_CLOSE));
89 } 89 }
90 } else if (item().type == ash::TYPE_DIALOG) { 90 } else if (item().type == ash::TYPE_DIALOG) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 return (extension_items_ && 163 return (extension_items_ &&
164 extension_items_->IsCommandIdChecked(command_id)); 164 extension_items_->IsCommandIdChecked(command_id));
165 } 165 }
166 } 166 }
167 167
168 bool ExtensionLauncherContextMenu::IsCommandIdEnabled(int command_id) const { 168 bool ExtensionLauncherContextMenu::IsCommandIdEnabled(int command_id) const {
169 switch (command_id) { 169 switch (command_id) {
170 case MENU_NEW_WINDOW: 170 case MENU_NEW_WINDOW:
171 // "Normal" windows are not allowed when incognito is enforced. 171 // "Normal" windows are not allowed when incognito is enforced.
172 return IncognitoModePrefs::GetAvailability( 172 return IncognitoModePrefs::GetAvailability(
173 controller()->profile()->GetPrefs()) != 173 controller()->GetProfile()->GetPrefs()) !=
174 IncognitoModePrefs::FORCED; 174 IncognitoModePrefs::FORCED;
175 case MENU_NEW_INCOGNITO_WINDOW: 175 case MENU_NEW_INCOGNITO_WINDOW:
176 // Incognito windows are not allowed when incognito is disabled. 176 // Incognito windows are not allowed when incognito is disabled.
177 return IncognitoModePrefs::GetAvailability( 177 return IncognitoModePrefs::GetAvailability(
178 controller()->profile()->GetPrefs()) != 178 controller()->GetProfile()->GetPrefs()) !=
179 IncognitoModePrefs::DISABLED; 179 IncognitoModePrefs::DISABLED;
180 default: 180 default:
181 if (command_id < MENU_ITEM_COUNT) 181 if (command_id < MENU_ITEM_COUNT)
182 return LauncherContextMenu::IsCommandIdEnabled(command_id); 182 return LauncherContextMenu::IsCommandIdEnabled(command_id);
183 return (extension_items_ && 183 return (extension_items_ &&
184 extension_items_->IsCommandIdEnabled(command_id)); 184 extension_items_->IsCommandIdEnabled(command_id));
185 } 185 }
186 } 186 }
187 187
188 void ExtensionLauncherContextMenu::ExecuteCommand(int command_id, 188 void ExtensionLauncherContextMenu::ExecuteCommand(int command_id,
(...skipping 18 matching lines...) Expand all
207 : extensions::LAUNCH_TYPE_WINDOW; 207 : extensions::LAUNCH_TYPE_WINDOW;
208 } 208 }
209 controller()->SetLaunchType(item().id, launch_type); 209 controller()->SetLaunchType(item().id, launch_type);
210 break; 210 break;
211 } 211 }
212 case LAUNCH_TYPE_FULLSCREEN: 212 case LAUNCH_TYPE_FULLSCREEN:
213 controller()->SetLaunchType(item().id, 213 controller()->SetLaunchType(item().id,
214 extensions::LAUNCH_TYPE_FULLSCREEN); 214 extensions::LAUNCH_TYPE_FULLSCREEN);
215 break; 215 break;
216 case MENU_NEW_WINDOW: 216 case MENU_NEW_WINDOW:
217 chrome::NewEmptyWindow(controller()->profile()); 217 chrome::NewEmptyWindow(controller()->GetProfile());
218 break; 218 break;
219 case MENU_NEW_INCOGNITO_WINDOW: 219 case MENU_NEW_INCOGNITO_WINDOW:
220 chrome::NewEmptyWindow(controller()->profile()->GetOffTheRecordProfile()); 220 chrome::NewEmptyWindow(
221 controller()->GetProfile()->GetOffTheRecordProfile());
221 break; 222 break;
222 default: 223 default:
223 if (extension_items_) { 224 if (extension_items_) {
224 extension_items_->ExecuteCommand(command_id, nullptr, nullptr, 225 extension_items_->ExecuteCommand(command_id, nullptr, nullptr,
225 content::ContextMenuParams()); 226 content::ContextMenuParams());
226 } 227 }
227 } 228 }
228 } 229 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698