| OLD | NEW |
| 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_manager.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 |
| 17 LauncherContextMenu::LauncherContextMenu(ChromeLauncherController* controller, | 19 LauncherContextMenu::LauncherContextMenu(ChromeLauncherController* controller, |
| 18 const ash::LauncherItem* item) | 20 const ash::LauncherItem* item) |
| 19 : ui::SimpleMenuModel(NULL), | 21 : ui::SimpleMenuModel(NULL), |
| 20 controller_(controller), | 22 controller_(controller), |
| 21 item_(item ? *item : ash::LauncherItem()) { | 23 item_(item ? *item : ash::LauncherItem()), |
| 24 context_menu_manager_(new extensions::ContextMenuManager( |
| 25 controller->profile(), this, this, |
| 26 base::Bind(extensions::ContextMenuManager::ContextIsLauncher))) { |
| 22 set_delegate(this); | 27 set_delegate(this); |
| 23 | 28 |
| 24 if (is_valid_item()) { | 29 if (is_valid_item()) { |
| 25 if (item_.type == ash::TYPE_APP_SHORTCUT) { | 30 if (item_.type == ash::TYPE_APP_SHORTCUT) { |
| 26 DCHECK(controller->IsPinned(item_.id)); | 31 DCHECK(controller->IsPinned(item_.id)); |
| 27 AddItem( | 32 AddItem( |
| 28 MENU_PIN, | 33 MENU_PIN, |
| 29 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_UNPIN)); | 34 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_UNPIN)); |
| 30 if (controller->IsOpen(item->id)) { | 35 if (controller->IsOpen(item->id)) { |
| 31 AddItem(MENU_CLOSE, | 36 AddItem(MENU_CLOSE, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 49 } else if (item_.type == ash::TYPE_BROWSER_SHORTCUT) { | 54 } else if (item_.type == ash::TYPE_BROWSER_SHORTCUT) { |
| 50 AddItem(MENU_NEW_WINDOW, | 55 AddItem(MENU_NEW_WINDOW, |
| 51 l10n_util::GetStringUTF16(IDS_LAUNCHER_NEW_WINDOW)); | 56 l10n_util::GetStringUTF16(IDS_LAUNCHER_NEW_WINDOW)); |
| 52 if (!controller_->IsLoggedInAsGuest()) { | 57 if (!controller_->IsLoggedInAsGuest()) { |
| 53 AddItem(MENU_NEW_INCOGNITO_WINDOW, | 58 AddItem(MENU_NEW_INCOGNITO_WINDOW, |
| 54 l10n_util::GetStringUTF16(IDS_LAUNCHER_NEW_INCOGNITO_WINDOW)); | 59 l10n_util::GetStringUTF16(IDS_LAUNCHER_NEW_INCOGNITO_WINDOW)); |
| 55 } | 60 } |
| 56 } else { | 61 } else { |
| 57 AddItem(MENU_OPEN, controller->GetTitle(item_)); | 62 AddItem(MENU_OPEN, controller->GetTitle(item_)); |
| 58 if (item_.type == ash::TYPE_PLATFORM_APP) { | 63 if (item_.type == ash::TYPE_PLATFORM_APP) { |
| 64 int index = 0; |
| 65 context_menu_manager_->AppendExtensionItems( |
| 66 controller->GetAppIDForLauncherID(item_.id), string16(), &index); |
| 67 if (index > 0) |
| 68 AddSeparator(ui::NORMAL_SEPARATOR); |
| 59 AddItem( | 69 AddItem( |
| 60 MENU_PIN, | 70 MENU_PIN, |
| 61 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_PIN)); | 71 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_PIN)); |
| 62 } | 72 } |
| 63 if (controller->IsOpen(item_.id)) { | 73 if (controller->IsOpen(item_.id)) { |
| 64 AddItem(MENU_CLOSE, | 74 AddItem(MENU_CLOSE, |
| 65 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_CLOSE)); | 75 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_CLOSE)); |
| 66 } | 76 } |
| 67 } | 77 } |
| 68 AddSeparator(ui::NORMAL_SEPARATOR); | 78 AddSeparator(ui::NORMAL_SEPARATOR); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 90 extensions::ExtensionPrefs::LAUNCH_REGULAR; | 100 extensions::ExtensionPrefs::LAUNCH_REGULAR; |
| 91 case LAUNCH_TYPE_WINDOW: | 101 case LAUNCH_TYPE_WINDOW: |
| 92 return controller_->GetLaunchType(item_.id) == | 102 return controller_->GetLaunchType(item_.id) == |
| 93 extensions::ExtensionPrefs::LAUNCH_WINDOW; | 103 extensions::ExtensionPrefs::LAUNCH_WINDOW; |
| 94 case LAUNCH_TYPE_FULLSCREEN: | 104 case LAUNCH_TYPE_FULLSCREEN: |
| 95 return controller_->GetLaunchType(item_.id) == | 105 return controller_->GetLaunchType(item_.id) == |
| 96 extensions::ExtensionPrefs::LAUNCH_FULLSCREEN; | 106 extensions::ExtensionPrefs::LAUNCH_FULLSCREEN; |
| 97 case MENU_AUTO_HIDE: | 107 case MENU_AUTO_HIDE: |
| 98 return ash::LauncherContextMenu::IsAutoHideMenuHideChecked(); | 108 return ash::LauncherContextMenu::IsAutoHideMenuHideChecked(); |
| 99 default: | 109 default: |
| 100 return false; | 110 return context_menu_manager_->IsCommandIdChecked(command_id); |
| 101 } | 111 } |
| 102 } | 112 } |
| 103 | 113 |
| 104 bool LauncherContextMenu::IsCommandIdEnabled(int command_id) const { | 114 bool LauncherContextMenu::IsCommandIdEnabled(int command_id) const { |
| 105 switch (command_id) { | 115 switch (command_id) { |
| 106 case MENU_PIN: | 116 case MENU_PIN: |
| 107 return item_.type == ash::TYPE_PLATFORM_APP || | 117 return item_.type == ash::TYPE_PLATFORM_APP || |
| 108 controller_->IsPinnable(item_.id); | 118 controller_->IsPinnable(item_.id); |
| 109 default: | 119 default: |
| 110 return true; | 120 return context_menu_manager_->IsCommandIdEnabled(command_id); |
| 111 } | 121 } |
| 112 } | 122 } |
| 113 | 123 |
| 114 bool LauncherContextMenu::GetAcceleratorForCommandId( | 124 bool LauncherContextMenu::GetAcceleratorForCommandId( |
| 115 int command_id, | 125 int command_id, |
| 116 ui::Accelerator* accelerator) { | 126 ui::Accelerator* accelerator) { |
| 117 return false; | 127 return false; |
| 118 } | 128 } |
| 119 | 129 |
| 120 void LauncherContextMenu::ExecuteCommand(int command_id) { | 130 void LauncherContextMenu::ExecuteCommand(int command_id) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 149 ash::LauncherContextMenu::GetToggledAutoHideBehavior()); | 159 ash::LauncherContextMenu::GetToggledAutoHideBehavior()); |
| 150 break; | 160 break; |
| 151 case MENU_NEW_WINDOW: | 161 case MENU_NEW_WINDOW: |
| 152 controller_->CreateNewWindow(); | 162 controller_->CreateNewWindow(); |
| 153 break; | 163 break; |
| 154 case MENU_NEW_INCOGNITO_WINDOW: | 164 case MENU_NEW_INCOGNITO_WINDOW: |
| 155 controller_->CreateNewIncognitoWindow(); | 165 controller_->CreateNewIncognitoWindow(); |
| 156 break; | 166 break; |
| 157 case MENU_ALIGNMENT_MENU: | 167 case MENU_ALIGNMENT_MENU: |
| 158 break; | 168 break; |
| 169 default: |
| 170 content::ContextMenuParams params; |
| 171 // TODO(mek): maybe make page_url not required? |
| 172 params.page_url = GURL("about:blank"); |
| 173 context_menu_manager_->ExecuteCommand(command_id, params); |
| 159 } | 174 } |
| 160 } | 175 } |
| OLD | NEW |