Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(241)

Side by Side Diff: chrome/common/extensions/api/storage/storage_schema_manifest_handler.cc

Issue 1786263002: Remove uses of ENABLE_CONFIGURATION_POLICY from src/chrome. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sort Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.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 "components/policy/core/common/schema.h"
16 #include "extensions/common/extension.h" 17 #include "extensions/common/extension.h"
17 #include "extensions/common/install_warning.h" 18 #include "extensions/common/install_warning.h"
18 #include "extensions/common/manifest.h" 19 #include "extensions/common/manifest.h"
19 #include "extensions/common/manifest_constants.h" 20 #include "extensions/common/manifest_constants.h"
20 #include "extensions/common/manifest_handlers/permissions_parser.h" 21 #include "extensions/common/manifest_handlers/permissions_parser.h"
21 #include "extensions/common/permissions/api_permission.h" 22 #include "extensions/common/permissions/api_permission.h"
22 #include "extensions/common/permissions/api_permission_set.h" 23 #include "extensions/common/permissions/api_permission_set.h"
23 #include "extensions/common/permissions/permissions_info.h" 24 #include "extensions/common/permissions/permissions_info.h"
24 25
25 #if defined(ENABLE_CONFIGURATION_POLICY)
26 #include "components/policy/core/common/schema.h"
27 #endif
28
29 using extensions::manifest_keys::kStorageManagedSchema; 26 using extensions::manifest_keys::kStorageManagedSchema;
30 27
31 namespace extensions { 28 namespace extensions {
32 29
33 StorageSchemaManifestHandler::StorageSchemaManifestHandler() {} 30 StorageSchemaManifestHandler::StorageSchemaManifestHandler() {}
34 31
35 StorageSchemaManifestHandler::~StorageSchemaManifestHandler() {} 32 StorageSchemaManifestHandler::~StorageSchemaManifestHandler() {}
36 33
37 #if defined(ENABLE_CONFIGURATION_POLICY)
38 // static 34 // static
39 policy::Schema StorageSchemaManifestHandler::GetSchema( 35 policy::Schema StorageSchemaManifestHandler::GetSchema(
40 const Extension* extension, 36 const Extension* extension,
41 std::string* error) { 37 std::string* error) {
42 std::string path; 38 std::string path;
43 extension->manifest()->GetString(kStorageManagedSchema, &path); 39 extension->manifest()->GetString(kStorageManagedSchema, &path);
44 base::FilePath file = base::FilePath::FromUTF8Unsafe(path); 40 base::FilePath file = base::FilePath::FromUTF8Unsafe(path);
45 if (file.IsAbsolute() || file.ReferencesParent()) { 41 if (file.IsAbsolute() || file.ReferencesParent()) {
46 *error = base::StringPrintf("%s must be a relative path without ..", 42 *error = base::StringPrintf("%s must be a relative path without ..",
47 kStorageManagedSchema); 43 kStorageManagedSchema);
48 return policy::Schema(); 44 return policy::Schema();
49 } 45 }
50 file = extension->path().AppendASCII(path); 46 file = extension->path().AppendASCII(path);
51 if (!base::PathExists(file)) { 47 if (!base::PathExists(file)) {
52 *error = base::StringPrintf("File does not exist: %" PRIsFP, 48 *error = base::StringPrintf("File does not exist: %" PRIsFP,
53 file.value().c_str()); 49 file.value().c_str());
54 return policy::Schema(); 50 return policy::Schema();
55 } 51 }
56 std::string content; 52 std::string content;
57 if (!base::ReadFileToString(file, &content)) { 53 if (!base::ReadFileToString(file, &content)) {
58 *error = base::StringPrintf("Can't read %" PRIsFP, file.value().c_str()); 54 *error = base::StringPrintf("Can't read %" PRIsFP, file.value().c_str());
59 return policy::Schema(); 55 return policy::Schema();
60 } 56 }
61 return policy::Schema::Parse(content, error); 57 return policy::Schema::Parse(content, error);
62 } 58 }
63 #endif
64 59
65 bool StorageSchemaManifestHandler::Parse(Extension* extension, 60 bool StorageSchemaManifestHandler::Parse(Extension* extension,
66 base::string16* error) { 61 base::string16* error) {
67 std::string path; 62 std::string path;
68 if (!extension->manifest()->GetString(kStorageManagedSchema, &path)) { 63 if (!extension->manifest()->GetString(kStorageManagedSchema, &path)) {
69 *error = base::ASCIIToUTF16( 64 *error = base::ASCIIToUTF16(
70 base::StringPrintf("%s must be a string", kStorageManagedSchema)); 65 base::StringPrintf("%s must be a string", kStorageManagedSchema));
71 return false; 66 return false;
72 } 67 }
73 68
74 // If an extension declares the "storage.managed_schema" key then it gets 69 // If an extension declares the "storage.managed_schema" key then it gets
75 // the "storage" permission implicitly. 70 // the "storage" permission implicitly.
76 PermissionsParser::AddAPIPermission(extension, APIPermission::kStorage); 71 PermissionsParser::AddAPIPermission(extension, APIPermission::kStorage);
77 72
78 return true; 73 return true;
79 } 74 }
80 75
81 bool StorageSchemaManifestHandler::Validate( 76 bool StorageSchemaManifestHandler::Validate(
82 const Extension* extension, 77 const Extension* extension,
83 std::string* error, 78 std::string* error,
84 std::vector<InstallWarning>* warnings) const { 79 std::vector<InstallWarning>* warnings) const {
85 #if defined(ENABLE_CONFIGURATION_POLICY)
86 return GetSchema(extension, error).valid(); 80 return GetSchema(extension, error).valid();
87 #else
88 return true;
89 #endif
90 } 81 }
91 82
92 const std::vector<std::string> StorageSchemaManifestHandler::Keys() const { 83 const std::vector<std::string> StorageSchemaManifestHandler::Keys() const {
93 return SingleKey(kStorageManagedSchema); 84 return SingleKey(kStorageManagedSchema);
94 } 85 }
95 86
96 } // namespace extensions 87 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698