1// Copyright 2013 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chrome/browser/ui/app_list/app_list_controller_delegate_impl.h" 6 7#include "chrome/browser/browser_process.h" 8#include "chrome/browser/extensions/extension_service.h" 9#include "chrome/browser/profiles/profile_manager.h" 10#include "chrome/browser/ui/app_list/app_list_service_impl.h" 11#include "chrome/browser/ui/browser_commands.h" 12#include "chrome/browser/ui/browser_dialogs.h" 13#include "chrome/browser/ui/extensions/application_launch.h" 14#include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 15#include "extensions/browser/extension_system.h" 16#include "extensions/common/constants.h" 17#include "extensions/common/extension.h" 18#include "net/base/url_util.h" 19#include "ui/gfx/image/image_skia.h" 20 21AppListControllerDelegateImpl::AppListControllerDelegateImpl( 22 AppListService* service) 23 : service_(service) {} 24 25AppListControllerDelegateImpl::~AppListControllerDelegateImpl() {} 26 27void AppListControllerDelegateImpl::DismissView() { 28 service_->DismissAppList(); 29} 30 31gfx::NativeWindow AppListControllerDelegateImpl::GetAppListWindow() { 32 return service_->GetAppListWindow(); 33} 34 35gfx::ImageSkia AppListControllerDelegateImpl::GetWindowIcon() { 36 return gfx::ImageSkia(); 37} 38 39bool AppListControllerDelegateImpl::IsAppPinned( 40 const std::string& extension_id) { 41 return false; 42} 43 44void AppListControllerDelegateImpl::PinApp(const std::string& extension_id) { 45 NOTREACHED(); 46} 47 48void AppListControllerDelegateImpl::UnpinApp(const std::string& extension_id) { 49 NOTREACHED(); 50} 51 52AppListControllerDelegateImpl::Pinnable 53 AppListControllerDelegateImpl::GetPinnable() { 54 return NO_PIN; 55} 56 57bool AppListControllerDelegateImpl::CanDoCreateShortcutsFlow() { 58 return false; 59} 60 61void AppListControllerDelegateImpl::DoCreateShortcutsFlow( 62 Profile* profile, 63 const std::string& extension_id) { 64 DCHECK(CanDoCreateShortcutsFlow()); 65 ExtensionService* service = 66 extensions::ExtensionSystem::Get(profile)->extension_service(); 67 DCHECK(service); 68 const extensions::Extension* extension = service->GetInstalledExtension( 69 extension_id); 70 DCHECK(extension); 71 72 gfx::NativeWindow parent_window = GetAppListWindow(); 73 if (!parent_window) 74 return; 75 OnShowChildDialog(); 76 chrome::ShowCreateChromeAppShortcutsDialog( 77 parent_window, profile, extension, 78 base::Bind(&AppListControllerDelegateImpl::OnCloseCreateShortcutsPrompt, 79 base::Unretained(this))); 80} 81 82void AppListControllerDelegateImpl::CreateNewWindow(Profile* profile, 83 bool incognito) { 84 Profile* window_profile = incognito ? 85 profile->GetOffTheRecordProfile() : profile; 86 chrome::NewEmptyWindow(window_profile, chrome::HOST_DESKTOP_TYPE_NATIVE); 87} 88 89void AppListControllerDelegateImpl::ActivateApp( 90 Profile* profile, 91 const extensions::Extension* extension, 92 AppListSource source, 93 int event_flags) { 94 LaunchApp(profile, extension, source, event_flags); 95} 96 97void AppListControllerDelegateImpl::LaunchApp( 98 Profile* profile, 99 const extensions::Extension* extension, 100 AppListSource source, 101 int event_flags) { 102 AppListServiceImpl::RecordAppListAppLaunch(); 103 104 AppLaunchParams params(profile, extension, NEW_FOREGROUND_TAB); 105 106 if (source != LAUNCH_FROM_UNKNOWN && 107 extension->id() == extensions::kWebStoreAppId) { 108 // Set an override URL to include the source. 109 GURL extension_url = extensions::AppLaunchInfo::GetFullLaunchURL(extension); 110 params.override_url = net::AppendQueryParameter( 111 extension_url, 112 extension_urls::kWebstoreSourceField, 113 AppListSourceToString(source)); 114 } 115 116 FillLaunchParams(¶ms); 117 OpenApplication(params); 118} 119 120void AppListControllerDelegateImpl::ShowForProfileByPath( 121 const base::FilePath& profile_path) { 122 service_->SetProfilePath(profile_path); 123 service_->Show(); 124} 125 126bool AppListControllerDelegateImpl::ShouldShowUserIcon() { 127 return g_browser_process->profile_manager()->GetNumberOfProfiles() > 1; 128} 129 130void AppListControllerDelegateImpl::FillLaunchParams(AppLaunchParams* params) {} 131 132void AppListControllerDelegateImpl::OnCloseCreateShortcutsPrompt( 133 bool created) { 134 OnCloseChildDialog(); 135} 136