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

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: patch-rebased 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 using extensions::csp_validator::ContentSecurityPolicyIsSandboxed; 65 using extensions::csp_validator::ContentSecurityPolicyIsSandboxed;
66 using extensions::csp_validator::ContentSecurityPolicyIsSecure; 66 using extensions::csp_validator::ContentSecurityPolicyIsSecure;
67 67
68 namespace extensions { 68 namespace extensions {
69 69
70 namespace { 70 namespace {
71 71
72 const int kModernManifestVersion = 2; 72 const int kModernManifestVersion = 2;
73 const int kPEMOutputColumns = 65; 73 const int kPEMOutputColumns = 65;
74 74
75 const char kOverrideExtentUrlPatternFormat[] = "chrome://%s/*";
76
77 // The maximum number of commands (including page action/browser actions) an 75 // The maximum number of commands (including page action/browser actions) an
78 // extension can have. 76 // extension can have.
79 const size_t kMaxCommandsPerExtension = 4; 77 const size_t kMaxCommandsPerExtension = 4;
80 78
81 // KEY MARKERS 79 // KEY MARKERS
82 const char kKeyBeginHeaderMarker[] = "-----BEGIN"; 80 const char kKeyBeginHeaderMarker[] = "-----BEGIN";
83 const char kKeyBeginFooterMarker[] = "-----END"; 81 const char kKeyBeginFooterMarker[] = "-----END";
84 const char kKeyInfoEndMarker[] = "KEY-----"; 82 const char kKeyInfoEndMarker[] = "KEY-----";
85 const char kPublic[] = "PUBLIC"; 83 const char kPublic[] = "PUBLIC";
86 const char kPrivate[] = "PRIVATE"; 84 const char kPrivate[] = "PRIVATE";
(...skipping 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1319 } 1317 }
1320 1318
1321 bool Extension::is_extension() const { 1319 bool Extension::is_extension() const {
1322 return manifest()->is_extension(); 1320 return manifest()->is_extension();
1323 } 1321 }
1324 1322
1325 bool Extension::can_be_incognito_enabled() const { 1323 bool Extension::can_be_incognito_enabled() const {
1326 return !is_platform_app(); 1324 return !is_platform_app();
1327 } 1325 }
1328 1326
1327 void Extension::AddWebExtentPattern(const URLPattern& pattern) {
1328 extent_.AddPattern(pattern);
1329 }
1330
1329 bool Extension::is_theme() const { 1331 bool Extension::is_theme() const {
1330 return manifest()->is_theme(); 1332 return manifest()->is_theme();
1331 } 1333 }
1332 1334
1333 ExtensionResource Extension::GetContentPackSiteList() const { 1335 ExtensionResource Extension::GetContentPackSiteList() const {
1334 if (content_pack_site_list_.empty()) 1336 if (content_pack_site_list_.empty())
1335 return ExtensionResource(); 1337 return ExtensionResource();
1336 1338
1337 return GetResource(content_pack_site_list_); 1339 return GetResource(content_pack_site_list_);
1338 } 1340 }
(...skipping 1296 matching lines...) Expand 10 before | Expand all | Expand 10 after
2635 if (manifest_->HasKey(keys::kConvertedFromUserScript)) 2637 if (manifest_->HasKey(keys::kConvertedFromUserScript))
2636 manifest_->GetBoolean(keys::kConvertedFromUserScript, 2638 manifest_->GetBoolean(keys::kConvertedFromUserScript,
2637 &converted_from_user_script_); 2639 &converted_from_user_script_);
2638 2640
2639 if (!LoadManifestHandlerFeatures(error) || 2641 if (!LoadManifestHandlerFeatures(error) ||
2640 !LoadContentScripts(error) || 2642 !LoadContentScripts(error) ||
2641 !LoadPageAction(error) || 2643 !LoadPageAction(error) ||
2642 !LoadBrowserAction(error) || 2644 !LoadBrowserAction(error) ||
2643 !LoadSystemIndicator(api_permissions, error) || 2645 !LoadSystemIndicator(api_permissions, error) ||
2644 !LoadScriptBadge(error) || 2646 !LoadScriptBadge(error) ||
2645 !LoadChromeURLOverrides(error) ||
2646 !LoadIncognitoMode(error) || 2647 !LoadIncognitoMode(error) ||
2647 !LoadFileHandlers(error) || 2648 !LoadFileHandlers(error) ||
2648 !LoadContentSecurityPolicy(error)) 2649 !LoadContentSecurityPolicy(error))
2649 return false; 2650 return false;
2650 2651
2651 return true; 2652 return true;
2652 } 2653 }
2653 2654
2654 bool Extension::LoadManifestHandlerFeatures(string16* error) { 2655 bool Extension::LoadManifestHandlerFeatures(string16* error) {
2655 std::vector<std::string> keys = ManifestHandler::GetKeys(); 2656 std::vector<std::string> keys = ManifestHandler::GetKeys();
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
2830 return false; 2831 return false;
2831 } 2832 }
2832 2833
2833 // Because the manifest was successfully parsed, auto-grant the permission. 2834 // Because the manifest was successfully parsed, auto-grant the permission.
2834 // TODO(dewittj) Add this for all extension action APIs. 2835 // TODO(dewittj) Add this for all extension action APIs.
2835 api_permissions->insert(APIPermission::kSystemIndicator); 2836 api_permissions->insert(APIPermission::kSystemIndicator);
2836 2837
2837 return true; 2838 return true;
2838 } 2839 }
2839 2840
2840
2841 bool Extension::LoadChromeURLOverrides(string16* error) {
2842 if (!manifest_->HasKey(keys::kChromeURLOverrides))
2843 return true;
2844 DictionaryValue* overrides = NULL;
2845 if (!manifest_->GetDictionary(keys::kChromeURLOverrides, &overrides)) {
2846 *error = ASCIIToUTF16(errors::kInvalidChromeURLOverrides);
2847 return false;
2848 }
2849
2850 // Validate that the overrides are all strings
2851 for (DictionaryValue::key_iterator iter = overrides->begin_keys();
2852 iter != overrides->end_keys(); ++iter) {
2853 std::string page = *iter;
2854 std::string val;
2855 // Restrict override pages to a list of supported URLs.
2856 bool is_override = (page != chrome::kChromeUINewTabHost &&
2857 page != chrome::kChromeUIBookmarksHost &&
2858 page != chrome::kChromeUIHistoryHost);
2859 #if defined(OS_CHROMEOS)
2860 is_override = (is_override &&
2861 page != chrome::kChromeUIActivationMessageHost);
2862 #endif
2863 #if defined(FILE_MANAGER_EXTENSION)
2864 is_override = (is_override &&
2865 !(location() == COMPONENT &&
2866 page == chrome::kChromeUIFileManagerHost));
2867 #endif
2868
2869 if (is_override || !overrides->GetStringWithoutPathExpansion(*iter, &val)) {
2870 *error = ASCIIToUTF16(errors::kInvalidChromeURLOverrides);
2871 return false;
2872 }
2873 // Replace the entry with a fully qualified chrome-extension:// URL.
2874 chrome_url_overrides_[page] = GetResourceURL(val);
2875
2876 // For component extensions, add override URL to extent patterns.
2877 if (is_legacy_packaged_app() && location() == COMPONENT) {
2878 URLPattern pattern(URLPattern::SCHEME_CHROMEUI);
2879 std::string url = base::StringPrintf(kOverrideExtentUrlPatternFormat,
2880 page.c_str());
2881 if (pattern.Parse(url) != URLPattern::PARSE_SUCCESS) {
2882 *error = ErrorUtils::FormatErrorMessageUTF16(
2883 errors::kInvalidURLPatternError, url);
2884 return false;
2885 }
2886 extent_.AddPattern(pattern);
2887 }
2888 }
2889
2890 // An extension may override at most one page.
2891 if (overrides->size() > 1) {
2892 *error = ASCIIToUTF16(errors::kMultipleOverrides);
2893 return false;
2894 }
2895
2896 return true;
2897 }
2898
2899 bool Extension::LoadIncognitoMode(string16* error) { 2841 bool Extension::LoadIncognitoMode(string16* error) {
2900 // Apps default to split mode, extensions default to spanning. 2842 // Apps default to split mode, extensions default to spanning.
2901 incognito_split_mode_ = is_app(); 2843 incognito_split_mode_ = is_app();
2902 if (!manifest_->HasKey(keys::kIncognito)) 2844 if (!manifest_->HasKey(keys::kIncognito))
2903 return true; 2845 return true;
2904 std::string value; 2846 std::string value;
2905 if (!manifest_->GetString(keys::kIncognito, &value)) { 2847 if (!manifest_->GetString(keys::kIncognito, &value)) {
2906 *error = ASCIIToUTF16(errors::kInvalidIncognitoBehavior); 2848 *error = ASCIIToUTF16(errors::kInvalidIncognitoBehavior);
2907 return false; 2849 return false;
2908 } 2850 }
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
3662 3604
3663 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 3605 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
3664 const Extension* extension, 3606 const Extension* extension,
3665 const PermissionSet* permissions, 3607 const PermissionSet* permissions,
3666 Reason reason) 3608 Reason reason)
3667 : reason(reason), 3609 : reason(reason),
3668 extension(extension), 3610 extension(extension),
3669 permissions(permissions) {} 3611 permissions(permissions) {}
3670 3612
3671 } // namespace extensions 3613 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/manifest_tests/extension_manifests_override_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698