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

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: Refactor and comments&inlucdes cleanup 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 } // name space
khmel 2016/03/30 00:58:46 // namespace
lgcheng 2016/03/30 02:06:25 Done.
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 AddItem(MENU_CLOSE,
53 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_CLOSE));
54 }
55 if (!controller()->IsPlatformApp(item().id) &&
56 item().type != ash::TYPE_WINDOWED_APP) {
57 AddSeparator(ui::NORMAL_SEPARATOR);
58 if (extensions::util::IsNewBookmarkAppsEnabled()) {
59 // With bookmark apps enabled, hosted apps launch in a window by
60 // default. This menu item is re-interpreted as a single, toggle-able
61 // option to launch the hosted app as a tab.
62 AddCheckItemWithStringId(LAUNCH_TYPE_WINDOW,
63 IDS_APP_CONTEXT_MENU_OPEN_WINDOW);
64 } else {
65 AddCheckItemWithStringId(LAUNCH_TYPE_REGULAR_TAB,
66 IDS_APP_CONTEXT_MENU_OPEN_REGULAR);
67 AddCheckItemWithStringId(LAUNCH_TYPE_PINNED_TAB,
68 IDS_APP_CONTEXT_MENU_OPEN_PINNED);
69 AddCheckItemWithStringId(LAUNCH_TYPE_WINDOW,
70 IDS_APP_CONTEXT_MENU_OPEN_WINDOW);
71 // Even though the launch type is Full Screen it is more accurately
72 // described as Maximized in Ash.
73 AddCheckItemWithStringId(LAUNCH_TYPE_FULLSCREEN,
74 IDS_APP_CONTEXT_MENU_OPEN_MAXIMIZED);
75 }
76 }
77 } else if (item().type == ash::TYPE_BROWSER_SHORTCUT) {
78 AddItem(MENU_NEW_WINDOW,
79 l10n_util::GetStringUTF16(IDS_APP_LIST_NEW_WINDOW));
80 if (!controller()->IsLoggedInAsGuest()) {
81 AddItem(MENU_NEW_INCOGNITO_WINDOW,
82 l10n_util::GetStringUTF16(IDS_APP_LIST_NEW_INCOGNITO_WINDOW));
83 }
84 } else if (item().type == ash::TYPE_DIALOG) {
85 AddItem(MENU_CLOSE,
86 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_CLOSE));
87 } else {
88 if (item().type == ash::TYPE_PLATFORM_APP) {
89 AddItem(MENU_PIN,
90 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_PIN));
91 }
92 bool show_close_button = controller()->IsOpen(item().id);
93 #if defined(OS_CHROMEOS)
94 if (extension_misc::IsImeMenuExtensionId(
95 controller()->GetAppIDForShelfID(item().id))) {
96 show_close_button = false;
97 }
98 #endif
99 if (show_close_button) {
100 AddItem(MENU_CLOSE,
101 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_CLOSE));
102 }
103 }
104 AddSeparator(ui::NORMAL_SEPARATOR);
105 if (item().type == ash::TYPE_APP_SHORTCUT ||
106 item().type == ash::TYPE_WINDOWED_APP ||
107 item().type == ash::TYPE_PLATFORM_APP) {
108 const extensions::MenuItem::ExtensionKey app_key(
109 controller()->GetAppIDForShelfID(item().id));
110 if (!app_key.empty()) {
111 int index = 0;
112 extension_items_->AppendExtensionItems(app_key, base::string16(), &index,
113 false); // is_action_menu
114 AddSeparator(ui::NORMAL_SEPARATOR);
115 }
116 }
117 AddAutohideAlignmentWallpaperMenu();
118 }
119
120 bool ExtensionLauncherContextMenu::IsItemForCommandIdDynamic(
121 int command_id) const {
122 return command_id == MENU_OPEN_NEW;
123 }
124
125 base::string16 ExtensionLauncherContextMenu::GetLabelForCommandId(
126 int command_id) const {
127 if (command_id == MENU_OPEN_NEW) {
128 if (item().type == ash::TYPE_PLATFORM_APP) {
khmel 2016/03/30 00:58:46 {} is not required for one-line
lgcheng 2016/03/30 02:06:25 Done.
129 return l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_NEW_WINDOW);
130 }
131 switch (controller()->GetLaunchType(item().id)) {
132 case extensions::LAUNCH_TYPE_PINNED:
133 case extensions::LAUNCH_TYPE_REGULAR:
134 return l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_NEW_TAB);
135 case extensions::LAUNCH_TYPE_FULLSCREEN:
136 case extensions::LAUNCH_TYPE_WINDOW:
137 return l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_NEW_WINDOW);
138 default:
139 NOTREACHED();
140 return base::string16();
141 }
142 }
143 NOTREACHED();
144 return base::string16();
145 }
146
147 bool ExtensionLauncherContextMenu::IsCommandIdChecked(int command_id) const {
148 switch (command_id) {
149 case LAUNCH_TYPE_PINNED_TAB:
150 return controller()->GetLaunchType(item().id) ==
151 extensions::LAUNCH_TYPE_PINNED;
152 case LAUNCH_TYPE_REGULAR_TAB:
153 return controller()->GetLaunchType(item().id) ==
154 extensions::LAUNCH_TYPE_REGULAR;
155 case LAUNCH_TYPE_WINDOW:
156 return controller()->GetLaunchType(item().id) ==
157 extensions::LAUNCH_TYPE_WINDOW;
158 case LAUNCH_TYPE_FULLSCREEN:
159 return controller()->GetLaunchType(item().id) ==
160 extensions::LAUNCH_TYPE_FULLSCREEN;
161 case MENU_AUTO_HIDE:
162 return shelf()->GetAutoHideBehavior() ==
163 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
164 default:
165 if (command_id < MENU_ITEM_COUNT)
166 return false;
167 return (extension_items_ &&
168 extension_items_->IsCommandIdChecked(command_id));
169 }
170 }
171
172 bool ExtensionLauncherContextMenu::IsCommandIdEnabled(int command_id) const {
173 if (IsCommonCommandId(command_id))
174 return LauncherContextMenu::IsCommandIdEnabled(command_id);
175 switch (command_id) {
176 case MENU_NEW_WINDOW:
177 // "Normal" windows are not allowed when incognito is enforced.
178 return IncognitoModePrefs::GetAvailability(
179 controller()->profile()->GetPrefs()) !=
180 IncognitoModePrefs::FORCED;
181 case MENU_NEW_INCOGNITO_WINDOW:
182 // Incognito windows are not allowed when incognito is disabled.
183 return IncognitoModePrefs::GetAvailability(
184 controller()->profile()->GetPrefs()) !=
185 IncognitoModePrefs::DISABLED;
186 default:
187 if (command_id < MENU_ITEM_COUNT)
188 return true;
189 return (extension_items_ &&
190 extension_items_->IsCommandIdEnabled(command_id));
191 }
192 }
193
194 void ExtensionLauncherContextMenu::ExecuteCommand(int command_id,
195 int event_flags) {
196 if (IsCommonCommandId(command_id))
197 return LauncherContextMenu::ExecuteCommand(command_id, event_flags);
198 switch (static_cast<MenuItem>(command_id)) {
199 case MENU_OPEN_NEW:
200 controller()->Launch(item().id, ui::EF_NONE);
201 break;
202 case LAUNCH_TYPE_PINNED_TAB:
203 controller()->SetLaunchType(item().id, extensions::LAUNCH_TYPE_PINNED);
204 break;
205 case LAUNCH_TYPE_REGULAR_TAB:
206 controller()->SetLaunchType(item().id, extensions::LAUNCH_TYPE_REGULAR);
207 break;
208 case LAUNCH_TYPE_WINDOW: {
209 extensions::LaunchType launch_type = extensions::LAUNCH_TYPE_WINDOW;
210 // With bookmark apps enabled, hosted apps can only toggle between
211 // LAUNCH_WINDOW and LAUNCH_REGULAR.
212 if (extensions::util::IsNewBookmarkAppsEnabled()) {
213 launch_type = controller()->GetLaunchType(item().id) ==
214 extensions::LAUNCH_TYPE_WINDOW
215 ? extensions::LAUNCH_TYPE_REGULAR
216 : extensions::LAUNCH_TYPE_WINDOW;
217 }
218 controller()->SetLaunchType(item().id, launch_type);
219 break;
220 }
221 case LAUNCH_TYPE_FULLSCREEN:
222 controller()->SetLaunchType(item().id,
223 extensions::LAUNCH_TYPE_FULLSCREEN);
224 break;
225 case MENU_NEW_WINDOW:
226 controller()->CreateNewWindow();
227 break;
228 case MENU_NEW_INCOGNITO_WINDOW:
229 controller()->CreateNewIncognitoWindow();
230 break;
231 default:
232 if (extension_items_) {
233 extension_items_->ExecuteCommand(command_id, nullptr, nullptr,
234 content::ContextMenuParams());
235 }
236 }
237 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698