OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/extensions/api/storage/storage_schema_manifest_handler. h" | |
6 | |
7 #include <string> | |
8 #include <vector> | |
9 | |
10 #include "base/file_util.h" | |
11 #include "base/files/file_path.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/string16.h" | |
14 #include "base/stringprintf.h" | |
15 #include "base/utf_string_conversions.h" | |
16 #include "chrome/browser/policy/policy_schema.h" | |
17 #include "chrome/common/extensions/extension.h" | |
18 #include "chrome/common/extensions/extension_manifest_constants.h" | |
19 #include "chrome/common/extensions/manifest.h" | |
20 #include "chrome/common/extensions/permissions/api_permission.h" | |
21 #include "extensions/common/install_warning.h" | |
22 | |
23 using extension_manifest_keys::kStorageManagedSchema; | |
24 | |
25 namespace extensions { | |
26 | |
27 StorageSchemaManifestHandler::StorageSchemaManifestHandler() {} | |
28 | |
29 StorageSchemaManifestHandler::~StorageSchemaManifestHandler() {} | |
30 | |
31 // static | |
32 scoped_ptr<policy::PolicySchema> StorageSchemaManifestHandler::GetSchema( | |
33 const Extension* extension, | |
34 std::string* error) { | |
not at google - send to devlin
2013/05/25 00:50:57
DCHECK(FILE)?
Joao da Silva
2013/05/27 12:13:11
The file operations (file_util::*) eventually hit
| |
35 if (!extension->HasAPIPermission(APIPermission::kStorage)) { | |
36 *error = base::StringPrintf("The storage permission is required to use %s", | |
37 kStorageManagedSchema); | |
38 return scoped_ptr<policy::PolicySchema>(); | |
39 } | |
40 std::string path; | |
41 extension->manifest()->GetString(kStorageManagedSchema, &path); | |
42 base::FilePath file = base::FilePath::FromUTF8Unsafe(path); | |
43 if (file.IsAbsolute() || file.ReferencesParent()) { | |
44 *error = base::StringPrintf("%s must be a relative path without ..", | |
45 kStorageManagedSchema); | |
46 return scoped_ptr<policy::PolicySchema>(); | |
47 } | |
48 file = extension->path().AppendASCII(path); | |
49 if (!file_util::PathExists(file)) { | |
50 *error = | |
51 base::StringPrintf("File does not exist: %s", file.value().c_str()); | |
52 return scoped_ptr<policy::PolicySchema>(); | |
53 } | |
54 std::string content; | |
55 if (!file_util::ReadFileToString(file, &content)) { | |
56 *error = base::StringPrintf("Can't read %s", file.value().c_str()); | |
57 return scoped_ptr<policy::PolicySchema>(); | |
58 } | |
59 return policy::PolicySchema::Parse(content, error); | |
60 } | |
61 | |
62 bool StorageSchemaManifestHandler::Parse(Extension* extension, | |
63 string16* error) { | |
64 std::string path; | |
65 if (!extension->manifest()->GetString(kStorageManagedSchema, &path)) { | |
66 *error = ASCIIToUTF16( | |
67 base::StringPrintf("%s must be a string", kStorageManagedSchema)); | |
68 return false; | |
69 } | |
70 return true; | |
71 } | |
72 | |
73 bool StorageSchemaManifestHandler::Validate( | |
74 const Extension* extension, | |
75 std::string* error, | |
76 std::vector<InstallWarning>* warnings) const { | |
77 return !!GetSchema(extension, error); | |
78 } | |
79 | |
80 const std::vector<std::string> StorageSchemaManifestHandler::Keys() const { | |
81 return SingleKey(kStorageManagedSchema); | |
82 } | |
83 | |
84 } // namespace extensions | |
OLD | NEW |