| Index: chrome/browser/ui/ash/launcher/extension_launcher_context_menu.cc
|
| diff --git a/chrome/browser/ui/ash/launcher/launcher_context_menu.cc b/chrome/browser/ui/ash/launcher/extension_launcher_context_menu.cc
|
| similarity index 26%
|
| copy from chrome/browser/ui/ash/launcher/launcher_context_menu.cc
|
| copy to chrome/browser/ui/ash/launcher/extension_launcher_context_menu.cc
|
| index 1539ae9e7467d641949afd8fe1a90abdfdcf2df2..cea24f8fcee2e0868dad4dda695615c22d4d005b 100644
|
| --- a/chrome/browser/ui/ash/launcher/launcher_context_menu.cc
|
| +++ b/chrome/browser/ui/ash/launcher/extension_launcher_context_menu.cc
|
| @@ -1,31 +1,19 @@
|
| -// Copyright 2012 The Chromium Authors. All rights reserved.
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
|
| +#include "chrome/browser/ui/ash/launcher/extension_launcher_context_menu.h"
|
|
|
| -#include <string>
|
| -
|
| -#include "ash/desktop_background/user_wallpaper_delegate.h"
|
| -#include "ash/metrics/user_metrics_recorder.h"
|
| -#include "ash/session/session_state_delegate.h"
|
| #include "ash/shelf/shelf.h"
|
| #include "ash/shelf/shelf_item_delegate.h"
|
| -#include "ash/shelf/shelf_widget.h"
|
| -#include "ash/shell.h"
|
| #include "base/bind.h"
|
| -#include "build/build_config.h"
|
| #include "chrome/browser/extensions/context_menu_matcher.h"
|
| #include "chrome/browser/extensions/extension_util.h"
|
| -#include "chrome/browser/fullscreen.h"
|
| #include "chrome/browser/prefs/incognito_mode_prefs.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| -#include "chrome/browser/ui/ash/chrome_shell_delegate.h"
|
| #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
|
| #include "chrome/common/extensions/extension_constants.h"
|
| -#include "chrome/common/pref_names.h"
|
| #include "chrome/grit/generated_resources.h"
|
| -#include "components/prefs/pref_service.h"
|
| #include "content/public/common/context_menu_params.h"
|
| #include "grit/ash_strings.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
| @@ -36,158 +24,102 @@ bool MenuItemHasLauncherContext(const extensions::MenuItem* item) {
|
| return item->contexts().Contains(extensions::MenuItem::LAUNCHER);
|
| }
|
|
|
| -// Returns true if the user can modify the |shelf|'s auto-hide behavior.
|
| -bool CanUserModifyShelfAutoHideBehavior(const Profile* profile) {
|
| - const std::string& pref = prefs::kShelfAutoHideBehaviorLocal;
|
| - return profile->GetPrefs()->FindPreference(pref)->IsUserModifiable();
|
| -}
|
| -
|
| } // namespace
|
|
|
| -LauncherContextMenu::LauncherContextMenu(ChromeLauncherController* controller,
|
| - const ash::ShelfItem* item,
|
| - ash::Shelf* shelf)
|
| - : ui::SimpleMenuModel(nullptr),
|
| - controller_(controller),
|
| - item_(item ? *item : ash::ShelfItem()),
|
| - shelf_alignment_menu_(shelf),
|
| - shelf_(shelf) {
|
| - DCHECK(shelf_);
|
| +ExtensionLauncherContextMenu::ExtensionLauncherContextMenu(
|
| + ChromeLauncherController* controller,
|
| + const ash::ShelfItem* item,
|
| + ash::Shelf* shelf)
|
| + : LauncherContextMenu(controller, item, shelf) {
|
| Init();
|
| }
|
|
|
| -void LauncherContextMenu::Init() {
|
| - set_delegate(this);
|
| +ExtensionLauncherContextMenu::~ExtensionLauncherContextMenu() {}
|
| +
|
| +void ExtensionLauncherContextMenu::Init() {
|
| + extension_items_.reset(new extensions::ContextMenuMatcher(
|
| + controller()->profile(), this, this,
|
| + base::Bind(MenuItemHasLauncherContext)));
|
| + if (item().type == ash::TYPE_APP_SHORTCUT ||
|
| + item().type == ash::TYPE_WINDOWED_APP) {
|
| + // V1 apps can be started from the menu - but V2 apps should not.
|
| + if (!controller()->IsPlatformApp(item().id)) {
|
| + AddItem(MENU_OPEN_NEW, base::string16());
|
| + AddSeparator(ui::NORMAL_SEPARATOR);
|
| + }
|
| + AddPinMenu();
|
| + if (controller()->IsOpen(item().id))
|
| + AddItemWithStringId(MENU_CLOSE, IDS_LAUNCHER_CONTEXT_MENU_CLOSE);
|
|
|
| - if (item_.id != 0) {
|
| - extension_items_.reset(new extensions::ContextMenuMatcher(
|
| - controller_->profile(), this, this,
|
| - base::Bind(MenuItemHasLauncherContext)));
|
| - if (item_.type == ash::TYPE_APP_SHORTCUT ||
|
| - item_.type == ash::TYPE_WINDOWED_APP) {
|
| - // V1 apps can be started from the menu - but V2 apps should not.
|
| - if (!controller_->IsPlatformApp(item_.id)) {
|
| - AddItem(MENU_OPEN_NEW, base::string16());
|
| - AddSeparator(ui::NORMAL_SEPARATOR);
|
| - }
|
| - const std::string app_id = controller_->GetAppIDForShelfID(item_.id);
|
| - int menu_pin_string_id;
|
| - if (!controller_->CanPin(app_id))
|
| - menu_pin_string_id = IDS_LAUNCHER_CONTEXT_MENU_PIN_ENFORCED_BY_POLICY;
|
| - else if (controller_->IsPinned(item_.id))
|
| - menu_pin_string_id = IDS_LAUNCHER_CONTEXT_MENU_UNPIN;
|
| - else
|
| - menu_pin_string_id = IDS_LAUNCHER_CONTEXT_MENU_PIN;
|
| - AddItem(MENU_PIN, l10n_util::GetStringUTF16(menu_pin_string_id));
|
| - if (controller_->IsOpen(item_.id)) {
|
| - AddItem(MENU_CLOSE,
|
| - l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_CLOSE));
|
| - }
|
| - if (!controller_->IsPlatformApp(item_.id) &&
|
| - item_.type != ash::TYPE_WINDOWED_APP) {
|
| - AddSeparator(ui::NORMAL_SEPARATOR);
|
| - if (extensions::util::IsNewBookmarkAppsEnabled()) {
|
| - // With bookmark apps enabled, hosted apps launch in a window by
|
| - // default. This menu item is re-interpreted as a single, toggle-able
|
| - // option to launch the hosted app as a tab.
|
| - AddCheckItemWithStringId(LAUNCH_TYPE_WINDOW,
|
| - IDS_APP_CONTEXT_MENU_OPEN_WINDOW);
|
| - } else {
|
| - AddCheckItemWithStringId(
|
| - LAUNCH_TYPE_REGULAR_TAB,
|
| - IDS_APP_CONTEXT_MENU_OPEN_REGULAR);
|
| - AddCheckItemWithStringId(
|
| - LAUNCH_TYPE_PINNED_TAB,
|
| - IDS_APP_CONTEXT_MENU_OPEN_PINNED);
|
| - AddCheckItemWithStringId(
|
| - LAUNCH_TYPE_WINDOW,
|
| - IDS_APP_CONTEXT_MENU_OPEN_WINDOW);
|
| - // Even though the launch type is Full Screen it is more accurately
|
| - // described as Maximized in Ash.
|
| - AddCheckItemWithStringId(
|
| - LAUNCH_TYPE_FULLSCREEN,
|
| - IDS_APP_CONTEXT_MENU_OPEN_MAXIMIZED);
|
| - }
|
| - }
|
| - } else if (item_.type == ash::TYPE_BROWSER_SHORTCUT) {
|
| - AddItem(MENU_NEW_WINDOW,
|
| - l10n_util::GetStringUTF16(IDS_APP_LIST_NEW_WINDOW));
|
| - if (!controller_->IsLoggedInAsGuest()) {
|
| - AddItem(MENU_NEW_INCOGNITO_WINDOW,
|
| - l10n_util::GetStringUTF16(IDS_APP_LIST_NEW_INCOGNITO_WINDOW));
|
| - }
|
| - } else if (item_.type == ash::TYPE_DIALOG) {
|
| - AddItem(MENU_CLOSE,
|
| - l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_CLOSE));
|
| - } else {
|
| - if (item_.type == ash::TYPE_PLATFORM_APP) {
|
| - AddItem(
|
| - MENU_PIN,
|
| - l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_PIN));
|
| - }
|
| - bool show_close_button = controller_->IsOpen(item_.id);
|
| -#if defined(OS_CHROMEOS)
|
| - if (extension_misc::IsImeMenuExtensionId(
|
| - controller_->GetAppIDForShelfID(item_.id))) {
|
| - show_close_button = false;
|
| - }
|
| -#endif
|
| - if (show_close_button) {
|
| - AddItem(MENU_CLOSE,
|
| - l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_CLOSE));
|
| + if (!controller()->IsPlatformApp(item().id) &&
|
| + item().type != ash::TYPE_WINDOWED_APP) {
|
| + AddSeparator(ui::NORMAL_SEPARATOR);
|
| + if (extensions::util::IsNewBookmarkAppsEnabled()) {
|
| + // With bookmark apps enabled, hosted apps launch in a window by
|
| + // default. This menu item is re-interpreted as a single, toggle-able
|
| + // option to launch the hosted app as a tab.
|
| + AddCheckItemWithStringId(LAUNCH_TYPE_WINDOW,
|
| + IDS_APP_CONTEXT_MENU_OPEN_WINDOW);
|
| + } else {
|
| + AddCheckItemWithStringId(LAUNCH_TYPE_REGULAR_TAB,
|
| + IDS_APP_CONTEXT_MENU_OPEN_REGULAR);
|
| + AddCheckItemWithStringId(LAUNCH_TYPE_PINNED_TAB,
|
| + IDS_APP_CONTEXT_MENU_OPEN_PINNED);
|
| + AddCheckItemWithStringId(LAUNCH_TYPE_WINDOW,
|
| + IDS_APP_CONTEXT_MENU_OPEN_WINDOW);
|
| + // Even though the launch type is Full Screen it is more accurately
|
| + // described as Maximized in Ash.
|
| + AddCheckItemWithStringId(LAUNCH_TYPE_FULLSCREEN,
|
| + IDS_APP_CONTEXT_MENU_OPEN_MAXIMIZED);
|
| }
|
| }
|
| - AddSeparator(ui::NORMAL_SEPARATOR);
|
| - if (item_.type == ash::TYPE_APP_SHORTCUT ||
|
| - item_.type == ash::TYPE_WINDOWED_APP ||
|
| - item_.type == ash::TYPE_PLATFORM_APP) {
|
| - const extensions::MenuItem::ExtensionKey app_key(
|
| - controller_->GetAppIDForShelfID(item_.id));
|
| - if (!app_key.empty()) {
|
| - int index = 0;
|
| - extension_items_->AppendExtensionItems(app_key,
|
| - base::string16(),
|
| - &index,
|
| - false); // is_action_menu
|
| - AddSeparator(ui::NORMAL_SEPARATOR);
|
| - }
|
| + } else if (item().type == ash::TYPE_BROWSER_SHORTCUT) {
|
| + AddItemWithStringId(MENU_NEW_WINDOW, IDS_APP_LIST_NEW_WINDOW);
|
| + if (!controller()->IsLoggedInAsGuest()) {
|
| + AddItemWithStringId(MENU_NEW_INCOGNITO_WINDOW,
|
| + IDS_APP_LIST_NEW_INCOGNITO_WINDOW);
|
| }
|
| - }
|
| - // In fullscreen, the launcher is either hidden or autohidden depending on the
|
| - // type of fullscreen. Do not show the auto-hide menu item while in fullscreen
|
| - // because it is confusing when the preference appears not to apply.
|
| - if (!IsFullScreenMode() &&
|
| - CanUserModifyShelfAutoHideBehavior(controller_->profile())) {
|
| - AddCheckItemWithStringId(MENU_AUTO_HIDE,
|
| - IDS_ASH_SHELF_CONTEXT_MENU_AUTO_HIDE);
|
| - }
|
| - if (ash::ShelfWidget::ShelfAlignmentAllowed() &&
|
| - !ash::Shell::GetInstance()->session_state_delegate()->IsScreenLocked()) {
|
| - AddSubMenuWithStringId(MENU_ALIGNMENT_MENU,
|
| - IDS_ASH_SHELF_CONTEXT_MENU_POSITION,
|
| - &shelf_alignment_menu_);
|
| - }
|
| + } else if (item().type == ash::TYPE_DIALOG) {
|
| + AddItemWithStringId(MENU_CLOSE, IDS_LAUNCHER_CONTEXT_MENU_CLOSE);
|
| + } else {
|
| + if (item().type == ash::TYPE_PLATFORM_APP)
|
| + AddItemWithStringId(MENU_PIN, IDS_LAUNCHER_CONTEXT_MENU_PIN);
|
| + bool show_close_button = controller()->IsOpen(item().id);
|
| #if defined(OS_CHROMEOS)
|
| - if (!controller_->IsLoggedInAsGuest()) {
|
| - AddItem(MENU_CHANGE_WALLPAPER,
|
| - l10n_util::GetStringUTF16(IDS_AURA_SET_DESKTOP_WALLPAPER));
|
| - }
|
| + if (extension_misc::IsImeMenuExtensionId(
|
| + controller()->GetAppIDForShelfID(item().id)))
|
| + show_close_button = false;
|
| #endif
|
| + if (show_close_button)
|
| + AddItemWithStringId(MENU_CLOSE, IDS_LAUNCHER_CONTEXT_MENU_CLOSE);
|
| + }
|
| + AddSeparator(ui::NORMAL_SEPARATOR);
|
| + if (item().type == ash::TYPE_APP_SHORTCUT ||
|
| + item().type == ash::TYPE_WINDOWED_APP ||
|
| + item().type == ash::TYPE_PLATFORM_APP) {
|
| + const extensions::MenuItem::ExtensionKey app_key(
|
| + controller()->GetAppIDForShelfID(item().id));
|
| + if (!app_key.empty()) {
|
| + int index = 0;
|
| + extension_items_->AppendExtensionItems(app_key, base::string16(), &index,
|
| + false); // is_action_menu
|
| + AddSeparator(ui::NORMAL_SEPARATOR);
|
| + }
|
| + }
|
| + AddShelfOptionsMenu();
|
| }
|
|
|
| -LauncherContextMenu::~LauncherContextMenu() {
|
| -}
|
| -
|
| -bool LauncherContextMenu::IsItemForCommandIdDynamic(int command_id) const {
|
| +bool ExtensionLauncherContextMenu::IsItemForCommandIdDynamic(
|
| + int command_id) const {
|
| return command_id == MENU_OPEN_NEW;
|
| }
|
|
|
| -base::string16 LauncherContextMenu::GetLabelForCommandId(int command_id) const {
|
| +base::string16 ExtensionLauncherContextMenu::GetLabelForCommandId(
|
| + int command_id) const {
|
| if (command_id == MENU_OPEN_NEW) {
|
| - if (item_.type == ash::TYPE_PLATFORM_APP) {
|
| + if (item().type == ash::TYPE_PLATFORM_APP)
|
| return l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_NEW_WINDOW);
|
| - }
|
| - switch (controller_->GetLaunchType(item_.id)) {
|
| + switch (controller()->GetLaunchType(item().id)) {
|
| case extensions::LAUNCH_TYPE_PINNED:
|
| case extensions::LAUNCH_TYPE_REGULAR:
|
| return l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_NEW_TAB);
|
| @@ -203,124 +135,81 @@ base::string16 LauncherContextMenu::GetLabelForCommandId(int command_id) const {
|
| return base::string16();
|
| }
|
|
|
| -bool LauncherContextMenu::IsCommandIdChecked(int command_id) const {
|
| +bool ExtensionLauncherContextMenu::IsCommandIdChecked(int command_id) const {
|
| switch (command_id) {
|
| case LAUNCH_TYPE_PINNED_TAB:
|
| - return controller_->GetLaunchType(item_.id) ==
|
| - extensions::LAUNCH_TYPE_PINNED;
|
| + return controller()->GetLaunchType(item().id) ==
|
| + extensions::LAUNCH_TYPE_PINNED;
|
| case LAUNCH_TYPE_REGULAR_TAB:
|
| - return controller_->GetLaunchType(item_.id) ==
|
| - extensions::LAUNCH_TYPE_REGULAR;
|
| + return controller()->GetLaunchType(item().id) ==
|
| + extensions::LAUNCH_TYPE_REGULAR;
|
| case LAUNCH_TYPE_WINDOW:
|
| - return controller_->GetLaunchType(item_.id) ==
|
| - extensions::LAUNCH_TYPE_WINDOW;
|
| + return controller()->GetLaunchType(item().id) ==
|
| + extensions::LAUNCH_TYPE_WINDOW;
|
| case LAUNCH_TYPE_FULLSCREEN:
|
| - return controller_->GetLaunchType(item_.id) ==
|
| - extensions::LAUNCH_TYPE_FULLSCREEN;
|
| - case MENU_AUTO_HIDE:
|
| - return shelf_->GetAutoHideBehavior() ==
|
| - ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
|
| + return controller()->GetLaunchType(item().id) ==
|
| + extensions::LAUNCH_TYPE_FULLSCREEN;
|
| default:
|
| if (command_id < MENU_ITEM_COUNT)
|
| - return false;
|
| + return LauncherContextMenu::IsCommandIdChecked(command_id);
|
| return (extension_items_ &&
|
| extension_items_->IsCommandIdChecked(command_id));
|
| }
|
| }
|
|
|
| -bool LauncherContextMenu::IsCommandIdEnabled(int command_id) const {
|
| +bool ExtensionLauncherContextMenu::IsCommandIdEnabled(int command_id) const {
|
| switch (command_id) {
|
| - case MENU_PIN:
|
| - return controller_->IsPinnable(item_.id);
|
| - case MENU_CHANGE_WALLPAPER:
|
| - return ash::Shell::GetInstance()->user_wallpaper_delegate()->
|
| - CanOpenSetWallpaperPage();
|
| case MENU_NEW_WINDOW:
|
| // "Normal" windows are not allowed when incognito is enforced.
|
| return IncognitoModePrefs::GetAvailability(
|
| - controller_->profile()->GetPrefs()) != IncognitoModePrefs::FORCED;
|
| - case MENU_AUTO_HIDE:
|
| - return CanUserModifyShelfAutoHideBehavior(controller_->profile());
|
| + controller()->profile()->GetPrefs()) !=
|
| + IncognitoModePrefs::FORCED;
|
| case MENU_NEW_INCOGNITO_WINDOW:
|
| // Incognito windows are not allowed when incognito is disabled.
|
| return IncognitoModePrefs::GetAvailability(
|
| - controller_->profile()->GetPrefs()) != IncognitoModePrefs::DISABLED;
|
| + controller()->profile()->GetPrefs()) !=
|
| + IncognitoModePrefs::DISABLED;
|
| default:
|
| if (command_id < MENU_ITEM_COUNT)
|
| - return true;
|
| + return LauncherContextMenu::IsCommandIdEnabled(command_id);
|
| return (extension_items_ &&
|
| extension_items_->IsCommandIdEnabled(command_id));
|
| }
|
| }
|
|
|
| -bool LauncherContextMenu::GetAcceleratorForCommandId(
|
| - int command_id,
|
| - ui::Accelerator* accelerator) {
|
| - return false;
|
| -}
|
| -
|
| -void LauncherContextMenu::ExecuteCommand(int command_id, int event_flags) {
|
| +void ExtensionLauncherContextMenu::ExecuteCommand(int command_id,
|
| + int event_flags) {
|
| + if (ExecuteCommonCommand(command_id, event_flags))
|
| + return;
|
| switch (static_cast<MenuItem>(command_id)) {
|
| - case MENU_OPEN_NEW:
|
| - controller_->Launch(item_.id, ui::EF_NONE);
|
| - break;
|
| - case MENU_CLOSE:
|
| - if (item_.type == ash::TYPE_DIALOG) {
|
| - ash::ShelfItemDelegate* item_delegate =
|
| - ash::Shell::GetInstance()
|
| - ->shelf_item_delegate_manager()
|
| - ->GetShelfItemDelegate(item_.id);
|
| - DCHECK(item_delegate);
|
| - item_delegate->Close();
|
| - } else {
|
| - // TODO(simonhong): Use ShelfItemDelegate::Close().
|
| - controller_->Close(item_.id);
|
| - }
|
| - ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction(
|
| - ash::UMA_CLOSE_THROUGH_CONTEXT_MENU);
|
| - break;
|
| - case MENU_PIN:
|
| - controller_->TogglePinned(item_.id);
|
| - break;
|
| case LAUNCH_TYPE_PINNED_TAB:
|
| - controller_->SetLaunchType(item_.id, extensions::LAUNCH_TYPE_PINNED);
|
| + controller()->SetLaunchType(item().id, extensions::LAUNCH_TYPE_PINNED);
|
| break;
|
| case LAUNCH_TYPE_REGULAR_TAB:
|
| - controller_->SetLaunchType(item_.id, extensions::LAUNCH_TYPE_REGULAR);
|
| + controller()->SetLaunchType(item().id, extensions::LAUNCH_TYPE_REGULAR);
|
| break;
|
| case LAUNCH_TYPE_WINDOW: {
|
| extensions::LaunchType launch_type = extensions::LAUNCH_TYPE_WINDOW;
|
| // With bookmark apps enabled, hosted apps can only toggle between
|
| // LAUNCH_WINDOW and LAUNCH_REGULAR.
|
| if (extensions::util::IsNewBookmarkAppsEnabled()) {
|
| - launch_type = controller_->GetLaunchType(item_.id) ==
|
| + launch_type = controller()->GetLaunchType(item().id) ==
|
| extensions::LAUNCH_TYPE_WINDOW
|
| ? extensions::LAUNCH_TYPE_REGULAR
|
| : extensions::LAUNCH_TYPE_WINDOW;
|
| }
|
| - controller_->SetLaunchType(item_.id, launch_type);
|
| + controller()->SetLaunchType(item().id, launch_type);
|
| break;
|
| }
|
| case LAUNCH_TYPE_FULLSCREEN:
|
| - controller_->SetLaunchType(item_.id, extensions::LAUNCH_TYPE_FULLSCREEN);
|
| - break;
|
| - case MENU_AUTO_HIDE:
|
| - shelf_->SetAutoHideBehavior(shelf_->GetAutoHideBehavior() ==
|
| - ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
|
| - ? ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER
|
| - : ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
|
| + controller()->SetLaunchType(item().id,
|
| + extensions::LAUNCH_TYPE_FULLSCREEN);
|
| break;
|
| case MENU_NEW_WINDOW:
|
| - controller_->CreateNewWindow();
|
| + controller()->CreateNewWindow();
|
| break;
|
| case MENU_NEW_INCOGNITO_WINDOW:
|
| - controller_->CreateNewIncognitoWindow();
|
| - break;
|
| - case MENU_ALIGNMENT_MENU:
|
| - break;
|
| - case MENU_CHANGE_WALLPAPER:
|
| - ash::Shell::GetInstance()->user_wallpaper_delegate()->
|
| - OpenSetWallpaperPage();
|
| + controller()->CreateNewIncognitoWindow();
|
| break;
|
| default:
|
| if (extension_items_) {
|
|
|