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