app_list_controller_delegate_win.cc revision 4e180b6a0b4720a9b8e9e959a882386f690f08ff
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/views/app_list/win/app_list_controller_delegate_win.h" 6 7#include "chrome/browser/extensions/extension_service.h" 8#include "chrome/browser/extensions/extension_system.h" 9#include "chrome/browser/ui/app_list/app_list_icon_win.h" 10#include "chrome/browser/ui/browser_commands.h" 11#include "chrome/browser/ui/extensions/application_launch.h" 12#include "chrome/browser/ui/views/app_list/win/app_list_service_win.h" 13#include "chrome/browser/ui/views/browser_dialogs.h" 14#include "chrome/common/extensions/extension.h" 15#include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 16#include "net/base/url_util.h" 17#include "ui/base/resource/resource_bundle.h" 18 19AppListControllerDelegateWin::AppListControllerDelegateWin( 20 AppListServiceWin* service) 21 : service_(service) { 22} 23 24AppListControllerDelegateWin::~AppListControllerDelegateWin() {} 25 26void AppListControllerDelegateWin::DismissView() { 27 service_->DismissAppList(); 28} 29 30void AppListControllerDelegateWin::ViewClosing() { 31 service_->OnAppListClosing(); 32} 33 34gfx::NativeWindow AppListControllerDelegateWin::GetAppListWindow() { 35 return service_->GetAppListWindow(); 36} 37 38gfx::ImageSkia AppListControllerDelegateWin::GetWindowIcon() { 39 gfx::ImageSkia* resource = ResourceBundle::GetSharedInstance(). 40 GetImageSkiaNamed(GetAppListIconResourceId()); 41 return *resource; 42} 43 44AppListControllerDelegate::Pinnable 45 AppListControllerDelegateWin::GetPinnable() { 46 return NO_PIN; 47} 48 49void AppListControllerDelegateWin::ShowForProfileByPath( 50 const base::FilePath& profile_path) { 51 service_->SetProfilePath(profile_path); 52 service_->Show(); 53} 54 55void AppListControllerDelegateWin::OnShowExtensionPrompt() { 56 service_->set_can_close(false); 57} 58 59void AppListControllerDelegateWin::OnCloseExtensionPrompt() { 60 service_->set_can_close(true); 61} 62 63bool AppListControllerDelegateWin::CanDoCreateShortcutsFlow( 64 bool is_platform_app) { 65 return true; 66} 67 68void AppListControllerDelegateWin::DoCreateShortcutsFlow( 69 Profile* profile, 70 const std::string& extension_id) { 71 ExtensionService* service = 72 extensions::ExtensionSystem::Get(profile)->extension_service(); 73 DCHECK(service); 74 const extensions::Extension* extension = service->GetInstalledExtension( 75 extension_id); 76 DCHECK(extension); 77 78 gfx::NativeWindow parent_hwnd = GetAppListWindow(); 79 if (!parent_hwnd) 80 return; 81 OnShowExtensionPrompt(); 82 chrome::ShowCreateChromeAppShortcutsDialog( 83 parent_hwnd, profile, extension, 84 base::Bind(&AppListControllerDelegateWin::OnCloseExtensionPrompt, 85 base::Unretained(this))); 86} 87 88void AppListControllerDelegateWin::CreateNewWindow(Profile* profile, 89 bool incognito) { 90 Profile* window_profile = incognito ? 91 profile->GetOffTheRecordProfile() : profile; 92 chrome::NewEmptyWindow(window_profile, chrome::GetActiveDesktop()); 93} 94 95void AppListControllerDelegateWin::ActivateApp( 96 Profile* profile, 97 const extensions::Extension* extension, 98 AppListSource source, 99 int event_flags) { 100 LaunchApp(profile, extension, source, event_flags); 101} 102 103void AppListControllerDelegateWin::LaunchApp( 104 Profile* profile, 105 const extensions::Extension* extension, 106 AppListSource source, 107 int event_flags) { 108 AppListServiceImpl::RecordAppListAppLaunch(); 109 110 AppLaunchParams params(profile, extension, NEW_FOREGROUND_TAB); 111 112 if (source != LAUNCH_FROM_UNKNOWN && 113 extension->id() == extension_misc::kWebStoreAppId) { 114 // Set an override URL to include the source. 115 GURL extension_url = extensions::AppLaunchInfo::GetFullLaunchURL(extension); 116 params.override_url = net::AppendQueryParameter( 117 extension_url, 118 extension_urls::kWebstoreSourceField, 119 AppListSourceToString(source)); 120 } 121 122 OpenApplication(params); 123} 124 125