| 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 "chrome/common/extensions/api/storage/storage_schema_manifest_handler.h
" | 5 #include "chrome/common/extensions/api/storage/storage_schema_manifest_handler.h
" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 using extensions::manifest_keys::kStorageManagedSchema; | 26 using extensions::manifest_keys::kStorageManagedSchema; |
| 27 | 27 |
| 28 namespace extensions { | 28 namespace extensions { |
| 29 | 29 |
| 30 StorageSchemaManifestHandler::StorageSchemaManifestHandler() {} | 30 StorageSchemaManifestHandler::StorageSchemaManifestHandler() {} |
| 31 | 31 |
| 32 StorageSchemaManifestHandler::~StorageSchemaManifestHandler() {} | 32 StorageSchemaManifestHandler::~StorageSchemaManifestHandler() {} |
| 33 | 33 |
| 34 #if defined(ENABLE_CONFIGURATION_POLICY) | 34 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 35 // static | 35 // static |
| 36 scoped_ptr<policy::SchemaOwner> StorageSchemaManifestHandler::GetSchema( | 36 policy::Schema StorageSchemaManifestHandler::GetSchema( |
| 37 const Extension* extension, | 37 const Extension* extension, |
| 38 std::string* error) { | 38 std::string* error) { |
| 39 if (!extension->HasAPIPermission(APIPermission::kStorage)) { | 39 if (!extension->HasAPIPermission(APIPermission::kStorage)) { |
| 40 *error = base::StringPrintf("The storage permission is required to use %s", | 40 *error = base::StringPrintf("The storage permission is required to use %s", |
| 41 kStorageManagedSchema); | 41 kStorageManagedSchema); |
| 42 return scoped_ptr<policy::SchemaOwner>(); | 42 return policy::Schema(); |
| 43 } | 43 } |
| 44 std::string path; | 44 std::string path; |
| 45 extension->manifest()->GetString(kStorageManagedSchema, &path); | 45 extension->manifest()->GetString(kStorageManagedSchema, &path); |
| 46 base::FilePath file = base::FilePath::FromUTF8Unsafe(path); | 46 base::FilePath file = base::FilePath::FromUTF8Unsafe(path); |
| 47 if (file.IsAbsolute() || file.ReferencesParent()) { | 47 if (file.IsAbsolute() || file.ReferencesParent()) { |
| 48 *error = base::StringPrintf("%s must be a relative path without ..", | 48 *error = base::StringPrintf("%s must be a relative path without ..", |
| 49 kStorageManagedSchema); | 49 kStorageManagedSchema); |
| 50 return scoped_ptr<policy::SchemaOwner>(); | 50 return policy::Schema(); |
| 51 } | 51 } |
| 52 file = extension->path().AppendASCII(path); | 52 file = extension->path().AppendASCII(path); |
| 53 if (!base::PathExists(file)) { | 53 if (!base::PathExists(file)) { |
| 54 *error = | 54 *error = |
| 55 base::StringPrintf("File does not exist: %s", file.value().c_str()); | 55 base::StringPrintf("File does not exist: %s", file.value().c_str()); |
| 56 return scoped_ptr<policy::SchemaOwner>(); | 56 return policy::Schema(); |
| 57 } | 57 } |
| 58 std::string content; | 58 std::string content; |
| 59 if (!base::ReadFileToString(file, &content)) { | 59 if (!base::ReadFileToString(file, &content)) { |
| 60 *error = base::StringPrintf("Can't read %s", file.value().c_str()); | 60 *error = base::StringPrintf("Can't read %s", file.value().c_str()); |
| 61 return scoped_ptr<policy::SchemaOwner>(); | 61 return policy::Schema(); |
| 62 } | 62 } |
| 63 return policy::SchemaOwner::Parse(content, error); | 63 return policy::Schema::Parse(content, error); |
| 64 } | 64 } |
| 65 #endif | 65 #endif |
| 66 | 66 |
| 67 bool StorageSchemaManifestHandler::Parse(Extension* extension, | 67 bool StorageSchemaManifestHandler::Parse(Extension* extension, |
| 68 string16* error) { | 68 string16* error) { |
| 69 std::string path; | 69 std::string path; |
| 70 if (!extension->manifest()->GetString(kStorageManagedSchema, &path)) { | 70 if (!extension->manifest()->GetString(kStorageManagedSchema, &path)) { |
| 71 *error = ASCIIToUTF16( | 71 *error = ASCIIToUTF16( |
| 72 base::StringPrintf("%s must be a string", kStorageManagedSchema)); | 72 base::StringPrintf("%s must be a string", kStorageManagedSchema)); |
| 73 return false; | 73 return false; |
| 74 } | 74 } |
| 75 return true; | 75 return true; |
| 76 } | 76 } |
| 77 | 77 |
| 78 bool StorageSchemaManifestHandler::Validate( | 78 bool StorageSchemaManifestHandler::Validate( |
| 79 const Extension* extension, | 79 const Extension* extension, |
| 80 std::string* error, | 80 std::string* error, |
| 81 std::vector<InstallWarning>* warnings) const { | 81 std::vector<InstallWarning>* warnings) const { |
| 82 #if defined(ENABLE_CONFIGURATION_POLICY) | 82 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 83 return !!GetSchema(extension, error); | 83 return GetSchema(extension, error).valid(); |
| 84 #else | 84 #else |
| 85 return true; | 85 return true; |
| 86 #endif | 86 #endif |
| 87 } | 87 } |
| 88 | 88 |
| 89 const std::vector<std::string> StorageSchemaManifestHandler::Keys() const { | 89 const std::vector<std::string> StorageSchemaManifestHandler::Keys() const { |
| 90 return SingleKey(kStorageManagedSchema); | 90 return SingleKey(kStorageManagedSchema); |
| 91 } | 91 } |
| 92 | 92 |
| 93 } // namespace extensions | 93 } // namespace extensions |
| OLD | NEW |