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

Side by Side Diff: extensions/renderer/argument_spec.cc

Issue 2805123002: [Extensions Bindings] Allow schema violations through sendRequest (Closed)
Patch Set: Created 3 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/renderer/argument_spec.h" 5 #include "extensions/renderer/argument_spec.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "content/public/child/v8_value_converter.h" 9 #include "content/public/child/v8_value_converter.h"
10 #include "extensions/renderer/api_type_reference_map.h" 10 #include "extensions/renderer/api_type_reference_map.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 137 }
138 138
139 ArgumentSpec::~ArgumentSpec() {} 139 ArgumentSpec::~ArgumentSpec() {}
140 140
141 bool ArgumentSpec::ParseArgument(v8::Local<v8::Context> context, 141 bool ArgumentSpec::ParseArgument(v8::Local<v8::Context> context,
142 v8::Local<v8::Value> value, 142 v8::Local<v8::Value> value,
143 const APITypeReferenceMap& refs, 143 const APITypeReferenceMap& refs,
144 std::unique_ptr<base::Value>* out_value, 144 std::unique_ptr<base::Value>* out_value,
145 std::string* error) const { 145 std::string* error) const {
146 if (type_ == ArgumentType::FUNCTION) { 146 if (type_ == ArgumentType::FUNCTION) {
147 // We can't serialize functions. We shouldn't be asked to. 147 if (!value->IsFunction())
148 DCHECK(!out_value); 148 return false;
149 return value->IsFunction(); 149
150 if (out_value) {
151 // Certain APIs (contextMenus) have functions as parameters other than the
152 // callback (contextMenus uses it for an onclick listener). Our generated
153 // types have adapted to consider functions "objects" and serialize them
154 // as dictionaries.
155 // TODO(devlin): It'd be awfully nice to get rid of this eccentricity.
156 *out_value = base::MakeUnique<base::DictionaryValue>();
157 }
158 return true;
150 } 159 }
151 160
152 if (type_ == ArgumentType::REF) { 161 if (type_ == ArgumentType::REF) {
153 DCHECK(ref_); 162 DCHECK(ref_);
154 const ArgumentSpec* reference = refs.GetSpec(ref_.value()); 163 const ArgumentSpec* reference = refs.GetSpec(ref_.value());
155 DCHECK(reference) << ref_.value(); 164 DCHECK(reference) << ref_.value();
156 return reference->ParseArgument(context, value, refs, out_value, error); 165 return reference->ParseArgument(context, value, refs, out_value, error);
157 } 166 }
158 167
159 if (type_ == ArgumentType::CHOICES) { 168 if (type_ == ArgumentType::CHOICES) {
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 return false; 439 return false;
431 } 440 }
432 if (type_ == ArgumentType::BINARY) 441 if (type_ == ArgumentType::BINARY)
433 DCHECK_EQ(base::Value::Type::BINARY, converted->GetType()); 442 DCHECK_EQ(base::Value::Type::BINARY, converted->GetType());
434 *out_value = std::move(converted); 443 *out_value = std::move(converted);
435 } 444 }
436 return true; 445 return true;
437 } 446 }
438 447
439 } // namespace extensions 448 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698