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

Side by Side Diff: chrome/browser/extensions/extension_service.cc

Issue 8827013: Move/replace/rename URL-based extension getters from ExtensionService to/in ExtensionSet. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: extent Created 9 years 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 | Annotate | Revision Log
OLDNEW
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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 246
247 // If a download url matches one of these patterns and has a referrer of the 247 // If a download url matches one of these patterns and has a referrer of the
248 // webstore, then we're willing to treat that as a gallery download. 248 // webstore, then we're willing to treat that as a gallery download.
249 static const char* kAllowedDownloadURLPatterns[] = { 249 static const char* kAllowedDownloadURLPatterns[] = {
250 "https://clients2.google.com/service/update2*", 250 "https://clients2.google.com/service/update2*",
251 "https://clients2.googleusercontent.com/crx/*" 251 "https://clients2.googleusercontent.com/crx/*"
252 }; 252 };
253 253
254 bool ExtensionService::IsDownloadFromGallery(const GURL& download_url, 254 bool ExtensionService::IsDownloadFromGallery(const GURL& download_url,
255 const GURL& referrer_url) { 255 const GURL& referrer_url) {
256 const Extension* download_extension = GetExtensionByWebExtent(download_url); 256 const Extension* download_extension =
257 const Extension* referrer_extension = GetExtensionByWebExtent(referrer_url); 257 extensions()->GetByWebExtent(download_url);
258 const Extension* referrer_extension =
259 extensions()->GetByWebExtent(referrer_url);
258 const Extension* webstore_app = GetWebStoreApp(); 260 const Extension* webstore_app = GetWebStoreApp();
259 261
260 bool referrer_valid = (referrer_extension == webstore_app); 262 bool referrer_valid = (referrer_extension == webstore_app);
261 bool download_valid = (download_extension == webstore_app); 263 bool download_valid = (download_extension == webstore_app);
262 264
263 // We also allow the download to be from a small set of trusted paths. 265 // We also allow the download to be from a small set of trusted paths.
264 if (!download_valid) { 266 if (!download_valid) {
265 for (size_t i = 0; i < arraysize(kAllowedDownloadURLPatterns); i++) { 267 for (size_t i = 0; i < arraysize(kAllowedDownloadURLPatterns); i++) {
266 URLPattern pattern(URLPattern::SCHEME_HTTPS, 268 URLPattern pattern(URLPattern::SCHEME_HTTPS,
267 kAllowedDownloadURLPatterns[i]); 269 kAllowedDownloadURLPatterns[i]);
(...skipping 30 matching lines...) Expand all
298 300
299 // Otherwise, the TLD must match the TLD of the command-line url. 301 // Otherwise, the TLD must match the TLD of the command-line url.
300 download_valid = (download_tld == store_tld); 302 download_valid = (download_tld == store_tld);
301 } 303 }
302 } 304 }
303 305
304 return (referrer_valid && download_valid); 306 return (referrer_valid && download_valid);
305 } 307 }
306 308
307 const Extension* ExtensionService::GetInstalledApp(const GURL& url) { 309 const Extension* ExtensionService::GetInstalledApp(const GURL& url) {
308 // Check for hosted app. 310 const Extension* app = extensions_.GetByURL(ExtensionURLInfo(url));
309 const Extension* app = GetExtensionByWebExtent(url);
310 if (app)
311 return app;
312
313 // Check for packaged app.
314 app = GetExtensionByURL(url);
315 if (app && app->is_app()) 311 if (app && app->is_app())
316 return app; 312 return app;
317 313
318 return NULL; 314 return NULL;
319 } 315 }
320 316
321 bool ExtensionService::IsInstalledApp(const GURL& url) { 317 bool ExtensionService::IsInstalledApp(const GURL& url) {
322 return !!GetInstalledApp(url); 318 return !!GetInstalledApp(url);
323 } 319 }
324 320
(...skipping 1820 matching lines...) Expand 10 before | Expand all | Expand 10 after
2145 2141
2146 const Extension* ExtensionService::GetInstalledExtension( 2142 const Extension* ExtensionService::GetInstalledExtension(
2147 const std::string& id) const { 2143 const std::string& id) const {
2148 return GetExtensionByIdInternal(id, true, true, true); 2144 return GetExtensionByIdInternal(id, true, true, true);
2149 } 2145 }
2150 2146
2151 const Extension* ExtensionService::GetWebStoreApp() { 2147 const Extension* ExtensionService::GetWebStoreApp() {
2152 return GetExtensionById(extension_misc::kWebStoreAppId, false); 2148 return GetExtensionById(extension_misc::kWebStoreAppId, false);
2153 } 2149 }
2154 2150
2155 const Extension* ExtensionService::GetExtensionByURL(const GURL& url) {
2156 return url.scheme() != chrome::kExtensionScheme ? NULL :
2157 GetExtensionById(url.host(), false);
2158 }
2159
2160 const Extension* ExtensionService::GetExtensionByWebExtent(const GURL& url) {
2161 // TODO(yoz): Should be ExtensionSet::GetByURL.
2162 for (ExtensionSet::const_iterator iter = extensions_.begin();
2163 iter != extensions_.end(); ++iter) {
2164 if ((*iter)->web_extent().MatchesURL(url))
2165 return *iter;
2166 }
2167 return NULL;
2168 }
2169
2170 const Extension* ExtensionService::GetDisabledExtensionByWebExtent(
2171 const GURL& url) {
2172 // TODO(yoz): Should be ExtensionSet::GetByURL.
2173 for (ExtensionSet::const_iterator iter = disabled_extensions_.begin();
2174 iter != disabled_extensions_.end(); ++iter) {
2175 if ((*iter)->web_extent().MatchesURL(url))
2176 return *iter;
2177 }
2178 return NULL;
2179 }
2180
2181 bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) { 2151 bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) {
2182 // Allow bindings for all packaged extensions. 2152 // Allow bindings for all packaged extensions and component hosted apps.
2183 // Note that GetExtensionByURL may return an Extension for hosted apps 2153 const Extension* extension = extensions_.GetByURL(ExtensionURLInfo(url));
2184 // (excluding bookmark apps) if the URL came from GetEffectiveURL. 2154 return extension && (!extension->is_hosted_app() ||
2185 const Extension* extension = GetExtensionByURL(url); 2155 extension->location() == Extension::COMPONENT);
2186 if (extension && extension->GetType() != Extension::TYPE_HOSTED_APP)
2187 return true;
2188
2189 // Allow bindings for all component, hosted apps.
2190 if (!extension)
2191 extension = GetExtensionByWebExtent(url);
2192 return (extension && extension->location() == Extension::COMPONENT);
2193 }
2194
2195 const Extension* ExtensionService::GetExtensionByOverlappingWebExtent(
2196 const URLPatternSet& extent) {
2197 // TODO(yoz): Should be in ExtensionSet.
2198 for (ExtensionSet::const_iterator iter = extensions_.begin();
2199 iter != extensions_.end(); ++iter) {
2200 if ((*iter)->web_extent().OverlapsWith(extent))
2201 return *iter;
2202 }
2203
2204 return NULL;
2205 } 2156 }
2206 2157
2207 const SkBitmap& ExtensionService::GetOmniboxIcon( 2158 const SkBitmap& ExtensionService::GetOmniboxIcon(
2208 const std::string& extension_id) { 2159 const std::string& extension_id) {
2209 return omnibox_icon_manager_.GetIcon(extension_id); 2160 return omnibox_icon_manager_.GetIcon(extension_id);
2210 } 2161 }
2211 2162
2212 const SkBitmap& ExtensionService::GetOmniboxPopupIcon( 2163 const SkBitmap& ExtensionService::GetOmniboxPopupIcon(
2213 const std::string& extension_id) { 2164 const std::string& extension_id) {
2214 return omnibox_popup_icon_manager_.GetIcon(extension_id); 2165 return omnibox_popup_icon_manager_.GetIcon(extension_id);
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
2505 2456
2506 ExtensionService::NaClModuleInfoList::iterator 2457 ExtensionService::NaClModuleInfoList::iterator
2507 ExtensionService::FindNaClModule(const GURL& url) { 2458 ExtensionService::FindNaClModule(const GURL& url) {
2508 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); 2459 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin();
2509 iter != nacl_module_list_.end(); ++iter) { 2460 iter != nacl_module_list_.end(); ++iter) {
2510 if (iter->url == url) 2461 if (iter->url == url)
2511 return iter; 2462 return iter;
2512 } 2463 }
2513 return nacl_module_list_.end(); 2464 return nacl_module_list_.end();
2514 } 2465 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698