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_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
13 #include "base/json/json_file_value_serializer.h" | 13 #include "base/json/json_file_value_serializer.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
17 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" |
18 #include "base/threading/thread_restrictions.h" | 18 #include "base/threading/thread_restrictions.h" |
19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
20 #include "chrome/common/chrome_constants.h" | 20 #include "chrome/common/chrome_constants.h" |
21 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
22 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
23 #include "chrome/common/extensions/extension_icon_set.h" | 23 #include "chrome/common/extensions/extension_icon_set.h" |
24 #include "chrome/common/extensions/extension_l10n_util.h" | 24 #include "chrome/common/extensions/extension_l10n_util.h" |
25 #include "chrome/common/extensions/extension_manifest_constants.h" | 25 #include "chrome/common/extensions/extension_manifest_constants.h" |
26 #include "chrome/common/extensions/extension_messages.h" | 26 #include "chrome/common/extensions/extension_messages.h" |
27 #include "chrome/common/extensions/extension_resource.h" | |
28 #include "chrome/common/extensions/manifest.h" | 27 #include "chrome/common/extensions/manifest.h" |
29 #include "chrome/common/extensions/manifest_handler.h" | 28 #include "chrome/common/extensions/manifest_handler.h" |
30 #include "chrome/common/extensions/message_bundle.h" | 29 #include "chrome/common/extensions/message_bundle.h" |
| 30 #include "extensions/common/constants.h" |
| 31 #include "extensions/common/extension_resource.h" |
31 #include "extensions/common/install_warning.h" | 32 #include "extensions/common/install_warning.h" |
32 #include "grit/generated_resources.h" | 33 #include "grit/generated_resources.h" |
33 #include "net/base/escape.h" | 34 #include "net/base/escape.h" |
34 #include "net/base/file_stream.h" | 35 #include "net/base/file_stream.h" |
35 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
36 | 37 |
37 using extensions::Extension; | 38 using extensions::Extension; |
| 39 using extensions::ExtensionResource; |
38 using extensions::Manifest; | 40 using extensions::Manifest; |
39 | 41 |
40 namespace errors = extension_manifest_errors; | 42 namespace errors = extension_manifest_errors; |
41 | 43 |
42 namespace { | 44 namespace { |
43 | 45 |
44 const base::FilePath::CharType kTempDirectoryName[] = FILE_PATH_LITERAL("Temp"); | 46 const base::FilePath::CharType kTempDirectoryName[] = FILE_PATH_LITERAL("Temp"); |
45 | 47 |
46 } // namespace | 48 } // namespace |
47 | 49 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 if (!ValidateExtension(extension.get(), error, &warnings)) | 152 if (!ValidateExtension(extension.get(), error, &warnings)) |
151 return NULL; | 153 return NULL; |
152 extension->AddInstallWarnings(warnings); | 154 extension->AddInstallWarnings(warnings); |
153 | 155 |
154 return extension; | 156 return extension; |
155 } | 157 } |
156 | 158 |
157 DictionaryValue* LoadManifest(const base::FilePath& extension_path, | 159 DictionaryValue* LoadManifest(const base::FilePath& extension_path, |
158 std::string* error) { | 160 std::string* error) { |
159 base::FilePath manifest_path = | 161 base::FilePath manifest_path = |
160 extension_path.Append(Extension::kManifestFilename); | 162 extension_path.Append(extensions::kManifestFilename); |
161 if (!file_util::PathExists(manifest_path)) { | 163 if (!file_util::PathExists(manifest_path)) { |
162 *error = l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_UNREADABLE); | 164 *error = l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_UNREADABLE); |
163 return NULL; | 165 return NULL; |
164 } | 166 } |
165 | 167 |
166 JSONFileValueSerializer serializer(manifest_path); | 168 JSONFileValueSerializer serializer(manifest_path); |
167 scoped_ptr<Value> root(serializer.Deserialize(NULL, error)); | 169 scoped_ptr<Value> root(serializer.Deserialize(NULL, error)); |
168 if (!root.get()) { | 170 if (!root.get()) { |
169 if (error->empty()) { | 171 if (error->empty()) { |
170 // If |error| is empty, than the file could not be read. | 172 // If |error| is empty, than the file could not be read. |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 } | 396 } |
395 } | 397 } |
396 } | 398 } |
397 | 399 |
398 extensions::MessageBundle* LoadMessageBundle( | 400 extensions::MessageBundle* LoadMessageBundle( |
399 const base::FilePath& extension_path, | 401 const base::FilePath& extension_path, |
400 const std::string& default_locale, | 402 const std::string& default_locale, |
401 std::string* error) { | 403 std::string* error) { |
402 error->clear(); | 404 error->clear(); |
403 // Load locale information if available. | 405 // Load locale information if available. |
404 base::FilePath locale_path = extension_path.Append( | 406 base::FilePath locale_path = extension_path.Append(extensions::kLocaleFolder); |
405 Extension::kLocaleFolder); | |
406 if (!file_util::PathExists(locale_path)) | 407 if (!file_util::PathExists(locale_path)) |
407 return NULL; | 408 return NULL; |
408 | 409 |
409 std::set<std::string> locales; | 410 std::set<std::string> locales; |
410 if (!extension_l10n_util::GetValidLocales(locale_path, &locales, error)) | 411 if (!extension_l10n_util::GetValidLocales(locale_path, &locales, error)) |
411 return NULL; | 412 return NULL; |
412 | 413 |
413 if (default_locale.empty() || | 414 if (default_locale.empty() || |
414 locales.find(default_locale) == locales.end()) { | 415 locales.find(default_locale) == locales.end()) { |
415 *error = l10n_util::GetStringUTF8( | 416 *error = l10n_util::GetStringUTF8( |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 return false; | 472 return false; |
472 } | 473 } |
473 | 474 |
474 return true; | 475 return true; |
475 } | 476 } |
476 | 477 |
477 bool CheckForIllegalFilenames(const base::FilePath& extension_path, | 478 bool CheckForIllegalFilenames(const base::FilePath& extension_path, |
478 std::string* error) { | 479 std::string* error) { |
479 // Reserved underscore names. | 480 // Reserved underscore names. |
480 static const base::FilePath::CharType* reserved_names[] = { | 481 static const base::FilePath::CharType* reserved_names[] = { |
481 Extension::kLocaleFolder, | 482 extensions::kLocaleFolder, |
482 Extension::kPlatformSpecificFolder, | 483 extensions::kPlatformSpecificFolder, |
483 FILE_PATH_LITERAL("__MACOSX"), | 484 FILE_PATH_LITERAL("__MACOSX"), |
484 }; | 485 }; |
485 CR_DEFINE_STATIC_LOCAL( | 486 CR_DEFINE_STATIC_LOCAL( |
486 std::set<base::FilePath::StringType>, reserved_underscore_names, | 487 std::set<base::FilePath::StringType>, reserved_underscore_names, |
487 (reserved_names, reserved_names + arraysize(reserved_names))); | 488 (reserved_names, reserved_names + arraysize(reserved_names))); |
488 | 489 |
489 // Enumerate all files and directories in the extension root. | 490 // Enumerate all files and directories in the extension root. |
490 // There is a problem when using pattern "_*" with FileEnumerator, so we have | 491 // There is a problem when using pattern "_*" with FileEnumerator, so we have |
491 // to cheat with find_first_of and match all. | 492 // to cheat with find_first_of and match all. |
492 const int kFilesAndDirectories = | 493 const int kFilesAndDirectories = |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 return base::FilePath(); | 594 return base::FilePath(); |
594 } | 595 } |
595 return temp_path; | 596 return temp_path; |
596 } | 597 } |
597 | 598 |
598 void DeleteFile(const base::FilePath& path, bool recursive) { | 599 void DeleteFile(const base::FilePath& path, bool recursive) { |
599 file_util::Delete(path, recursive); | 600 file_util::Delete(path, recursive); |
600 } | 601 } |
601 | 602 |
602 } // namespace extension_file_util | 603 } // namespace extension_file_util |
OLD | NEW |