Chromium Code Reviews| 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/policy/policy_manifest_handler.h" | |
| 6 | |
| 7 #include "base/file_util.h" | |
| 8 #include "base/files/file_path.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/string16.h" | |
| 11 #include "base/stringprintf.h" | |
| 12 #include "base/utf_string_conversions.h" | |
| 13 #include "chrome/browser/policy/policy_schema.h" | |
| 14 #include "chrome/common/extensions/extension.h" | |
| 15 #include "chrome/common/extensions/extension_manifest_constants.h" | |
| 16 #include "chrome/common/extensions/manifest.h" | |
| 17 #include "chrome/common/extensions/permissions/api_permission.h" | |
| 18 | |
| 19 namespace policy { | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 const char kInvalidPermission[] = | |
|
Mattias Nissler (ping if slow)
2013/05/15 10:37:39
nit: kMissingPermission would be more accurate.
Joao da Silva
2013/05/19 13:21:35
Done.
| |
| 24 "The storage permission is required to use storage.managed_schema"; | |
| 25 const char kInvalidValue[] = | |
| 26 "Invalid value for storage.managed_schema - must be a string"; | |
| 27 const char kInvalidPath[] = "storage.managed_schema must be a relative path"; | |
| 28 | |
| 29 } // namespace | |
| 30 | |
| 31 PolicyManifestHandler::PolicyManifestHandler() {} | |
| 32 | |
| 33 PolicyManifestHandler::~PolicyManifestHandler() {} | |
| 34 | |
| 35 bool PolicyManifestHandler::Parse(extensions::Extension* extension, | |
| 36 string16* error) { | |
| 37 std::string path; | |
| 38 if (!extension->manifest()->GetString( | |
| 39 extension_manifest_keys::kStorageManagedSchema, &path)) { | |
| 40 *error = ASCIIToUTF16(kInvalidValue); | |
| 41 return false; | |
| 42 } | |
| 43 return true; | |
| 44 } | |
| 45 | |
| 46 bool PolicyManifestHandler::Validate( | |
| 47 const extensions::Extension* extension, | |
| 48 std::string* error, | |
| 49 std::vector<extensions::InstallWarning>* warnings) const { | |
| 50 if (!extension->HasAPIPermission(extensions::APIPermission::kStorage)) { | |
| 51 *error = kInvalidPermission; | |
| 52 return false; | |
| 53 } | |
| 54 std::string path; | |
| 55 extension->manifest()->GetString( | |
| 56 extension_manifest_keys::kStorageManagedSchema, &path); | |
| 57 base::FilePath file(path); | |
| 58 if (file.IsAbsolute()) { | |
| 59 *error = kInvalidPath; | |
| 60 return false; | |
| 61 } | |
| 62 file = extension->path().Append(path); | |
|
Mattias Nissler (ping if slow)
2013/05/15 10:37:39
Does this make sure I can't put ../../../../../../
Joao da Silva
2013/05/19 13:21:35
It doesn't, but FilePath::ReferencesParent() does.
| |
| 63 if (!file_util::PathExists(file)) { | |
| 64 *error = | |
| 65 base::StringPrintf("File does not exist: %s", file.value().c_str()); | |
| 66 return false; | |
| 67 } | |
| 68 std::string content; | |
| 69 if (!file_util::ReadFileToString(file, &content)) { | |
| 70 *error = base::StringPrintf("Can't read %s", file.value().c_str()); | |
| 71 return false; | |
| 72 } | |
| 73 scoped_ptr<policy::PolicySchema> schema = | |
| 74 policy::PolicySchema::Parse(content, error); | |
| 75 return schema; | |
|
Yoyo Zhou
2013/05/16 19:14:16
I'd expect !!schema or such for readability.
Joao da Silva
2013/05/19 13:21:35
Done.
| |
| 76 } | |
| 77 | |
| 78 const std::vector<std::string> PolicyManifestHandler::Keys() const { | |
| 79 return SingleKey(extension_manifest_keys::kStorageManagedSchema); | |
| 80 } | |
| 81 | |
| 82 } // namespace policy | |
| OLD | NEW |