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

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

Issue 1838263002: Arc app integration in shelf launcher context menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits update Created 4 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/ash/launcher/extension_launcher_context_menu.h"
6
7 #include "ash/shelf/shelf.h"
8 #include "ash/shelf/shelf_item_delegate.h"
9 #include "base/bind.h"
10 #include "chrome/browser/extensions/context_menu_matcher.h"
11 #include "chrome/browser/extensions/extension_util.h"
12 #include "chrome/browser/prefs/incognito_mode_prefs.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
15 #include "chrome/common/extensions/extension_constants.h"
16 #include "chrome/grit/generated_resources.h"
17 #include "content/public/common/context_menu_params.h"
18 #include "grit/ash_strings.h"
19 #include "ui/base/l10n/l10n_util.h"
20
21 namespace {
22
23 bool MenuItemHasLauncherContext(const extensions::MenuItem* item) {
24 return item->contexts().Contains(extensions::MenuItem::LAUNCHER);
25 }
26
27 } // namespace
28
29 ExtensionLauncherContextMenu::ExtensionLauncherContextMenu(
30 ChromeLauncherController* controller,
31 const ash::ShelfItem* item,
32 ash::Shelf* shelf)
33 : LauncherContextMenu(controller, item, shelf) {
34 Init();
35 }
36
37 ExtensionLauncherContextMenu::~ExtensionLauncherContextMenu() {}
38
39 void ExtensionLauncherContextMenu::Init() {
40 extension_items_.reset(new extensions::ContextMenuMatcher(
41 controller()->profile(), this, this,
42 base::Bind(MenuItemHasLauncherContext)));
43 if (item().type == ash::TYPE_APP_SHORTCUT ||
44 item().type == ash::TYPE_WINDOWED_APP) {
45 // V1 apps can be started from the menu - but V2 apps should not.
46 if (!controller()->IsPlatformApp(item().id)) {
47 AddItem(MENU_OPEN_NEW, base::string16());
48 AddSeparator(ui::NORMAL_SEPARATOR);
49 }
50 AddPinMenu();
51 if (controller()->IsOpen(item().id))
52 AddItemWithStringId(MENU_CLOSE, IDS_LAUNCHER_CONTEXT_MENU_CLOSE);
53 if (!controller()->IsPlatformApp(item().id) &&
54 item().type != ash::TYPE_WINDOWED_APP) {
55 AddSeparator(ui::NORMAL_SEPARATOR);
56 if (extensions::util::IsNewBookmarkAppsEnabled()) {
57 // With bookmark apps enabled, hosted apps launch in a window by
58 // default. This menu item is re-interpreted as a single, toggle-able
59 // option to launch the hosted app as a tab.
60 AddCheckItemWithStringId(LAUNCH_TYPE_WINDOW,
61 IDS_APP_CONTEXT_MENU_OPEN_WINDOW);
62 } else {
63 AddCheckItemWithStringId(LAUNCH_TYPE_REGULAR_TAB,
64 IDS_APP_CONTEXT_MENU_OPEN_REGULAR);
65 AddCheckItemWithStringId(LAUNCH_TYPE_PINNED_TAB,
66 IDS_APP_CONTEXT_MENU_OPEN_PINNED);
67 AddCheckItemWithStringId(LAUNCH_TYPE_WINDOW,
68 IDS_APP_CONTEXT_MENU_OPEN_WINDOW);
69 // Even though the launch type is Full Screen it is more accurately
70 // described as Maximized in Ash.
71 AddCheckItemWithStringId(LAUNCH_TYPE_FULLSCREEN,
72 IDS_APP_CONTEXT_MENU_OPEN_MAXIMIZED);
73 }
74 }
75 } else if (item().type == ash::TYPE_BROWSER_SHORTCUT) {
76 AddItemWithStringId(MENU_NEW_WINDOW, IDS_APP_LIST_NEW_WINDOW);
77 if (!controller()->IsLoggedInAsGuest()) {
78 AddItemWithStringId(MENU_NEW_INCOGNITO_WINDOW,
79 IDS_APP_LIST_NEW_INCOGNITO_WINDOW);
80 }
81 } else if (item().type == ash::TYPE_DIALOG) {
82 AddItemWithStringId(MENU_CLOSE, IDS_LAUNCHER_CONTEXT_MENU_CLOSE);
83 } else {
84 if (item().type == ash::TYPE_PLATFORM_APP)
85 AddItemWithStringId(MENU_PIN, IDS_LAUNCHER_CONTEXT_MENU_PIN);
86 bool show_close_button = controller()->IsOpen(item().id);
87 #if defined(OS_CHROMEOS)
88 if (extension_misc::IsImeMenuExtensionId(
89 controller()->GetAppIDForShelfID(item().id)))
90 show_close_button = false;
91 #endif
92 if (show_close_button)
93 AddItemWithStringId(MENU_CLOSE, IDS_LAUNCHER_CONTEXT_MENU_CLOSE);
94 }
95 AddSeparator(ui::NORMAL_SEPARATOR);
96 if (item().type == ash::TYPE_APP_SHORTCUT ||
97 item().type == ash::TYPE_WINDOWED_APP ||
98 item().type == ash::TYPE_PLATFORM_APP) {
99 const extensions::MenuItem::ExtensionKey app_key(
100 controller()->GetAppIDForShelfID(item().id));
101 if (!app_key.empty()) {
102 int index = 0;
103 extension_items_->AppendExtensionItems(app_key, base::string16(), &index,
104 false); // is_action_menu
105 AddSeparator(ui::NORMAL_SEPARATOR);
106 }
107 }
108 AddAutohideAlignmentWallpaperMenu();
109 }
110
111 bool ExtensionLauncherContextMenu::IsItemForCommandIdDynamic(
112 int command_id) const {
113 return command_id == MENU_OPEN_NEW;
114 }
115
116 base::string16 ExtensionLauncherContextMenu::GetLabelForCommandId(
117 int command_id) const {
118 if (command_id == MENU_OPEN_NEW) {
119 if (item().type == ash::TYPE_PLATFORM_APP)
120 return l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_NEW_WINDOW);
121 switch (controller()->GetLaunchType(item().id)) {
122 case extensions::LAUNCH_TYPE_PINNED:
123 case extensions::LAUNCH_TYPE_REGULAR:
124 return l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_NEW_TAB);
125 case extensions::LAUNCH_TYPE_FULLSCREEN:
126 case extensions::LAUNCH_TYPE_WINDOW:
127 return l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_NEW_WINDOW);
128 default:
129 NOTREACHED();
130 return base::string16();
131 }
132 }
133 NOTREACHED();
134 return base::string16();
135 }
136
137 bool ExtensionLauncherContextMenu::IsCommandIdChecked(int command_id) const {
138 switch (command_id) {
139 case LAUNCH_TYPE_PINNED_TAB:
140 return controller()->GetLaunchType(item().id) ==
141 extensions::LAUNCH_TYPE_PINNED;
142 case LAUNCH_TYPE_REGULAR_TAB:
143 return controller()->GetLaunchType(item().id) ==
144 extensions::LAUNCH_TYPE_REGULAR;
145 case LAUNCH_TYPE_WINDOW:
146 return controller()->GetLaunchType(item().id) ==
147 extensions::LAUNCH_TYPE_WINDOW;
148 case LAUNCH_TYPE_FULLSCREEN:
149 return controller()->GetLaunchType(item().id) ==
150 extensions::LAUNCH_TYPE_FULLSCREEN;
151 case MENU_AUTO_HIDE:
khmel 2016/03/31 21:41:57 Please Use handling MENU_AUTO_HIDE in base class
lgcheng 2016/03/31 23:18:10 Done.
152 return shelf()->GetAutoHideBehavior() ==
153 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
154 default:
155 if (command_id < MENU_ITEM_COUNT)
156 return false;
157 return (extension_items_ &&
158 extension_items_->IsCommandIdChecked(command_id));
159 }
160 }
161
162 bool ExtensionLauncherContextMenu::IsCommandIdEnabled(int command_id) const {
163 if (IsCommonCommandId(command_id))
164 return LauncherContextMenu::IsCommandIdEnabled(command_id);
165 switch (command_id) {
166 case MENU_NEW_WINDOW:
167 // "Normal" windows are not allowed when incognito is enforced.
168 return IncognitoModePrefs::GetAvailability(
169 controller()->profile()->GetPrefs()) !=
170 IncognitoModePrefs::FORCED;
171 case MENU_NEW_INCOGNITO_WINDOW:
172 // Incognito windows are not allowed when incognito is disabled.
173 return IncognitoModePrefs::GetAvailability(
174 controller()->profile()->GetPrefs()) !=
175 IncognitoModePrefs::DISABLED;
176 default:
177 if (command_id < MENU_ITEM_COUNT)
178 return true;
179 return (extension_items_ &&
180 extension_items_->IsCommandIdEnabled(command_id));
181 }
182 }
183
184 void ExtensionLauncherContextMenu::ExecuteCommand(int command_id,
185 int event_flags) {
186 if (IsCommonCommandId(command_id))
187 return LauncherContextMenu::ExecuteCommand(command_id, event_flags);
188 switch (static_cast<MenuItem>(command_id)) {
189 case MENU_OPEN_NEW:
190 controller()->Launch(item().id, ui::EF_NONE);
191 break;
192 case LAUNCH_TYPE_PINNED_TAB:
193 controller()->SetLaunchType(item().id, extensions::LAUNCH_TYPE_PINNED);
194 break;
195 case LAUNCH_TYPE_REGULAR_TAB:
196 controller()->SetLaunchType(item().id, extensions::LAUNCH_TYPE_REGULAR);
197 break;
198 case LAUNCH_TYPE_WINDOW: {
199 extensions::LaunchType launch_type = extensions::LAUNCH_TYPE_WINDOW;
200 // With bookmark apps enabled, hosted apps can only toggle between
201 // LAUNCH_WINDOW and LAUNCH_REGULAR.
202 if (extensions::util::IsNewBookmarkAppsEnabled()) {
203 launch_type = controller()->GetLaunchType(item().id) ==
204 extensions::LAUNCH_TYPE_WINDOW
205 ? extensions::LAUNCH_TYPE_REGULAR
206 : extensions::LAUNCH_TYPE_WINDOW;
207 }
208 controller()->SetLaunchType(item().id, launch_type);
209 break;
210 }
211 case LAUNCH_TYPE_FULLSCREEN:
212 controller()->SetLaunchType(item().id,
213 extensions::LAUNCH_TYPE_FULLSCREEN);
214 break;
215 case MENU_NEW_WINDOW:
216 controller()->CreateNewWindow();
217 break;
218 case MENU_NEW_INCOGNITO_WINDOW:
219 controller()->CreateNewIncognitoWindow();
220 break;
221 default:
222 if (extension_items_) {
223 extension_items_->ExecuteCommand(command_id, nullptr, nullptr,
224 content::ContextMenuParams());
225 }
226 }
227 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698