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 "extensions/common/permissions/manifest_permission_set.h" | 5 #include "extensions/common/permissions/manifest_permission_set.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "extensions/common/error_utils.h" | 10 #include "extensions/common/error_utils.h" |
11 #include "extensions/common/manifest_constants.h" | 11 #include "extensions/common/manifest_constants.h" |
12 #include "extensions/common/manifest_handler.h" | 12 #include "extensions/common/manifest_handler.h" |
13 #include "extensions/common/permissions/manifest_permission.h" | 13 #include "extensions/common/permissions/manifest_permission.h" |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 using extensions::ErrorUtils; | 17 using extensions::ErrorUtils; |
18 using extensions::ManifestPermission; | 18 using extensions::ManifestPermission; |
19 using extensions::ManifestPermissionSet; | 19 using extensions::ManifestPermissionSet; |
20 using extensions::ManifestHandler; | 20 using extensions::ManifestHandler; |
21 namespace errors = extensions::manifest_errors; | 21 namespace errors = extensions::manifest_errors; |
22 | 22 |
23 bool CreateManifestPermission( | 23 bool CreateManifestPermission( |
24 const std::string& permission_name, | 24 const std::string& permission_name, |
25 const base::Value* permission_value, | 25 const base::Value* permission_value, |
26 ManifestPermissionSet* manifest_permissions, | 26 ManifestPermissionSet* manifest_permissions, |
27 string16* error, | 27 base::string16* error, |
28 std::vector<std::string>* unhandled_permissions) { | 28 std::vector<std::string>* unhandled_permissions) { |
29 | 29 |
30 scoped_ptr<ManifestPermission> permission( | 30 scoped_ptr<ManifestPermission> permission( |
31 ManifestHandler::CreatePermission(permission_name)); | 31 ManifestHandler::CreatePermission(permission_name)); |
32 | 32 |
33 if (!permission) { | 33 if (!permission) { |
34 if (unhandled_permissions) | 34 if (unhandled_permissions) |
35 unhandled_permissions->push_back(permission_name); | 35 unhandled_permissions->push_back(permission_name); |
36 else | 36 else |
37 LOG(WARNING) << "Unknown permission[" << permission_name << "]."; | 37 LOG(WARNING) << "Unknown permission[" << permission_name << "]."; |
(...skipping 15 matching lines...) Expand all Loading... |
53 } | 53 } |
54 | 54 |
55 } // namespace | 55 } // namespace |
56 | 56 |
57 namespace extensions { | 57 namespace extensions { |
58 | 58 |
59 // static | 59 // static |
60 bool ManifestPermissionSet::ParseFromJSON( | 60 bool ManifestPermissionSet::ParseFromJSON( |
61 const base::ListValue* permissions, | 61 const base::ListValue* permissions, |
62 ManifestPermissionSet* manifest_permissions, | 62 ManifestPermissionSet* manifest_permissions, |
63 string16* error, | 63 base::string16* error, |
64 std::vector<std::string>* unhandled_permissions) { | 64 std::vector<std::string>* unhandled_permissions) { |
65 for (size_t i = 0; i < permissions->GetSize(); ++i) { | 65 for (size_t i = 0; i < permissions->GetSize(); ++i) { |
66 std::string permission_name; | 66 std::string permission_name; |
67 const base::Value* permission_value = NULL; | 67 const base::Value* permission_value = NULL; |
68 if (!permissions->GetString(i, &permission_name)) { | 68 if (!permissions->GetString(i, &permission_name)) { |
69 const base::DictionaryValue* dict = NULL; | 69 const base::DictionaryValue* dict = NULL; |
70 // permission should be a string or a single key dict. | 70 // permission should be a string or a single key dict. |
71 if (!permissions->GetDictionary(i, &dict) || dict->size() != 1) { | 71 if (!permissions->GetDictionary(i, &dict) || dict->size() != 1) { |
72 if (error) { | 72 if (error) { |
73 *error = ErrorUtils::FormatErrorMessageUTF16( | 73 *error = ErrorUtils::FormatErrorMessageUTF16( |
(...skipping 10 matching lines...) Expand all Loading... |
84 | 84 |
85 if (!CreateManifestPermission(permission_name, permission_value, | 85 if (!CreateManifestPermission(permission_name, permission_value, |
86 manifest_permissions, error, | 86 manifest_permissions, error, |
87 unhandled_permissions)) | 87 unhandled_permissions)) |
88 return false; | 88 return false; |
89 } | 89 } |
90 return true; | 90 return true; |
91 } | 91 } |
92 | 92 |
93 } // namespace extensions | 93 } // namespace extensions |
OLD | NEW |