| 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/extension_request_sender.h" | 9 #include "chrome/renderer/extensions/extension_request_sender.h" |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 // Starts an API request to the browser, with an optional callback. The | 34 // Starts an API request to the browser, with an optional callback. The |
| 35 // callback will be dispatched to EventBindings::HandleResponse. | 35 // callback will be dispatched to EventBindings::HandleResponse. |
| 36 v8::Handle<v8::Value> SendRequestNatives::StartRequest( | 36 v8::Handle<v8::Value> SendRequestNatives::StartRequest( |
| 37 const v8::Arguments& args) { | 37 const v8::Arguments& args) { |
| 38 std::string name = *v8::String::AsciiValue(args[0]); | 38 std::string name = *v8::String::AsciiValue(args[0]); |
| 39 int request_id = args[2]->Int32Value(); | 39 int request_id = args[2]->Int32Value(); |
| 40 bool has_callback = args[3]->BooleanValue(); | 40 bool has_callback = args[3]->BooleanValue(); |
| 41 bool for_io_thread = args[4]->BooleanValue(); | 41 bool for_io_thread = args[4]->BooleanValue(); |
| 42 | 42 |
| 43 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); | 43 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
| 44 converter->SetUndefinedAllowed(true); // Allow passing optional values. |
| 44 scoped_ptr<Value> value_args( | 45 scoped_ptr<Value> value_args( |
| 45 converter->FromV8Value(args[1], v8::Context::GetCurrent())); | 46 converter->FromV8Value(args[1], v8::Context::GetCurrent())); |
| 46 if (!value_args.get() || !value_args->IsType(Value::TYPE_LIST)) { | 47 if (!value_args.get() || !value_args->IsType(Value::TYPE_LIST)) { |
| 47 NOTREACHED() << "Unable to convert args passed to StartRequest"; | 48 NOTREACHED() << "Unable to convert args passed to StartRequest"; |
| 48 return v8::Undefined(); | 49 return v8::Undefined(); |
| 49 } | 50 } |
| 50 | 51 |
| 51 request_sender_->StartRequest(name, request_id, has_callback, for_io_thread, | 52 request_sender_->StartRequest(name, request_id, has_callback, for_io_thread, |
| 52 static_cast<ListValue*>(value_args.get())); | 53 static_cast<ListValue*>(value_args.get())); |
| 53 return v8::Undefined(); | 54 return v8::Undefined(); |
| 54 } | 55 } |
| 55 | 56 |
| 56 } // namespace extensions | 57 } // namespace extensions |
| OLD | NEW |