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

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

Issue 11660016: Move the parsing of "chrome_url_overrides" out of Extension. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments addressed 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 using extensions::csp_validator::ContentSecurityPolicyIsSandboxed; 66 using extensions::csp_validator::ContentSecurityPolicyIsSandboxed;
67 using extensions::csp_validator::ContentSecurityPolicyIsSecure; 67 using extensions::csp_validator::ContentSecurityPolicyIsSecure;
68 68
69 namespace extensions { 69 namespace extensions {
70 70
71 namespace { 71 namespace {
72 72
73 const int kModernManifestVersion = 2; 73 const int kModernManifestVersion = 2;
74 const int kPEMOutputColumns = 65; 74 const int kPEMOutputColumns = 65;
75 75
76 const char kOverrideExtentUrlPatternFormat[] = "chrome://%s/*";
77
78 // The maximum number of commands (including page action/browser actions) an 76 // The maximum number of commands (including page action/browser actions) an
79 // extension can have. 77 // extension can have.
80 const size_t kMaxCommandsPerExtension = 4; 78 const size_t kMaxCommandsPerExtension = 4;
81 79
82 // KEY MARKERS 80 // KEY MARKERS
83 const char kKeyBeginHeaderMarker[] = "-----BEGIN"; 81 const char kKeyBeginHeaderMarker[] = "-----BEGIN";
84 const char kKeyBeginFooterMarker[] = "-----END"; 82 const char kKeyBeginFooterMarker[] = "-----END";
85 const char kKeyInfoEndMarker[] = "KEY-----"; 83 const char kKeyInfoEndMarker[] = "KEY-----";
86 const char kPublic[] = "PUBLIC"; 84 const char kPublic[] = "PUBLIC";
87 const char kPrivate[] = "PRIVATE"; 85 const char kPrivate[] = "PRIVATE";
(...skipping 1244 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 } 1330 }
1333 1331
1334 bool Extension::is_extension() const { 1332 bool Extension::is_extension() const {
1335 return manifest()->is_extension(); 1333 return manifest()->is_extension();
1336 } 1334 }
1337 1335
1338 bool Extension::can_be_incognito_enabled() const { 1336 bool Extension::can_be_incognito_enabled() const {
1339 return !is_platform_app(); 1337 return !is_platform_app();
1340 } 1338 }
1341 1339
1340 void Extension::AddWebExtentPattern(const URLPattern& pattern) {
1341 extent_.AddPattern(pattern);
1342 }
1343
1342 bool Extension::is_theme() const { 1344 bool Extension::is_theme() const {
1343 return manifest()->is_theme(); 1345 return manifest()->is_theme();
1344 } 1346 }
1345 1347
1346 GURL Extension::GetBackgroundURL() const { 1348 GURL Extension::GetBackgroundURL() const {
1347 if (background_scripts_.empty()) 1349 if (background_scripts_.empty())
1348 return background_url_; 1350 return background_url_;
1349 return GetResourceURL(extension_filenames::kGeneratedBackgroundPageFilename); 1351 return GetResourceURL(extension_filenames::kGeneratedBackgroundPageFilename);
1350 } 1352 }
1351 1353
(...skipping 1409 matching lines...) Expand 10 before | Expand all | Expand 10 after
2761 manifest_->GetBoolean(keys::kConvertedFromUserScript, 2763 manifest_->GetBoolean(keys::kConvertedFromUserScript,
2762 &converted_from_user_script_); 2764 &converted_from_user_script_);
2763 2765
2764 if (!LoadManifestHandlerFeatures(error) || 2766 if (!LoadManifestHandlerFeatures(error) ||
2765 !LoadInputComponents(*api_permissions, error) || 2767 !LoadInputComponents(*api_permissions, error) ||
2766 !LoadContentScripts(error) || 2768 !LoadContentScripts(error) ||
2767 !LoadPageAction(error) || 2769 !LoadPageAction(error) ||
2768 !LoadBrowserAction(error) || 2770 !LoadBrowserAction(error) ||
2769 !LoadSystemIndicator(api_permissions, error) || 2771 !LoadSystemIndicator(api_permissions, error) ||
2770 !LoadScriptBadge(error) || 2772 !LoadScriptBadge(error) ||
2771 !LoadChromeURLOverrides(error) ||
2772 !LoadTextToSpeechVoices(error) || 2773 !LoadTextToSpeechVoices(error) ||
2773 !LoadIncognitoMode(error) || 2774 !LoadIncognitoMode(error) ||
2774 !LoadFileHandlers(error) || 2775 !LoadFileHandlers(error) ||
2775 !LoadContentSecurityPolicy(error)) 2776 !LoadContentSecurityPolicy(error))
2776 return false; 2777 return false;
2777 2778
2778 return true; 2779 return true;
2779 } 2780 }
2780 2781
2781 bool Extension::LoadManifestHandlerFeatures(string16* error) { 2782 bool Extension::LoadManifestHandlerFeatures(string16* error) {
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
3090 return false; 3091 return false;
3091 } 3092 }
3092 3093
3093 // Because the manifest was successfully parsed, auto-grant the permission. 3094 // Because the manifest was successfully parsed, auto-grant the permission.
3094 // TODO(dewittj) Add this for all extension action APIs. 3095 // TODO(dewittj) Add this for all extension action APIs.
3095 api_permissions->insert(APIPermission::kSystemIndicator); 3096 api_permissions->insert(APIPermission::kSystemIndicator);
3096 3097
3097 return true; 3098 return true;
3098 } 3099 }
3099 3100
3100
3101 bool Extension::LoadChromeURLOverrides(string16* error) {
3102 if (!manifest_->HasKey(keys::kChromeURLOverrides))
3103 return true;
3104 DictionaryValue* overrides = NULL;
3105 if (!manifest_->GetDictionary(keys::kChromeURLOverrides, &overrides)) {
3106 *error = ASCIIToUTF16(errors::kInvalidChromeURLOverrides);
3107 return false;
3108 }
3109
3110 // Validate that the overrides are all strings
3111 for (DictionaryValue::key_iterator iter = overrides->begin_keys();
3112 iter != overrides->end_keys(); ++iter) {
3113 std::string page = *iter;
3114 std::string val;
3115 // Restrict override pages to a list of supported URLs.
3116 bool is_override = (page != chrome::kChromeUINewTabHost &&
3117 page != chrome::kChromeUIBookmarksHost &&
3118 page != chrome::kChromeUIHistoryHost);
3119 #if defined(OS_CHROMEOS)
3120 is_override = (is_override &&
3121 page != chrome::kChromeUIActivationMessageHost);
3122 #endif
3123 #if defined(FILE_MANAGER_EXTENSION)
3124 is_override = (is_override &&
3125 !(location() == COMPONENT &&
3126 page == chrome::kChromeUIFileManagerHost));
3127 #endif
3128
3129 if (is_override || !overrides->GetStringWithoutPathExpansion(*iter, &val)) {
3130 *error = ASCIIToUTF16(errors::kInvalidChromeURLOverrides);
3131 return false;
3132 }
3133 // Replace the entry with a fully qualified chrome-extension:// URL.
3134 chrome_url_overrides_[page] = GetResourceURL(val);
3135
3136 // For component extensions, add override URL to extent patterns.
3137 if (is_legacy_packaged_app() && location() == COMPONENT) {
3138 URLPattern pattern(URLPattern::SCHEME_CHROMEUI);
3139 std::string url = base::StringPrintf(kOverrideExtentUrlPatternFormat,
3140 page.c_str());
3141 if (pattern.Parse(url) != URLPattern::PARSE_SUCCESS) {
3142 *error = ErrorUtils::FormatErrorMessageUTF16(
3143 errors::kInvalidURLPatternError, url);
3144 return false;
3145 }
3146 extent_.AddPattern(pattern);
3147 }
3148 }
3149
3150 // An extension may override at most one page.
3151 if (overrides->size() > 1) {
3152 *error = ASCIIToUTF16(errors::kMultipleOverrides);
3153 return false;
3154 }
3155
3156 return true;
3157 }
3158
3159 bool Extension::LoadTextToSpeechVoices(string16* error) { 3101 bool Extension::LoadTextToSpeechVoices(string16* error) {
3160 if (!manifest_->HasKey(keys::kTtsEngine)) 3102 if (!manifest_->HasKey(keys::kTtsEngine))
3161 return true; 3103 return true;
3162 DictionaryValue* tts_dict = NULL; 3104 DictionaryValue* tts_dict = NULL;
3163 if (!manifest_->GetDictionary(keys::kTtsEngine, &tts_dict)) { 3105 if (!manifest_->GetDictionary(keys::kTtsEngine, &tts_dict)) {
3164 *error = ASCIIToUTF16(errors::kInvalidTts); 3106 *error = ASCIIToUTF16(errors::kInvalidTts);
3165 return false; 3107 return false;
3166 } 3108 }
3167 3109
3168 if (tts_dict->HasKey(keys::kTtsVoices)) { 3110 if (tts_dict->HasKey(keys::kTtsVoices)) {
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after
4007 3949
4008 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 3950 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
4009 const Extension* extension, 3951 const Extension* extension,
4010 const PermissionSet* permissions, 3952 const PermissionSet* permissions,
4011 Reason reason) 3953 Reason reason)
4012 : reason(reason), 3954 : reason(reason),
4013 extension(extension), 3955 extension(extension),
4014 permissions(permissions) {} 3956 permissions(permissions) {}
4015 3957
4016 } // namespace extensions 3958 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698