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

Side by Side Diff: extensions/common/permissions/set_disjunction_permission.h

Issue 221353003: Make unknown extension subpermissions warnings instead of errors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
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
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
126 for (size_t i = 0; i < list->GetSize(); ++i) { 129 for (size_t i = 0; i < list->GetSize(); ++i) {
127 const base::Value* item_value = NULL; 130 const base::Value* item_value = NULL;
128 bool got_item = list->Get(i, &item_value); 131 bool got_item = list->Get(i, &item_value);
129 DCHECK(got_item); 132 DCHECK(got_item);
130 DCHECK(item_value); 133 DCHECK(item_value);
131 134
132 PermissionDataType data; 135 PermissionDataType data;
133 if (!data.FromValue(item_value)) { 136 if (data.FromValue(item_value)) {
134 if (error) 137 data_set_.insert(data);
135 *error = "Cannot parse an item from the permission list"; 138 } else {
136 return false; 139 std::string unknown_permission;
140 base::JSONWriter::Write(item_value, &unknown_permission);
141 if (unhandled_permissions) {
142 unhandled_permissions->push_back(unknown_permission);
143 } else {
144 if (error) {
145 *error = "Cannot parse an item from the permission list: " +
146 unknown_permission;
147 }
148 return false;
149 }
137 } 150 }
138
139 data_set_.insert(data);
140 } 151 }
141 return true; 152 return true;
142 } 153 }
143 154
144 virtual scoped_ptr<base::Value> ToValue() const OVERRIDE { 155 virtual scoped_ptr<base::Value> ToValue() const OVERRIDE {
145 base::ListValue* list = new base::ListValue(); 156 base::ListValue* list = new base::ListValue();
146 typename std::set<PermissionDataType>::const_iterator i; 157 typename std::set<PermissionDataType>::const_iterator i;
147 for (i = data_set_.begin(); i != data_set_.end(); ++i) { 158 for (i = data_set_.begin(); i != data_set_.end(); ++i) {
148 scoped_ptr<base::Value> item_value(i->ToValue()); 159 scoped_ptr<base::Value> item_value(i->ToValue());
149 list->Append(item_value.release()); 160 list->Append(item_value.release());
(...skipping 13 matching lines...) Expand all
163 IPC::LogParam(data_set_, log); 174 IPC::LogParam(data_set_, log);
164 } 175 }
165 176
166 protected: 177 protected:
167 std::set<PermissionDataType> data_set_; 178 std::set<PermissionDataType> data_set_;
168 }; 179 };
169 180
170 } // namespace extensions 181 } // namespace extensions
171 182
172 #endif // EXTENSIONS_COMMON_PERMISSIONS_SET_DISJUNCTION_PERMISSION_H_ 183 #endif // EXTENSIONS_COMMON_PERMISSIONS_SET_DISJUNCTION_PERMISSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698