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