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

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: fixed HomepageURLManifestTest.GetHomepageURL 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
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_file_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 457
458 void Extension::GetBasicInfo(bool enabled, 458 void Extension::GetBasicInfo(bool enabled,
459 DictionaryValue* info) const { 459 DictionaryValue* info) const {
460 info->SetString(info_keys::kIdKey, id()); 460 info->SetString(info_keys::kIdKey, id());
461 info->SetString(info_keys::kNameKey, name()); 461 info->SetString(info_keys::kNameKey, name());
462 info->SetBoolean(info_keys::kEnabledKey, enabled); 462 info->SetBoolean(info_keys::kEnabledKey, enabled);
463 info->SetBoolean(info_keys::kOfflineEnabledKey, offline_enabled()); 463 info->SetBoolean(info_keys::kOfflineEnabledKey, offline_enabled());
464 info->SetString(info_keys::kVersionKey, VersionString()); 464 info->SetString(info_keys::kVersionKey, VersionString());
465 info->SetString(info_keys::kDescriptionKey, description()); 465 info->SetString(info_keys::kDescriptionKey, description());
466 info->SetString(info_keys::kOptionsUrlKey, 466 info->SetString(info_keys::kOptionsUrlKey,
467 options_url().possibly_invalid_spec()); 467 ManifestURL::GetOptionsPage(this).possibly_invalid_spec());
468 info->SetString(info_keys::kHomepageUrlKey, 468 info->SetString(info_keys::kHomepageUrlKey,
469 ManifestURL::GetHomepageURL(this).possibly_invalid_spec()); 469 ManifestURL::GetHomepageURL(this).possibly_invalid_spec());
470 info->SetString(info_keys::kDetailsUrlKey, 470 info->SetString(info_keys::kDetailsUrlKey,
471 details_url().possibly_invalid_spec()); 471 details_url().possibly_invalid_spec());
472 info->SetBoolean(info_keys::kPackagedAppKey, is_platform_app()); 472 info->SetBoolean(info_keys::kPackagedAppKey, is_platform_app());
473 } 473 }
474 474
475 Extension::Type Extension::GetType() const { 475 Extension::Type Extension::GetType() const {
476 return converted_from_user_script() ? TYPE_USER_SCRIPT : manifest_->type(); 476 return converted_from_user_script() ? TYPE_USER_SCRIPT : manifest_->type();
477 } 477 }
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
1113 return true; 1113 return true;
1114 1114
1115 if (error) { 1115 if (error) {
1116 *error = ErrorUtils::FormatErrorMessage(errors::kCannotAccessPage, 1116 *error = ErrorUtils::FormatErrorMessage(errors::kCannotAccessPage,
1117 page_url.spec()); 1117 page_url.spec());
1118 } 1118 }
1119 return false; 1119 return false;
1120 } 1120 }
1121 1121
1122 bool Extension::UpdatesFromGallery() const { 1122 bool Extension::UpdatesFromGallery() const {
1123 return extension_urls::IsWebstoreUpdateUrl(update_url()); 1123 return extension_urls::IsWebstoreUpdateUrl(ManifestURL::GetUpdateURL(this));
1124 } 1124 }
1125 1125
1126 bool Extension::OverlapsWithOrigin(const GURL& origin) const { 1126 bool Extension::OverlapsWithOrigin(const GURL& origin) const {
1127 if (url() == origin) 1127 if (url() == origin)
1128 return true; 1128 return true;
1129 1129
1130 if (web_extent().is_empty()) 1130 if (web_extent().is_empty())
1131 return false; 1131 return false;
1132 1132
1133 // Note: patterns and extents ignore port numbers. 1133 // Note: patterns and extents ignore port numbers.
(...skipping 12 matching lines...) Expand all
1146 Extension::SyncType Extension::GetSyncType() const { 1146 Extension::SyncType Extension::GetSyncType() const {
1147 if (!IsSyncable()) { 1147 if (!IsSyncable()) {
1148 // We have a non-standard location. 1148 // We have a non-standard location.
1149 return SYNC_TYPE_NONE; 1149 return SYNC_TYPE_NONE;
1150 } 1150 }
1151 1151
1152 // Disallow extensions with non-gallery auto-update URLs for now. 1152 // Disallow extensions with non-gallery auto-update URLs for now.
1153 // 1153 //
1154 // TODO(akalin): Relax this restriction once we've put in UI to 1154 // TODO(akalin): Relax this restriction once we've put in UI to
1155 // approve synced extensions. 1155 // approve synced extensions.
1156 if (!update_url().is_empty() && !UpdatesFromGallery()) 1156 if (!ManifestURL::GetUpdateURL(this).is_empty() && !UpdatesFromGallery())
1157 return SYNC_TYPE_NONE; 1157 return SYNC_TYPE_NONE;
1158 1158
1159 // Disallow extensions with native code plugins. 1159 // Disallow extensions with native code plugins.
1160 // 1160 //
1161 // TODO(akalin): Relax this restriction once we've put in UI to 1161 // TODO(akalin): Relax this restriction once we've put in UI to
1162 // approve synced extensions. 1162 // approve synced extensions.
1163 if (!plugins().empty()) { 1163 if (!plugins().empty()) {
1164 return SYNC_TYPE_NONE; 1164 return SYNC_TYPE_NONE;
1165 } 1165 }
1166 1166
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after
1956 extent_.ClearPatterns(); 1956 extent_.ClearPatterns();
1957 } 1957 }
1958 1958
1959 return true; 1959 return true;
1960 } 1960 }
1961 1961
1962 bool Extension::LoadSharedFeatures( 1962 bool Extension::LoadSharedFeatures(
1963 const APIPermissionSet& api_permissions, 1963 const APIPermissionSet& api_permissions,
1964 string16* error) { 1964 string16* error) {
1965 if (!LoadDescription(error) || 1965 if (!LoadDescription(error) ||
1966 !LoadUpdateURL(error) ||
1967 !LoadIcons(error) || 1966 !LoadIcons(error) ||
1968 !LoadCommands(error) || 1967 !LoadCommands(error) ||
1969 !LoadPlugins(error) || 1968 !LoadPlugins(error) ||
1970 !LoadNaClModules(error) || 1969 !LoadNaClModules(error) ||
1971 !LoadWebAccessibleResources(error) || 1970 !LoadWebAccessibleResources(error) ||
1972 !LoadSandboxedPages(error) || 1971 !LoadSandboxedPages(error) ||
1973 !LoadRequirements(error) || 1972 !LoadRequirements(error) ||
1974 !LoadDefaultLocale(error) || 1973 !LoadDefaultLocale(error) ||
1975 !LoadOfflineEnabled(error) || 1974 !LoadOfflineEnabled(error) ||
1976 !LoadOptionsPage(error) ||
1977 // LoadBackgroundScripts() must be called before LoadBackgroundPage(). 1975 // LoadBackgroundScripts() must be called before LoadBackgroundPage().
1978 !LoadBackgroundScripts(error) || 1976 !LoadBackgroundScripts(error) ||
1979 !LoadBackgroundPage(api_permissions, error) || 1977 !LoadBackgroundPage(api_permissions, error) ||
1980 !LoadBackgroundPersistent(api_permissions, error) || 1978 !LoadBackgroundPersistent(api_permissions, error) ||
1981 !LoadBackgroundAllowJSAccess(api_permissions, error) || 1979 !LoadBackgroundAllowJSAccess(api_permissions, error) ||
1982 !LoadOAuth2Info(error)) 1980 !LoadOAuth2Info(error))
1983 return false; 1981 return false;
1984 1982
1985 return true; 1983 return true;
1986 } 1984 }
(...skipping 26 matching lines...) Expand all
2013 switches::kAllowLegacyExtensionManifests)) { 2011 switches::kAllowLegacyExtensionManifests)) {
2014 *error = ErrorUtils::FormatErrorMessageUTF16( 2012 *error = ErrorUtils::FormatErrorMessageUTF16(
2015 errors::kInvalidManifestVersionOld, 2013 errors::kInvalidManifestVersionOld,
2016 base::IntToString(kModernManifestVersion)); 2014 base::IntToString(kModernManifestVersion));
2017 return false; 2015 return false;
2018 } 2016 }
2019 2017
2020 return true; 2018 return true;
2021 } 2019 }
2022 2020
2023 bool Extension::LoadUpdateURL(string16* error) {
2024 if (!manifest_->HasKey(keys::kUpdateURL))
2025 return true;
2026 std::string tmp_update_url;
2027 if (!manifest_->GetString(keys::kUpdateURL, &tmp_update_url)) {
2028 *error = ErrorUtils::FormatErrorMessageUTF16(
2029 errors::kInvalidUpdateURL, "");
2030 return false;
2031 }
2032 update_url_ = GURL(tmp_update_url);
2033 if (!update_url_.is_valid() ||
2034 update_url_.has_ref()) {
2035 *error = ErrorUtils::FormatErrorMessageUTF16(
2036 errors::kInvalidUpdateURL, tmp_update_url);
2037 return false;
2038 }
2039 return true;
2040 }
2041
2042 bool Extension::LoadIcons(string16* error) { 2021 bool Extension::LoadIcons(string16* error) {
2043 if (!manifest_->HasKey(keys::kIcons)) 2022 if (!manifest_->HasKey(keys::kIcons))
2044 return true; 2023 return true;
2045 DictionaryValue* icons_value = NULL; 2024 DictionaryValue* icons_value = NULL;
2046 if (!manifest_->GetDictionary(keys::kIcons, &icons_value)) { 2025 if (!manifest_->GetDictionary(keys::kIcons, &icons_value)) {
2047 *error = ASCIIToUTF16(errors::kInvalidIcons); 2026 *error = ASCIIToUTF16(errors::kInvalidIcons);
2048 return false; 2027 return false;
2049 } 2028 }
2050 2029
2051 return LoadIconsFromDictionary(icons_value, 2030 return LoadIconsFromDictionary(icons_value,
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
2383 offline_enabled_ = is_platform_app(); 2362 offline_enabled_ = is_platform_app();
2384 return true; 2363 return true;
2385 } 2364 }
2386 if (!manifest_->GetBoolean(keys::kOfflineEnabled, &offline_enabled_)) { 2365 if (!manifest_->GetBoolean(keys::kOfflineEnabled, &offline_enabled_)) {
2387 *error = ASCIIToUTF16(errors::kInvalidOfflineEnabled); 2366 *error = ASCIIToUTF16(errors::kInvalidOfflineEnabled);
2388 return false; 2367 return false;
2389 } 2368 }
2390 return true; 2369 return true;
2391 } 2370 }
2392 2371
2393 bool Extension::LoadOptionsPage(string16* error) {
2394 if (!manifest_->HasKey(keys::kOptionsPage))
2395 return true;
2396 std::string options_str;
2397 if (!manifest_->GetString(keys::kOptionsPage, &options_str)) {
2398 *error = ASCIIToUTF16(errors::kInvalidOptionsPage);
2399 return false;
2400 }
2401
2402 if (is_hosted_app()) {
2403 // hosted apps require an absolute URL.
2404 GURL options_url(options_str);
2405 if (!options_url.is_valid() ||
2406 !(options_url.SchemeIs("http") || options_url.SchemeIs("https"))) {
2407 *error = ASCIIToUTF16(errors::kInvalidOptionsPageInHostedApp);
2408 return false;
2409 }
2410 options_url_ = options_url;
2411 } else {
2412 GURL absolute(options_str);
2413 if (absolute.is_valid()) {
2414 *error = ASCIIToUTF16(errors::kInvalidOptionsPageExpectUrlInPackage);
2415 return false;
2416 }
2417 options_url_ = GetResourceURL(options_str);
2418 if (!options_url_.is_valid()) {
2419 *error = ASCIIToUTF16(errors::kInvalidOptionsPage);
2420 return false;
2421 }
2422 }
2423
2424 return true;
2425 }
2426
2427 bool Extension::LoadBackgroundScripts(string16* error) { 2372 bool Extension::LoadBackgroundScripts(string16* error) {
2428 const std::string& key = is_platform_app() ? 2373 const std::string& key = is_platform_app() ?
2429 keys::kPlatformAppBackgroundScripts : keys::kBackgroundScripts; 2374 keys::kPlatformAppBackgroundScripts : keys::kBackgroundScripts;
2430 return LoadBackgroundScripts(key, error); 2375 return LoadBackgroundScripts(key, error);
2431 } 2376 }
2432 2377
2433 bool Extension::LoadBackgroundScripts(const std::string& key, string16* error) { 2378 bool Extension::LoadBackgroundScripts(const std::string& key, string16* error) {
2434 Value* background_scripts_value = NULL; 2379 Value* background_scripts_value = NULL;
2435 if (!manifest_->Get(key, &background_scripts_value)) 2380 if (!manifest_->Get(key, &background_scripts_value))
2436 return true; 2381 return true;
(...skipping 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after
3533 3478
3534 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 3479 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
3535 const Extension* extension, 3480 const Extension* extension,
3536 const PermissionSet* permissions, 3481 const PermissionSet* permissions,
3537 Reason reason) 3482 Reason reason)
3538 : reason(reason), 3483 : reason(reason),
3539 extension(extension), 3484 extension(extension),
3540 permissions(permissions) {} 3485 permissions(permissions) {}
3541 3486
3542 } // namespace extensions 3487 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_file_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698