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

Side by Side Diff: chrome/browser/ui/app_list/extension_app_item.cc

Issue 10984034: Revert 158691 - Give platform apps control over launcher right-click context menu. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 2 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 | Annotate | Revision Log
OLDNEW
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/app_list/extension_app_item.h" 5 #include "chrome/browser/ui/app_list/extension_app_item.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/extensions/context_menu_matcher.h"
10 #include "chrome/browser/extensions/extension_prefs.h" 8 #include "chrome/browser/extensions/extension_prefs.h"
11 #include "chrome/browser/extensions/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/extension_sorting.h" 10 #include "chrome/browser/extensions/extension_sorting.h"
13 #include "chrome/browser/extensions/extension_system.h" 11 #include "chrome/browser/extensions/extension_system.h"
14 #include "chrome/browser/extensions/extension_uninstall_dialog.h" 12 #include "chrome/browser/extensions/extension_uninstall_dialog.h"
15 #include "chrome/browser/extensions/management_policy.h" 13 #include "chrome/browser/extensions/management_policy.h"
16 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ui/app_list/app_list_controller.h" 15 #include "chrome/browser/ui/app_list/app_list_controller.h"
18 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_navigator.h" 17 #include "chrome/browser/ui/browser_navigator.h"
20 #include "chrome/browser/ui/browser_tabstrip.h" 18 #include "chrome/browser/ui/browser_tabstrip.h"
21 #include "chrome/browser/ui/browser_window.h" 19 #include "chrome/browser/ui/browser_window.h"
22 #include "chrome/common/extensions/extension.h" 20 #include "chrome/common/extensions/extension.h"
23 #include "chrome/common/extensions/extension_constants.h" 21 #include "chrome/common/extensions/extension_constants.h"
24 #include "chrome/common/extensions/extension_icon_set.h" 22 #include "chrome/common/extensions/extension_icon_set.h"
25 #include "content/public/common/context_menu_params.h"
26 #include "grit/chromium_strings.h" 23 #include "grit/chromium_strings.h"
27 #include "grit/generated_resources.h" 24 #include "grit/generated_resources.h"
28 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
29 #include "ui/gfx/image/image.h" 26 #include "ui/gfx/image/image.h"
30 27
31 #if defined(OS_CHROMEOS) 28 #if defined(OS_CHROMEOS)
32 #include "chrome/browser/extensions/api/rtc_private/rtc_private_api.h" 29 #include "chrome/browser/extensions/api/rtc_private/rtc_private_api.h"
33 #endif 30 #endif
34 31
35 using extensions::Extension; 32 using extensions::Extension;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 bool IsExtensionEnabled(Profile* profile, const std::string& extension_id) { 118 bool IsExtensionEnabled(Profile* profile, const std::string& extension_id) {
122 ExtensionService* service = profile->GetExtensionService(); 119 ExtensionService* service = profile->GetExtensionService();
123 return service->IsExtensionEnabled(extension_id) && 120 return service->IsExtensionEnabled(extension_id) &&
124 !service->GetTerminatedExtension(extension_id); 121 !service->GetTerminatedExtension(extension_id);
125 } 122 }
126 123
127 ExtensionSorting* GetExtensionSorting(Profile* profile) { 124 ExtensionSorting* GetExtensionSorting(Profile* profile) {
128 return profile->GetExtensionService()->extension_prefs()->extension_sorting(); 125 return profile->GetExtensionService()->extension_prefs()->extension_sorting();
129 } 126 }
130 127
131 bool MenuItemHasLauncherContext(const extensions::MenuItem* item) {
132 return item->contexts().Contains(extensions::MenuItem::LAUNCHER);
133 }
134
135 } // namespace 128 } // namespace
136 129
137 ExtensionAppItem::ExtensionAppItem(Profile* profile, 130 ExtensionAppItem::ExtensionAppItem(Profile* profile,
138 const Extension* extension, 131 const Extension* extension,
139 AppListController* controller) 132 AppListController* controller)
140 : ChromeAppListItem(TYPE_APP), 133 : ChromeAppListItem(TYPE_APP),
141 profile_(profile), 134 profile_(profile),
142 extension_id_(extension->id()), 135 extension_id_(extension->id()),
143 controller_(controller) { 136 controller_(controller) {
144 SetTitle(extension->name()); 137 SetTitle(extension->name());
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } else { 220 } else {
228 NOTREACHED(); 221 NOTREACHED();
229 return string16(); 222 return string16();
230 } 223 }
231 } 224 }
232 225
233 bool ExtensionAppItem::IsCommandIdChecked(int command_id) const { 226 bool ExtensionAppItem::IsCommandIdChecked(int command_id) const {
234 if (command_id >= LAUNCH_TYPE_START && command_id < LAUNCH_TYPE_LAST) { 227 if (command_id >= LAUNCH_TYPE_START && command_id < LAUNCH_TYPE_LAST) {
235 return static_cast<int>(GetExtensionLaunchType(profile_, extension_id_)) + 228 return static_cast<int>(GetExtensionLaunchType(profile_, extension_id_)) +
236 LAUNCH_TYPE_START == command_id; 229 LAUNCH_TYPE_START == command_id;
237 } else if (command_id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST &&
238 command_id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) {
239 return extension_menu_items_->IsCommandIdChecked(command_id);
240 } 230 }
241 return false; 231 return false;
242 } 232 }
243 233
244 bool ExtensionAppItem::IsCommandIdEnabled(int command_id) const { 234 bool ExtensionAppItem::IsCommandIdEnabled(int command_id) const {
245 if (command_id == TOGGLE_PIN) { 235 if (command_id == TOGGLE_PIN) {
246 return controller_->CanPin(); 236 return controller_->CanPin();
247 } else if (command_id == OPTIONS) { 237 } else if (command_id == OPTIONS) {
248 const Extension* extension = GetExtension(); 238 const Extension* extension = GetExtension();
249 return IsExtensionEnabled(profile_, extension_id_) && extension && 239 return IsExtensionEnabled(profile_, extension_id_) && extension &&
250 !extension->options_url().is_empty(); 240 !extension->options_url().is_empty();
251 } else if (command_id == UNINSTALL) { 241 } else if (command_id == UNINSTALL) {
252 const Extension* extension = GetExtension(); 242 const Extension* extension = GetExtension();
253 const extensions::ManagementPolicy* policy = 243 const extensions::ManagementPolicy* policy =
254 extensions::ExtensionSystem::Get(profile_)->management_policy(); 244 extensions::ExtensionSystem::Get(profile_)->management_policy();
255 return extension && 245 return extension &&
256 policy->UserMayModifySettings(extension, NULL); 246 policy->UserMayModifySettings(extension, NULL);
257 } else if (command_id == DETAILS) { 247 } else if (command_id == DETAILS) {
258 const Extension* extension = GetExtension(); 248 const Extension* extension = GetExtension();
259 return extension && extension->from_webstore(); 249 return extension && extension->from_webstore();
260 } else if (command_id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST &&
261 command_id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) {
262 return extension_menu_items_->IsCommandIdEnabled(command_id);
263 } 250 }
264 return true; 251 return true;
265 } 252 }
266 253
267 bool ExtensionAppItem::GetAcceleratorForCommandId( 254 bool ExtensionAppItem::GetAcceleratorForCommandId(
268 int command_id, 255 int command_id,
269 ui::Accelerator* acclelrator) { 256 ui::Accelerator* acclelrator) {
270 return false; 257 return false;
271 } 258 }
272 259
(...skipping 10 matching lines...) Expand all
283 SetExtensionLaunchType(profile_, 270 SetExtensionLaunchType(profile_,
284 extension_id_, 271 extension_id_,
285 static_cast<extensions::ExtensionPrefs::LaunchType>( 272 static_cast<extensions::ExtensionPrefs::LaunchType>(
286 command_id - LAUNCH_TYPE_START)); 273 command_id - LAUNCH_TYPE_START));
287 } else if (command_id == OPTIONS) { 274 } else if (command_id == OPTIONS) {
288 ShowExtensionOptions(); 275 ShowExtensionOptions();
289 } else if (command_id == UNINSTALL) { 276 } else if (command_id == UNINSTALL) {
290 StartExtensionUninstall(); 277 StartExtensionUninstall();
291 } else if (command_id == DETAILS) { 278 } else if (command_id == DETAILS) {
292 ShowExtensionDetails(); 279 ShowExtensionDetails();
293 } else if (command_id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST &&
294 command_id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) {
295 extension_menu_items_->ExecuteCommand(command_id,
296 content::ContextMenuParams());
297 } 280 }
298 } 281 }
299 282
300 void ExtensionAppItem::Activate(int event_flags) { 283 void ExtensionAppItem::Activate(int event_flags) {
301 const Extension* extension = GetExtension(); 284 const Extension* extension = GetExtension();
302 if (!extension) 285 if (!extension)
303 return; 286 return;
304 287
305 #if defined(OS_CHROMEOS) 288 #if defined(OS_CHROMEOS)
306 // Talk extension isn't an app, send special rtcPrivate API message to 289 // Talk extension isn't an app, send special rtcPrivate API message to
(...skipping 10 matching lines...) Expand all
317 controller_->ActivateApp(profile_, extension->id(), event_flags); 300 controller_->ActivateApp(profile_, extension->id(), event_flags);
318 } 301 }
319 302
320 ui::MenuModel* ExtensionAppItem::GetContextMenuModel() { 303 ui::MenuModel* ExtensionAppItem::GetContextMenuModel() {
321 // No context menu for Chrome app. 304 // No context menu for Chrome app.
322 if (extension_id_ == extension_misc::kChromeAppId) 305 if (extension_id_ == extension_misc::kChromeAppId)
323 return NULL; 306 return NULL;
324 307
325 if (!context_menu_model_.get()) { 308 if (!context_menu_model_.get()) {
326 context_menu_model_.reset(new ui::SimpleMenuModel(this)); 309 context_menu_model_.reset(new ui::SimpleMenuModel(this));
327 extension_menu_items_.reset(new extensions::ContextMenuMatcher(
328 profile_, this, context_menu_model_.get(),
329 base::Bind(MenuItemHasLauncherContext)));
330
331 context_menu_model_->AddItem(LAUNCH, UTF8ToUTF16(title())); 310 context_menu_model_->AddItem(LAUNCH, UTF8ToUTF16(title()));
332 // Talk extension isn't an app and so doesn't support most launch options. 311 // Talk extension isn't an app and so doesn't support most launch options.
333 if (!IsTalkExtension()) { 312 if (!IsTalkExtension()) {
334 int index = 0;
335 extension_menu_items_->AppendExtensionItems(extension_id_, string16(),
336 &index);
337 context_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); 313 context_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR);
338 context_menu_model_->AddItemWithStringId( 314 context_menu_model_->AddItemWithStringId(
339 TOGGLE_PIN, 315 TOGGLE_PIN,
340 controller_->IsAppPinned(extension_id_) ? 316 controller_->IsAppPinned(extension_id_) ?
341 IDS_APP_LIST_CONTEXT_MENU_UNPIN : 317 IDS_APP_LIST_CONTEXT_MENU_UNPIN :
342 IDS_APP_LIST_CONTEXT_MENU_PIN); 318 IDS_APP_LIST_CONTEXT_MENU_PIN);
343 context_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); 319 context_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR);
344 context_menu_model_->AddCheckItemWithStringId( 320 context_menu_model_->AddCheckItemWithStringId(
345 LAUNCH_TYPE_REGULAR_TAB, 321 LAUNCH_TYPE_REGULAR_TAB,
346 IDS_APP_CONTEXT_MENU_OPEN_REGULAR); 322 IDS_APP_CONTEXT_MENU_OPEN_REGULAR);
(...skipping 11 matching lines...) Expand all
358 } 334 }
359 context_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); 335 context_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR);
360 context_menu_model_->AddItemWithStringId(OPTIONS, IDS_NEW_TAB_APP_OPTIONS); 336 context_menu_model_->AddItemWithStringId(OPTIONS, IDS_NEW_TAB_APP_OPTIONS);
361 context_menu_model_->AddItemWithStringId(DETAILS, IDS_NEW_TAB_APP_DETAILS); 337 context_menu_model_->AddItemWithStringId(DETAILS, IDS_NEW_TAB_APP_DETAILS);
362 context_menu_model_->AddItemWithStringId(UNINSTALL, 338 context_menu_model_->AddItemWithStringId(UNINSTALL,
363 IDS_EXTENSIONS_UNINSTALL); 339 IDS_EXTENSIONS_UNINSTALL);
364 } 340 }
365 341
366 return context_menu_model_.get(); 342 return context_menu_model_.get();
367 } 343 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/extension_app_item.h ('k') | chrome/browser/ui/ash/launcher/chrome_launcher_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698