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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after 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(extensions::kExtensionKeyFileExtension)) |
212 continue; | 211 continue; |
213 | 212 |
214 std::string key_contents; | 213 std::string key_contents; |
215 if (!file_util::ReadFileToString(current, &key_contents)) { | 214 if (!file_util::ReadFileToString(current, &key_contents)) { |
216 // If we can't read the file, assume it's not a private key. | 215 // If we can't read the file, assume it's not a private key. |
217 continue; | 216 continue; |
218 } | 217 } |
219 std::string key_bytes; | 218 std::string key_bytes; |
220 if (!Extension::ParsePEMKeyBytes(key_contents, &key_bytes)) { | 219 if (!Extension::ParsePEMKeyBytes(key_contents, &key_bytes)) { |
221 // If we can't parse the key, assume it's ok too. | 220 // If we can't parse the key, assume it's ok too. |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 return base::FilePath(); | 566 return base::FilePath(); |
568 } | 567 } |
569 return temp_path; | 568 return temp_path; |
570 } | 569 } |
571 | 570 |
572 void DeleteFile(const base::FilePath& path, bool recursive) { | 571 void DeleteFile(const base::FilePath& path, bool recursive) { |
573 base::DeleteFile(path, recursive); | 572 base::DeleteFile(path, recursive); |
574 } | 573 } |
575 | 574 |
576 } // namespace extension_file_util | 575 } // namespace extension_file_util |
OLD | NEW |