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" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
14 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
18 #include "base/string16.h" | |
19 #include "base/string_number_conversions.h" | 18 #include "base/string_number_conversions.h" |
20 #include "base/string_piece.h" | 19 #include "base/string_piece.h" |
21 #include "base/string_util.h" | 20 #include "base/string_util.h" |
21 #include "base/string16.h" | |
22 #include "base/stringprintf.h" | 22 #include "base/stringprintf.h" |
23 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
24 #include "base/values.h" | 24 #include "base/values.h" |
25 #include "base/version.h" | 25 #include "base/version.h" |
26 #include "chrome/common/chrome_constants.h" | 26 #include "chrome/common/chrome_constants.h" |
27 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
28 #include "chrome/common/chrome_version_info.h" | 28 #include "chrome/common/chrome_version_info.h" |
29 #include "chrome/common/extensions/csp_validator.h" | 29 #include "chrome/common/extensions/csp_validator.h" |
30 #include "chrome/common/extensions/extension_error_utils.h" | 30 #include "chrome/common/extensions/extension_error_utils.h" |
31 #include "chrome/common/extensions/extension_manifest_constants.h" | 31 #include "chrome/common/extensions/extension_manifest_constants.h" |
32 #include "chrome/common/extensions/extension_resource.h" | 32 #include "chrome/common/extensions/extension_resource.h" |
33 #include "chrome/common/extensions/feature_switch.h" | 33 #include "chrome/common/extensions/feature_switch.h" |
34 #include "chrome/common/extensions/features/feature.h" | 34 #include "chrome/common/extensions/features/feature.h" |
35 #include "chrome/common/extensions/features/simple_feature_provider.h" | 35 #include "chrome/common/extensions/features/simple_feature_provider.h" |
36 #include "chrome/common/extensions/file_browser_handler.h" | 36 #include "chrome/common/extensions/file_browser_handler.h" |
37 #include "chrome/common/extensions/manifest.h" | 37 #include "chrome/common/extensions/manifest.h" |
38 #include "chrome/common/extensions/permissions/permission_set.h" | |
38 #include "chrome/common/extensions/permissions/permissions_info.h" | 39 #include "chrome/common/extensions/permissions/permissions_info.h" |
39 #include "chrome/common/extensions/permissions/permission_set.h" | |
40 #include "chrome/common/extensions/url_pattern_set.h" | 40 #include "chrome/common/extensions/url_pattern_set.h" |
41 #include "chrome/common/extensions/user_script.h" | 41 #include "chrome/common/extensions/user_script.h" |
42 #include "chrome/common/url_constants.h" | 42 #include "chrome/common/url_constants.h" |
43 #include "crypto/sha2.h" | 43 #include "crypto/sha2.h" |
44 #include "googleurl/src/url_util.h" | 44 #include "googleurl/src/url_util.h" |
45 #include "grit/chromium_strings.h" | 45 #include "grit/chromium_strings.h" |
46 #include "grit/theme_resources.h" | 46 #include "grit/theme_resources.h" |
47 #include "third_party/skia/include/core/SkBitmap.h" | 47 #include "third_party/skia/include/core/SkBitmap.h" |
48 #include "ui/base/l10n/l10n_util.h" | 48 #include "ui/base/l10n/l10n_util.h" |
49 #include "ui/base/resource/resource_bundle.h" | 49 #include "ui/base/resource/resource_bundle.h" |
(...skipping 2051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2101 *error = ASCIIToUTF16(errors::kInvalidIntent); | 2101 *error = ASCIIToUTF16(errors::kInvalidIntent); |
2102 return false; | 2102 return false; |
2103 } | 2103 } |
2104 if (!LoadWebIntentAction(*iter, *one_service, error)) | 2104 if (!LoadWebIntentAction(*iter, *one_service, error)) |
2105 return false; | 2105 return false; |
2106 } | 2106 } |
2107 } | 2107 } |
2108 return true; | 2108 return true; |
2109 } | 2109 } |
2110 | 2110 |
2111 bool Extension::LoadFileHandler(const std::string& handler_id, | |
2112 const DictionaryValue& handler_info, | |
2113 string16* error) { | |
2114 DCHECK(error); | |
2115 DCHECK(is_platform_app()); | |
2116 webkit_glue::WebIntentServiceData service; | |
2117 std::string value; | |
2118 | |
2119 service.action = ASCIIToUTF16("http://webintents.org/view"); | |
benwells
2012/11/01 04:00:55
Add a TODO to create new fields to map this to and
jeremya
2012/11/01 04:21:41
Done.
| |
2120 | |
2121 const ListValue* mime_types = NULL; | |
2122 if (!handler_info.HasKey(keys::kFileHandlerTypes) || | |
2123 !handler_info.GetList(keys::kFileHandlerTypes, &mime_types) || | |
2124 mime_types->GetSize() == 0) { | |
2125 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | |
2126 errors::kInvalidFileHandlerType, handler_id); | |
2127 return false; | |
2128 } | |
2129 | |
2130 service.service_url = GetBackgroundURL(); | |
2131 | |
2132 if (handler_info.HasKey(keys::kIntentTitle) && | |
2133 !handler_info.GetString(keys::kFileHandlerTitle, &service.title)) { | |
2134 *error = ASCIIToUTF16(errors::kInvalidFileHandlerTitle); | |
2135 return false; | |
2136 } | |
2137 | |
2138 for (size_t i = 0; i < mime_types->GetSize(); ++i) { | |
2139 if (!mime_types->GetString(i, &service.type)) { | |
2140 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | |
2141 errors::kInvalidFileHandlerTypeElement, handler_id, | |
2142 std::string(base::IntToString(i))); | |
2143 return false; | |
2144 } | |
2145 intents_services_.push_back(service); | |
2146 } | |
2147 return true; | |
2148 } | |
2149 | |
2150 bool Extension::LoadFileHandlers(string16* error) { | |
2151 DCHECK(error); | |
2152 | |
2153 if (!manifest_->HasKey(keys::kFileHandlers)) | |
2154 return true; | |
2155 | |
2156 if (!is_platform_app()) { | |
2157 // XXX isn't this handled somehow by _manifest_features.json? | |
benwells
2012/11/01 04:00:55
Should be. Feel free to remove.
jeremya
2012/11/01 04:21:41
Done.
| |
2158 *error = ASCIIToUTF16(errors::kInvalidFileHandlers); | |
2159 return false; | |
2160 } | |
2161 | |
2162 DictionaryValue* all_handlers = NULL; | |
2163 if (!manifest_->GetDictionary(keys::kFileHandlers, &all_handlers)) { | |
2164 *error = ASCIIToUTF16(errors::kInvalidFileHandlers); | |
2165 return false; | |
2166 } | |
2167 | |
2168 for (DictionaryValue::key_iterator iter(all_handlers->begin_keys()); | |
2169 iter != all_handlers->end_keys(); ++iter) { | |
2170 // A file handler entry is a title, optional icons, and either a list of | |
benwells
2012/11/01 04:00:55
This isn't yet true, let's make the comment match
jeremya
2012/11/01 04:21:41
Done.
| |
2171 // MIME types to handle or a list of file extensions (or both). | |
2172 DictionaryValue* handler = NULL; | |
2173 if (all_handlers->GetDictionaryWithoutPathExpansion(*iter, &handler)) { | |
2174 if (!LoadFileHandler(*iter, *handler, error)) | |
2175 return false; | |
2176 } else { | |
2177 *error = ASCIIToUTF16(errors::kInvalidIntent); | |
2178 return false; | |
2179 } | |
2180 } | |
2181 return true; | |
2182 } | |
2183 | |
2111 bool Extension::LoadExtensionFeatures(const APIPermissionSet& api_permissions, | 2184 bool Extension::LoadExtensionFeatures(const APIPermissionSet& api_permissions, |
2112 string16* error) { | 2185 string16* error) { |
2113 if (manifest_->HasKey(keys::kConvertedFromUserScript)) | 2186 if (manifest_->HasKey(keys::kConvertedFromUserScript)) |
2114 manifest_->GetBoolean(keys::kConvertedFromUserScript, | 2187 manifest_->GetBoolean(keys::kConvertedFromUserScript, |
2115 &converted_from_user_script_); | 2188 &converted_from_user_script_); |
2116 | 2189 |
2117 if (!LoadDevToolsPage(error) || | 2190 if (!LoadDevToolsPage(error) || |
2118 !LoadInputComponents(api_permissions, error) || | 2191 !LoadInputComponents(api_permissions, error) || |
2119 !LoadContentScripts(error) || | 2192 !LoadContentScripts(error) || |
2120 !LoadPageAction(error) || | 2193 !LoadPageAction(error) || |
2121 !LoadBrowserAction(error) || | 2194 !LoadBrowserAction(error) || |
2122 !LoadScriptBadge(error) || | 2195 !LoadScriptBadge(error) || |
2123 !LoadFileBrowserHandlers(error) || | 2196 !LoadFileBrowserHandlers(error) || |
2124 !LoadChromeURLOverrides(error) || | 2197 !LoadChromeURLOverrides(error) || |
2125 !LoadOmnibox(error) || | 2198 !LoadOmnibox(error) || |
2126 !LoadTextToSpeechVoices(error) || | 2199 !LoadTextToSpeechVoices(error) || |
2127 !LoadIncognitoMode(error) || | 2200 !LoadIncognitoMode(error) || |
2201 !LoadFileHandlers(error) || | |
2128 !LoadContentSecurityPolicy(error)) | 2202 !LoadContentSecurityPolicy(error)) |
2129 return false; | 2203 return false; |
2130 | 2204 |
2131 return true; | 2205 return true; |
2132 } | 2206 } |
2133 | 2207 |
2134 bool Extension::LoadDevToolsPage(string16* error) { | 2208 bool Extension::LoadDevToolsPage(string16* error) { |
2135 if (!manifest_->HasKey(keys::kDevToolsPage)) | 2209 if (!manifest_->HasKey(keys::kDevToolsPage)) |
2136 return true; | 2210 return true; |
2137 std::string devtools_str; | 2211 std::string devtools_str; |
(...skipping 1863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4001 | 4075 |
4002 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 4076 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
4003 const Extension* extension, | 4077 const Extension* extension, |
4004 const PermissionSet* permissions, | 4078 const PermissionSet* permissions, |
4005 Reason reason) | 4079 Reason reason) |
4006 : reason(reason), | 4080 : reason(reason), |
4007 extension(extension), | 4081 extension(extension), |
4008 permissions(permissions) {} | 4082 permissions(permissions) {} |
4009 | 4083 |
4010 } // namespace extensions | 4084 } // namespace extensions |
OLD | NEW |