| OLD | NEW |
| 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" | 10 #include "base/command_line.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 const Extension* GetExtension(const AppLaunchParams& params) { | 116 const Extension* GetExtension(const AppLaunchParams& params) { |
| 117 if (params.extension_id.empty()) | 117 if (params.extension_id.empty()) |
| 118 return NULL; | 118 return NULL; |
| 119 ExtensionRegistry* registry = ExtensionRegistry::Get(params.profile); | 119 ExtensionRegistry* registry = ExtensionRegistry::Get(params.profile); |
| 120 return registry->GetExtensionById(params.extension_id, | 120 return registry->GetExtensionById(params.extension_id, |
| 121 ExtensionRegistry::ENABLED | | 121 ExtensionRegistry::ENABLED | |
| 122 ExtensionRegistry::DISABLED | | 122 ExtensionRegistry::DISABLED | |
| 123 ExtensionRegistry::TERMINATED); | 123 ExtensionRegistry::TERMINATED); |
| 124 } | 124 } |
| 125 | 125 |
| 126 // Get the launch URL for a given extension, with optional override/fallback. | |
| 127 // |override_url|, if non-empty, will be preferred over the extension's | |
| 128 // launch url. | |
| 129 GURL UrlForExtension(const Extension* extension, | |
| 130 const GURL& override_url) { | |
| 131 if (!extension) | |
| 132 return override_url; | |
| 133 | |
| 134 GURL url; | |
| 135 if (!override_url.is_empty()) { | |
| 136 DCHECK(extension->web_extent().MatchesURL(override_url) || | |
| 137 override_url.GetOrigin() == extension->url()); | |
| 138 url = override_url; | |
| 139 } else { | |
| 140 url = extensions::AppLaunchInfo::GetFullLaunchURL(extension); | |
| 141 } | |
| 142 | |
| 143 // For extensions lacking launch urls, determine a reasonable fallback. | |
| 144 if (!url.is_valid()) { | |
| 145 url = extensions::ManifestURL::GetOptionsPage(extension); | |
| 146 if (!url.is_valid()) | |
| 147 url = GURL(chrome::kChromeUIExtensionsURL); | |
| 148 } | |
| 149 | |
| 150 return url; | |
| 151 } | |
| 152 | |
| 153 ui::WindowShowState DetermineWindowShowState( | 126 ui::WindowShowState DetermineWindowShowState( |
| 154 Profile* profile, | 127 Profile* profile, |
| 155 extensions::LaunchContainer container, | 128 extensions::LaunchContainer container, |
| 156 const Extension* extension) { | 129 const Extension* extension) { |
| 157 if (!extension || container != extensions::LAUNCH_CONTAINER_WINDOW) | 130 if (!extension || container != extensions::LAUNCH_CONTAINER_WINDOW) |
| 158 return ui::SHOW_STATE_DEFAULT; | 131 return ui::SHOW_STATE_DEFAULT; |
| 159 | 132 |
| 160 if (chrome::IsRunningInForcedAppMode()) | 133 if (chrome::IsRunningInForcedAppMode()) |
| 161 return ui::SHOW_STATE_FULLSCREEN; | 134 return ui::SHOW_STATE_FULLSCREEN; |
| 162 | 135 |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 | 433 |
| 461 return tab; | 434 return tab; |
| 462 } | 435 } |
| 463 | 436 |
| 464 bool CanLaunchViaEvent(const extensions::Extension* extension) { | 437 bool CanLaunchViaEvent(const extensions::Extension* extension) { |
| 465 const extensions::FeatureProvider* feature_provider = | 438 const extensions::FeatureProvider* feature_provider = |
| 466 extensions::FeatureProvider::GetAPIFeatures(); | 439 extensions::FeatureProvider::GetAPIFeatures(); |
| 467 extensions::Feature* feature = feature_provider->GetFeature("app.runtime"); | 440 extensions::Feature* feature = feature_provider->GetFeature("app.runtime"); |
| 468 return feature->IsAvailableToExtension(extension).is_available(); | 441 return feature->IsAvailableToExtension(extension).is_available(); |
| 469 } | 442 } |
| 443 |
| 444 GURL UrlForExtension(const Extension* extension, const GURL& override_url) { |
| 445 if (!extension) |
| 446 return override_url; |
| 447 |
| 448 GURL url; |
| 449 if (!override_url.is_empty()) { |
| 450 DCHECK(extension->web_extent().MatchesURL(override_url) || |
| 451 override_url.GetOrigin() == extension->url()); |
| 452 url = override_url; |
| 453 } else { |
| 454 url = extensions::AppLaunchInfo::GetFullLaunchURL(extension); |
| 455 } |
| 456 |
| 457 // For extensions lacking launch urls, determine a reasonable fallback. |
| 458 if (!url.is_valid()) { |
| 459 url = extensions::ManifestURL::GetOptionsPage(extension); |
| 460 if (!url.is_valid()) |
| 461 url = GURL(chrome::kChromeUIExtensionsURL); |
| 462 } |
| 463 |
| 464 return url; |
| 465 } |
| OLD | NEW |