Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / app_list / app_list_controller_delegate_impl.cc
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/extension.h"
17 #include "net/base/url_util.h"
18 #include "ui/gfx/image/image_skia.h"
19
20 AppListControllerDelegateImpl::AppListControllerDelegateImpl(
21     AppListService* service)
22     : service_(service) {}
23
24 AppListControllerDelegateImpl::~AppListControllerDelegateImpl() {}
25
26 void AppListControllerDelegateImpl::DismissView() {
27   service_->DismissAppList();
28 }
29
30 gfx::NativeWindow AppListControllerDelegateImpl::GetAppListWindow() {
31   return service_->GetAppListWindow();
32 }
33
34 gfx::ImageSkia AppListControllerDelegateImpl::GetWindowIcon() {
35   return gfx::ImageSkia();
36 }
37
38 bool AppListControllerDelegateImpl::IsAppPinned(
39     const std::string& extension_id) {
40   return false;
41 }
42
43 void AppListControllerDelegateImpl::PinApp(const std::string& extension_id) {
44   NOTREACHED();
45 }
46
47 void AppListControllerDelegateImpl::UnpinApp(const std::string& extension_id) {
48   NOTREACHED();
49 }
50
51 AppListControllerDelegateImpl::Pinnable
52     AppListControllerDelegateImpl::GetPinnable() {
53   return NO_PIN;
54 }
55
56 bool AppListControllerDelegateImpl::CanDoCreateShortcutsFlow() {
57   return false;
58 }
59
60 void AppListControllerDelegateImpl::DoCreateShortcutsFlow(
61     Profile* profile,
62     const std::string& extension_id) {
63   DCHECK(CanDoCreateShortcutsFlow());
64   ExtensionService* service =
65       extensions::ExtensionSystem::Get(profile)->extension_service();
66   DCHECK(service);
67   const extensions::Extension* extension = service->GetInstalledExtension(
68       extension_id);
69   DCHECK(extension);
70
71   gfx::NativeWindow parent_window = GetAppListWindow();
72   if (!parent_window)
73     return;
74   OnShowExtensionPrompt();
75   chrome::ShowCreateChromeAppShortcutsDialog(
76       parent_window, profile, extension,
77       base::Bind(&AppListControllerDelegateImpl::OnCloseExtensionPrompt,
78                  base::Unretained(this)));
79 }
80
81 void AppListControllerDelegateImpl::CreateNewWindow(Profile* profile,
82                                                    bool incognito) {
83   Profile* window_profile = incognito ?
84       profile->GetOffTheRecordProfile() : profile;
85   chrome::NewEmptyWindow(window_profile, chrome::HOST_DESKTOP_TYPE_NATIVE);
86 }
87
88 void AppListControllerDelegateImpl::ActivateApp(
89     Profile* profile,
90     const extensions::Extension* extension,
91     AppListSource source,
92     int event_flags) {
93   LaunchApp(profile, extension, source, event_flags);
94 }
95
96 void AppListControllerDelegateImpl::LaunchApp(
97     Profile* profile,
98     const extensions::Extension* extension,
99     AppListSource source,
100     int event_flags) {
101   AppListServiceImpl::RecordAppListAppLaunch();
102
103   AppLaunchParams params(profile, extension, NEW_FOREGROUND_TAB);
104
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(
110         extension_url,
111         extension_urls::kWebstoreSourceField,
112         AppListSourceToString(source));
113   }
114
115   FillLaunchParams(&params);
116   OpenApplication(params);
117 }
118
119 void AppListControllerDelegateImpl::ShowForProfileByPath(
120     const base::FilePath& profile_path) {
121   service_->SetProfilePath(profile_path);
122   service_->Show();
123 }
124
125 bool AppListControllerDelegateImpl::ShouldShowUserIcon() {
126   return g_browser_process->profile_manager()->GetNumberOfProfiles() > 1;
127 }
128
129 void AppListControllerDelegateImpl::FillLaunchParams(AppLaunchParams* params) {}