Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef EXTENSIONS_COMMON_PERMISSIONS_SET_DISJUNCTION_PERMISSION_H_ | 5 #ifndef EXTENSIONS_COMMON_PERMISSIONS_SET_DISJUNCTION_PERMISSION_H_ |
| 6 #define EXTENSIONS_COMMON_PERMISSIONS_SET_DISJUNCTION_PERMISSION_H_ | 6 #define EXTENSIONS_COMMON_PERMISSIONS_SET_DISJUNCTION_PERMISSION_H_ |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/json/json_writer.h" | |
| 12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/values.h" | 14 #include "base/values.h" |
| 14 #include "extensions/common/extension_messages.h" | 15 #include "extensions/common/extension_messages.h" |
| 15 #include "extensions/common/permissions/api_permission.h" | 16 #include "extensions/common/permissions/api_permission.h" |
| 16 #include "ipc/ipc_message.h" | 17 #include "ipc/ipc_message.h" |
| 17 #include "ipc/ipc_message_utils.h" | 18 #include "ipc/ipc_message_utils.h" |
| 18 | 19 |
| 19 namespace extensions { | 20 namespace extensions { |
| 20 | 21 |
| 21 // An abstract base class for permissions that are represented by the | 22 // An abstract base class for permissions that are represented by the |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 scoped_ptr<SetDisjunctionPermission> result(new DerivedType(info())); | 106 scoped_ptr<SetDisjunctionPermission> result(new DerivedType(info())); |
| 106 std::set_intersection(data_set_.begin(), | 107 std::set_intersection(data_set_.begin(), |
| 107 data_set_.end(), | 108 data_set_.end(), |
| 108 perm->data_set_.begin(), | 109 perm->data_set_.begin(), |
| 109 perm->data_set_.end(), | 110 perm->data_set_.end(), |
| 110 std::inserter<std::set<PermissionDataType> >( | 111 std::inserter<std::set<PermissionDataType> >( |
| 111 result->data_set_, result->data_set_.begin())); | 112 result->data_set_, result->data_set_.begin())); |
| 112 return result->data_set_.empty() ? NULL : result.release(); | 113 return result->data_set_.empty() ? NULL : result.release(); |
| 113 } | 114 } |
| 114 | 115 |
| 115 virtual bool FromValue(const base::Value* value, | 116 virtual bool FromValue( |
| 116 std::string* error) OVERRIDE { | 117 const base::Value* value, |
| 118 std::string* error, | |
| 119 std::vector<std::string>* unhandled_permissions) OVERRIDE { | |
| 117 data_set_.clear(); | 120 data_set_.clear(); |
| 118 const base::ListValue* list = NULL; | 121 const base::ListValue* list = NULL; |
| 119 | 122 |
| 120 if (!value || !value->GetAsList(&list) || list->GetSize() == 0) { | 123 if (!value || !value->GetAsList(&list) || list->GetSize() == 0) { |
| 121 if (error) | 124 if (error) |
| 122 *error = "NULL or empty permission list"; | 125 *error = "NULL or empty permission list"; |
| 123 return false; | 126 return false; |
| 124 } | 127 } |
| 125 | 128 |
| 129 bool unhandled = false; | |
| 126 for (size_t i = 0; i < list->GetSize(); ++i) { | 130 for (size_t i = 0; i < list->GetSize(); ++i) { |
| 127 const base::Value* item_value = NULL; | 131 const base::Value* item_value = NULL; |
| 128 bool got_item = list->Get(i, &item_value); | 132 bool got_item = list->Get(i, &item_value); |
| 129 DCHECK(got_item); | 133 DCHECK(got_item); |
| 130 DCHECK(item_value); | 134 DCHECK(item_value); |
| 131 | 135 |
| 132 PermissionDataType data; | 136 PermissionDataType data; |
| 133 if (!data.FromValue(item_value)) { | 137 if (data.FromValue(item_value)) { |
| 134 if (error) | 138 data_set_.insert(data); |
| 135 *error = "Cannot parse an item from the permission list"; | 139 } else { |
| 136 return false; | 140 unhandled = true; |
|
vandebo (ex-Chrome)
2014/04/01 23:11:04
This is the meat of the change.
| |
| 141 if (unhandled_permissions) { | |
| 142 std::string unknown_permission; | |
| 143 base::JSONWriter::Write(item_value, &unknown_permission); | |
| 144 unhandled_permissions->push_back(unknown_permission); | |
| 145 } | |
| 137 } | 146 } |
| 138 | 147 } |
| 139 data_set_.insert(data); | 148 if (unhandled && !unhandled_permissions) { |
|
Yoyo Zhou
2014/04/02 00:31:31
Seems like you can put this inside the for loop an
vandebo (ex-Chrome)
2014/04/02 16:46:59
Done.
| |
| 149 if (error) | |
| 150 *error = "Cannot parse an item from the permission list"; | |
| 151 return false; | |
| 140 } | 152 } |
| 141 return true; | 153 return true; |
| 142 } | 154 } |
| 143 | 155 |
| 144 virtual scoped_ptr<base::Value> ToValue() const OVERRIDE { | 156 virtual scoped_ptr<base::Value> ToValue() const OVERRIDE { |
| 145 base::ListValue* list = new base::ListValue(); | 157 base::ListValue* list = new base::ListValue(); |
| 146 typename std::set<PermissionDataType>::const_iterator i; | 158 typename std::set<PermissionDataType>::const_iterator i; |
| 147 for (i = data_set_.begin(); i != data_set_.end(); ++i) { | 159 for (i = data_set_.begin(); i != data_set_.end(); ++i) { |
| 148 scoped_ptr<base::Value> item_value(i->ToValue()); | 160 scoped_ptr<base::Value> item_value(i->ToValue()); |
| 149 list->Append(item_value.release()); | 161 list->Append(item_value.release()); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 163 IPC::LogParam(data_set_, log); | 175 IPC::LogParam(data_set_, log); |
| 164 } | 176 } |
| 165 | 177 |
| 166 protected: | 178 protected: |
| 167 std::set<PermissionDataType> data_set_; | 179 std::set<PermissionDataType> data_set_; |
| 168 }; | 180 }; |
| 169 | 181 |
| 170 } // namespace extensions | 182 } // namespace extensions |
| 171 | 183 |
| 172 #endif // EXTENSIONS_COMMON_PERMISSIONS_SET_DISJUNCTION_PERMISSION_H_ | 184 #endif // EXTENSIONS_COMMON_PERMISSIONS_SET_DISJUNCTION_PERMISSION_H_ |
| OLD | NEW |