190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// found in the LICENSE file. 490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/browser/ui/app_list/app_context_menu.h" 690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 7f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/bind.h" 81e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/command_line.h" 990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/app/chrome_command_ids.h" 10f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "chrome/browser/chromeos/genius_app/app_id.h" 1190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/browser/extensions/context_menu_matcher.h" 12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/extensions/menu_manager.h" 1390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/browser/prefs/incognito_mode_prefs.h" 1490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/browser/profiles/profile.h" 1590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/browser/ui/app_list/app_context_menu_delegate.h" 1690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/browser/ui/app_list/app_list_controller_delegate.h" 171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/common/chrome_switches.h" 18f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "chrome/common/extensions/extension_constants.h" 1990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/common/extensions/manifest_url_handler.h" 2090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "content/public/common/context_menu_params.h" 2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "grit/chromium_strings.h" 2290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "grit/generated_resources.h" 2390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/base/l10n/l10n_util.h" 2490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 2590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#if defined(USE_ASH) 2690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ash/shell.h" 2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif 2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace app_list { 3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 3190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace { 3290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 3390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)enum CommandId { 3490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) LAUNCH_NEW = 100, 3590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) TOGGLE_PIN, 3690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) CREATE_SHORTCUTS, 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SHOW_APP_INFO, 3890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) OPTIONS, 3990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) UNINSTALL, 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) REMOVE_FROM_FOLDER, 4190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DETAILS, 4290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MENU_NEW_WINDOW, 4390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MENU_NEW_INCOGNITO_WINDOW, 44a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Order matters in USE_LAUNCH_TYPE_* and must match the LaunchType enum. 45a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) USE_LAUNCH_TYPE_COMMAND_START = 200, 46a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) USE_LAUNCH_TYPE_PINNED = USE_LAUNCH_TYPE_COMMAND_START, 47a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) USE_LAUNCH_TYPE_REGULAR, 48a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) USE_LAUNCH_TYPE_FULLSCREEN, 49a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) USE_LAUNCH_TYPE_WINDOW, 50a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) USE_LAUNCH_TYPE_COMMAND_END, 5190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 5290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 5390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)bool MenuItemHasLauncherContext(const extensions::MenuItem* item) { 5490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return item->contexts().Contains(extensions::MenuItem::LAUNCHER); 5590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 5690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 5790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} // namespace 5890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 5990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)AppContextMenu::AppContextMenu(AppContextMenuDelegate* delegate, 6090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) Profile* profile, 6190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const std::string& app_id, 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AppListControllerDelegate* controller) 6390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) : delegate_(delegate), 6490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) profile_(profile), 6590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) app_id_(app_id), 6690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller_(controller), 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) is_platform_app_(false), 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) is_search_result_(false), 695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) is_in_folder_(false) { 7090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 7190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)AppContextMenu::~AppContextMenu() { 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 7490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 7590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)ui::MenuModel* AppContextMenu::GetMenuModel() { 761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (!controller_->IsExtensionInstalled(profile_, app_id_)) 7790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return NULL; 7890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 7990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (menu_model_.get()) 8090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return menu_model_.get(); 8190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 8290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) menu_model_.reset(new ui::SimpleMenuModel(this)); 8390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 8490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (app_id_ == extension_misc::kChromeAppId) { 8590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) menu_model_->AddItemWithStringId( 8690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MENU_NEW_WINDOW, 8790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) IDS_APP_LIST_NEW_WINDOW); 8890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (!profile_->IsOffTheRecord()) { 8990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) menu_model_->AddItemWithStringId( 9090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MENU_NEW_INCOGNITO_WINDOW, 9190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) IDS_APP_LIST_NEW_INCOGNITO_WINDOW); 9290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 9390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } else { 9490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) extension_menu_items_.reset(new extensions::ContextMenuMatcher( 9590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) profile_, this, menu_model_.get(), 9690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) base::Bind(MenuItemHasLauncherContext))); 9790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 9890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (!is_platform_app_) 99a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) menu_model_->AddItem(LAUNCH_NEW, base::string16()); 10090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 10190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) int index = 0; 102a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) extension_menu_items_->AppendExtensionItems( 103a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) extensions::MenuItem::ExtensionKey(app_id_), base::string16(), &index); 10490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1054e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Show Pin/Unpin option if shelf is available. 1064e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (controller_->GetPinnable() != AppListControllerDelegate::NO_PIN) { 10790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); 10890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) menu_model_->AddItemWithStringId( 10990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) TOGGLE_PIN, 11090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller_->IsAppPinned(app_id_) ? 11190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) IDS_APP_LIST_CONTEXT_MENU_UNPIN : 11290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) IDS_APP_LIST_CONTEXT_MENU_PIN); 11390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 11490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (controller_->CanDoCreateShortcutsFlow()) { 11690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) menu_model_->AddItemWithStringId(CREATE_SHORTCUTS, 11790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) IDS_NEW_TAB_APP_CREATE_SHORTCUT); 11890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 11990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 120f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // Don't display the app info dialog for the Store app or the Genius app. 121f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // TODO(sashab): Update the metadata for these apps so their dialogs can be 122f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // re-enabled (see crbug.com/383713). 123cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (controller_->CanDoShowAppInfoFlow() && 124f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) app_id_ != extension_misc::kWebStoreAppId && 125f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) app_id_ != genius_app::kGeniusAppId) { 1265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) menu_model_->AddItemWithStringId(SHOW_APP_INFO, 1275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) IDS_APP_CONTEXT_MENU_SHOW_INFO); 1285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 13090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (!is_platform_app_) { 13190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); 132a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Streamlined hosted apps can only toggle between USE_LAUNCH_TYPE_WINDOW 133a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // and USE_LAUNCH_TYPE_REGULAR. 1341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (CommandLine::ForCurrentProcess()->HasSwitch( 1351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) switches::kEnableStreamlinedHostedApps)) { 1361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) menu_model_->AddCheckItemWithStringId( 137a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) USE_LAUNCH_TYPE_REGULAR, 1381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) IDS_APP_CONTEXT_MENU_OPEN_TAB); 1391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } else { 1401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) menu_model_->AddCheckItemWithStringId( 141a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) USE_LAUNCH_TYPE_REGULAR, 1421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) IDS_APP_CONTEXT_MENU_OPEN_REGULAR); 1431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) menu_model_->AddCheckItemWithStringId( 144a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) USE_LAUNCH_TYPE_PINNED, 1451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) IDS_APP_CONTEXT_MENU_OPEN_PINNED); 146eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#if defined(OS_MACOSX) 1471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Mac does not support standalone web app browser windows or maximize. 1481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) menu_model_->AddCheckItemWithStringId( 149a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) USE_LAUNCH_TYPE_FULLSCREEN, 1501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) IDS_APP_CONTEXT_MENU_OPEN_FULLSCREEN); 151eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#else 1521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) menu_model_->AddCheckItemWithStringId( 153a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) USE_LAUNCH_TYPE_WINDOW, 1541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) IDS_APP_CONTEXT_MENU_OPEN_WINDOW); 1551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Even though the launch type is Full Screen it is more accurately 1561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // described as Maximized in Ash. 1571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) menu_model_->AddCheckItemWithStringId( 158a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) USE_LAUNCH_TYPE_FULLSCREEN, 1591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) IDS_APP_CONTEXT_MENU_OPEN_MAXIMIZED); 160eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#endif 1611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 16290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); 16390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) menu_model_->AddItemWithStringId(OPTIONS, IDS_NEW_TAB_APP_OPTIONS); 16490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 16590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 16690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) menu_model_->AddItemWithStringId(DETAILS, IDS_NEW_TAB_APP_DETAILS); 16790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) menu_model_->AddItemWithStringId( 16890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) UNINSTALL, 16990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) is_platform_app_ ? IDS_APP_LIST_UNINSTALL_ITEM 17090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) : IDS_EXTENSIONS_UNINSTALL); 17190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 17290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 17390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return menu_model_.get(); 17490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 17590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 17690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)bool AppContextMenu::IsItemForCommandIdDynamic(int command_id) const { 17790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return command_id == TOGGLE_PIN || command_id == LAUNCH_NEW; 17890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 17990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)base::string16 AppContextMenu::GetLabelForCommandId(int command_id) const { 18190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (command_id == TOGGLE_PIN) { 18290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return controller_->IsAppPinned(app_id_) ? 18390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_UNPIN) : 18490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_PIN); 18590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } else if (command_id == LAUNCH_NEW) { 1863240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch#if defined(OS_MACOSX) 1873240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch // Even fullscreen windows launch in a browser tab on Mac. 1883240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch const bool launches_in_tab = true; 1893240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch#else 190a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const bool launches_in_tab = IsCommandIdChecked(USE_LAUNCH_TYPE_PINNED) || 191a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) IsCommandIdChecked(USE_LAUNCH_TYPE_REGULAR); 1923240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch#endif 1933240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch return launches_in_tab ? 1943240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_NEW_TAB) : 1953240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_NEW_WINDOW); 19690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } else { 19790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) NOTREACHED(); 198a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return base::string16(); 19990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 20090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 20190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 20290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)bool AppContextMenu::IsCommandIdChecked(int command_id) const { 203a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (command_id >= USE_LAUNCH_TYPE_COMMAND_START && 204a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) command_id < USE_LAUNCH_TYPE_COMMAND_END) { 2051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return static_cast<int>(controller_->GetExtensionLaunchType( 206a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) profile_, app_id_)) + USE_LAUNCH_TYPE_COMMAND_START == command_id; 20790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } else if (command_id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && 20890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) command_id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { 20990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return extension_menu_items_->IsCommandIdChecked(command_id); 21090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 21190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return false; 21290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 21390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 21490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)bool AppContextMenu::IsCommandIdEnabled(int command_id) const { 21590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (command_id == TOGGLE_PIN) { 2164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) return controller_->GetPinnable() == 2174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AppListControllerDelegate::PIN_EDITABLE; 21890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } else if (command_id == OPTIONS) { 2191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return controller_->HasOptionsPage(profile_, app_id_); 22090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } else if (command_id == UNINSTALL) { 2211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return controller_->UserMayModifySettings(profile_, app_id_); 22290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } else if (command_id == DETAILS) { 2231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return controller_->IsAppFromWebStore(profile_, app_id_); 22490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } else if (command_id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && 22590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) command_id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { 22690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return extension_menu_items_->IsCommandIdEnabled(command_id); 22790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } else if (command_id == MENU_NEW_WINDOW) { 22890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // "Normal" windows are not allowed when incognito is enforced. 22990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) != 23090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) IncognitoModePrefs::FORCED; 23190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } else if (command_id == MENU_NEW_INCOGNITO_WINDOW) { 23290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Incognito windows are not allowed when incognito is disabled. 23390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) != 23490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) IncognitoModePrefs::DISABLED; 23590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 23690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return true; 23790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 23890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 23990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)bool AppContextMenu::GetAcceleratorForCommandId( 24090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) int command_id, 24190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ui::Accelerator* acclelrator) { 24290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return false; 24390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 24490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 24590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)void AppContextMenu::ExecuteCommand(int command_id, int event_flags) { 24690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (command_id == LAUNCH_NEW) { 24790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) delegate_->ExecuteLaunchCommand(event_flags); 2484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } else if (command_id == TOGGLE_PIN && controller_->GetPinnable() == 2494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AppListControllerDelegate::PIN_EDITABLE) { 25090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (controller_->IsAppPinned(app_id_)) 25190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller_->UnpinApp(app_id_); 25290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) else 25390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller_->PinApp(app_id_); 25490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } else if (command_id == CREATE_SHORTCUTS) { 255eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller_->DoCreateShortcutsFlow(profile_, app_id_); 2565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } else if (command_id == SHOW_APP_INFO) { 2575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) controller_->DoShowAppInfoFlow(profile_, app_id_); 258a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } else if (command_id >= USE_LAUNCH_TYPE_COMMAND_START && 259a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) command_id < USE_LAUNCH_TYPE_COMMAND_END) { 260a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) extensions::LaunchType launch_type = static_cast<extensions::LaunchType>( 261a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) command_id - USE_LAUNCH_TYPE_COMMAND_START); 262a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Streamlined hosted apps can only toggle between LAUNCH_TYPE_WINDOW and 263a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // LAUNCH_TYPE_REGULAR. 2641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (CommandLine::ForCurrentProcess()->HasSwitch( 2651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) switches::kEnableStreamlinedHostedApps)) { 266a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) launch_type = (controller_->GetExtensionLaunchType(profile_, app_id_) == 267a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) extensions::LAUNCH_TYPE_REGULAR) ? 268a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) extensions::LAUNCH_TYPE_WINDOW : 269a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) extensions::LAUNCH_TYPE_REGULAR; 2701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 271a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) controller_->SetExtensionLaunchType(profile_, app_id_, launch_type); 27290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } else if (command_id == OPTIONS) { 2731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) controller_->ShowOptionsPage(profile_, app_id_); 27490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } else if (command_id == UNINSTALL) { 2751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) controller_->UninstallApp(profile_, app_id_); 27690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } else if (command_id == DETAILS) { 2771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) controller_->ShowAppInWebStore(profile_, app_id_, is_search_result_); 27890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } else if (command_id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && 27990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) command_id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { 28090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) extension_menu_items_->ExecuteCommand(command_id, NULL, 28190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) content::ContextMenuParams()); 28290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } else if (command_id == MENU_NEW_WINDOW) { 28390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller_->CreateNewWindow(profile_, false); 28490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } else if (command_id == MENU_NEW_INCOGNITO_WINDOW) { 28590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) controller_->CreateNewWindow(profile_, true); 28690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 28790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 28890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 28990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} // namespace app_list 290