OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "chrome/common/extensions/extension_file_util.h" | 5 #include "chrome/common/extensions/extension_file_util.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/files/file_enumerator.h" | 11 #include "base/files/file_enumerator.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
14 #include "base/json/json_file_value_serializer.h" | 14 #include "base/json/json_file_value_serializer.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
20 #include "base/threading/thread_restrictions.h" | 20 #include "base/threading/thread_restrictions.h" |
21 #include "chrome/common/chrome_constants.h" | |
22 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
23 #include "chrome/common/extensions/api/extension_action/action_info.h" | 22 #include "chrome/common/extensions/api/extension_action/action_info.h" |
24 #include "chrome/common/extensions/extension.h" | 23 #include "chrome/common/extensions/extension.h" |
25 #include "chrome/common/extensions/extension_icon_set.h" | 24 #include "chrome/common/extensions/extension_icon_set.h" |
26 #include "chrome/common/extensions/extension_l10n_util.h" | 25 #include "chrome/common/extensions/extension_l10n_util.h" |
27 #include "chrome/common/extensions/extension_manifest_constants.h" | 26 #include "chrome/common/extensions/extension_manifest_constants.h" |
28 #include "chrome/common/extensions/extension_messages.h" | 27 #include "chrome/common/extensions/extension_messages.h" |
29 #include "chrome/common/extensions/manifest.h" | 28 #include "chrome/common/extensions/manifest.h" |
30 #include "chrome/common/extensions/manifest_handler.h" | 29 #include "chrome/common/extensions/manifest_handler.h" |
31 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" | 30 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 if (!ValidateExtension(extension.get(), error, &warnings)) | 161 if (!ValidateExtension(extension.get(), error, &warnings)) |
163 return NULL; | 162 return NULL; |
164 extension->AddInstallWarnings(warnings); | 163 extension->AddInstallWarnings(warnings); |
165 | 164 |
166 return extension; | 165 return extension; |
167 } | 166 } |
168 | 167 |
169 base::DictionaryValue* LoadManifest(const base::FilePath& extension_path, | 168 base::DictionaryValue* LoadManifest(const base::FilePath& extension_path, |
170 std::string* error) { | 169 std::string* error) { |
171 base::FilePath manifest_path = | 170 base::FilePath manifest_path = |
172 extension_path.Append(extensions::kManifestFilename); | 171 extension_path.Append(extensions::filenames::kManifestFilename); |
173 if (!base::PathExists(manifest_path)) { | 172 if (!base::PathExists(manifest_path)) { |
174 *error = l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_UNREADABLE); | 173 *error = l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_UNREADABLE); |
175 return NULL; | 174 return NULL; |
176 } | 175 } |
177 | 176 |
178 JSONFileValueSerializer serializer(manifest_path); | 177 JSONFileValueSerializer serializer(manifest_path); |
179 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, error)); | 178 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, error)); |
180 if (!root.get()) { | 179 if (!root.get()) { |
181 if (error->empty()) { | 180 if (error->empty()) { |
182 // If |error| is empty, than the file could not be read. | 181 // If |error| is empty, than the file could not be read. |
(...skipping 18 matching lines...) Expand all Loading... |
201 } | 200 } |
202 | 201 |
203 std::vector<base::FilePath> FindPrivateKeyFiles( | 202 std::vector<base::FilePath> FindPrivateKeyFiles( |
204 const base::FilePath& extension_dir) { | 203 const base::FilePath& extension_dir) { |
205 std::vector<base::FilePath> result; | 204 std::vector<base::FilePath> result; |
206 // Pattern matching only works at the root level, so filter manually. | 205 // Pattern matching only works at the root level, so filter manually. |
207 base::FileEnumerator traversal(extension_dir, /*recursive=*/true, | 206 base::FileEnumerator traversal(extension_dir, /*recursive=*/true, |
208 base::FileEnumerator::FILES); | 207 base::FileEnumerator::FILES); |
209 for (base::FilePath current = traversal.Next(); !current.empty(); | 208 for (base::FilePath current = traversal.Next(); !current.empty(); |
210 current = traversal.Next()) { | 209 current = traversal.Next()) { |
211 if (!current.MatchesExtension(chrome::kExtensionKeyFileExtension)) | 210 if (!current.MatchesExtension( |
| 211 extensions::filenames::kExtensionKeyFileExtension)) |
212 continue; | 212 continue; |
213 | 213 |
214 std::string key_contents; | 214 std::string key_contents; |
215 if (!file_util::ReadFileToString(current, &key_contents)) { | 215 if (!file_util::ReadFileToString(current, &key_contents)) { |
216 // If we can't read the file, assume it's not a private key. | 216 // If we can't read the file, assume it's not a private key. |
217 continue; | 217 continue; |
218 } | 218 } |
219 std::string key_bytes; | 219 std::string key_bytes; |
220 if (!Extension::ParsePEMKeyBytes(key_contents, &key_bytes)) { | 220 if (!Extension::ParsePEMKeyBytes(key_contents, &key_bytes)) { |
221 // If we can't parse the key, assume it's ok too. | 221 // If we can't parse the key, assume it's ok too. |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 } | 401 } |
402 } | 402 } |
403 } | 403 } |
404 | 404 |
405 extensions::MessageBundle* LoadMessageBundle( | 405 extensions::MessageBundle* LoadMessageBundle( |
406 const base::FilePath& extension_path, | 406 const base::FilePath& extension_path, |
407 const std::string& default_locale, | 407 const std::string& default_locale, |
408 std::string* error) { | 408 std::string* error) { |
409 error->clear(); | 409 error->clear(); |
410 // Load locale information if available. | 410 // Load locale information if available. |
411 base::FilePath locale_path = extension_path.Append(extensions::kLocaleFolder); | 411 base::FilePath locale_path = |
| 412 extension_path.Append(extensions::filenames::kLocaleFolder); |
412 if (!base::PathExists(locale_path)) | 413 if (!base::PathExists(locale_path)) |
413 return NULL; | 414 return NULL; |
414 | 415 |
415 std::set<std::string> locales; | 416 std::set<std::string> locales; |
416 if (!extension_l10n_util::GetValidLocales(locale_path, &locales, error)) | 417 if (!extension_l10n_util::GetValidLocales(locale_path, &locales, error)) |
417 return NULL; | 418 return NULL; |
418 | 419 |
419 if (default_locale.empty() || | 420 if (default_locale.empty() || |
420 locales.find(default_locale) == locales.end()) { | 421 locales.find(default_locale) == locales.end()) { |
421 *error = l10n_util::GetStringUTF8( | 422 *error = l10n_util::GetStringUTF8( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 returnValue->insert( | 455 returnValue->insert( |
455 std::make_pair(extensions::MessageBundle::kExtensionIdKey, extension_id)); | 456 std::make_pair(extensions::MessageBundle::kExtensionIdKey, extension_id)); |
456 | 457 |
457 return returnValue; | 458 return returnValue; |
458 } | 459 } |
459 | 460 |
460 bool CheckForIllegalFilenames(const base::FilePath& extension_path, | 461 bool CheckForIllegalFilenames(const base::FilePath& extension_path, |
461 std::string* error) { | 462 std::string* error) { |
462 // Reserved underscore names. | 463 // Reserved underscore names. |
463 static const base::FilePath::CharType* reserved_names[] = { | 464 static const base::FilePath::CharType* reserved_names[] = { |
464 extensions::kLocaleFolder, | 465 extensions::filenames::kLocaleFolder, |
465 extensions::kPlatformSpecificFolder, | 466 extensions::filenames::kPlatformSpecificFolder, |
466 FILE_PATH_LITERAL("__MACOSX"), | 467 FILE_PATH_LITERAL("__MACOSX"), |
467 }; | 468 }; |
468 CR_DEFINE_STATIC_LOCAL( | 469 CR_DEFINE_STATIC_LOCAL( |
469 std::set<base::FilePath::StringType>, reserved_underscore_names, | 470 std::set<base::FilePath::StringType>, reserved_underscore_names, |
470 (reserved_names, reserved_names + arraysize(reserved_names))); | 471 (reserved_names, reserved_names + arraysize(reserved_names))); |
471 | 472 |
472 // Enumerate all files and directories in the extension root. | 473 // Enumerate all files and directories in the extension root. |
473 // There is a problem when using pattern "_*" with FileEnumerator, so we have | 474 // There is a problem when using pattern "_*" with FileEnumerator, so we have |
474 // to cheat with find_first_of and match all. | 475 // to cheat with find_first_of and match all. |
475 const int kFilesAndDirectories = | 476 const int kFilesAndDirectories = |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 return base::FilePath(); | 568 return base::FilePath(); |
568 } | 569 } |
569 return temp_path; | 570 return temp_path; |
570 } | 571 } |
571 | 572 |
572 void DeleteFile(const base::FilePath& path, bool recursive) { | 573 void DeleteFile(const base::FilePath& path, bool recursive) { |
573 base::DeleteFile(path, recursive); | 574 base::DeleteFile(path, recursive); |
574 } | 575 } |
575 | 576 |
576 } // namespace extension_file_util | 577 } // namespace extension_file_util |
OLD | NEW |