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

Side by Side Diff: chrome/common/extensions/extension.cc

Issue 11726002: Move the parsing of 'update_url' & 'options_page' URLs out of Extension. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@url_parse
Patch Set: Created 7 years, 11 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/common/extensions/extension.h" 5 #include "chrome/common/extensions/extension.h"
6 6
7 #include <ostream> 7 #include <ostream>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 475
476 void Extension::GetBasicInfo(bool enabled, 476 void Extension::GetBasicInfo(bool enabled,
477 DictionaryValue* info) const { 477 DictionaryValue* info) const {
478 info->SetString(info_keys::kIdKey, id()); 478 info->SetString(info_keys::kIdKey, id());
479 info->SetString(info_keys::kNameKey, name()); 479 info->SetString(info_keys::kNameKey, name());
480 info->SetBoolean(info_keys::kEnabledKey, enabled); 480 info->SetBoolean(info_keys::kEnabledKey, enabled);
481 info->SetBoolean(info_keys::kOfflineEnabledKey, offline_enabled()); 481 info->SetBoolean(info_keys::kOfflineEnabledKey, offline_enabled());
482 info->SetString(info_keys::kVersionKey, VersionString()); 482 info->SetString(info_keys::kVersionKey, VersionString());
483 info->SetString(info_keys::kDescriptionKey, description()); 483 info->SetString(info_keys::kDescriptionKey, description());
484 info->SetString(info_keys::kOptionsUrlKey, 484 info->SetString(info_keys::kOptionsUrlKey,
485 options_url().possibly_invalid_spec()); 485 ManifestURLInfo::GetOptionsPage(this).possibly_invalid_spec());
486 info->SetString(info_keys::kHomepageUrlKey, 486 info->SetString(info_keys::kHomepageUrlKey,
487 ManifestURLInfo::GetHomepageURL(this).possibly_invalid_spec()); 487 ManifestURLInfo::GetHomepageURL(this).possibly_invalid_spec());
488 info->SetString(info_keys::kDetailsUrlKey, 488 info->SetString(info_keys::kDetailsUrlKey,
489 details_url().possibly_invalid_spec()); 489 details_url().possibly_invalid_spec());
490 info->SetBoolean(info_keys::kPackagedAppKey, is_platform_app()); 490 info->SetBoolean(info_keys::kPackagedAppKey, is_platform_app());
491 } 491 }
492 492
493 Extension::Type Extension::GetType() const { 493 Extension::Type Extension::GetType() const {
494 return converted_from_user_script() ? TYPE_USER_SCRIPT : manifest_->type(); 494 return converted_from_user_script() ? TYPE_USER_SCRIPT : manifest_->type();
495 } 495 }
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 return true; 1131 return true;
1132 1132
1133 if (error) { 1133 if (error) {
1134 *error = ErrorUtils::FormatErrorMessage(errors::kCannotAccessPage, 1134 *error = ErrorUtils::FormatErrorMessage(errors::kCannotAccessPage,
1135 page_url.spec()); 1135 page_url.spec());
1136 } 1136 }
1137 return false; 1137 return false;
1138 } 1138 }
1139 1139
1140 bool Extension::UpdatesFromGallery() const { 1140 bool Extension::UpdatesFromGallery() const {
1141 return extension_urls::IsWebstoreUpdateUrl(update_url()); 1141 return extension_urls::IsWebstoreUpdateUrl(
1142 ManifestURLInfo::GetUpdateURL(this));
1142 } 1143 }
1143 1144
1144 bool Extension::OverlapsWithOrigin(const GURL& origin) const { 1145 bool Extension::OverlapsWithOrigin(const GURL& origin) const {
1145 if (url() == origin) 1146 if (url() == origin)
1146 return true; 1147 return true;
1147 1148
1148 if (web_extent().is_empty()) 1149 if (web_extent().is_empty())
1149 return false; 1150 return false;
1150 1151
1151 // Note: patterns and extents ignore port numbers. 1152 // Note: patterns and extents ignore port numbers.
(...skipping 12 matching lines...) Expand all
1164 Extension::SyncType Extension::GetSyncType() const { 1165 Extension::SyncType Extension::GetSyncType() const {
1165 if (!IsSyncable()) { 1166 if (!IsSyncable()) {
1166 // We have a non-standard location. 1167 // We have a non-standard location.
1167 return SYNC_TYPE_NONE; 1168 return SYNC_TYPE_NONE;
1168 } 1169 }
1169 1170
1170 // Disallow extensions with non-gallery auto-update URLs for now. 1171 // Disallow extensions with non-gallery auto-update URLs for now.
1171 // 1172 //
1172 // TODO(akalin): Relax this restriction once we've put in UI to 1173 // TODO(akalin): Relax this restriction once we've put in UI to
1173 // approve synced extensions. 1174 // approve synced extensions.
1174 if (!update_url().is_empty() && !UpdatesFromGallery()) 1175 if (!ManifestURLInfo::GetUpdateURL(this).is_empty() && !UpdatesFromGallery())
1175 return SYNC_TYPE_NONE; 1176 return SYNC_TYPE_NONE;
1176 1177
1177 // Disallow extensions with native code plugins. 1178 // Disallow extensions with native code plugins.
1178 // 1179 //
1179 // TODO(akalin): Relax this restriction once we've put in UI to 1180 // TODO(akalin): Relax this restriction once we've put in UI to
1180 // approve synced extensions. 1181 // approve synced extensions.
1181 if (!plugins().empty()) { 1182 if (!plugins().empty()) {
1182 return SYNC_TYPE_NONE; 1183 return SYNC_TYPE_NONE;
1183 } 1184 }
1184 1185
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after
1919 extent_.ClearPatterns(); 1920 extent_.ClearPatterns();
1920 } 1921 }
1921 1922
1922 return true; 1923 return true;
1923 } 1924 }
1924 1925
1925 bool Extension::LoadSharedFeatures( 1926 bool Extension::LoadSharedFeatures(
1926 const APIPermissionSet& api_permissions, 1927 const APIPermissionSet& api_permissions,
1927 string16* error) { 1928 string16* error) {
1928 if (!LoadDescription(error) || 1929 if (!LoadDescription(error) ||
1929 !LoadUpdateURL(error) ||
1930 !LoadIcons(error) || 1930 !LoadIcons(error) ||
1931 !LoadCommands(error) || 1931 !LoadCommands(error) ||
1932 !LoadPlugins(error) || 1932 !LoadPlugins(error) ||
1933 !LoadNaClModules(error) || 1933 !LoadNaClModules(error) ||
1934 !LoadWebAccessibleResources(error) || 1934 !LoadWebAccessibleResources(error) ||
1935 !LoadSandboxedPages(error) || 1935 !LoadSandboxedPages(error) ||
1936 !LoadRequirements(error) || 1936 !LoadRequirements(error) ||
1937 !LoadDefaultLocale(error) || 1937 !LoadDefaultLocale(error) ||
1938 !LoadOfflineEnabled(error) || 1938 !LoadOfflineEnabled(error) ||
1939 !LoadOptionsPage(error) ||
1940 // LoadBackgroundScripts() must be called before LoadBackgroundPage(). 1939 // LoadBackgroundScripts() must be called before LoadBackgroundPage().
1941 !LoadBackgroundScripts(error) || 1940 !LoadBackgroundScripts(error) ||
1942 !LoadBackgroundPage(api_permissions, error) || 1941 !LoadBackgroundPage(api_permissions, error) ||
1943 !LoadBackgroundPersistent(api_permissions, error) || 1942 !LoadBackgroundPersistent(api_permissions, error) ||
1944 !LoadBackgroundAllowJSAccess(api_permissions, error) || 1943 !LoadBackgroundAllowJSAccess(api_permissions, error) ||
1945 !LoadWebIntentServices(error) || 1944 !LoadWebIntentServices(error) ||
1946 !LoadOAuth2Info(error)) 1945 !LoadOAuth2Info(error))
1947 return false; 1946 return false;
1948 1947
1949 return true; 1948 return true;
(...skipping 27 matching lines...) Expand all
1977 switches::kAllowLegacyExtensionManifests)) { 1976 switches::kAllowLegacyExtensionManifests)) {
1978 *error = ErrorUtils::FormatErrorMessageUTF16( 1977 *error = ErrorUtils::FormatErrorMessageUTF16(
1979 errors::kInvalidManifestVersionOld, 1978 errors::kInvalidManifestVersionOld,
1980 base::IntToString(kModernManifestVersion)); 1979 base::IntToString(kModernManifestVersion));
1981 return false; 1980 return false;
1982 } 1981 }
1983 1982
1984 return true; 1983 return true;
1985 } 1984 }
1986 1985
1987 bool Extension::LoadUpdateURL(string16* error) {
1988 if (!manifest_->HasKey(keys::kUpdateURL))
1989 return true;
1990 std::string tmp_update_url;
1991 if (!manifest_->GetString(keys::kUpdateURL, &tmp_update_url)) {
1992 *error = ErrorUtils::FormatErrorMessageUTF16(
1993 errors::kInvalidUpdateURL, "");
1994 return false;
1995 }
1996 update_url_ = GURL(tmp_update_url);
1997 if (!update_url_.is_valid() ||
1998 update_url_.has_ref()) {
1999 *error = ErrorUtils::FormatErrorMessageUTF16(
2000 errors::kInvalidUpdateURL, tmp_update_url);
2001 return false;
2002 }
2003 return true;
2004 }
2005
2006 bool Extension::LoadIcons(string16* error) { 1986 bool Extension::LoadIcons(string16* error) {
2007 if (!manifest_->HasKey(keys::kIcons)) 1987 if (!manifest_->HasKey(keys::kIcons))
2008 return true; 1988 return true;
2009 DictionaryValue* icons_value = NULL; 1989 DictionaryValue* icons_value = NULL;
2010 if (!manifest_->GetDictionary(keys::kIcons, &icons_value)) { 1990 if (!manifest_->GetDictionary(keys::kIcons, &icons_value)) {
2011 *error = ASCIIToUTF16(errors::kInvalidIcons); 1991 *error = ASCIIToUTF16(errors::kInvalidIcons);
2012 return false; 1992 return false;
2013 } 1993 }
2014 1994
2015 return LoadIconsFromDictionary(icons_value, 1995 return LoadIconsFromDictionary(icons_value,
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
2347 offline_enabled_ = is_platform_app(); 2327 offline_enabled_ = is_platform_app();
2348 return true; 2328 return true;
2349 } 2329 }
2350 if (!manifest_->GetBoolean(keys::kOfflineEnabled, &offline_enabled_)) { 2330 if (!manifest_->GetBoolean(keys::kOfflineEnabled, &offline_enabled_)) {
2351 *error = ASCIIToUTF16(errors::kInvalidOfflineEnabled); 2331 *error = ASCIIToUTF16(errors::kInvalidOfflineEnabled);
2352 return false; 2332 return false;
2353 } 2333 }
2354 return true; 2334 return true;
2355 } 2335 }
2356 2336
2357 bool Extension::LoadOptionsPage(string16* error) {
2358 if (!manifest_->HasKey(keys::kOptionsPage))
2359 return true;
2360 std::string options_str;
2361 if (!manifest_->GetString(keys::kOptionsPage, &options_str)) {
2362 *error = ASCIIToUTF16(errors::kInvalidOptionsPage);
2363 return false;
2364 }
2365
2366 if (is_hosted_app()) {
2367 // hosted apps require an absolute URL.
2368 GURL options_url(options_str);
2369 if (!options_url.is_valid() ||
2370 !(options_url.SchemeIs("http") || options_url.SchemeIs("https"))) {
2371 *error = ASCIIToUTF16(errors::kInvalidOptionsPageInHostedApp);
2372 return false;
2373 }
2374 options_url_ = options_url;
2375 } else {
2376 GURL absolute(options_str);
2377 if (absolute.is_valid()) {
2378 *error = ASCIIToUTF16(errors::kInvalidOptionsPageExpectUrlInPackage);
2379 return false;
2380 }
2381 options_url_ = GetResourceURL(options_str);
2382 if (!options_url_.is_valid()) {
2383 *error = ASCIIToUTF16(errors::kInvalidOptionsPage);
2384 return false;
2385 }
2386 }
2387
2388 return true;
2389 }
2390
2391 bool Extension::LoadBackgroundScripts(string16* error) { 2337 bool Extension::LoadBackgroundScripts(string16* error) {
2392 const std::string& key = is_platform_app() ? 2338 const std::string& key = is_platform_app() ?
2393 keys::kPlatformAppBackgroundScripts : keys::kBackgroundScripts; 2339 keys::kPlatformAppBackgroundScripts : keys::kBackgroundScripts;
2394 return LoadBackgroundScripts(key, error); 2340 return LoadBackgroundScripts(key, error);
2395 } 2341 }
2396 2342
2397 bool Extension::LoadBackgroundScripts(const std::string& key, string16* error) { 2343 bool Extension::LoadBackgroundScripts(const std::string& key, string16* error) {
2398 Value* background_scripts_value = NULL; 2344 Value* background_scripts_value = NULL;
2399 if (!manifest_->Get(key, &background_scripts_value)) 2345 if (!manifest_->Get(key, &background_scripts_value))
2400 return true; 2346 return true;
(...skipping 1606 matching lines...) Expand 10 before | Expand all | Expand 10 after
4007 3953
4008 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 3954 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
4009 const Extension* extension, 3955 const Extension* extension,
4010 const PermissionSet* permissions, 3956 const PermissionSet* permissions,
4011 Reason reason) 3957 Reason reason)
4012 : reason(reason), 3958 : reason(reason),
4013 extension(extension), 3959 extension(extension),
4014 permissions(permissions) {} 3960 permissions(permissions) {}
4015 3961
4016 } // namespace extensions 3962 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698