| OLD | NEW |
| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 89 |
| 90 const int kRSAKeySize = 1024; | 90 const int kRSAKeySize = 1024; |
| 91 | 91 |
| 92 const char kDefaultContentSecurityPolicy[] = | 92 const char kDefaultContentSecurityPolicy[] = |
| 93 "script-src 'self' chrome-extension-resource:; object-src 'self'"; | 93 "script-src 'self' chrome-extension-resource:; object-src 'self'"; |
| 94 | 94 |
| 95 #define PLATFORM_APP_LOCAL_CSP_SOURCES \ | 95 #define PLATFORM_APP_LOCAL_CSP_SOURCES \ |
| 96 "'self' blob: data: filesystem: chrome-extension-resource:" | 96 "'self' blob: data: filesystem: chrome-extension-resource:" |
| 97 const char kDefaultPlatformAppContentSecurityPolicy[] = | 97 const char kDefaultPlatformAppContentSecurityPolicy[] = |
| 98 // Platform apps can only use local resources by default. | 98 // Platform apps can only use local resources by default. |
| 99 "default-src 'self' chrome-extension-resource:;" | 99 "default-src 'self' chrome-extension-resource:;" |
| 100 // For remote resources, they can fetch them via XMLHttpRequest. | 100 // For remote resources, they can fetch them via XMLHttpRequest. |
| 101 "connect-src *;" | 101 "connect-src *;" |
| 102 // And serve them via blob:, data: or filesystem: URLs | 102 // And serve them via blob:, data: or filesystem: URLs |
| 103 "style-src " PLATFORM_APP_LOCAL_CSP_SOURCES " 'unsafe-inline';" | 103 "style-src " PLATFORM_APP_LOCAL_CSP_SOURCES " 'unsafe-inline';" |
| 104 "img-src " PLATFORM_APP_LOCAL_CSP_SOURCES ";" | 104 "img-src " PLATFORM_APP_LOCAL_CSP_SOURCES ";" |
| 105 "frame-src " PLATFORM_APP_LOCAL_CSP_SOURCES ";" | 105 "frame-src " PLATFORM_APP_LOCAL_CSP_SOURCES ";" |
| 106 "font-src " PLATFORM_APP_LOCAL_CSP_SOURCES ";" | 106 "font-src " PLATFORM_APP_LOCAL_CSP_SOURCES ";" |
| 107 // Media can be loaded from remote resources since: | 107 // Media can be loaded from remote resources since: |
| 108 // 1. <video> and <audio> have good fallback behavior when offline or under | 108 // 1. <video> and <audio> have good fallback behavior when offline or under |
| 109 // spotty connectivity. | 109 // spotty connectivity. |
| 110 // 2. Fetching via XHR and serving via blob: URLs currently does not allow | 110 // 2. Fetching via XHR and serving via blob: URLs currently does not allow |
| 111 // streaming or partial buffering. | 111 // streaming or partial buffering. |
| 112 "media-src *;"; | 112 "media-src *;"; |
| 113 | 113 |
| 114 const char kDefaultSandboxedPageContentSecurityPolicy[] = | 114 const char kDefaultSandboxedPageContentSecurityPolicy[] = |
| 115 "sandbox allow-scripts allow-forms"; | 115 "sandbox allow-scripts allow-forms"; |
| 116 | 116 |
| 117 // Converts a normal hexadecimal string into the alphabet used by extensions. | 117 // Converts a normal hexadecimal string into the alphabet used by extensions. |
| 118 // We use the characters 'a'-'p' instead of '0'-'f' to avoid ever having a | 118 // We use the characters 'a'-'p' instead of '0'-'f' to avoid ever having a |
| 119 // completely numeric host, since some software interprets that as an IP | 119 // completely numeric host, since some software interprets that as an IP |
| 120 // address. | 120 // address. |
| 121 static void ConvertHexadecimalToIDAlphabet(std::string* id) { | 121 static void ConvertHexadecimalToIDAlphabet(std::string* id) { |
| 122 for (size_t i = 0; i < id->size(); ++i) { | 122 for (size_t i = 0; i < id->size(); ++i) { |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 | 768 |
| 769 return true; | 769 return true; |
| 770 } | 770 } |
| 771 | 771 |
| 772 bool Extension::LoadGlobsHelper( | 772 bool Extension::LoadGlobsHelper( |
| 773 const DictionaryValue* content_script, | 773 const DictionaryValue* content_script, |
| 774 int content_script_index, | 774 int content_script_index, |
| 775 const char* globs_property_name, | 775 const char* globs_property_name, |
| 776 string16* error, | 776 string16* error, |
| 777 void(UserScript::*add_method)(const std::string& glob), | 777 void(UserScript::*add_method)(const std::string& glob), |
| 778 UserScript *instance) { | 778 UserScript* instance) { |
| 779 if (!content_script->HasKey(globs_property_name)) | 779 if (!content_script->HasKey(globs_property_name)) |
| 780 return true; // they are optional | 780 return true; // they are optional |
| 781 | 781 |
| 782 ListValue* list = NULL; | 782 ListValue* list = NULL; |
| 783 if (!content_script->GetList(globs_property_name, &list)) { | 783 if (!content_script->GetList(globs_property_name, &list)) { |
| 784 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 784 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| 785 errors::kInvalidGlobList, | 785 errors::kInvalidGlobList, |
| 786 base::IntToString(content_script_index), | 786 base::IntToString(content_script_index), |
| 787 globs_property_name); | 787 globs_property_name); |
| 788 return false; | 788 return false; |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1246 switches::kCloudPrintServiceURL)); | 1246 switches::kCloudPrintServiceURL)); |
| 1247 if (!cloud_print_service_url.is_empty()) { | 1247 if (!cloud_print_service_url.is_empty()) { |
| 1248 std::string path( | 1248 std::string path( |
| 1249 cloud_print_service_url.path() + "/enable_chrome_connector"); | 1249 cloud_print_service_url.path() + "/enable_chrome_connector"); |
| 1250 GURL::Replacements replacements; | 1250 GURL::Replacements replacements; |
| 1251 replacements.SetPathStr(path); | 1251 replacements.SetPathStr(path); |
| 1252 GURL cloud_print_enable_connector_url = | 1252 GURL cloud_print_enable_connector_url = |
| 1253 cloud_print_service_url.ReplaceComponents(replacements); | 1253 cloud_print_service_url.ReplaceComponents(replacements); |
| 1254 OverrideLaunchUrl(cloud_print_enable_connector_url); | 1254 OverrideLaunchUrl(cloud_print_enable_connector_url); |
| 1255 } | 1255 } |
| 1256 } else if (id() == extension_misc::kChromeAppId) { |
| 1257 // Override launch url to new tab. |
| 1258 launch_web_url_ = chrome::kChromeUINewTabURL; |
| 1259 extent_.ClearPatterns(); |
| 1256 } | 1260 } |
| 1257 | 1261 |
| 1258 return true; | 1262 return true; |
| 1259 } | 1263 } |
| 1260 | 1264 |
| 1261 bool Extension::LoadLaunchContainer(string16* error) { | 1265 bool Extension::LoadLaunchContainer(string16* error) { |
| 1262 Value* temp = NULL; | 1266 Value* temp = NULL; |
| 1263 if (!manifest_->Get(keys::kLaunchContainer, &temp)) | 1267 if (!manifest_->Get(keys::kLaunchContainer, &temp)) |
| 1264 return true; | 1268 return true; |
| 1265 | 1269 |
| (...skipping 2428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3694 | 3698 |
| 3695 bool Extension::ShouldDisplayInLauncher() const { | 3699 bool Extension::ShouldDisplayInLauncher() const { |
| 3696 // All apps should be displayed on the NTP except for the Cloud Print App. | 3700 // All apps should be displayed on the NTP except for the Cloud Print App. |
| 3697 return is_app() && id() != extension_misc::kCloudPrintAppId; | 3701 return is_app() && id() != extension_misc::kCloudPrintAppId; |
| 3698 } | 3702 } |
| 3699 | 3703 |
| 3700 bool Extension::InstallWarning::operator==(const InstallWarning& other) const { | 3704 bool Extension::InstallWarning::operator==(const InstallWarning& other) const { |
| 3701 return format == other.format && message == other.message; | 3705 return format == other.format && message == other.message; |
| 3702 } | 3706 } |
| 3703 | 3707 |
| 3704 void PrintTo(const Extension::InstallWarning& warning, ::std::ostream* os){ | 3708 void PrintTo(const Extension::InstallWarning& warning, ::std::ostream* os) { |
| 3705 *os << "InstallWarning("; | 3709 *os << "InstallWarning("; |
| 3706 switch (warning.format) { | 3710 switch (warning.format) { |
| 3707 case Extension::InstallWarning::FORMAT_TEXT: | 3711 case Extension::InstallWarning::FORMAT_TEXT: |
| 3708 *os << "FORMAT_TEXT, \""; | 3712 *os << "FORMAT_TEXT, \""; |
| 3709 break; | 3713 break; |
| 3710 case Extension::InstallWarning::FORMAT_HTML: | 3714 case Extension::InstallWarning::FORMAT_HTML: |
| 3711 *os << "FORMAT_HTML, \""; | 3715 *os << "FORMAT_HTML, \""; |
| 3712 break; | 3716 break; |
| 3713 } | 3717 } |
| 3714 // This is just for test error messages, so no need to escape '"' | 3718 // This is just for test error messages, so no need to escape '"' |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3850 | 3854 |
| 3851 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3855 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
| 3852 const Extension* extension, | 3856 const Extension* extension, |
| 3853 const ExtensionPermissionSet* permissions, | 3857 const ExtensionPermissionSet* permissions, |
| 3854 Reason reason) | 3858 Reason reason) |
| 3855 : reason(reason), | 3859 : reason(reason), |
| 3856 extension(extension), | 3860 extension(extension), |
| 3857 permissions(permissions) {} | 3861 permissions(permissions) {} |
| 3858 | 3862 |
| 3859 } // namespace extensions | 3863 } // namespace extensions |
| OLD | NEW |