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

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: Created 8 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
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 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1340 } 1338 }
1341 1339
1342 bool Extension::is_extension() const { 1340 bool Extension::is_extension() const {
1343 return manifest()->is_extension(); 1341 return manifest()->is_extension();
1344 } 1342 }
1345 1343
1346 bool Extension::can_be_incognito_enabled() const { 1344 bool Extension::can_be_incognito_enabled() const {
1347 return !is_platform_app(); 1345 return !is_platform_app();
1348 } 1346 }
1349 1347
1348 void Extension::AddWebExtentPattern(const URLPattern& pattern) {
1349 extent_.AddPattern(pattern);
1350 }
1351
1350 bool Extension::is_theme() const { 1352 bool Extension::is_theme() const {
1351 return manifest()->is_theme(); 1353 return manifest()->is_theme();
1352 } 1354 }
1353 1355
1354 GURL Extension::GetBackgroundURL() const { 1356 GURL Extension::GetBackgroundURL() const {
1355 if (background_scripts_.empty()) 1357 if (background_scripts_.empty())
1356 return background_url_; 1358 return background_url_;
1357 return GetResourceURL(extension_filenames::kGeneratedBackgroundPageFilename); 1359 return GetResourceURL(extension_filenames::kGeneratedBackgroundPageFilename);
1358 } 1360 }
1359 1361
(...skipping 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after
2792 2794
2793 if (!LoadManifestHandlerFeatures(error) || 2795 if (!LoadManifestHandlerFeatures(error) ||
2794 !LoadDevToolsPage(error) || 2796 !LoadDevToolsPage(error) ||
2795 !LoadInputComponents(*api_permissions, error) || 2797 !LoadInputComponents(*api_permissions, error) ||
2796 !LoadContentScripts(error) || 2798 !LoadContentScripts(error) ||
2797 !LoadPageAction(error) || 2799 !LoadPageAction(error) ||
2798 !LoadBrowserAction(error) || 2800 !LoadBrowserAction(error) ||
2799 !LoadSystemIndicator(api_permissions, error) || 2801 !LoadSystemIndicator(api_permissions, error) ||
2800 !LoadScriptBadge(error) || 2802 !LoadScriptBadge(error) ||
2801 !LoadFileBrowserHandlers(error) || 2803 !LoadFileBrowserHandlers(error) ||
2802 !LoadChromeURLOverrides(error) ||
2803 !LoadTextToSpeechVoices(error) || 2804 !LoadTextToSpeechVoices(error) ||
2804 !LoadIncognitoMode(error) || 2805 !LoadIncognitoMode(error) ||
2805 !LoadFileHandlers(error) || 2806 !LoadFileHandlers(error) ||
2806 !LoadContentSecurityPolicy(error)) 2807 !LoadContentSecurityPolicy(error))
2807 return false; 2808 return false;
2808 2809
2809 return true; 2810 return true;
2810 } 2811 }
2811 2812
2812 bool Extension::LoadManifestHandlerFeatures(string16* error) { 2813 bool Extension::LoadManifestHandlerFeatures(string16* error) {
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
3308 default_icon.empty()) { 3309 default_icon.empty()) {
3309 *error = ASCIIToUTF16(errors::kInvalidPageActionIconPath); 3310 *error = ASCIIToUTF16(errors::kInvalidPageActionIconPath);
3310 return NULL; 3311 return NULL;
3311 } 3312 }
3312 result->set_icon_path(default_icon); 3313 result->set_icon_path(default_icon);
3313 } 3314 }
3314 3315
3315 return result.release(); 3316 return result.release();
3316 } 3317 }
3317 3318
3318 bool Extension::LoadChromeURLOverrides(string16* error) {
3319 if (!manifest_->HasKey(keys::kChromeURLOverrides))
3320 return true;
3321 DictionaryValue* overrides = NULL;
3322 if (!manifest_->GetDictionary(keys::kChromeURLOverrides, &overrides)) {
3323 *error = ASCIIToUTF16(errors::kInvalidChromeURLOverrides);
3324 return false;
3325 }
3326
3327 // Validate that the overrides are all strings
3328 for (DictionaryValue::key_iterator iter = overrides->begin_keys();
3329 iter != overrides->end_keys(); ++iter) {
3330 std::string page = *iter;
3331 std::string val;
3332 // Restrict override pages to a list of supported URLs.
3333 bool is_override = (page != chrome::kChromeUINewTabHost &&
3334 page != chrome::kChromeUIBookmarksHost &&
3335 page != chrome::kChromeUIHistoryHost);
3336 #if defined(OS_CHROMEOS)
3337 is_override = (is_override &&
3338 page != chrome::kChromeUIActivationMessageHost);
3339 #endif
3340 #if defined(FILE_MANAGER_EXTENSION)
3341 is_override = (is_override &&
3342 !(location() == COMPONENT &&
3343 page == chrome::kChromeUIFileManagerHost));
3344 #endif
3345
3346 if (is_override || !overrides->GetStringWithoutPathExpansion(*iter, &val)) {
3347 *error = ASCIIToUTF16(errors::kInvalidChromeURLOverrides);
3348 return false;
3349 }
3350 // Replace the entry with a fully qualified chrome-extension:// URL.
3351 chrome_url_overrides_[page] = GetResourceURL(val);
3352
3353 // For component extensions, add override URL to extent patterns.
3354 if (is_legacy_packaged_app() && location() == COMPONENT) {
3355 URLPattern pattern(URLPattern::SCHEME_CHROMEUI);
3356 std::string url = base::StringPrintf(kOverrideExtentUrlPatternFormat,
3357 page.c_str());
3358 if (pattern.Parse(url) != URLPattern::PARSE_SUCCESS) {
3359 *error = ErrorUtils::FormatErrorMessageUTF16(
3360 errors::kInvalidURLPatternError, url);
3361 return false;
3362 }
3363 extent_.AddPattern(pattern);
3364 }
3365 }
3366
3367 // An extension may override at most one page.
3368 if (overrides->size() > 1) {
3369 *error = ASCIIToUTF16(errors::kMultipleOverrides);
3370 return false;
3371 }
3372
3373 return true;
3374 }
3375
3376 bool Extension::LoadTextToSpeechVoices(string16* error) { 3319 bool Extension::LoadTextToSpeechVoices(string16* error) {
3377 if (!manifest_->HasKey(keys::kTtsEngine)) 3320 if (!manifest_->HasKey(keys::kTtsEngine))
3378 return true; 3321 return true;
3379 DictionaryValue* tts_dict = NULL; 3322 DictionaryValue* tts_dict = NULL;
3380 if (!manifest_->GetDictionary(keys::kTtsEngine, &tts_dict)) { 3323 if (!manifest_->GetDictionary(keys::kTtsEngine, &tts_dict)) {
3381 *error = ASCIIToUTF16(errors::kInvalidTts); 3324 *error = ASCIIToUTF16(errors::kInvalidTts);
3382 return false; 3325 return false;
3383 } 3326 }
3384 3327
3385 if (tts_dict->HasKey(keys::kTtsVoices)) { 3328 if (tts_dict->HasKey(keys::kTtsVoices)) {
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after
4224 4167
4225 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 4168 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
4226 const Extension* extension, 4169 const Extension* extension,
4227 const PermissionSet* permissions, 4170 const PermissionSet* permissions,
4228 Reason reason) 4171 Reason reason)
4229 : reason(reason), 4172 : reason(reason),
4230 extension(extension), 4173 extension(extension),
4231 permissions(permissions) {} 4174 permissions(permissions) {}
4232 4175
4233 } // namespace extensions 4176 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698