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/browser_navigator.h"
14 #include "chrome/browser/ui/extensions/application_launch.h"
15 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
16 #include "extensions/browser/extension_system.h"
17 #include "extensions/common/constants.h"
18 #include "extensions/common/extension.h"
19 #include "net/base/url_util.h"
20 #include "ui/gfx/image/image_skia.h"
22 AppListControllerDelegateImpl::AppListControllerDelegateImpl(
23 AppListService* service)
24 : service_(service) {}
26 AppListControllerDelegateImpl::~AppListControllerDelegateImpl() {}
28 void AppListControllerDelegateImpl::DismissView() {
29 service_->DismissAppList();
32 gfx::NativeWindow AppListControllerDelegateImpl::GetAppListWindow() {
33 return service_->GetAppListWindow();
36 gfx::ImageSkia AppListControllerDelegateImpl::GetWindowIcon() {
37 return gfx::ImageSkia();
40 bool AppListControllerDelegateImpl::IsAppPinned(
41 const std::string& extension_id) {
45 void AppListControllerDelegateImpl::PinApp(const std::string& extension_id) {
49 void AppListControllerDelegateImpl::UnpinApp(const std::string& extension_id) {
53 AppListControllerDelegateImpl::Pinnable
54 AppListControllerDelegateImpl::GetPinnable() {
58 bool AppListControllerDelegateImpl::CanDoCreateShortcutsFlow() {
62 void AppListControllerDelegateImpl::DoCreateShortcutsFlow(
64 const std::string& extension_id) {
65 DCHECK(CanDoCreateShortcutsFlow());
66 ExtensionService* service =
67 extensions::ExtensionSystem::Get(profile)->extension_service();
69 const extensions::Extension* extension = service->GetInstalledExtension(
73 gfx::NativeWindow parent_window = GetAppListWindow();
77 chrome::ShowCreateChromeAppShortcutsDialog(
78 parent_window, profile, extension,
79 base::Bind(&AppListControllerDelegateImpl::OnCloseCreateShortcutsPrompt,
80 base::Unretained(this)));
83 void AppListControllerDelegateImpl::CreateNewWindow(Profile* profile,
85 Profile* window_profile = incognito ?
86 profile->GetOffTheRecordProfile() : profile;
87 chrome::NewEmptyWindow(window_profile, chrome::HOST_DESKTOP_TYPE_NATIVE);
90 void AppListControllerDelegateImpl::OpenURL(Profile* profile,
92 ui::PageTransition transition,
93 WindowOpenDisposition disposition) {
94 chrome::NavigateParams params(profile, url, transition);
95 params.disposition = disposition;
96 chrome::Navigate(¶ms);
99 void AppListControllerDelegateImpl::ActivateApp(
101 const extensions::Extension* extension,
102 AppListSource source,
104 LaunchApp(profile, extension, source, event_flags);
107 void AppListControllerDelegateImpl::LaunchApp(
109 const extensions::Extension* extension,
110 AppListSource source,
112 AppListServiceImpl::RecordAppListAppLaunch();
114 AppLaunchParams params(profile, extension, NEW_FOREGROUND_TAB);
116 if (source != LAUNCH_FROM_UNKNOWN &&
117 extension->id() == extensions::kWebStoreAppId) {
118 // Set an override URL to include the source.
119 GURL extension_url = extensions::AppLaunchInfo::GetFullLaunchURL(extension);
120 params.override_url = net::AppendQueryParameter(
122 extension_urls::kWebstoreSourceField,
123 AppListSourceToString(source));
125 params.source = extensions::SOURCE_APP_LAUNCHER;
127 FillLaunchParams(¶ms);
128 OpenApplication(params);
131 void AppListControllerDelegateImpl::ShowForProfileByPath(
132 const base::FilePath& profile_path) {
133 service_->SetProfilePath(profile_path);
137 bool AppListControllerDelegateImpl::ShouldShowUserIcon() {
138 return g_browser_process->profile_manager()->GetNumberOfProfiles() > 1;
141 void AppListControllerDelegateImpl::FillLaunchParams(AppLaunchParams* params) {}
143 void AppListControllerDelegateImpl::OnCloseCreateShortcutsPrompt(
145 OnCloseChildDialog();