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

Side by Side Diff: chrome/renderer/extensions/send_request_natives.cc

Issue 10890002: Make V8ValueConverter.FromV8Value behave similarly to JSON.stringify (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use the actual objects, not empty objects Created 8 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/renderer/extensions/send_request_natives.h" 5 #include "chrome/renderer/extensions/send_request_natives.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "content/public/renderer/v8_value_converter.h" 8 #include "content/public/renderer/v8_value_converter.h"
9 #include "chrome/renderer/extensions/request_sender.h" 9 #include "chrome/renderer/extensions/request_sender.h"
10 10
(...skipping 19 matching lines...) Expand all
30 } 30 }
31 31
32 // Starts an API request to the browser, with an optional callback. The 32 // Starts an API request to the browser, with an optional callback. The
33 // callback will be dispatched to EventBindings::HandleResponse. 33 // callback will be dispatched to EventBindings::HandleResponse.
34 v8::Handle<v8::Value> SendRequestNatives::StartRequest( 34 v8::Handle<v8::Value> SendRequestNatives::StartRequest(
35 const v8::Arguments& args) { 35 const v8::Arguments& args) {
36 std::string name = *v8::String::AsciiValue(args[0]); 36 std::string name = *v8::String::AsciiValue(args[0]);
37 int request_id = args[2]->Int32Value(); 37 int request_id = args[2]->Int32Value();
38 bool has_callback = args[3]->BooleanValue(); 38 bool has_callback = args[3]->BooleanValue();
39 bool for_io_thread = args[4]->BooleanValue(); 39 bool for_io_thread = args[4]->BooleanValue();
40 bool preserve_null_in_objects = args[5]->BooleanValue();
41 bool allow_functions_in_objects = args[6]->BooleanValue();
40 42
41 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); 43 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
42 44
43 // Make "undefined" the same as "null" for optional arguments, but for objects 45 if (!preserve_null_in_objects)
44 // strip nulls (like {foo: null}, and therefore {foo: undefined} as well) to 46 converter->SetStripNullFromObjects(true);
45 // make it easier for extension APIs to check for optional arguments. 47 if (allow_functions_in_objects)
46 converter->SetUndefinedAllowed(true); 48 converter->SetFunctionAllowed(true);
47 converter->SetStripNullFromObjects(true);
48 49
49 scoped_ptr<Value> value_args( 50 scoped_ptr<Value> value_args(
50 converter->FromV8Value(args[1], v8::Context::GetCurrent())); 51 converter->FromV8Value(args[1], v8::Context::GetCurrent()));
51 if (!value_args.get() || !value_args->IsType(Value::TYPE_LIST)) { 52 if (!value_args.get() || !value_args->IsType(Value::TYPE_LIST)) {
52 NOTREACHED() << "Unable to convert args passed to StartRequest"; 53 NOTREACHED() << "Unable to convert args passed to StartRequest";
53 return v8::Undefined(); 54 return v8::Undefined();
54 } 55 }
55 56
56 request_sender_->StartRequest(name, request_id, has_callback, for_io_thread, 57 request_sender_->StartRequest(name, request_id, has_callback, for_io_thread,
57 static_cast<ListValue*>(value_args.get())); 58 static_cast<ListValue*>(value_args.get()));
58 return v8::Undefined(); 59 return v8::Undefined();
59 } 60 }
60 61
61 } // namespace extensions 62 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698