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 |
| 2118 // TODO(jeremya): use a file-handler-specific data structure instead of web |
| 2119 // intents. |
| 2120 service.action = ASCIIToUTF16("http://webintents.org/view"); |
| 2121 |
| 2122 const ListValue* mime_types = NULL; |
| 2123 if (!handler_info.HasKey(keys::kFileHandlerTypes) || |
| 2124 !handler_info.GetList(keys::kFileHandlerTypes, &mime_types) || |
| 2125 mime_types->GetSize() == 0) { |
| 2126 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| 2127 errors::kInvalidFileHandlerType, handler_id); |
| 2128 return false; |
| 2129 } |
| 2130 |
| 2131 service.service_url = GetBackgroundURL(); |
| 2132 |
| 2133 if (handler_info.HasKey(keys::kFileHandlerTitle) && |
| 2134 !handler_info.GetString(keys::kFileHandlerTitle, &service.title)) { |
| 2135 *error = ASCIIToUTF16(errors::kInvalidFileHandlerTitle); |
| 2136 return false; |
| 2137 } |
| 2138 |
| 2139 for (size_t i = 0; i < mime_types->GetSize(); ++i) { |
| 2140 if (!mime_types->GetString(i, &service.type)) { |
| 2141 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| 2142 errors::kInvalidFileHandlerTypeElement, handler_id, |
| 2143 std::string(base::IntToString(i))); |
| 2144 return false; |
| 2145 } |
| 2146 intents_services_.push_back(service); |
| 2147 } |
| 2148 return true; |
| 2149 } |
| 2150 |
| 2151 bool Extension::LoadFileHandlers(string16* error) { |
| 2152 DCHECK(error); |
| 2153 |
| 2154 if (!manifest_->HasKey(keys::kFileHandlers)) |
| 2155 return true; |
| 2156 |
| 2157 DictionaryValue* all_handlers = NULL; |
| 2158 if (!manifest_->GetDictionary(keys::kFileHandlers, &all_handlers)) { |
| 2159 *error = ASCIIToUTF16(errors::kInvalidFileHandlers); |
| 2160 return false; |
| 2161 } |
| 2162 |
| 2163 for (DictionaryValue::key_iterator iter(all_handlers->begin_keys()); |
| 2164 iter != all_handlers->end_keys(); ++iter) { |
| 2165 // A file handler entry is a title and a list of MIME types to handle. |
| 2166 DictionaryValue* handler = NULL; |
| 2167 if (all_handlers->GetDictionaryWithoutPathExpansion(*iter, &handler)) { |
| 2168 if (!LoadFileHandler(*iter, *handler, error)) |
| 2169 return false; |
| 2170 } else { |
| 2171 *error = ASCIIToUTF16(errors::kInvalidFileHandlers); |
| 2172 return false; |
| 2173 } |
| 2174 } |
| 2175 return true; |
| 2176 } |
| 2177 |
2111 bool Extension::LoadExtensionFeatures(const APIPermissionSet& api_permissions, | 2178 bool Extension::LoadExtensionFeatures(const APIPermissionSet& api_permissions, |
2112 string16* error) { | 2179 string16* error) { |
2113 if (manifest_->HasKey(keys::kConvertedFromUserScript)) | 2180 if (manifest_->HasKey(keys::kConvertedFromUserScript)) |
2114 manifest_->GetBoolean(keys::kConvertedFromUserScript, | 2181 manifest_->GetBoolean(keys::kConvertedFromUserScript, |
2115 &converted_from_user_script_); | 2182 &converted_from_user_script_); |
2116 | 2183 |
2117 if (!LoadDevToolsPage(error) || | 2184 if (!LoadDevToolsPage(error) || |
2118 !LoadInputComponents(api_permissions, error) || | 2185 !LoadInputComponents(api_permissions, error) || |
2119 !LoadContentScripts(error) || | 2186 !LoadContentScripts(error) || |
2120 !LoadPageAction(error) || | 2187 !LoadPageAction(error) || |
2121 !LoadBrowserAction(error) || | 2188 !LoadBrowserAction(error) || |
2122 !LoadScriptBadge(error) || | 2189 !LoadScriptBadge(error) || |
2123 !LoadFileBrowserHandlers(error) || | 2190 !LoadFileBrowserHandlers(error) || |
2124 !LoadChromeURLOverrides(error) || | 2191 !LoadChromeURLOverrides(error) || |
2125 !LoadOmnibox(error) || | 2192 !LoadOmnibox(error) || |
2126 !LoadTextToSpeechVoices(error) || | 2193 !LoadTextToSpeechVoices(error) || |
2127 !LoadIncognitoMode(error) || | 2194 !LoadIncognitoMode(error) || |
| 2195 !LoadFileHandlers(error) || |
2128 !LoadContentSecurityPolicy(error)) | 2196 !LoadContentSecurityPolicy(error)) |
2129 return false; | 2197 return false; |
2130 | 2198 |
2131 return true; | 2199 return true; |
2132 } | 2200 } |
2133 | 2201 |
2134 bool Extension::LoadDevToolsPage(string16* error) { | 2202 bool Extension::LoadDevToolsPage(string16* error) { |
2135 if (!manifest_->HasKey(keys::kDevToolsPage)) | 2203 if (!manifest_->HasKey(keys::kDevToolsPage)) |
2136 return true; | 2204 return true; |
2137 std::string devtools_str; | 2205 std::string devtools_str; |
(...skipping 1863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4001 | 4069 |
4002 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 4070 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
4003 const Extension* extension, | 4071 const Extension* extension, |
4004 const PermissionSet* permissions, | 4072 const PermissionSet* permissions, |
4005 Reason reason) | 4073 Reason reason) |
4006 : reason(reason), | 4074 : reason(reason), |
4007 extension(extension), | 4075 extension(extension), |
4008 permissions(permissions) {} | 4076 permissions(permissions) {} |
4009 | 4077 |
4010 } // namespace extensions | 4078 } // namespace extensions |
OLD | NEW |