| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "extensions/common/file_util.h" | 5 #include "extensions/common/file_util.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 } | 127 } |
| 128 | 128 |
| 129 scoped_refptr<Extension> LoadExtension(const base::FilePath& extension_path, | 129 scoped_refptr<Extension> LoadExtension(const base::FilePath& extension_path, |
| 130 const std::string& extension_id, | 130 const std::string& extension_id, |
| 131 Manifest::Location location, | 131 Manifest::Location location, |
| 132 int flags, | 132 int flags, |
| 133 std::string* error) { | 133 std::string* error) { |
| 134 scoped_ptr<base::DictionaryValue> manifest( | 134 scoped_ptr<base::DictionaryValue> manifest( |
| 135 LoadManifest(extension_path, error)); | 135 LoadManifest(extension_path, error)); |
| 136 if (!manifest.get()) | 136 if (!manifest.get()) |
| 137 return NULL; | 137 return nullptr; |
| 138 if (!extension_l10n_util::LocalizeExtension( | 138 if (!extension_l10n_util::LocalizeExtension( |
| 139 extension_path, manifest.get(), error)) { | 139 extension_path, manifest.get(), error)) { |
| 140 return NULL; | 140 return nullptr; |
| 141 } | 141 } |
| 142 | 142 |
| 143 scoped_refptr<Extension> extension(Extension::Create( | 143 scoped_refptr<Extension> extension(Extension::Create( |
| 144 extension_path, location, *manifest, flags, extension_id, error)); | 144 extension_path, location, *manifest, flags, extension_id, error)); |
| 145 if (!extension.get()) | 145 if (!extension.get()) |
| 146 return NULL; | 146 return nullptr; |
| 147 | 147 |
| 148 std::vector<InstallWarning> warnings; | 148 std::vector<InstallWarning> warnings; |
| 149 if (!ValidateExtension(extension.get(), error, &warnings)) | 149 if (!ValidateExtension(extension.get(), error, &warnings)) |
| 150 return NULL; | 150 return nullptr; |
| 151 extension->AddInstallWarnings(warnings); | 151 extension->AddInstallWarnings(warnings); |
| 152 | 152 |
| 153 return extension; | 153 return extension; |
| 154 } | 154 } |
| 155 | 155 |
| 156 base::DictionaryValue* LoadManifest(const base::FilePath& extension_path, | 156 base::DictionaryValue* LoadManifest(const base::FilePath& extension_path, |
| 157 std::string* error) { | 157 std::string* error) { |
| 158 return LoadManifest(extension_path, kManifestFilename, error); | 158 return LoadManifest(extension_path, kManifestFilename, error); |
| 159 } | 159 } |
| 160 | 160 |
| 161 base::DictionaryValue* LoadManifest( | 161 base::DictionaryValue* LoadManifest( |
| 162 const base::FilePath& extension_path, | 162 const base::FilePath& extension_path, |
| 163 const base::FilePath::CharType* manifest_filename, | 163 const base::FilePath::CharType* manifest_filename, |
| 164 std::string* error) { | 164 std::string* error) { |
| 165 base::FilePath manifest_path = extension_path.Append(manifest_filename); | 165 base::FilePath manifest_path = extension_path.Append(manifest_filename); |
| 166 if (!base::PathExists(manifest_path)) { | 166 if (!base::PathExists(manifest_path)) { |
| 167 *error = l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_UNREADABLE); | 167 *error = l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_UNREADABLE); |
| 168 return NULL; | 168 return nullptr; |
| 169 } | 169 } |
| 170 | 170 |
| 171 JSONFileValueSerializer serializer(manifest_path); | 171 JSONFileValueSerializer serializer(manifest_path); |
| 172 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, error)); | 172 scoped_ptr<base::Value> root(serializer.Deserialize(nullptr, error)); |
| 173 if (!root.get()) { | 173 if (!root.get()) { |
| 174 if (error->empty()) { | 174 if (error->empty()) { |
| 175 // If |error| is empty, than the file could not be read. | 175 // If |error| is empty, than the file could not be read. |
| 176 // It would be cleaner to have the JSON reader give a specific error | 176 // It would be cleaner to have the JSON reader give a specific error |
| 177 // in this case, but other code tests for a file error with | 177 // in this case, but other code tests for a file error with |
| 178 // error->empty(). For now, be consistent. | 178 // error->empty(). For now, be consistent. |
| 179 *error = l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_UNREADABLE); | 179 *error = l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_UNREADABLE); |
| 180 } else { | 180 } else { |
| 181 *error = base::StringPrintf( | 181 *error = base::StringPrintf( |
| 182 "%s %s", manifest_errors::kManifestParseError, error->c_str()); | 182 "%s %s", manifest_errors::kManifestParseError, error->c_str()); |
| 183 } | 183 } |
| 184 return NULL; | 184 return nullptr; |
| 185 } | 185 } |
| 186 | 186 |
| 187 if (!root->IsType(base::Value::TYPE_DICTIONARY)) { | 187 if (!root->IsType(base::Value::TYPE_DICTIONARY)) { |
| 188 *error = l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_INVALID); | 188 *error = l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_INVALID); |
| 189 return NULL; | 189 return nullptr; |
| 190 } | 190 } |
| 191 | 191 |
| 192 return static_cast<base::DictionaryValue*>(root.release()); | 192 return static_cast<base::DictionaryValue*>(root.release()); |
| 193 } | 193 } |
| 194 | 194 |
| 195 bool ValidateExtension(const Extension* extension, | 195 bool ValidateExtension(const Extension* extension, |
| 196 std::string* error, | 196 std::string* error, |
| 197 std::vector<InstallWarning>* warnings) { | 197 std::vector<InstallWarning>* warnings) { |
| 198 // Ask registered manifest handlers to validate their paths. | 198 // Ask registered manifest handlers to validate their paths. |
| 199 if (!ManifestHandler::ValidateExtension(extension, error, warnings)) | 199 if (!ManifestHandler::ValidateExtension(extension, error, warnings)) |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 } | 390 } |
| 391 | 391 |
| 392 MessageBundle* LoadMessageBundle( | 392 MessageBundle* LoadMessageBundle( |
| 393 const base::FilePath& extension_path, | 393 const base::FilePath& extension_path, |
| 394 const std::string& default_locale, | 394 const std::string& default_locale, |
| 395 std::string* error) { | 395 std::string* error) { |
| 396 error->clear(); | 396 error->clear(); |
| 397 // Load locale information if available. | 397 // Load locale information if available. |
| 398 base::FilePath locale_path = extension_path.Append(kLocaleFolder); | 398 base::FilePath locale_path = extension_path.Append(kLocaleFolder); |
| 399 if (!base::PathExists(locale_path)) | 399 if (!base::PathExists(locale_path)) |
| 400 return NULL; | 400 return nullptr; |
| 401 | 401 |
| 402 std::set<std::string> locales; | 402 std::set<std::string> locales; |
| 403 if (!extension_l10n_util::GetValidLocales(locale_path, &locales, error)) | 403 if (!extension_l10n_util::GetValidLocales(locale_path, &locales, error)) |
| 404 return NULL; | 404 return nullptr; |
| 405 | 405 |
| 406 if (default_locale.empty() || locales.find(default_locale) == locales.end()) { | 406 if (default_locale.empty() || locales.find(default_locale) == locales.end()) { |
| 407 *error = l10n_util::GetStringUTF8( | 407 *error = l10n_util::GetStringUTF8( |
| 408 IDS_EXTENSION_LOCALES_NO_DEFAULT_LOCALE_SPECIFIED); | 408 IDS_EXTENSION_LOCALES_NO_DEFAULT_LOCALE_SPECIFIED); |
| 409 return NULL; | 409 return nullptr; |
| 410 } | 410 } |
| 411 | 411 |
| 412 MessageBundle* message_bundle = | 412 MessageBundle* message_bundle = |
| 413 extension_l10n_util::LoadMessageCatalogs( | 413 extension_l10n_util::LoadMessageCatalogs( |
| 414 locale_path, | 414 locale_path, |
| 415 default_locale, | 415 default_locale, |
| 416 extension_l10n_util::CurrentLocaleOrDefault(), | 416 extension_l10n_util::CurrentLocaleOrDefault(), |
| 417 locales, | 417 locales, |
| 418 error); | 418 error); |
| 419 | 419 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 447 base::FilePath GetVerifiedContentsPath(const base::FilePath& extension_path) { | 447 base::FilePath GetVerifiedContentsPath(const base::FilePath& extension_path) { |
| 448 return extension_path.Append(kMetadataFolder) | 448 return extension_path.Append(kMetadataFolder) |
| 449 .Append(kVerifiedContentsFilename); | 449 .Append(kVerifiedContentsFilename); |
| 450 } | 450 } |
| 451 base::FilePath GetComputedHashesPath(const base::FilePath& extension_path) { | 451 base::FilePath GetComputedHashesPath(const base::FilePath& extension_path) { |
| 452 return extension_path.Append(kMetadataFolder).Append(kComputedHashesFilename); | 452 return extension_path.Append(kMetadataFolder).Append(kComputedHashesFilename); |
| 453 } | 453 } |
| 454 | 454 |
| 455 } // namespace file_util | 455 } // namespace file_util |
| 456 } // namespace extensions | 456 } // namespace extensions |
| OLD | NEW |