OLD | NEW |
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/common/wm_shell.h" | 8 #include "ash/common/wm_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" |
(...skipping 21 matching lines...) Expand all Loading... |
32 const ash::ShelfItem* item, | 32 const ash::ShelfItem* item, |
33 ash::WmShelf* wm_shelf) | 33 ash::WmShelf* wm_shelf) |
34 : LauncherContextMenu(controller, item, wm_shelf) { | 34 : LauncherContextMenu(controller, item, wm_shelf) { |
35 Init(); | 35 Init(); |
36 } | 36 } |
37 | 37 |
38 ExtensionLauncherContextMenu::~ExtensionLauncherContextMenu() {} | 38 ExtensionLauncherContextMenu::~ExtensionLauncherContextMenu() {} |
39 | 39 |
40 void ExtensionLauncherContextMenu::Init() { | 40 void ExtensionLauncherContextMenu::Init() { |
41 extension_items_.reset(new extensions::ContextMenuMatcher( | 41 extension_items_.reset(new extensions::ContextMenuMatcher( |
42 controller()->GetProfile(), this, this, | 42 controller()->profile(), this, this, |
43 base::Bind(MenuItemHasLauncherContext))); | 43 base::Bind(MenuItemHasLauncherContext))); |
44 if (item().type == ash::TYPE_APP_SHORTCUT || | 44 if (item().type == ash::TYPE_APP_SHORTCUT || |
45 item().type == ash::TYPE_WINDOWED_APP) { | 45 item().type == ash::TYPE_WINDOWED_APP) { |
46 // V1 apps can be started from the menu - but V2 apps should not. | 46 // V1 apps can be started from the menu - but V2 apps should not. |
47 if (!controller()->IsPlatformApp(item().id)) { | 47 if (!controller()->IsPlatformApp(item().id)) { |
48 AddItem(MENU_OPEN_NEW, base::string16()); | 48 AddItem(MENU_OPEN_NEW, base::string16()); |
49 AddSeparator(ui::NORMAL_SEPARATOR); | 49 AddSeparator(ui::NORMAL_SEPARATOR); |
50 } | 50 } |
51 AddPinMenu(); | 51 AddPinMenu(); |
52 if (controller()->IsOpen(item().id)) | 52 if (controller()->IsOpen(item().id)) |
(...skipping 16 matching lines...) Expand all Loading... |
69 AddCheckItemWithStringId(LAUNCH_TYPE_WINDOW, | 69 AddCheckItemWithStringId(LAUNCH_TYPE_WINDOW, |
70 IDS_APP_CONTEXT_MENU_OPEN_WINDOW); | 70 IDS_APP_CONTEXT_MENU_OPEN_WINDOW); |
71 // Even though the launch type is Full Screen it is more accurately | 71 // Even though the launch type is Full Screen it is more accurately |
72 // described as Maximized in Ash. | 72 // described as Maximized in Ash. |
73 AddCheckItemWithStringId(LAUNCH_TYPE_FULLSCREEN, | 73 AddCheckItemWithStringId(LAUNCH_TYPE_FULLSCREEN, |
74 IDS_APP_CONTEXT_MENU_OPEN_MAXIMIZED); | 74 IDS_APP_CONTEXT_MENU_OPEN_MAXIMIZED); |
75 } | 75 } |
76 } | 76 } |
77 } else if (item().type == ash::TYPE_BROWSER_SHORTCUT) { | 77 } else if (item().type == ash::TYPE_BROWSER_SHORTCUT) { |
78 AddItemWithStringId(MENU_NEW_WINDOW, IDS_APP_LIST_NEW_WINDOW); | 78 AddItemWithStringId(MENU_NEW_WINDOW, IDS_APP_LIST_NEW_WINDOW); |
79 if (!controller()->GetProfile()->IsGuestSession()) { | 79 if (!controller()->profile()->IsGuestSession()) { |
80 AddItemWithStringId(MENU_NEW_INCOGNITO_WINDOW, | 80 AddItemWithStringId(MENU_NEW_INCOGNITO_WINDOW, |
81 IDS_APP_LIST_NEW_INCOGNITO_WINDOW); | 81 IDS_APP_LIST_NEW_INCOGNITO_WINDOW); |
82 } | 82 } |
83 if (!BrowserShortcutLauncherItemController( | 83 if (!BrowserShortcutLauncherItemController( |
84 controller(), ash::WmShell::Get()->shelf_model()) | 84 controller(), ash::WmShell::Get()->shelf_model()) |
85 .IsListOfActiveBrowserEmpty()) { | 85 .IsListOfActiveBrowserEmpty()) { |
86 AddItem(MENU_CLOSE, | 86 AddItem(MENU_CLOSE, |
87 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_CLOSE)); | 87 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_CLOSE)); |
88 } | 88 } |
89 } else if (item().type == ash::TYPE_DIALOG) { | 89 } else if (item().type == ash::TYPE_DIALOG) { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 return (extension_items_ && | 162 return (extension_items_ && |
163 extension_items_->IsCommandIdChecked(command_id)); | 163 extension_items_->IsCommandIdChecked(command_id)); |
164 } | 164 } |
165 } | 165 } |
166 | 166 |
167 bool ExtensionLauncherContextMenu::IsCommandIdEnabled(int command_id) const { | 167 bool ExtensionLauncherContextMenu::IsCommandIdEnabled(int command_id) const { |
168 switch (command_id) { | 168 switch (command_id) { |
169 case MENU_NEW_WINDOW: | 169 case MENU_NEW_WINDOW: |
170 // "Normal" windows are not allowed when incognito is enforced. | 170 // "Normal" windows are not allowed when incognito is enforced. |
171 return IncognitoModePrefs::GetAvailability( | 171 return IncognitoModePrefs::GetAvailability( |
172 controller()->GetProfile()->GetPrefs()) != | 172 controller()->profile()->GetPrefs()) != |
173 IncognitoModePrefs::FORCED; | 173 IncognitoModePrefs::FORCED; |
174 case MENU_NEW_INCOGNITO_WINDOW: | 174 case MENU_NEW_INCOGNITO_WINDOW: |
175 // Incognito windows are not allowed when incognito is disabled. | 175 // Incognito windows are not allowed when incognito is disabled. |
176 return IncognitoModePrefs::GetAvailability( | 176 return IncognitoModePrefs::GetAvailability( |
177 controller()->GetProfile()->GetPrefs()) != | 177 controller()->profile()->GetPrefs()) != |
178 IncognitoModePrefs::DISABLED; | 178 IncognitoModePrefs::DISABLED; |
179 default: | 179 default: |
180 if (command_id < MENU_ITEM_COUNT) | 180 if (command_id < MENU_ITEM_COUNT) |
181 return LauncherContextMenu::IsCommandIdEnabled(command_id); | 181 return LauncherContextMenu::IsCommandIdEnabled(command_id); |
182 return (extension_items_ && | 182 return (extension_items_ && |
183 extension_items_->IsCommandIdEnabled(command_id)); | 183 extension_items_->IsCommandIdEnabled(command_id)); |
184 } | 184 } |
185 } | 185 } |
186 | 186 |
187 void ExtensionLauncherContextMenu::ExecuteCommand(int command_id, | 187 void ExtensionLauncherContextMenu::ExecuteCommand(int command_id, |
(...skipping 18 matching lines...) Expand all Loading... |
206 : extensions::LAUNCH_TYPE_WINDOW; | 206 : extensions::LAUNCH_TYPE_WINDOW; |
207 } | 207 } |
208 controller()->SetLaunchType(item().id, launch_type); | 208 controller()->SetLaunchType(item().id, launch_type); |
209 break; | 209 break; |
210 } | 210 } |
211 case LAUNCH_TYPE_FULLSCREEN: | 211 case LAUNCH_TYPE_FULLSCREEN: |
212 controller()->SetLaunchType(item().id, | 212 controller()->SetLaunchType(item().id, |
213 extensions::LAUNCH_TYPE_FULLSCREEN); | 213 extensions::LAUNCH_TYPE_FULLSCREEN); |
214 break; | 214 break; |
215 case MENU_NEW_WINDOW: | 215 case MENU_NEW_WINDOW: |
216 chrome::NewEmptyWindow(controller()->GetProfile()); | 216 chrome::NewEmptyWindow(controller()->profile()); |
217 break; | 217 break; |
218 case MENU_NEW_INCOGNITO_WINDOW: | 218 case MENU_NEW_INCOGNITO_WINDOW: |
219 chrome::NewEmptyWindow( | 219 chrome::NewEmptyWindow(controller()->profile()->GetOffTheRecordProfile()); |
220 controller()->GetProfile()->GetOffTheRecordProfile()); | |
221 break; | 220 break; |
222 default: | 221 default: |
223 if (extension_items_) { | 222 if (extension_items_) { |
224 extension_items_->ExecuteCommand(command_id, nullptr, nullptr, | 223 extension_items_->ExecuteCommand(command_id, nullptr, nullptr, |
225 content::ContextMenuParams()); | 224 content::ContextMenuParams()); |
226 } | 225 } |
227 } | 226 } |
228 } | 227 } |
OLD | NEW |