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 namespace extensions { | |
24 | |
25 namespace { | |
26 | |
27 const char kMissingPermission[] = | |
28 "The storage permission is required to use storage.managed_schema"; | |
29 const char kInvalidValue[] = | |
30 "Invalid value for storage.managed_schema - must be a string"; | |
not at google - send to devlin
2013/05/23 16:56:18
"storage.managed_schema must be a string"
Joao da Silva
2013/05/24 21:31:49
Done.
| |
31 const char kInvalidPath[] = | |
32 "storage.managed_schema must be a relative path without .."; | |
33 | |
34 } // namespace | |
35 | |
36 StorageSchemaManifestHandler::StorageSchemaManifestHandler() {} | |
37 | |
38 StorageSchemaManifestHandler::~StorageSchemaManifestHandler() {} | |
39 | |
40 bool StorageSchemaManifestHandler::Parse(Extension* extension, | |
41 string16* error) { | |
42 std::string path; | |
43 if (!extension->manifest()->GetString( | |
44 extension_manifest_keys::kStorageManagedSchema, &path)) { | |
45 *error = ASCIIToUTF16(kInvalidValue); | |
46 return false; | |
47 } | |
48 return true; | |
49 } | |
50 | |
51 bool StorageSchemaManifestHandler::Validate( | |
52 const Extension* extension, | |
53 std::string* error, | |
54 std::vector<InstallWarning>* warnings) const { | |
55 if (!extension->HasAPIPermission(APIPermission::kStorage)) { | |
not at google - send to devlin
2013/05/23 16:56:18
we should make the storage permission implied by t
Joao da Silva
2013/05/24 21:31:49
I've cc'ed myself on that issue, I'll update this
| |
56 *error = kMissingPermission; | |
57 return false; | |
58 } | |
59 std::string path; | |
60 extension->manifest()->GetString( | |
61 extension_manifest_keys::kStorageManagedSchema, &path); | |
62 base::FilePath file = base::FilePath::FromUTF8Unsafe(path); | |
63 if (file.IsAbsolute() || file.ReferencesParent()) { | |
64 *error = kInvalidPath; | |
65 return false; | |
66 } | |
67 file = extension->path().AppendASCII(path); | |
68 if (!file_util::PathExists(file)) { | |
69 *error = | |
70 base::StringPrintf("File does not exist: %s", file.value().c_str()); | |
not at google - send to devlin
2013/05/23 16:56:18
"%s referenced by storage.managed_schema does not
Joao da Silva
2013/05/24 21:31:49
Done.
| |
71 return false; | |
72 } | |
73 std::string content; | |
74 if (!file_util::ReadFileToString(file, &content)) { | |
75 *error = base::StringPrintf("Can't read %s", file.value().c_str()); | |
76 return false; | |
77 } | |
78 scoped_ptr<policy::PolicySchema> schema = | |
79 policy::PolicySchema::Parse(content, error); | |
80 return !!schema; | |
81 } | |
82 | |
83 const std::vector<std::string> StorageSchemaManifestHandler::Keys() const { | |
84 return SingleKey(extension_manifest_keys::kStorageManagedSchema); | |
85 } | |
86 | |
87 } // namespace extensions | |
OLD | NEW |