11e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 21e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 31e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// found in the LICENSE file. 41e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 51e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/ui/app_list/app_list_controller_delegate_impl.h" 61e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 71e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/browser_process.h" 81e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/extensions/extension_service.h" 91e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/profiles/profile_manager.h" 101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/ui/app_list/app_list_service_impl.h" 111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/ui/browser_commands.h" 121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/ui/browser_dialogs.h" 131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/ui/extensions/application_launch.h" 141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "extensions/browser/extension_system.h" 161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "extensions/common/constants.h" 17f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "extensions/common/extension.h" 181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "net/base/url_util.h" 191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ui/gfx/image/image_skia.h" 201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)AppListControllerDelegateImpl::AppListControllerDelegateImpl( 221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) AppListService* service) 231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) : service_(service) {} 241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)AppListControllerDelegateImpl::~AppListControllerDelegateImpl() {} 261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void AppListControllerDelegateImpl::DismissView() { 281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) service_->DismissAppList(); 291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)gfx::NativeWindow AppListControllerDelegateImpl::GetAppListWindow() { 321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return service_->GetAppListWindow(); 331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)gfx::ImageSkia AppListControllerDelegateImpl::GetWindowIcon() { 361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return gfx::ImageSkia(); 371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)bool AppListControllerDelegateImpl::IsAppPinned( 401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const std::string& extension_id) { 411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return false; 421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void AppListControllerDelegateImpl::PinApp(const std::string& extension_id) { 451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) NOTREACHED(); 461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void AppListControllerDelegateImpl::UnpinApp(const std::string& extension_id) { 491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) NOTREACHED(); 501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)AppListControllerDelegateImpl::Pinnable 531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) AppListControllerDelegateImpl::GetPinnable() { 541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return NO_PIN; 551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)bool AppListControllerDelegateImpl::CanDoCreateShortcutsFlow() { 581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return false; 591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void AppListControllerDelegateImpl::DoCreateShortcutsFlow( 621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Profile* profile, 631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const std::string& extension_id) { 641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DCHECK(CanDoCreateShortcutsFlow()); 651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ExtensionService* service = 661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) extensions::ExtensionSystem::Get(profile)->extension_service(); 671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DCHECK(service); 681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const extensions::Extension* extension = service->GetInstalledExtension( 691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) extension_id); 701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DCHECK(extension); 711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) gfx::NativeWindow parent_window = GetAppListWindow(); 731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (!parent_window) 741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return; 75cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) OnShowChildDialog(); 761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) chrome::ShowCreateChromeAppShortcutsDialog( 771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) parent_window, profile, extension, 78010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) base::Bind(&AppListControllerDelegateImpl::OnCloseCreateShortcutsPrompt, 791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) base::Unretained(this))); 801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void AppListControllerDelegateImpl::CreateNewWindow(Profile* profile, 831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) bool incognito) { 841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Profile* window_profile = incognito ? 851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) profile->GetOffTheRecordProfile() : profile; 861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) chrome::NewEmptyWindow(window_profile, chrome::HOST_DESKTOP_TYPE_NATIVE); 871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void AppListControllerDelegateImpl::ActivateApp( 901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Profile* profile, 911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const extensions::Extension* extension, 921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) AppListSource source, 931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) int event_flags) { 941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) LaunchApp(profile, extension, source, event_flags); 951e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void AppListControllerDelegateImpl::LaunchApp( 981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Profile* profile, 991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const extensions::Extension* extension, 1001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) AppListSource source, 1011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) int event_flags) { 1021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) AppListServiceImpl::RecordAppListAppLaunch(); 1031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) AppLaunchParams params(profile, extension, NEW_FOREGROUND_TAB); 1051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (source != LAUNCH_FROM_UNKNOWN && 1071320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci extension->id() == extensions::kWebStoreAppId) { 1081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Set an override URL to include the source. 1091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) GURL extension_url = extensions::AppLaunchInfo::GetFullLaunchURL(extension); 1101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) params.override_url = net::AppendQueryParameter( 1111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) extension_url, 1121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) extension_urls::kWebstoreSourceField, 1131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) AppListSourceToString(source)); 1141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 1151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 116f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) FillLaunchParams(¶ms); 1171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) OpenApplication(params); 1181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 1191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void AppListControllerDelegateImpl::ShowForProfileByPath( 1211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const base::FilePath& profile_path) { 1221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) service_->SetProfilePath(profile_path); 1231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) service_->Show(); 1241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 1251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)bool AppListControllerDelegateImpl::ShouldShowUserIcon() { 1271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return g_browser_process->profile_manager()->GetNumberOfProfiles() > 1; 1281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 129f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 130f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void AppListControllerDelegateImpl::FillLaunchParams(AppLaunchParams* params) {} 131010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 132010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)void AppListControllerDelegateImpl::OnCloseCreateShortcutsPrompt( 133010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) bool created) { 134cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) OnCloseChildDialog(); 135010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)} 136