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

Side by Side Diff: chrome/browser/ui/extensions/application_launch.cc

Issue 635233008: Make management.launchApp() work for hosted apps on Athena (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webstore_dialogs_athena
Patch Set: Created 6 years, 2 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/extensions/application_launch.h" 5 #include "chrome/browser/ui/extensions/application_launch.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "apps/launcher.h" 9 #include "apps/launcher.h"
10 #include "base/command_line.h"
11 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/browser/app_mode/app_mode_utils.h"
14 #include "chrome/browser/apps/per_app_settings_service.h" 11 #include "chrome/browser/apps/per_app_settings_service.h"
15 #include "chrome/browser/apps/per_app_settings_service_factory.h" 12 #include "chrome/browser/apps/per_app_settings_service_factory.h"
16 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
17 #include "chrome/browser/extensions/launch_util.h"
18 #include "chrome/browser/extensions/tab_helper.h" 14 #include "chrome/browser/extensions/tab_helper.h"
19 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/app_list/app_list_service.h" 16 #include "chrome/browser/ui/app_list/app_list_service.h"
21 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/extensions/app_launch_params.h"
22 #include "chrome/browser/ui/browser_commands.h" 18 #include "chrome/browser/ui/extensions/application_launch_web_app.h"
23 #include "chrome/browser/ui/browser_finder.h"
24 #include "chrome/browser/ui/browser_tabstrip.h"
25 #include "chrome/browser/ui/browser_window.h"
26 #include "chrome/browser/ui/extensions/extension_enable_flow.h" 19 #include "chrome/browser/ui/extensions/extension_enable_flow.h"
27 #include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h" 20 #include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h"
28 #include "chrome/browser/ui/tabs/tab_strip_model.h"
29 #include "chrome/browser/web_applications/web_app.h"
30 #include "chrome/common/chrome_switches.h"
31 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 21 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
32 #include "chrome/common/url_constants.h" 22 #include "chrome/common/url_constants.h"
33 #include "content/public/browser/render_view_host.h"
34 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
35 #include "content/public/common/renderer_preferences.h"
36 #include "extensions/browser/extension_prefs.h" 24 #include "extensions/browser/extension_prefs.h"
37 #include "extensions/browser/extension_registry.h" 25 #include "extensions/browser/extension_registry.h"
38 #include "extensions/browser/extension_system.h" 26 #include "extensions/browser/extension_system.h"
39 #include "extensions/common/constants.h"
40 #include "extensions/common/extension.h" 27 #include "extensions/common/extension.h"
41 #include "extensions/common/features/feature.h" 28 #include "extensions/common/features/feature.h"
42 #include "extensions/common/features/feature_provider.h" 29 #include "extensions/common/features/feature_provider.h"
43 #include "extensions/common/manifest_handlers/options_page_info.h" 30 #include "extensions/common/manifest_handlers/options_page_info.h"
44 #include "ui/base/window_open_disposition.h"
45 #include "ui/gfx/rect.h"
46
47 #if defined(OS_MACOSX)
48 #include "chrome/browser/ui/browser_commands_mac.h"
49 #endif
50 31
51 using content::WebContents; 32 using content::WebContents;
52 using extensions::Extension; 33 using extensions::Extension;
53 using extensions::ExtensionPrefs; 34 using extensions::ExtensionPrefs;
54 using extensions::ExtensionRegistry; 35 using extensions::ExtensionRegistry;
55 36
56 namespace { 37 namespace {
57 38
58 // Attempts to launch a packaged app, prompting the user to enable it if 39 #if !defined(USE_ATHENA)
59 // necessary. If a prompt is required it will be shown inside the AppList. 40 // Shows the app list for |desktop_type| and returns the app list's window.
41 gfx::NativeWindow ShowAppListAndGetNativeWindow(
42 chrome::HostDesktopType desktop_type) {
43 AppListService* app_list_service = AppListService::Get(desktop_type);
44 app_list_service->Show();
45 return app_list_service->GetAppListWindow();
46 }
47 #endif
48
49 // Attempts to launch an app, prompting the user to enable it if necessary. If
50 // a prompt is required it will be shown inside the window returned by
51 // |parent_window_getter|.
60 // This class manages its own lifetime. 52 // This class manages its own lifetime.
61 class EnableViaAppListFlow : public ExtensionEnableFlowDelegate { 53 class EnableViaDialogFlow : public ExtensionEnableFlowDelegate {
62 public: 54 public:
63 EnableViaAppListFlow(ExtensionService* service, 55 EnableViaDialogFlow(
64 Profile* profile, 56 ExtensionService* service,
65 chrome::HostDesktopType desktop_type, 57 Profile* profile,
66 const std::string& extension_id, 58 const std::string& extension_id,
67 const base::Closure& callback) 59 const base::Callback<gfx::NativeWindow(void)>& parent_window_getter,
60 const base::Closure& callback)
68 : service_(service), 61 : service_(service),
69 profile_(profile), 62 profile_(profile),
70 desktop_type_(desktop_type),
71 extension_id_(extension_id), 63 extension_id_(extension_id),
64 parent_window_getter_(parent_window_getter),
72 callback_(callback) { 65 callback_(callback) {
73 } 66 }
74 67
75 ~EnableViaAppListFlow() override {} 68 ~EnableViaDialogFlow() override {}
76 69
77 void Run() { 70 void Run() {
78 DCHECK(!service_->IsExtensionEnabled(extension_id_)); 71 DCHECK(!service_->IsExtensionEnabled(extension_id_));
79 flow_.reset(new ExtensionEnableFlow(profile_, extension_id_, this)); 72 flow_.reset(new ExtensionEnableFlow(profile_, extension_id_, this));
80 flow_->StartForCurrentlyNonexistentWindow( 73 flow_->StartForCurrentlyNonexistentWindow(parent_window_getter_);
81 base::Bind(&EnableViaAppListFlow::ShowAppList, base::Unretained(this)));
82 } 74 }
83 75
84 private: 76 private:
85 gfx::NativeWindow ShowAppList() {
86 AppListService* app_list_service = AppListService::Get(desktop_type_);
87 app_list_service->Show();
88 return app_list_service->GetAppListWindow();
89 }
90
91 // ExtensionEnableFlowDelegate overrides. 77 // ExtensionEnableFlowDelegate overrides.
92 void ExtensionEnableFlowFinished() override { 78 void ExtensionEnableFlowFinished() override {
93 const Extension* extension = 79 const Extension* extension =
94 service_->GetExtensionById(extension_id_, false); 80 service_->GetExtensionById(extension_id_, false);
95 if (!extension) 81 if (!extension)
96 return; 82 return;
97 callback_.Run(); 83 callback_.Run();
98 delete this; 84 delete this;
99 } 85 }
100 86
101 void ExtensionEnableFlowAborted(bool user_initiated) override { delete this; } 87 void ExtensionEnableFlowAborted(bool user_initiated) override { delete this; }
102 88
103 ExtensionService* service_; 89 ExtensionService* service_;
104 Profile* profile_; 90 Profile* profile_;
105 chrome::HostDesktopType desktop_type_;
106 std::string extension_id_; 91 std::string extension_id_;
92 base::Callback<gfx::NativeWindow(void)> parent_window_getter_;
107 base::Closure callback_; 93 base::Closure callback_;
108 scoped_ptr<ExtensionEnableFlow> flow_; 94 scoped_ptr<ExtensionEnableFlow> flow_;
109 95
110 DISALLOW_COPY_AND_ASSIGN(EnableViaAppListFlow); 96 DISALLOW_COPY_AND_ASSIGN(EnableViaDialogFlow);
111 }; 97 };
112 98
113 const Extension* GetExtension(const AppLaunchParams& params) { 99 const Extension* GetExtension(const AppLaunchParams& params) {
114 if (params.extension_id.empty()) 100 if (params.extension_id.empty())
115 return NULL; 101 return NULL;
116 ExtensionRegistry* registry = ExtensionRegistry::Get(params.profile); 102 ExtensionRegistry* registry = ExtensionRegistry::Get(params.profile);
117 return registry->GetExtensionById(params.extension_id, 103 return registry->GetExtensionById(params.extension_id,
118 ExtensionRegistry::ENABLED | 104 ExtensionRegistry::ENABLED |
119 ExtensionRegistry::DISABLED | 105 ExtensionRegistry::DISABLED |
120 ExtensionRegistry::TERMINATED); 106 ExtensionRegistry::TERMINATED);
121 } 107 }
122 108
123 ui::WindowShowState DetermineWindowShowState( 109 // Get the launch URL for a given extension, with optional override/fallback.
124 Profile* profile, 110 // |override_url|, if non-empty, will be preferred over the extension's
125 extensions::LaunchContainer container, 111 // launch url.
126 const Extension* extension) { 112 GURL UrlForExtension(const extensions::Extension* extension,
127 if (!extension || container != extensions::LAUNCH_CONTAINER_WINDOW) 113 const GURL& override_url) {
128 return ui::SHOW_STATE_DEFAULT; 114 if (!extension)
115 return override_url;
129 116
130 if (chrome::IsRunningInForcedAppMode()) 117 GURL url;
131 return ui::SHOW_STATE_FULLSCREEN; 118 if (!override_url.is_empty()) {
132 119 DCHECK(extension->web_extent().MatchesURL(override_url) ||
133 #if defined(USE_ASH) 120 override_url.GetOrigin() == extension->url());
134 // In ash, LAUNCH_TYPE_FULLSCREEN launches in a maximized app window and 121 url = override_url;
135 // LAUNCH_TYPE_WINDOW launches in a normal app window. 122 } else {
136 extensions::LaunchType launch_type = 123 url = extensions::AppLaunchInfo::GetFullLaunchURL(extension);
137 extensions::GetLaunchType(ExtensionPrefs::Get(profile), extension);
138 if (launch_type == extensions::LAUNCH_TYPE_FULLSCREEN)
139 return ui::SHOW_STATE_MAXIMIZED;
140 else if (launch_type == extensions::LAUNCH_TYPE_WINDOW)
141 return ui::SHOW_STATE_NORMAL;
142 #endif
143
144 return ui::SHOW_STATE_DEFAULT;
145 }
146
147 WebContents* OpenApplicationWindow(const AppLaunchParams& params) {
148 Profile* const profile = params.profile;
149 const Extension* const extension = GetExtension(params);
150 const GURL url_input = params.override_url;
151
152 DCHECK(!url_input.is_empty() || extension);
153 GURL url = UrlForExtension(extension, url_input);
154 std::string app_name = extension ?
155 web_app::GenerateApplicationNameFromExtensionId(extension->id()) :
156 web_app::GenerateApplicationNameFromURL(url);
157
158 gfx::Rect initial_bounds;
159 if (!params.override_bounds.IsEmpty()) {
160 initial_bounds = params.override_bounds;
161 } else if (extension) {
162 initial_bounds.set_width(
163 extensions::AppLaunchInfo::GetLaunchWidth(extension));
164 initial_bounds.set_height(
165 extensions::AppLaunchInfo::GetLaunchHeight(extension));
166 } 124 }
167 125
168 Browser::CreateParams browser_params( 126 // For extensions lacking launch urls, determine a reasonable fallback.
169 Browser::CreateParams::CreateForApp(app_name, 127 if (!url.is_valid()) {
170 true /* trusted_source */, 128 url = extensions::OptionsPageInfo::GetOptionsPage(extension);
171 initial_bounds, 129 if (!url.is_valid())
172 profile, 130 url = GURL(chrome::kChromeUIExtensionsURL);
173 params.desktop_type));
174
175 browser_params.initial_show_state = DetermineWindowShowState(profile,
176 params.container,
177 extension);
178
179 Browser* browser = new Browser(browser_params);
180
181 WebContents* web_contents = chrome::AddSelectedTabWithURL(
182 browser, url, ui::PAGE_TRANSITION_AUTO_TOPLEVEL);
183 web_contents->GetMutableRendererPrefs()->can_accept_load_drops = false;
184 web_contents->GetRenderViewHost()->SyncRendererPrefs();
185
186 browser->window()->Show();
187
188 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial
189 // focus explicitly.
190 web_contents->SetInitialFocus();
191 return web_contents;
192 }
193
194 WebContents* OpenApplicationTab(const AppLaunchParams& launch_params) {
195 const Extension* extension = GetExtension(launch_params);
196 CHECK(extension);
197 Profile* const profile = launch_params.profile;
198 WindowOpenDisposition disposition = launch_params.disposition;
199
200 Browser* browser = chrome::FindTabbedBrowser(profile,
201 false,
202 launch_params.desktop_type);
203 WebContents* contents = NULL;
204 if (!browser) {
205 // No browser for this profile, need to open a new one.
206 browser = new Browser(Browser::CreateParams(Browser::TYPE_TABBED,
207 profile,
208 launch_params.desktop_type));
209 browser->window()->Show();
210 // There's no current tab in this browser window, so add a new one.
211 disposition = NEW_FOREGROUND_TAB;
212 } else {
213 // For existing browser, ensure its window is shown and activated.
214 browser->window()->Show();
215 browser->window()->Activate();
216 } 131 }
217 132
218 extensions::LaunchType launch_type = 133 return url;
219 extensions::GetLaunchType(ExtensionPrefs::Get(profile), extension);
220 UMA_HISTOGRAM_ENUMERATION("Extensions.AppTabLaunchType", launch_type, 100);
221
222 int add_type = TabStripModel::ADD_ACTIVE;
223 if (launch_type == extensions::LAUNCH_TYPE_PINNED)
224 add_type |= TabStripModel::ADD_PINNED;
225
226 GURL extension_url = UrlForExtension(extension, launch_params.override_url);
227 chrome::NavigateParams params(browser, extension_url,
228 ui::PAGE_TRANSITION_AUTO_TOPLEVEL);
229 params.tabstrip_add_types = add_type;
230 params.disposition = disposition;
231
232 if (disposition == CURRENT_TAB) {
233 WebContents* existing_tab =
234 browser->tab_strip_model()->GetActiveWebContents();
235 TabStripModel* model = browser->tab_strip_model();
236 int tab_index = model->GetIndexOfWebContents(existing_tab);
237
238 existing_tab->OpenURL(content::OpenURLParams(
239 extension_url,
240 content::Referrer(existing_tab->GetURL(),
241 blink::WebReferrerPolicyDefault),
242 disposition, ui::PAGE_TRANSITION_LINK, false));
243 // Reset existing_tab as OpenURL() may have clobbered it.
244 existing_tab = browser->tab_strip_model()->GetActiveWebContents();
245 if (params.tabstrip_add_types & TabStripModel::ADD_PINNED) {
246 model->SetTabPinned(tab_index, true);
247 // Pinning may have moved the tab.
248 tab_index = model->GetIndexOfWebContents(existing_tab);
249 }
250 if (params.tabstrip_add_types & TabStripModel::ADD_ACTIVE)
251 model->ActivateTabAt(tab_index, true);
252
253 contents = existing_tab;
254 } else {
255 chrome::Navigate(&params);
256 contents = params.target_contents;
257 }
258
259 // On Chrome OS the host desktop type for a browser window is always set to
260 // HOST_DESKTOP_TYPE_ASH. On Windows 8 it is only the case for Chrome ASH
261 // in metro mode.
262 if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) {
263 // In ash, LAUNCH_FULLSCREEN launches in the OpenApplicationWindow function
264 // i.e. it should not reach here.
265 DCHECK(launch_type != extensions::LAUNCH_TYPE_FULLSCREEN);
266 } else {
267 // TODO(skerner): If we are already in full screen mode, and the user
268 // set the app to open as a regular or pinned tab, what should happen?
269 // Today we open the tab, but stay in full screen mode. Should we leave
270 // full screen mode in this case?
271 if (launch_type == extensions::LAUNCH_TYPE_FULLSCREEN &&
272 !browser->window()->IsFullscreen()) {
273 #if defined(OS_MACOSX)
274 chrome::ToggleFullscreenWithChromeOrFallback(browser);
275 #else
276 chrome::ToggleFullscreenMode(browser);
277 #endif
278 }
279 }
280 return contents;
281 } 134 }
282 135
283 WebContents* OpenEnabledApplication(const AppLaunchParams& params) { 136 WebContents* OpenEnabledApplication(const AppLaunchParams& params) {
284 const Extension* extension = GetExtension(params); 137 const Extension* extension = GetExtension(params);
285 if (!extension) 138 if (!extension)
286 return NULL; 139 return NULL;
287 Profile* profile = params.profile; 140 Profile* profile = params.profile;
288 141
289 WebContents* tab = NULL; 142 WebContents* tab = NULL;
290 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile); 143 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile);
(...skipping 10 matching lines...) Expand all
301 154
302 apps::LaunchPlatformAppWithCommandLine( 155 apps::LaunchPlatformAppWithCommandLine(
303 profile, extension, params.command_line, params.current_directory); 156 profile, extension, params.command_line, params.current_directory);
304 return NULL; 157 return NULL;
305 } 158 }
306 159
307 // Record v1 app launch. Platform app launch is recorded when dispatching 160 // Record v1 app launch. Platform app launch is recorded when dispatching
308 // the onLaunched event. 161 // the onLaunched event.
309 prefs->SetLastLaunchTime(extension->id(), base::Time::Now()); 162 prefs->SetLastLaunchTime(extension->id(), base::Time::Now());
310 163
164 GURL url = UrlForExtension(extension, params.override_url);
311 switch (params.container) { 165 switch (params.container) {
312 case extensions::LAUNCH_CONTAINER_NONE: { 166 case extensions::LAUNCH_CONTAINER_NONE: {
313 NOTREACHED(); 167 NOTREACHED();
314 break; 168 break;
315 } 169 }
316 case extensions::LAUNCH_CONTAINER_PANEL: 170 case extensions::LAUNCH_CONTAINER_PANEL:
317 case extensions::LAUNCH_CONTAINER_WINDOW: 171 case extensions::LAUNCH_CONTAINER_WINDOW:
318 tab = OpenApplicationWindow(params); 172 tab = OpenWebAppWindow(params, url);
319 break; 173 break;
320 case extensions::LAUNCH_CONTAINER_TAB: { 174 case extensions::LAUNCH_CONTAINER_TAB: {
321 tab = OpenApplicationTab(params); 175 tab = OpenWebAppTab(params, url);
322 break; 176 break;
323 } 177 }
324 default: 178 default:
325 NOTREACHED(); 179 NOTREACHED();
326 break; 180 break;
327 } 181 }
328 return tab; 182 return tab;
329 } 183 }
330 184
331 } // namespace 185 } // namespace
332 186
333 AppLaunchParams::AppLaunchParams(Profile* profile,
334 const extensions::Extension* extension,
335 extensions::LaunchContainer container,
336 WindowOpenDisposition disposition)
337 : profile(profile),
338 extension_id(extension ? extension->id() : std::string()),
339 container(container),
340 disposition(disposition),
341 desktop_type(chrome::GetActiveDesktop()),
342 override_url(),
343 override_bounds(),
344 command_line(CommandLine::NO_PROGRAM) {}
345
346 AppLaunchParams::AppLaunchParams(Profile* profile,
347 const extensions::Extension* extension,
348 WindowOpenDisposition disposition)
349 : profile(profile),
350 extension_id(extension ? extension->id() : std::string()),
351 container(extensions::LAUNCH_CONTAINER_NONE),
352 disposition(disposition),
353 desktop_type(chrome::GetActiveDesktop()),
354 override_url(),
355 override_bounds(),
356 command_line(CommandLine::NO_PROGRAM) {
357 // Look up the app preference to find out the right launch container. Default
358 // is to launch as a regular tab.
359 container =
360 extensions::GetLaunchContainer(ExtensionPrefs::Get(profile), extension);
361 }
362
363 AppLaunchParams::AppLaunchParams(Profile* profile,
364 const extensions::Extension* extension,
365 int event_flags,
366 chrome::HostDesktopType desktop_type)
367 : profile(profile),
368 extension_id(extension ? extension->id() : std::string()),
369 container(extensions::LAUNCH_CONTAINER_NONE),
370 disposition(ui::DispositionFromEventFlags(event_flags)),
371 desktop_type(desktop_type),
372 override_url(),
373 override_bounds(),
374 command_line(CommandLine::NO_PROGRAM) {
375 if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) {
376 container = extensions::LAUNCH_CONTAINER_TAB;
377 } else if (disposition == NEW_WINDOW) {
378 container = extensions::LAUNCH_CONTAINER_WINDOW;
379 } else {
380 // Look at preference to find the right launch container. If no preference
381 // is set, launch as a regular tab.
382 container =
383 extensions::GetLaunchContainer(ExtensionPrefs::Get(profile), extension);
384 disposition = NEW_FOREGROUND_TAB;
385 }
386 }
387
388 AppLaunchParams::~AppLaunchParams() {
389 }
390
391 WebContents* OpenApplication(const AppLaunchParams& params) { 187 WebContents* OpenApplication(const AppLaunchParams& params) {
392 return OpenEnabledApplication(params); 188 return OpenEnabledApplication(params);
393 } 189 }
394 190
395 void OpenApplicationWithReenablePrompt(const AppLaunchParams& params) { 191 void OpenApplicationWithReenablePrompt(const AppLaunchParams& params) {
396 const Extension* extension = GetExtension(params); 192 const Extension* extension = GetExtension(params);
397 if (!extension) 193 if (!extension)
398 return; 194 return;
399 Profile* profile = params.profile; 195 Profile* profile = params.profile;
400 196
401 ExtensionService* service = 197 ExtensionService* service =
402 extensions::ExtensionSystem::Get(profile)->extension_service(); 198 extensions::ExtensionSystem::Get(profile)->extension_service();
403 if (!service->IsExtensionEnabled(extension->id()) || 199 if (!service->IsExtensionEnabled(extension->id()) ||
404 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( 200 extensions::ExtensionRegistry::Get(profile)->GetExtensionById(
405 extension->id(), extensions::ExtensionRegistry::TERMINATED)) { 201 extension->id(), extensions::ExtensionRegistry::TERMINATED)) {
406 (new EnableViaAppListFlow( 202 base::Callback<gfx::NativeWindow(void)> dialog_parent_window_getter;
407 service, profile, params.desktop_type, extension->id(), 203 // TODO(pkotwicz): Figure out which window should be used as the parent for
204 // the "enable application" dialog in Athena.
205 #if !defined(USE_ATHENA)
206 dialog_parent_window_getter =
207 base::Bind(&ShowAppListAndGetNativeWindow, params.desktop_type);
208 #endif
209 (new EnableViaDialogFlow(
210 service, profile, extension->id(), dialog_parent_window_getter,
408 base::Bind(base::IgnoreResult(OpenEnabledApplication), params)))->Run(); 211 base::Bind(base::IgnoreResult(OpenEnabledApplication), params)))->Run();
409 return; 212 return;
410 } 213 }
411 214
412 OpenEnabledApplication(params); 215 OpenEnabledApplication(params);
413 } 216 }
414 217
415 WebContents* OpenAppShortcutWindow(Profile* profile, 218 WebContents* OpenAppShortcutWindow(Profile* profile,
416 const GURL& url) { 219 const GURL& url) {
417 AppLaunchParams launch_params( 220 AppLaunchParams launch_params(
418 profile, 221 profile,
419 NULL, // this is a URL app. No extension. 222 NULL, // this is a URL app. No extension.
420 extensions::LAUNCH_CONTAINER_WINDOW, 223 extensions::LAUNCH_CONTAINER_WINDOW,
421 NEW_WINDOW); 224 NEW_WINDOW);
422 launch_params.override_url = url; 225 launch_params.override_url = url;
423 226
424 WebContents* tab = OpenApplicationWindow(launch_params); 227 WebContents* tab = OpenWebAppWindow(launch_params, url);
425 228
426 if (!tab) 229 if (!tab)
427 return NULL; 230 return NULL;
428 231
429 extensions::TabHelper::FromWebContents(tab)->UpdateShortcutOnLoadComplete(); 232 extensions::TabHelper::FromWebContents(tab)->UpdateShortcutOnLoadComplete();
430 233
431 return tab; 234 return tab;
432 } 235 }
433 236
434 bool CanLaunchViaEvent(const extensions::Extension* extension) { 237 bool CanLaunchViaEvent(const extensions::Extension* extension) {
435 const extensions::FeatureProvider* feature_provider = 238 const extensions::FeatureProvider* feature_provider =
436 extensions::FeatureProvider::GetAPIFeatures(); 239 extensions::FeatureProvider::GetAPIFeatures();
437 extensions::Feature* feature = feature_provider->GetFeature("app.runtime"); 240 extensions::Feature* feature = feature_provider->GetFeature("app.runtime");
438 return feature->IsAvailableToExtension(extension).is_available(); 241 return feature->IsAvailableToExtension(extension).is_available();
439 } 242 }
440
441 GURL UrlForExtension(const Extension* extension, const GURL& override_url) {
442 if (!extension)
443 return override_url;
444
445 GURL url;
446 if (!override_url.is_empty()) {
447 DCHECK(extension->web_extent().MatchesURL(override_url) ||
448 override_url.GetOrigin() == extension->url());
449 url = override_url;
450 } else {
451 url = extensions::AppLaunchInfo::GetFullLaunchURL(extension);
452 }
453
454 // For extensions lacking launch urls, determine a reasonable fallback.
455 if (!url.is_valid()) {
456 url = extensions::OptionsPageInfo::GetOptionsPage(extension);
457 if (!url.is_valid())
458 url = GURL(chrome::kChromeUIExtensionsURL);
459 }
460
461 return url;
462 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/extensions/application_launch.h ('k') | chrome/browser/ui/extensions/application_launch_web_app.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698