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/common/extensions/chrome_manifest_permission_set.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/strings/string_number_conversions.h" | |
9 #include "base/values.h" | |
10 #include "extensions/common/error_utils.h" | |
11 #include "extensions/common/manifest_constants.h" | |
12 #include "extensions/common/manifest_handler.h" | |
13 #include "extensions/common/permissions/api_permission.h" | |
14 #include "extensions/common/permissions/api_permission_set.h" | |
15 | |
16 namespace { | |
17 | |
18 using extensions::ErrorUtils; | |
19 using extensions::ManifestPermission; | |
20 using extensions::ManifestPermissionSet; | |
21 using extensions::ManifestHandler; | |
22 namespace errors = extensions::manifest_errors; | |
23 | |
24 bool CreateManifestPermission( | |
25 const std::string& permission_name, | |
26 const base::Value* permission_value, | |
27 ManifestPermissionSet* manifest_permissions, | |
28 string16* error, | |
29 std::vector<std::string>* unhandled_permissions) { | |
30 | |
31 scoped_ptr<ManifestPermission> permission( | |
32 ManifestHandler::CreatePermission(permission_name)); | |
33 | |
34 if (!permission) { | |
35 if (unhandled_permissions) | |
36 unhandled_permissions->push_back(permission_name); | |
37 else | |
38 LOG(WARNING) << "Unknown permission[" << permission_name << "]."; | |
39 return true; | |
40 } | |
41 | |
42 if (!permission->FromValue(permission_value)) { | |
43 if (error) { | |
44 *error = ErrorUtils::FormatErrorMessageUTF16( | |
45 errors::kInvalidPermission, permission_name); | |
46 return false; | |
47 } | |
48 LOG(WARNING) << "Parse permission failed."; | |
49 return true; | |
50 } else { | |
51 manifest_permissions->insert(permission.release()); | |
52 return true; | |
53 } | |
54 } | |
55 | |
56 } // namespace | |
57 | |
58 namespace extensions { | |
59 | |
60 // static | |
61 bool ChromeManifestPermissionSet::ParseFromJSON( | |
62 const base::ListValue* permissions, | |
63 ManifestPermissionSet* manifest_permissions, | |
64 string16* error, | |
65 std::vector<std::string>* unhandled_permissions) { | |
66 // TODO(rpaquay): Update name of local variables to reflect we are dealing | |
Yoyo Zhou
2013/11/12 02:39:29
Does this still need to be done?
rpaquay
2013/11/12 21:40:31
Nope. Removed comment.
| |
67 // with manifest_permissions entries. | |
68 for (size_t i = 0; i < permissions->GetSize(); ++i) { | |
69 std::string permission_name; | |
70 const base::Value* permission_value = NULL; | |
71 if (!permissions->GetString(i, &permission_name)) { | |
72 const base::DictionaryValue* dict = NULL; | |
73 // permission should be a string or a single key dict. | |
74 if (!permissions->GetDictionary(i, &dict) || dict->size() != 1) { | |
75 if (error) { | |
76 *error = ErrorUtils::FormatErrorMessageUTF16( | |
77 errors::kInvalidPermission, base::IntToString(i)); | |
78 return false; | |
79 } | |
80 LOG(WARNING) << "Permission is not a string or single key dict."; | |
81 continue; | |
82 } | |
83 base::DictionaryValue::Iterator it(*dict); | |
84 permission_name = it.key(); | |
85 permission_value = &it.value(); | |
86 } | |
87 | |
88 if (!CreateManifestPermission(permission_name, permission_value, | |
89 manifest_permissions, error, | |
90 unhandled_permissions)) | |
91 return false; | |
92 } | |
93 return true; | |
94 } | |
95 | |
96 } // namespace extensions | |
OLD | NEW |