Update To 11.40.268.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/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"
21
22 AppListControllerDelegateImpl::AppListControllerDelegateImpl(
23     AppListService* service)
24     : service_(service) {}
25
26 AppListControllerDelegateImpl::~AppListControllerDelegateImpl() {}
27
28 void AppListControllerDelegateImpl::DismissView() {
29   service_->DismissAppList();
30 }
31
32 gfx::NativeWindow AppListControllerDelegateImpl::GetAppListWindow() {
33   return service_->GetAppListWindow();
34 }
35
36 gfx::ImageSkia AppListControllerDelegateImpl::GetWindowIcon() {
37   return gfx::ImageSkia();
38 }
39
40 bool AppListControllerDelegateImpl::IsAppPinned(
41     const std::string& extension_id) {
42   return false;
43 }
44
45 void AppListControllerDelegateImpl::PinApp(const std::string& extension_id) {
46   NOTREACHED();
47 }
48
49 void AppListControllerDelegateImpl::UnpinApp(const std::string& extension_id) {
50   NOTREACHED();
51 }
52
53 AppListControllerDelegateImpl::Pinnable
54     AppListControllerDelegateImpl::GetPinnable() {
55   return NO_PIN;
56 }
57
58 bool AppListControllerDelegateImpl::CanDoCreateShortcutsFlow() {
59   return false;
60 }
61
62 void AppListControllerDelegateImpl::DoCreateShortcutsFlow(
63     Profile* profile,
64     const std::string& extension_id) {
65   DCHECK(CanDoCreateShortcutsFlow());
66   ExtensionService* service =
67       extensions::ExtensionSystem::Get(profile)->extension_service();
68   DCHECK(service);
69   const extensions::Extension* extension = service->GetInstalledExtension(
70       extension_id);
71   DCHECK(extension);
72
73   gfx::NativeWindow parent_window = GetAppListWindow();
74   if (!parent_window)
75     return;
76   OnShowChildDialog();
77   chrome::ShowCreateChromeAppShortcutsDialog(
78       parent_window, profile, extension,
79       base::Bind(&AppListControllerDelegateImpl::OnCloseCreateShortcutsPrompt,
80                  base::Unretained(this)));
81 }
82
83 void AppListControllerDelegateImpl::CreateNewWindow(Profile* profile,
84                                                    bool incognito) {
85   Profile* window_profile = incognito ?
86       profile->GetOffTheRecordProfile() : profile;
87   chrome::NewEmptyWindow(window_profile, chrome::HOST_DESKTOP_TYPE_NATIVE);
88 }
89
90 void AppListControllerDelegateImpl::OpenURL(Profile* profile,
91                                             const GURL& url,
92                                             ui::PageTransition transition,
93                                             WindowOpenDisposition disposition) {
94   chrome::NavigateParams params(profile, url, transition);
95   params.disposition = disposition;
96   chrome::Navigate(&params);
97 }
98
99 void AppListControllerDelegateImpl::ActivateApp(
100     Profile* profile,
101     const extensions::Extension* extension,
102     AppListSource source,
103     int event_flags) {
104   LaunchApp(profile, extension, source, event_flags);
105 }
106
107 void AppListControllerDelegateImpl::LaunchApp(
108     Profile* profile,
109     const extensions::Extension* extension,
110     AppListSource source,
111     int event_flags) {
112   AppListServiceImpl::RecordAppListAppLaunch();
113
114   AppLaunchParams params(profile, extension, NEW_FOREGROUND_TAB);
115
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(
121         extension_url,
122         extension_urls::kWebstoreSourceField,
123         AppListSourceToString(source));
124   }
125   params.source = extensions::SOURCE_APP_LAUNCHER;
126
127   FillLaunchParams(&params);
128   OpenApplication(params);
129 }
130
131 void AppListControllerDelegateImpl::ShowForProfileByPath(
132     const base::FilePath& profile_path) {
133   service_->SetProfilePath(profile_path);
134   service_->Show();
135 }
136
137 bool AppListControllerDelegateImpl::ShouldShowUserIcon() {
138   return g_browser_process->profile_manager()->GetNumberOfProfiles() > 1;
139 }
140
141 void AppListControllerDelegateImpl::FillLaunchParams(AppLaunchParams* params) {}
142
143 void AppListControllerDelegateImpl::OnCloseCreateShortcutsPrompt(
144     bool created) {
145   OnCloseChildDialog();
146 }