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.
5 #include "chrome/browser/ui/app_list/app_list_controller_delegate_impl.h"
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/extension.h"
17 #include "net/base/url_util.h"
18 #include "ui/gfx/image/image_skia.h"
20 AppListControllerDelegateImpl::AppListControllerDelegateImpl(
21 AppListService* service)
22 : service_(service) {}
24 AppListControllerDelegateImpl::~AppListControllerDelegateImpl() {}
26 void AppListControllerDelegateImpl::DismissView() {
27 service_->DismissAppList();
30 gfx::NativeWindow AppListControllerDelegateImpl::GetAppListWindow() {
31 return service_->GetAppListWindow();
34 gfx::ImageSkia AppListControllerDelegateImpl::GetWindowIcon() {
35 return gfx::ImageSkia();
38 bool AppListControllerDelegateImpl::IsAppPinned(
39 const std::string& extension_id) {
43 void AppListControllerDelegateImpl::PinApp(const std::string& extension_id) {
47 void AppListControllerDelegateImpl::UnpinApp(const std::string& extension_id) {
51 AppListControllerDelegateImpl::Pinnable
52 AppListControllerDelegateImpl::GetPinnable() {
56 bool AppListControllerDelegateImpl::CanDoCreateShortcutsFlow() {
60 void AppListControllerDelegateImpl::DoCreateShortcutsFlow(
62 const std::string& extension_id) {
63 DCHECK(CanDoCreateShortcutsFlow());
64 ExtensionService* service =
65 extensions::ExtensionSystem::Get(profile)->extension_service();
67 const extensions::Extension* extension = service->GetInstalledExtension(
71 gfx::NativeWindow parent_window = GetAppListWindow();
74 OnShowExtensionPrompt();
75 chrome::ShowCreateChromeAppShortcutsDialog(
76 parent_window, profile, extension,
77 base::Bind(&AppListControllerDelegateImpl::OnCloseExtensionPrompt,
78 base::Unretained(this)));
81 void AppListControllerDelegateImpl::CreateNewWindow(Profile* profile,
83 Profile* window_profile = incognito ?
84 profile->GetOffTheRecordProfile() : profile;
85 chrome::NewEmptyWindow(window_profile, chrome::HOST_DESKTOP_TYPE_NATIVE);
88 void AppListControllerDelegateImpl::ActivateApp(
90 const extensions::Extension* extension,
93 LaunchApp(profile, extension, source, event_flags);
96 void AppListControllerDelegateImpl::LaunchApp(
98 const extensions::Extension* extension,
101 AppListServiceImpl::RecordAppListAppLaunch();
103 AppLaunchParams params(profile, extension, NEW_FOREGROUND_TAB);
105 if (source != LAUNCH_FROM_UNKNOWN &&
106 extension->id() == extension_misc::kWebStoreAppId) {
107 // Set an override URL to include the source.
108 GURL extension_url = extensions::AppLaunchInfo::GetFullLaunchURL(extension);
109 params.override_url = net::AppendQueryParameter(
111 extension_urls::kWebstoreSourceField,
112 AppListSourceToString(source));
115 FillLaunchParams(¶ms);
116 OpenApplication(params);
119 void AppListControllerDelegateImpl::ShowForProfileByPath(
120 const base::FilePath& profile_path) {
121 service_->SetProfilePath(profile_path);
125 bool AppListControllerDelegateImpl::ShouldShowUserIcon() {
126 return g_browser_process->profile_manager()->GetNumberOfProfiles() > 1;
129 void AppListControllerDelegateImpl::FillLaunchParams(AppLaunchParams* params) {}