| 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 // Bindings should ensure that the value here is appropriate, but see the |
| 323 } | 323 // comment above for limitations. |
| 324 DCHECK(value->IsFunction() || value->IsUndefined() || value->IsNull()); |
| 325 if (value->IsFunction()) |
| 326 callback = value.As<v8::Function>(); |
| 324 } | 327 } |
| 325 | 328 |
| 326 auto json = base::MakeUnique<base::ListValue>(); | 329 auto json = base::MakeUnique<base::ListValue>(); |
| 327 std::unique_ptr<content::V8ValueConverter> converter( | 330 std::unique_ptr<content::V8ValueConverter> converter( |
| 328 content::V8ValueConverter::create()); | 331 content::V8ValueConverter::create()); |
| 329 converter->SetFunctionAllowed(true); | 332 converter->SetFunctionAllowed(true); |
| 330 for (size_t i = 0; i < size; ++i) { | 333 for (size_t i = 0; i < size; ++i) { |
| 331 std::unique_ptr<base::Value> converted = | 334 std::unique_ptr<base::Value> converted = |
| 332 converter->FromV8Value(arguments[i], context); | 335 converter->FromV8Value(arguments[i], context); |
| 333 if (!converted) | 336 if (!converted) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 351 pieces.push_back( | 354 pieces.push_back( |
| 352 base::StringPrintf("%s%s %s", spec->optional() ? kOptionalPrefix : "", | 355 base::StringPrintf("%s%s %s", spec->optional() ? kOptionalPrefix : "", |
| 353 spec->GetTypeName().c_str(), spec->name().c_str())); | 356 spec->GetTypeName().c_str(), spec->name().c_str())); |
| 354 } | 357 } |
| 355 expected_signature_ = base::JoinString(pieces, ", "); | 358 expected_signature_ = base::JoinString(pieces, ", "); |
| 356 | 359 |
| 357 return expected_signature_; | 360 return expected_signature_; |
| 358 } | 361 } |
| 359 | 362 |
| 360 } // namespace extensions | 363 } // namespace extensions |
| OLD | NEW |