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/constants.h"
17 #include "extensions/common/extension.h"
18 #include "net/base/url_util.h"
19 #include "ui/gfx/image/image_skia.h"
21 AppListControllerDelegateImpl::AppListControllerDelegateImpl(
22 AppListService* service)
23 : service_(service) {}
25 AppListControllerDelegateImpl::~AppListControllerDelegateImpl() {}
27 void AppListControllerDelegateImpl::DismissView() {
28 service_->DismissAppList();
31 gfx::NativeWindow AppListControllerDelegateImpl::GetAppListWindow() {
32 return service_->GetAppListWindow();
35 gfx::ImageSkia AppListControllerDelegateImpl::GetWindowIcon() {
36 return gfx::ImageSkia();
39 bool AppListControllerDelegateImpl::IsAppPinned(
40 const std::string& extension_id) {
44 void AppListControllerDelegateImpl::PinApp(const std::string& extension_id) {
48 void AppListControllerDelegateImpl::UnpinApp(const std::string& extension_id) {
52 AppListControllerDelegateImpl::Pinnable
53 AppListControllerDelegateImpl::GetPinnable() {
57 bool AppListControllerDelegateImpl::CanDoCreateShortcutsFlow() {
61 void AppListControllerDelegateImpl::DoCreateShortcutsFlow(
63 const std::string& extension_id) {
64 DCHECK(CanDoCreateShortcutsFlow());
65 ExtensionService* service =
66 extensions::ExtensionSystem::Get(profile)->extension_service();
68 const extensions::Extension* extension = service->GetInstalledExtension(
72 gfx::NativeWindow parent_window = GetAppListWindow();
76 chrome::ShowCreateChromeAppShortcutsDialog(
77 parent_window, profile, extension,
78 base::Bind(&AppListControllerDelegateImpl::OnCloseCreateShortcutsPrompt,
79 base::Unretained(this)));
82 void AppListControllerDelegateImpl::CreateNewWindow(Profile* profile,
84 Profile* window_profile = incognito ?
85 profile->GetOffTheRecordProfile() : profile;
86 chrome::NewEmptyWindow(window_profile, chrome::HOST_DESKTOP_TYPE_NATIVE);
89 void AppListControllerDelegateImpl::ActivateApp(
91 const extensions::Extension* extension,
94 LaunchApp(profile, extension, source, event_flags);
97 void AppListControllerDelegateImpl::LaunchApp(
99 const extensions::Extension* extension,
100 AppListSource source,
102 AppListServiceImpl::RecordAppListAppLaunch();
104 AppLaunchParams params(profile, extension, NEW_FOREGROUND_TAB);
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(
112 extension_urls::kWebstoreSourceField,
113 AppListSourceToString(source));
116 FillLaunchParams(¶ms);
117 OpenApplication(params);
120 void AppListControllerDelegateImpl::ShowForProfileByPath(
121 const base::FilePath& profile_path) {
122 service_->SetProfilePath(profile_path);
126 bool AppListControllerDelegateImpl::ShouldShowUserIcon() {
127 return g_browser_process->profile_manager()->GetNumberOfProfiles() > 1;
130 void AppListControllerDelegateImpl::FillLaunchParams(AppLaunchParams* params) {}
132 void AppListControllerDelegateImpl::OnCloseCreateShortcutsPrompt(
134 OnCloseChildDialog();