| 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/api_permission_set.h" | 5 #include "extensions/common/permissions/api_permission_set.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 if (error) { | 99 if (error) { |
| 100 *error = ErrorUtils::FormatErrorMessageUTF16( | 100 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 101 errors::kInvalidPermission, | 101 errors::kInvalidPermission, |
| 102 base_name + '.' + base::IntToString(i)); | 102 base_name + '.' + base::IntToString(i)); |
| 103 return false; | 103 return false; |
| 104 } | 104 } |
| 105 LOG(WARNING) << "Permission is not a string."; | 105 LOG(WARNING) << "Permission is not a string."; |
| 106 continue; | 106 continue; |
| 107 } | 107 } |
| 108 | 108 |
| 109 if (!CreateAPIPermission( | 109 if (!CreateAPIPermission(base_name + '.' + permission_str, |
| 110 base_name + '.' + permission_str, NULL, source, | 110 nullptr, |
| 111 api_permissions, error, unhandled_permissions)) | 111 source, |
| 112 api_permissions, |
| 113 error, |
| 114 unhandled_permissions)) |
| 112 return false; | 115 return false; |
| 113 } | 116 } |
| 114 } | 117 } |
| 115 | 118 |
| 116 return CreateAPIPermission(base_name, NULL, source, | 119 return CreateAPIPermission( |
| 117 api_permissions, error, NULL); | 120 base_name, nullptr, source, api_permissions, error, nullptr); |
| 118 } | 121 } |
| 119 | 122 |
| 120 } // namespace | 123 } // namespace |
| 121 | 124 |
| 122 void APIPermissionSet::insert(APIPermission::ID id) { | 125 void APIPermissionSet::insert(APIPermission::ID id) { |
| 123 const APIPermissionInfo* permission_info = | 126 const APIPermissionInfo* permission_info = |
| 124 PermissionsInfo::GetInstance()->GetByID(id); | 127 PermissionsInfo::GetInstance()->GetByID(id); |
| 125 DCHECK(permission_info); | 128 DCHECK(permission_info); |
| 126 insert(permission_info->CreateAPIPermission()); | 129 insert(permission_info->CreateAPIPermission()); |
| 127 } | 130 } |
| 128 | 131 |
| 129 void APIPermissionSet::insert(APIPermission* permission) { | 132 void APIPermissionSet::insert(APIPermission* permission) { |
| 130 BaseSetOperators<APIPermissionSet>::insert(permission); | 133 BaseSetOperators<APIPermissionSet>::insert(permission); |
| 131 } | 134 } |
| 132 | 135 |
| 133 // static | 136 // static |
| 134 bool APIPermissionSet::ParseFromJSON( | 137 bool APIPermissionSet::ParseFromJSON( |
| 135 const base::ListValue* permissions, | 138 const base::ListValue* permissions, |
| 136 APIPermissionSet::ParseSource source, | 139 APIPermissionSet::ParseSource source, |
| 137 APIPermissionSet* api_permissions, | 140 APIPermissionSet* api_permissions, |
| 138 base::string16* error, | 141 base::string16* error, |
| 139 std::vector<std::string>* unhandled_permissions) { | 142 std::vector<std::string>* unhandled_permissions) { |
| 140 for (size_t i = 0; i < permissions->GetSize(); ++i) { | 143 for (size_t i = 0; i < permissions->GetSize(); ++i) { |
| 141 std::string permission_str; | 144 std::string permission_str; |
| 142 const base::Value* permission_value = NULL; | 145 const base::Value* permission_value = nullptr; |
| 143 if (!permissions->GetString(i, &permission_str)) { | 146 if (!permissions->GetString(i, &permission_str)) { |
| 144 const base::DictionaryValue* dict = NULL; | 147 const base::DictionaryValue* dict = nullptr; |
| 145 // permission should be a string or a single key dict. | 148 // permission should be a string or a single key dict. |
| 146 if (!permissions->GetDictionary(i, &dict) || dict->size() != 1) { | 149 if (!permissions->GetDictionary(i, &dict) || dict->size() != 1) { |
| 147 if (error) { | 150 if (error) { |
| 148 *error = ErrorUtils::FormatErrorMessageUTF16( | 151 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 149 errors::kInvalidPermission, base::IntToString(i)); | 152 errors::kInvalidPermission, base::IntToString(i)); |
| 150 return false; | 153 return false; |
| 151 } | 154 } |
| 152 LOG(WARNING) << "Permission is not a string or single key dict."; | 155 LOG(WARNING) << "Permission is not a string or single key dict."; |
| 153 continue; | 156 continue; |
| 154 } | 157 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 177 // The fileSystem.write and fileSystem.directory permissions imply | 180 // The fileSystem.write and fileSystem.directory permissions imply |
| 178 // fileSystem.writeDirectory. | 181 // fileSystem.writeDirectory. |
| 179 // TODO(sammc): Remove this. See http://crbug.com/284849. | 182 // TODO(sammc): Remove this. See http://crbug.com/284849. |
| 180 if (ContainsKey(map(), APIPermission::kFileSystemWrite) && | 183 if (ContainsKey(map(), APIPermission::kFileSystemWrite) && |
| 181 ContainsKey(map(), APIPermission::kFileSystemDirectory)) { | 184 ContainsKey(map(), APIPermission::kFileSystemDirectory)) { |
| 182 insert(APIPermission::kFileSystemWriteDirectory); | 185 insert(APIPermission::kFileSystemWriteDirectory); |
| 183 } | 186 } |
| 184 } | 187 } |
| 185 | 188 |
| 186 } // namespace extensions | 189 } // namespace extensions |
| OLD | NEW |