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

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

Issue 2915813003: [Extensions Bindings] Accept null callbacks while ignoring schema (Closed)
Patch Set: jbroman's Created 3 years, 6 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
« no previous file with comments | « no previous file | extensions/renderer/api_signature_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
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
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
OLDNEW
« no previous file with comments | « no previous file | extensions/renderer/api_signature_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698