| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extensions/extension_service.h" | 5 #include "chrome/browser/extensions/extension_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 | 251 |
| 252 // If a download url matches one of these patterns and has a referrer of the | 252 // If a download url matches one of these patterns and has a referrer of the |
| 253 // webstore, then we're willing to treat that as a gallery download. | 253 // webstore, then we're willing to treat that as a gallery download. |
| 254 static const char* kAllowedDownloadURLPatterns[] = { | 254 static const char* kAllowedDownloadURLPatterns[] = { |
| 255 "https://clients2.google.com/service/update2*", | 255 "https://clients2.google.com/service/update2*", |
| 256 "https://clients2.googleusercontent.com/crx/*" | 256 "https://clients2.googleusercontent.com/crx/*" |
| 257 }; | 257 }; |
| 258 | 258 |
| 259 bool ExtensionService::IsDownloadFromGallery(const GURL& download_url, | 259 bool ExtensionService::IsDownloadFromGallery(const GURL& download_url, |
| 260 const GURL& referrer_url) { | 260 const GURL& referrer_url) { |
| 261 const Extension* download_extension = GetExtensionByWebExtent(download_url); | 261 const Extension* download_extension = |
| 262 const Extension* referrer_extension = GetExtensionByWebExtent(referrer_url); | 262 extensions_.GetHostedAppByURL(ExtensionURLInfo(download_url)); |
| 263 const Extension* referrer_extension = |
| 264 extensions_.GetHostedAppByURL(ExtensionURLInfo(referrer_url)); |
| 263 const Extension* webstore_app = GetWebStoreApp(); | 265 const Extension* webstore_app = GetWebStoreApp(); |
| 264 | 266 |
| 265 bool referrer_valid = (referrer_extension == webstore_app); | 267 bool referrer_valid = (referrer_extension == webstore_app); |
| 266 bool download_valid = (download_extension == webstore_app); | 268 bool download_valid = (download_extension == webstore_app); |
| 267 | 269 |
| 268 // We also allow the download to be from a small set of trusted paths. | 270 // We also allow the download to be from a small set of trusted paths. |
| 269 if (!download_valid) { | 271 if (!download_valid) { |
| 270 for (size_t i = 0; i < arraysize(kAllowedDownloadURLPatterns); i++) { | 272 for (size_t i = 0; i < arraysize(kAllowedDownloadURLPatterns); i++) { |
| 271 URLPattern pattern(URLPattern::SCHEME_HTTPS, | 273 URLPattern pattern(URLPattern::SCHEME_HTTPS, |
| 272 kAllowedDownloadURLPatterns[i]); | 274 kAllowedDownloadURLPatterns[i]); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 303 | 305 |
| 304 // Otherwise, the TLD must match the TLD of the command-line url. | 306 // Otherwise, the TLD must match the TLD of the command-line url. |
| 305 download_valid = (download_tld == store_tld); | 307 download_valid = (download_tld == store_tld); |
| 306 } | 308 } |
| 307 } | 309 } |
| 308 | 310 |
| 309 return (referrer_valid && download_valid); | 311 return (referrer_valid && download_valid); |
| 310 } | 312 } |
| 311 | 313 |
| 312 const Extension* ExtensionService::GetInstalledApp(const GURL& url) { | 314 const Extension* ExtensionService::GetInstalledApp(const GURL& url) { |
| 313 // Check for hosted app. | 315 const Extension* extension = extensions_.GetExtensionOrAppByURL( |
| 314 const Extension* app = GetExtensionByWebExtent(url); | 316 ExtensionURLInfo(url)); |
| 315 if (app) | 317 if (extension && extension->is_app()) |
| 316 return app; | 318 return extension; |
| 317 | |
| 318 // Check for packaged app. | |
| 319 app = GetExtensionByURL(url); | |
| 320 if (app && app->is_app()) | |
| 321 return app; | |
| 322 | 319 |
| 323 return NULL; | 320 return NULL; |
| 324 } | 321 } |
| 325 | 322 |
| 326 bool ExtensionService::IsInstalledApp(const GURL& url) { | 323 bool ExtensionService::IsInstalledApp(const GURL& url) { |
| 327 return !!GetInstalledApp(url); | 324 return !!GetInstalledApp(url); |
| 328 } | 325 } |
| 329 | 326 |
| 330 void ExtensionService::SetInstalledAppForRenderer(int renderer_child_id, | 327 void ExtensionService::SetInstalledAppForRenderer(int renderer_child_id, |
| 331 const Extension* app) { | 328 const Extension* app) { |
| (...skipping 1835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2167 | 2164 |
| 2168 const Extension* ExtensionService::GetInstalledExtension( | 2165 const Extension* ExtensionService::GetInstalledExtension( |
| 2169 const std::string& id) const { | 2166 const std::string& id) const { |
| 2170 return GetExtensionByIdInternal(id, true, true, true); | 2167 return GetExtensionByIdInternal(id, true, true, true); |
| 2171 } | 2168 } |
| 2172 | 2169 |
| 2173 const Extension* ExtensionService::GetWebStoreApp() { | 2170 const Extension* ExtensionService::GetWebStoreApp() { |
| 2174 return GetExtensionById(extension_misc::kWebStoreAppId, false); | 2171 return GetExtensionById(extension_misc::kWebStoreAppId, false); |
| 2175 } | 2172 } |
| 2176 | 2173 |
| 2177 const Extension* ExtensionService::GetExtensionByURL(const GURL& url) { | |
| 2178 return url.scheme() != chrome::kExtensionScheme ? NULL : | |
| 2179 GetExtensionById(url.host(), false); | |
| 2180 } | |
| 2181 | |
| 2182 const Extension* ExtensionService::GetExtensionByWebExtent(const GURL& url) { | |
| 2183 // TODO(yoz): Should be ExtensionSet::GetByURL. | |
| 2184 for (ExtensionSet::const_iterator iter = extensions_.begin(); | |
| 2185 iter != extensions_.end(); ++iter) { | |
| 2186 if ((*iter)->web_extent().MatchesURL(url)) | |
| 2187 return *iter; | |
| 2188 } | |
| 2189 return NULL; | |
| 2190 } | |
| 2191 | |
| 2192 const Extension* ExtensionService::GetDisabledExtensionByWebExtent( | |
| 2193 const GURL& url) { | |
| 2194 // TODO(yoz): Should be ExtensionSet::GetByURL. | |
| 2195 for (ExtensionSet::const_iterator iter = disabled_extensions_.begin(); | |
| 2196 iter != disabled_extensions_.end(); ++iter) { | |
| 2197 if ((*iter)->web_extent().MatchesURL(url)) | |
| 2198 return *iter; | |
| 2199 } | |
| 2200 return NULL; | |
| 2201 } | |
| 2202 | |
| 2203 bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) { | 2174 bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) { |
| 2204 // Allow bindings for all packaged extensions. | 2175 // Allow bindings for all packaged extensions and component hosted apps. |
| 2205 // Note that GetExtensionByURL may return an Extension for hosted apps | 2176 const Extension* extension = extensions_.GetExtensionOrAppByURL( |
| 2206 // (excluding bookmark apps) if the URL came from GetEffectiveURL. | 2177 ExtensionURLInfo(url)); |
| 2207 const Extension* extension = GetExtensionByURL(url); | 2178 return extension && (!extension->is_hosted_app() || |
| 2208 if (extension && extension->GetType() != Extension::TYPE_HOSTED_APP) | 2179 extension->location() == Extension::COMPONENT); |
| 2209 return true; | |
| 2210 | |
| 2211 // Allow bindings for all component, hosted apps. | |
| 2212 if (!extension) | |
| 2213 extension = GetExtensionByWebExtent(url); | |
| 2214 return (extension && extension->location() == Extension::COMPONENT); | |
| 2215 } | |
| 2216 | |
| 2217 const Extension* ExtensionService::GetExtensionByOverlappingWebExtent( | |
| 2218 const URLPatternSet& extent) { | |
| 2219 // TODO(yoz): Should be in ExtensionSet. | |
| 2220 for (ExtensionSet::const_iterator iter = extensions_.begin(); | |
| 2221 iter != extensions_.end(); ++iter) { | |
| 2222 if ((*iter)->web_extent().OverlapsWith(extent)) | |
| 2223 return *iter; | |
| 2224 } | |
| 2225 | |
| 2226 return NULL; | |
| 2227 } | 2180 } |
| 2228 | 2181 |
| 2229 const SkBitmap& ExtensionService::GetOmniboxIcon( | 2182 const SkBitmap& ExtensionService::GetOmniboxIcon( |
| 2230 const std::string& extension_id) { | 2183 const std::string& extension_id) { |
| 2231 return omnibox_icon_manager_.GetIcon(extension_id); | 2184 return omnibox_icon_manager_.GetIcon(extension_id); |
| 2232 } | 2185 } |
| 2233 | 2186 |
| 2234 const SkBitmap& ExtensionService::GetOmniboxPopupIcon( | 2187 const SkBitmap& ExtensionService::GetOmniboxPopupIcon( |
| 2235 const std::string& extension_id) { | 2188 const std::string& extension_id) { |
| 2236 return omnibox_popup_icon_manager_.GetIcon(extension_id); | 2189 return omnibox_popup_icon_manager_.GetIcon(extension_id); |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2580 const ExtensionResource &resource, | 2533 const ExtensionResource &resource, |
| 2581 int index) { | 2534 int index) { |
| 2582 // If the image failed to load (e.g. if the resource being loaded was empty) | 2535 // If the image failed to load (e.g. if the resource being loaded was empty) |
| 2583 // use the standard application icon. | 2536 // use the standard application icon. |
| 2584 if (!image || image->isNull()) | 2537 if (!image || image->isNull()) |
| 2585 image = ExtensionIconSource::LoadImageByResourceId(IDR_APP_DEFAULT_ICON); | 2538 image = ExtensionIconSource::LoadImageByResourceId(IDR_APP_DEFAULT_ICON); |
| 2586 | 2539 |
| 2587 shortcut_info_.favicon = *image; | 2540 shortcut_info_.favicon = *image; |
| 2588 web_app::CreateShortcut(profile_->GetPath(), shortcut_info_); | 2541 web_app::CreateShortcut(profile_->GetPath(), shortcut_info_); |
| 2589 } | 2542 } |
| OLD | NEW |