Chromium Code Reviews| 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/api_signature.h" | 5 #include "extensions/renderer/api_signature.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 // TODO(devlin): This is what the current bindings do, but it's quite terribly | 310 // TODO(devlin): This is what the current bindings do, but it's quite terribly |
| 311 // incorrect. We only hit this flow when an API method has a hook to update | 311 // incorrect. We only hit this flow when an API method has a hook to update |
| 312 // the arguments post-validation, and in some cases, the arguments returned by | 312 // the arguments post-validation, and in some cases, the arguments returned by |
| 313 // that hook do *not* match the signature of the API method (e.g. | 313 // that hook do *not* match the signature of the API method (e.g. |
| 314 // fileSystem.getDisplayPath); see also note in api_bindings.cc for why this | 314 // fileSystem.getDisplayPath); see also note in api_bindings.cc for why this |
| 315 // is bad. But then here, we *rely* on the signature to determine whether or | 315 // is bad. But then here, we *rely* on the signature to determine whether or |
| 316 // not the last parameter is a callback, even though the hooks may not return | 316 // not the last parameter is a callback, even though the hooks may not return |
| 317 // the arguments in the signature. This is very broken. | 317 // the arguments in the signature. This is very broken. |
| 318 if (HasCallback(signature_)) { | 318 if (HasCallback(signature_)) { |
| 319 CHECK(!arguments.empty()); | 319 CHECK(!arguments.empty()); |
| 320 if (arguments[size - 1]->IsFunction()) { | 320 v8::Local<v8::Value> value = arguments.back(); |
| 321 callback = arguments[size - 1].As<v8::Function>(); | 321 --size; |
| 322 --size; | 322 DCHECK(value->IsFunction() || value->IsUndefined() || value->IsNull()); |
|
jbroman
2017/06/05 18:16:32
This DCHECK implies this value can only come from
Devlin
2017/06/09 20:26:31
More-or-less. :/ In theory, we should only get he
| |
| 323 } | 323 if (value->IsFunction()) |
| 324 callback = value.As<v8::Function>(); | |
| 324 } | 325 } |
| 325 | 326 |
| 326 auto json = base::MakeUnique<base::ListValue>(); | 327 auto json = base::MakeUnique<base::ListValue>(); |
| 327 std::unique_ptr<content::V8ValueConverter> converter( | 328 std::unique_ptr<content::V8ValueConverter> converter( |
| 328 content::V8ValueConverter::create()); | 329 content::V8ValueConverter::create()); |
| 329 converter->SetFunctionAllowed(true); | 330 converter->SetFunctionAllowed(true); |
| 330 for (size_t i = 0; i < size; ++i) { | 331 for (size_t i = 0; i < size; ++i) { |
| 331 std::unique_ptr<base::Value> converted = | 332 std::unique_ptr<base::Value> converted = |
| 332 converter->FromV8Value(arguments[i], context); | 333 converter->FromV8Value(arguments[i], context); |
| 333 if (!converted) | 334 if (!converted) |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 351 pieces.push_back( | 352 pieces.push_back( |
| 352 base::StringPrintf("%s%s %s", spec->optional() ? kOptionalPrefix : "", | 353 base::StringPrintf("%s%s %s", spec->optional() ? kOptionalPrefix : "", |
| 353 spec->GetTypeName().c_str(), spec->name().c_str())); | 354 spec->GetTypeName().c_str(), spec->name().c_str())); |
| 354 } | 355 } |
| 355 expected_signature_ = base::JoinString(pieces, ", "); | 356 expected_signature_ = base::JoinString(pieces, ", "); |
| 356 | 357 |
| 357 return expected_signature_; | 358 return expected_signature_; |
| 358 } | 359 } |
| 359 | 360 |
| 360 } // namespace extensions | 361 } // namespace extensions |
| OLD | NEW |