| OLD | NEW |
| 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 Loading... |
| 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 allow_null_in_objects = args[5]->BooleanValue(); |
| 40 | 41 |
| 41 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); | 42 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
| 42 | 43 |
| 43 // Make "undefined" the same as "null" for optional arguments, but for objects | 44 if (allow_null_in_objects) { |
| 44 // strip nulls (like {foo: null}, and therefore {foo: undefined} as well) to | 45 converter->SetUndefinedValueBehavior(V8ValueConverter::OMIT); |
| 45 // make it easier for extension APIs to check for optional arguments. | 46 } else { |
| 46 converter->SetUndefinedAllowed(true); | 47 // Make undefined the same as null for optional arguments, but for objects |
| 47 converter->SetStripNullFromObjects(true); | 48 // strip nulls (like {foo: null}, and therefore {foo: undefined} as well) to |
| 49 // make it easier for extension APIs to check for optional arguments. |
| 50 converter->SetUndefinedValueBehavior(V8ValueConverter::CONVERT_TO_NULL); |
| 51 converter->SetStripNullFromObjects(true); |
| 52 } |
| 48 | 53 |
| 49 scoped_ptr<Value> value_args( | 54 scoped_ptr<Value> value_args( |
| 50 converter->FromV8Value(args[1], v8::Context::GetCurrent())); | 55 converter->FromV8Value(args[1], v8::Context::GetCurrent())); |
| 51 if (!value_args.get() || !value_args->IsType(Value::TYPE_LIST)) { | 56 if (!value_args.get() || !value_args->IsType(Value::TYPE_LIST)) { |
| 52 NOTREACHED() << "Unable to convert args passed to StartRequest"; | 57 NOTREACHED() << "Unable to convert args passed to StartRequest"; |
| 53 return v8::Undefined(); | 58 return v8::Undefined(); |
| 54 } | 59 } |
| 55 | 60 |
| 56 request_sender_->StartRequest(name, request_id, has_callback, for_io_thread, | 61 request_sender_->StartRequest(name, request_id, has_callback, for_io_thread, |
| 57 static_cast<ListValue*>(value_args.get())); | 62 static_cast<ListValue*>(value_args.get())); |
| 58 return v8::Undefined(); | 63 return v8::Undefined(); |
| 59 } | 64 } |
| 60 | 65 |
| 61 } // namespace extensions | 66 } // namespace extensions |
| OLD | NEW |