Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(324)

Side by Side Diff: chrome/browser/ui/ash/launcher/launcher_controller_helper.cc

Issue 1951523002: Add basic support for launching mash shelf pinned apps. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Only LaunchItem with no windows; otherwise kNoAction (for CreateApplicationMenu). Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" 5 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/extensions/extension_service.h" 11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/extension_util.h" 12 #include "chrome/browser/extensions/extension_util.h"
13 #include "chrome/browser/extensions/launch_util.h" 13 #include "chrome/browser/extensions/launch_util.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/profiles/profile_manager.h" 15 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/browser/ui/browser_finder.h" 16 #include "chrome/browser/ui/browser_finder.h"
17 #include "chrome/browser/ui/extensions/app_launch_params.h"
18 #include "chrome/browser/ui/extensions/application_launch.h"
19 #include "chrome/browser/ui/extensions/extension_enable_flow.h"
17 #include "chrome/browser/web_applications/web_app.h" 20 #include "chrome/browser/web_applications/web_app.h"
18 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 21 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
19 #include "content/public/browser/navigation_entry.h" 22 #include "content/public/browser/navigation_entry.h"
20 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
21 #include "extensions/browser/extension_registry.h" 24 #include "extensions/browser/extension_registry.h"
22 #include "extensions/browser/extension_system.h" 25 #include "extensions/browser/extension_system.h"
23 #include "extensions/common/extension.h" 26 #include "extensions/common/extension.h"
24 #include "extensions/common/extension_set.h" 27 #include "extensions/common/extension_set.h"
28 #include "net/base/url_util.h"
29 #include "ui/events/event_constants.h"
25 30
26 #if defined(OS_CHROMEOS) 31 #if defined(OS_CHROMEOS)
27 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" 32 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
33 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
28 #endif 34 #endif
29 35
30 namespace { 36 namespace {
31 37
32 const extensions::Extension* GetExtensionForTab(Profile* profile, 38 const extensions::Extension* GetExtensionForTab(Profile* profile,
33 content::WebContents* tab) { 39 content::WebContents* tab) {
34 ExtensionService* extension_service = 40 ExtensionService* extension_service =
35 extensions::ExtensionSystem::Get(profile)->extension_service(); 41 extensions::ExtensionSystem::Get(profile)->extension_service();
36 if (!extension_service || !extension_service->extensions_enabled()) 42 if (!extension_service || !extension_service->extensions_enabled())
37 return nullptr; 43 return nullptr;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 } 76 }
71 return nullptr; 77 return nullptr;
72 } 78 }
73 79
74 const extensions::Extension* GetExtensionByID(Profile* profile, 80 const extensions::Extension* GetExtensionByID(Profile* profile,
75 const std::string& id) { 81 const std::string& id) {
76 return extensions::ExtensionRegistry::Get(profile)->GetExtensionById( 82 return extensions::ExtensionRegistry::Get(profile)->GetExtensionById(
77 id, extensions::ExtensionRegistry::EVERYTHING); 83 id, extensions::ExtensionRegistry::EVERYTHING);
78 } 84 }
79 85
86 std::string GetSourceFromAppListSource(ash::LaunchSource source) {
87 switch (source) {
88 case ash::LAUNCH_FROM_APP_LIST:
89 return std::string(extension_urls::kLaunchSourceAppList);
90 case ash::LAUNCH_FROM_APP_LIST_SEARCH:
91 return std::string(extension_urls::kLaunchSourceAppListSearch);
92 default:
93 return std::string();
94 }
95 }
96
80 } // namespace 97 } // namespace
81 98
82 LauncherControllerHelper::LauncherControllerHelper(Profile* profile) 99 LauncherControllerHelper::LauncherControllerHelper(Profile* profile)
83 : profile_(profile) {} 100 : profile_(profile) {}
84 101
85 LauncherControllerHelper::~LauncherControllerHelper() {} 102 LauncherControllerHelper::~LauncherControllerHelper() {}
86 103
87 // static 104 // static
88 base::string16 LauncherControllerHelper::GetAppTitle( 105 base::string16 LauncherControllerHelper::GetAppTitle(
89 Profile* profile, 106 Profile* profile,
90 const std::string& app_id) { 107 const std::string& app_id) {
91 base::string16 title; 108 base::string16 title;
92 if (app_id.empty()) 109 if (app_id.empty())
93 return title; 110 return title;
94 111
95 #if defined(OS_CHROMEOS) 112 #if defined(OS_CHROMEOS)
96 // Get title if the app is an Arc app. 113 // Get title if the app is an Arc app.
97 ArcAppListPrefs* arc_prefs = ArcAppListPrefs::Get(profile); 114 ArcAppListPrefs* arc_prefs = ArcAppListPrefs::Get(profile);
98 DCHECK(arc_prefs); 115 DCHECK(arc_prefs);
99 if (arc_prefs->IsRegistered(app_id)) { 116 if (arc_prefs->IsRegistered(app_id)) {
100 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = 117 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info =
101 arc_prefs->GetApp(app_id); 118 arc_prefs->GetApp(app_id);
102 DCHECK(app_info.get()); 119 DCHECK(app_info.get());
103 if (app_info) 120 if (app_info)
104 title = base::UTF8ToUTF16(app_info->name); 121 title = base::UTF8ToUTF16(app_info->name);
105 return title; 122 return title;
106 } 123 }
107 #endif // defined(OS_CHROMEOS) 124 #endif // defined(OS_CHROMEOS)
108 125
109 const extensions::Extension* extension = 126 const extensions::Extension* extension = GetExtensionByID(profile, app_id);
110 extensions::ExtensionRegistry::Get(profile)->GetExtensionById(
111 app_id, extensions::ExtensionRegistry::EVERYTHING);
112 if (extension) 127 if (extension)
113 title = base::UTF8ToUTF16(extension->name()); 128 title = base::UTF8ToUTF16(extension->name());
114 return title; 129 return title;
115 } 130 }
116 131
117 std::string LauncherControllerHelper::GetAppID(content::WebContents* tab) { 132 std::string LauncherControllerHelper::GetAppID(content::WebContents* tab) {
118 ProfileManager* profile_manager = g_browser_process->profile_manager(); 133 ProfileManager* profile_manager = g_browser_process->profile_manager();
119 if (profile_manager) { 134 if (profile_manager) {
120 const std::vector<Profile*> profile_list = 135 const std::vector<Profile*> profile_list =
121 profile_manager->GetLoadedProfiles(); 136 profile_manager->GetLoadedProfiles();
(...skipping 15 matching lines...) Expand all
137 #if defined(OS_CHROMEOS) 152 #if defined(OS_CHROMEOS)
138 if (ArcAppListPrefs::Get(profile_)->IsRegistered(id)) 153 if (ArcAppListPrefs::Get(profile_)->IsRegistered(id))
139 return true; 154 return true;
140 #endif 155 #endif
141 return GetExtensionByID(profile_, id) != nullptr; 156 return GetExtensionByID(profile_, id) != nullptr;
142 } 157 }
143 158
144 void LauncherControllerHelper::SetCurrentUser(Profile* profile) { 159 void LauncherControllerHelper::SetCurrentUser(Profile* profile) {
145 profile_ = profile; 160 profile_ = profile;
146 } 161 }
162
163 void LauncherControllerHelper::LaunchApp(const std::string& app_id,
164 ash::LaunchSource source,
165 int event_flags) {
166 #if defined(OS_CHROMEOS)
167 if (ArcAppListPrefs::Get(profile_)->IsRegistered(app_id)) {
168 arc::LaunchApp(profile_, app_id);
169 return;
170 }
171 #endif
172
173 // |extension| could be null when it is being unloaded for updating.
174 const extensions::Extension* extension = GetExtensionByID(profile_, app_id);
175 if (!extension)
176 return;
177
178 if (!extensions::util::IsAppLaunchableWithoutEnabling(app_id, profile_)) {
179 // Do nothing if there is already a running enable flow.
180 if (extension_enable_flow_)
181 return;
182
183 extension_enable_flow_.reset(
184 new ExtensionEnableFlow(profile_, app_id, this));
185 extension_enable_flow_->StartForNativeWindow(nullptr);
186 return;
187 }
188
189 // The app will be created for the currently active profile.
190 AppLaunchParams params = CreateAppLaunchParamsWithEventFlags(
191 profile_, extension, event_flags, extensions::SOURCE_APP_LAUNCHER);
192 if (source != ash::LAUNCH_FROM_UNKNOWN &&
193 app_id == extensions::kWebStoreAppId) {
194 // Get the corresponding source string.
195 std::string source_value = GetSourceFromAppListSource(source);
196
197 // Set an override URL to include the source.
198 GURL extension_url = extensions::AppLaunchInfo::GetFullLaunchURL(extension);
199 params.override_url = net::AppendQueryParameter(
200 extension_url, extension_urls::kWebstoreSourceField, source_value);
201 }
202
203 OpenApplication(params);
204 }
205
206 void LauncherControllerHelper::ExtensionEnableFlowFinished() {
207 LaunchApp(extension_enable_flow_->extension_id(), ash::LAUNCH_FROM_UNKNOWN,
208 ui::EF_NONE);
209 extension_enable_flow_.reset();
210 }
211
212 void LauncherControllerHelper::ExtensionEnableFlowAborted(bool user_initiated) {
213 extension_enable_flow_.reset();
214 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/launcher/launcher_controller_helper.h ('k') | mash/shelf/public/interfaces/shelf.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698