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

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

Issue 10918103: Give platform apps control over launcher right-click context menu. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase and fix conflicts 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/ash/launcher/launcher_context_menu.h" 5 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
6 6
7 #include "ash/launcher/launcher_context_menu.h" 7 #include "ash/launcher/launcher_context_menu.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "chrome/browser/extensions/context_menu_matcher.h"
10 #include "chrome/browser/extensions/extension_prefs.h" 11 #include "chrome/browser/extensions/extension_prefs.h"
11 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 12 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
12 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
14 #include "content/public/common/context_menu_params.h"
13 #include "grit/ash_strings.h" 15 #include "grit/ash_strings.h"
14 #include "grit/generated_resources.h" 16 #include "grit/generated_resources.h"
15 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
16 18
19 namespace {
20
21 bool MenuItemHasLauncherContext(const extensions::MenuItem* item) {
22 return item->contexts().Contains(extensions::MenuItem::LAUNCHER);
23 }
24
25 } // namespace
26
17 LauncherContextMenu::LauncherContextMenu(ChromeLauncherController* controller, 27 LauncherContextMenu::LauncherContextMenu(ChromeLauncherController* controller,
18 const ash::LauncherItem* item) 28 const ash::LauncherItem* item)
19 : ui::SimpleMenuModel(NULL), 29 : ui::SimpleMenuModel(NULL),
20 controller_(controller), 30 controller_(controller),
21 item_(item ? *item : ash::LauncherItem()) { 31 item_(item ? *item : ash::LauncherItem()),
32 extension_items_(new extensions::ContextMenuMatcher(
33 controller->profile(), this, this,
34 base::Bind(MenuItemHasLauncherContext))) {
22 set_delegate(this); 35 set_delegate(this);
23 36
24 if (is_valid_item()) { 37 if (is_valid_item()) {
25 if (item_.type == ash::TYPE_APP_SHORTCUT) { 38 if (item_.type == ash::TYPE_APP_SHORTCUT) {
26 DCHECK(controller->IsPinned(item_.id)); 39 DCHECK(controller->IsPinned(item_.id));
27 AddItem( 40 AddItem(
28 MENU_PIN, 41 MENU_PIN,
29 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_UNPIN)); 42 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_UNPIN));
30 if (controller->IsOpen(item->id)) { 43 if (controller->IsOpen(item->id)) {
31 AddItem(MENU_CLOSE, 44 AddItem(MENU_CLOSE,
(...skipping 28 matching lines...) Expand all
60 MENU_PIN, 73 MENU_PIN,
61 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_PIN)); 74 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_PIN));
62 } 75 }
63 if (controller->IsOpen(item_.id)) { 76 if (controller->IsOpen(item_.id)) {
64 AddItem(MENU_CLOSE, 77 AddItem(MENU_CLOSE,
65 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_CLOSE)); 78 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_CLOSE));
66 } 79 }
67 } 80 }
68 AddSeparator(ui::NORMAL_SEPARATOR); 81 AddSeparator(ui::NORMAL_SEPARATOR);
69 } 82 }
83 std::string app_id = controller->GetAppIDForLauncherID(item_.id);
84 if (!app_id.empty()) {
85 int index = 0;
86 extension_items_->AppendExtensionItems(
87 app_id, string16(), &index);
88 if (index > 0)
89 AddSeparator(ui::NORMAL_SEPARATOR);
90 }
70 AddCheckItemWithStringId( 91 AddCheckItemWithStringId(
71 MENU_AUTO_HIDE, ash::LauncherContextMenu::GetAutoHideResourceStringId()); 92 MENU_AUTO_HIDE, ash::LauncherContextMenu::GetAutoHideResourceStringId());
72 if (CommandLine::ForCurrentProcess()->HasSwitch( 93 if (CommandLine::ForCurrentProcess()->HasSwitch(
73 switches::kShowLauncherAlignmentMenu)) { 94 switches::kShowLauncherAlignmentMenu)) {
74 AddSubMenuWithStringId(MENU_ALIGNMENT_MENU, 95 AddSubMenuWithStringId(MENU_ALIGNMENT_MENU,
75 IDS_AURA_LAUNCHER_CONTEXT_MENU_POSITION, 96 IDS_AURA_LAUNCHER_CONTEXT_MENU_POSITION,
76 &alignment_menu_); 97 &alignment_menu_);
77 } 98 }
78 } 99 }
79 100
(...skipping 10 matching lines...) Expand all
90 extensions::ExtensionPrefs::LAUNCH_REGULAR; 111 extensions::ExtensionPrefs::LAUNCH_REGULAR;
91 case LAUNCH_TYPE_WINDOW: 112 case LAUNCH_TYPE_WINDOW:
92 return controller_->GetLaunchType(item_.id) == 113 return controller_->GetLaunchType(item_.id) ==
93 extensions::ExtensionPrefs::LAUNCH_WINDOW; 114 extensions::ExtensionPrefs::LAUNCH_WINDOW;
94 case LAUNCH_TYPE_FULLSCREEN: 115 case LAUNCH_TYPE_FULLSCREEN:
95 return controller_->GetLaunchType(item_.id) == 116 return controller_->GetLaunchType(item_.id) ==
96 extensions::ExtensionPrefs::LAUNCH_FULLSCREEN; 117 extensions::ExtensionPrefs::LAUNCH_FULLSCREEN;
97 case MENU_AUTO_HIDE: 118 case MENU_AUTO_HIDE:
98 return ash::LauncherContextMenu::IsAutoHideMenuHideChecked(); 119 return ash::LauncherContextMenu::IsAutoHideMenuHideChecked();
99 default: 120 default:
100 return false; 121 return extension_items_->IsCommandIdChecked(command_id);
101 } 122 }
102 } 123 }
103 124
104 bool LauncherContextMenu::IsCommandIdEnabled(int command_id) const { 125 bool LauncherContextMenu::IsCommandIdEnabled(int command_id) const {
105 switch (command_id) { 126 switch (command_id) {
106 case MENU_PIN: 127 case MENU_PIN:
107 return item_.type == ash::TYPE_PLATFORM_APP || 128 return item_.type == ash::TYPE_PLATFORM_APP ||
108 controller_->IsPinnable(item_.id); 129 controller_->IsPinnable(item_.id);
109 default: 130 default:
110 return true; 131 return extension_items_->IsCommandIdEnabled(command_id);
111 } 132 }
112 } 133 }
113 134
114 bool LauncherContextMenu::GetAcceleratorForCommandId( 135 bool LauncherContextMenu::GetAcceleratorForCommandId(
115 int command_id, 136 int command_id,
116 ui::Accelerator* accelerator) { 137 ui::Accelerator* accelerator) {
117 return false; 138 return false;
118 } 139 }
119 140
120 void LauncherContextMenu::ExecuteCommand(int command_id) { 141 void LauncherContextMenu::ExecuteCommand(int command_id) {
(...skipping 28 matching lines...) Expand all
149 ash::LauncherContextMenu::GetToggledAutoHideBehavior()); 170 ash::LauncherContextMenu::GetToggledAutoHideBehavior());
150 break; 171 break;
151 case MENU_NEW_WINDOW: 172 case MENU_NEW_WINDOW:
152 controller_->CreateNewWindow(); 173 controller_->CreateNewWindow();
153 break; 174 break;
154 case MENU_NEW_INCOGNITO_WINDOW: 175 case MENU_NEW_INCOGNITO_WINDOW:
155 controller_->CreateNewIncognitoWindow(); 176 controller_->CreateNewIncognitoWindow();
156 break; 177 break;
157 case MENU_ALIGNMENT_MENU: 178 case MENU_ALIGNMENT_MENU:
158 break; 179 break;
180 default:
181 extension_items_->ExecuteCommand(command_id,
182 content::ContextMenuParams());
159 } 183 }
160 } 184 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/launcher/launcher_context_menu.h ('k') | chrome/chrome_browser_extensions.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698