OLD | NEW |
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/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "content/public/child/v8_value_converter.h" | 10 #include "content/public/child/v8_value_converter.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 ArgumentSpec::~ArgumentSpec() {} | 142 ArgumentSpec::~ArgumentSpec() {} |
143 | 143 |
144 bool ArgumentSpec::ParseArgument(v8::Local<v8::Context> context, | 144 bool ArgumentSpec::ParseArgument(v8::Local<v8::Context> context, |
145 v8::Local<v8::Value> value, | 145 v8::Local<v8::Value> value, |
146 const APITypeReferenceMap& refs, | 146 const APITypeReferenceMap& refs, |
147 std::unique_ptr<base::Value>* out_value, | 147 std::unique_ptr<base::Value>* out_value, |
148 std::string* error) const { | 148 std::string* error) const { |
149 if (type_ == ArgumentType::FUNCTION) { | 149 if (type_ == ArgumentType::FUNCTION) { |
150 if (!value->IsFunction()) | 150 if (!value->IsFunction()) |
151 return false; | 151 return false; |
152 // Certain APIs, like webRequest and contextMenus, have functions as | 152 |
153 // parameters that aren't the callback. We need these included in the | 153 if (out_value) { |
154 // signature for validation purposes, but don't *really* need to serialize | 154 // Certain APIs (contextMenus) have functions as parameters other than the |
155 // them. Unfortunately, if we don't, validation in the browser fails. For | 155 // callback (contextMenus uses it for an onclick listener). Our generated |
156 // now, the expectation is that functions are serialized as dictionaries, | 156 // types have adapted to consider functions "objects" and serialize them |
157 // to match the content::V8ValueConverter behavior. | 157 // as dictionaries. |
158 // TODO(devlin): Change this somehow. We could, for instance, add a | 158 // TODO(devlin): It'd be awfully nice to get rid of this eccentricity. |
159 // 'validation_only' property to the schema to indicate that a parameter | |
160 // or property shouldn't be serialized or included in the compiled types. | |
161 if (out_value) | |
162 *out_value = base::MakeUnique<base::DictionaryValue>(); | 159 *out_value = base::MakeUnique<base::DictionaryValue>(); |
| 160 } |
163 return true; | 161 return true; |
164 } | 162 } |
165 | 163 |
166 if (type_ == ArgumentType::REF) { | 164 if (type_ == ArgumentType::REF) { |
167 DCHECK(ref_); | 165 DCHECK(ref_); |
168 const ArgumentSpec* reference = refs.GetSpec(ref_.value()); | 166 const ArgumentSpec* reference = refs.GetSpec(ref_.value()); |
169 DCHECK(reference) << ref_.value(); | 167 DCHECK(reference) << ref_.value(); |
170 return reference->ParseArgument(context, value, refs, out_value, error); | 168 return reference->ParseArgument(context, value, refs, out_value, error); |
171 } | 169 } |
172 | 170 |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 return false; | 437 return false; |
440 } | 438 } |
441 if (type_ == ArgumentType::BINARY) | 439 if (type_ == ArgumentType::BINARY) |
442 DCHECK_EQ(base::Value::Type::BINARY, converted->GetType()); | 440 DCHECK_EQ(base::Value::Type::BINARY, converted->GetType()); |
443 *out_value = std::move(converted); | 441 *out_value = std::move(converted); |
444 } | 442 } |
445 return true; | 443 return true; |
446 } | 444 } |
447 | 445 |
448 } // namespace extensions | 446 } // namespace extensions |
OLD | NEW |