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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 namespace file_util { | 45 namespace file_util { |
46 namespace { | 46 namespace { |
47 | 47 |
48 enum SafeInstallationFlag { | 48 enum SafeInstallationFlag { |
49 DEFAULT, // Default case, controlled by a field trial. | 49 DEFAULT, // Default case, controlled by a field trial. |
50 DISABLED, // Safe installation is disabled. | 50 DISABLED, // Safe installation is disabled. |
51 ENABLED, // Safe installation is enabled. | 51 ENABLED, // Safe installation is enabled. |
52 }; | 52 }; |
53 SafeInstallationFlag g_use_safe_installation = DEFAULT; | 53 SafeInstallationFlag g_use_safe_installation = DEFAULT; |
54 | 54 |
| 55 // Returns true if the given file path exists and is not zero-length. |
| 56 bool ValidateFilePath(const base::FilePath& path) { |
| 57 int64 size = 0; |
| 58 if (!base::PathExists(path) || |
| 59 !base::GetFileSize(path, &size) || |
| 60 size == 0) { |
| 61 return false; |
| 62 } |
| 63 |
| 64 return true; |
| 65 } |
| 66 |
55 // Returns true if the extension installation should flush all files and the | 67 // Returns true if the extension installation should flush all files and the |
56 // directory. | 68 // directory. |
57 bool UseSafeInstallation() { | 69 bool UseSafeInstallation() { |
58 if (g_use_safe_installation == DEFAULT) { | 70 if (g_use_safe_installation == DEFAULT) { |
59 const char kFieldTrialName[] = "ExtensionUseSafeInstallation"; | 71 const char kFieldTrialName[] = "ExtensionUseSafeInstallation"; |
60 const char kEnable[] = "Enable"; | 72 const char kEnable[] = "Enable"; |
61 return base::FieldTrialList::FindFullName(kFieldTrialName) == kEnable; | 73 return base::FieldTrialList::FindFullName(kFieldTrialName) == kEnable; |
62 } | 74 } |
63 | 75 |
64 return g_use_safe_installation == ENABLED; | 76 return g_use_safe_installation == ENABLED; |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 } | 264 } |
253 | 265 |
254 if (!root->IsType(base::Value::TYPE_DICTIONARY)) { | 266 if (!root->IsType(base::Value::TYPE_DICTIONARY)) { |
255 *error = l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_INVALID); | 267 *error = l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_INVALID); |
256 return NULL; | 268 return NULL; |
257 } | 269 } |
258 | 270 |
259 return base::DictionaryValue::From(std::move(root)); | 271 return base::DictionaryValue::From(std::move(root)); |
260 } | 272 } |
261 | 273 |
262 bool ValidateFilePath(const base::FilePath& path) { | |
263 int64 size = 0; | |
264 return base::PathExists(path) && base::GetFileSize(path, &size) && size != 0; | |
265 } | |
266 | |
267 bool ValidateExtension(const Extension* extension, | 274 bool ValidateExtension(const Extension* extension, |
268 std::string* error, | 275 std::string* error, |
269 std::vector<InstallWarning>* warnings) { | 276 std::vector<InstallWarning>* warnings) { |
270 // Ask registered manifest handlers to validate their paths. | 277 // Ask registered manifest handlers to validate their paths. |
271 if (!ManifestHandler::ValidateExtension(extension, error, warnings)) | 278 if (!ManifestHandler::ValidateExtension(extension, error, warnings)) |
272 return false; | 279 return false; |
273 | 280 |
274 // Check children of extension root to see if any of them start with _ and is | 281 // Check children of extension root to see if any of them start with _ and is |
275 // not on the reserved list. We only warn, and do not block the loading of the | 282 // not on the reserved list. We only warn, and do not block the loading of the |
276 // extension. | 283 // extension. |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 base::FilePath GetVerifiedContentsPath(const base::FilePath& extension_path) { | 618 base::FilePath GetVerifiedContentsPath(const base::FilePath& extension_path) { |
612 return extension_path.Append(kMetadataFolder) | 619 return extension_path.Append(kMetadataFolder) |
613 .Append(kVerifiedContentsFilename); | 620 .Append(kVerifiedContentsFilename); |
614 } | 621 } |
615 base::FilePath GetComputedHashesPath(const base::FilePath& extension_path) { | 622 base::FilePath GetComputedHashesPath(const base::FilePath& extension_path) { |
616 return extension_path.Append(kMetadataFolder).Append(kComputedHashesFilename); | 623 return extension_path.Append(kMetadataFolder).Append(kComputedHashesFilename); |
617 } | 624 } |
618 | 625 |
619 } // namespace file_util | 626 } // namespace file_util |
620 } // namespace extensions | 627 } // namespace extensions |
OLD | NEW |