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

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

Issue 9960077: Modify the base::JSONReader interface to take a set of options rather than a boolean flag. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 8 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 "chrome/renderer/extensions/extension_request_sender.h" 8 #include "chrome/renderer/extensions/extension_request_sender.h"
9 9
10 namespace extensions { 10 namespace extensions {
(...skipping 15 matching lines...) Expand all
26 const v8::Arguments& args) { 26 const v8::Arguments& args) {
27 static int next_request_id = 0; 27 static int next_request_id = 0;
28 return v8::Integer::New(next_request_id++); 28 return v8::Integer::New(next_request_id++);
29 } 29 }
30 30
31 // Starts an API request to the browser, with an optional callback. The 31 // Starts an API request to the browser, with an optional callback. The
32 // callback will be dispatched to EventBindings::HandleResponse. 32 // callback will be dispatched to EventBindings::HandleResponse.
33 v8::Handle<v8::Value> SendRequestNatives::StartRequest( 33 v8::Handle<v8::Value> SendRequestNatives::StartRequest(
34 const v8::Arguments& args) { 34 const v8::Arguments& args) {
35 std::string str_args = *v8::String::Utf8Value(args[1]); 35 std::string str_args = *v8::String::Utf8Value(args[1]);
36 base::JSONReader reader; 36 scoped_ptr<Value> value_args(base::JSONReader::Read(str_args));
37 scoped_ptr<Value> value_args;
38 value_args.reset(reader.JsonToValue(str_args, false, false));
39 37
40 // Since we do the serialization in the v8 extension, we should always get 38 // Since we do the serialization in the v8 extension, we should always get
41 // valid JSON. 39 // valid JSON.
42 if (!value_args.get() || !value_args->IsType(Value::TYPE_LIST)) { 40 if (!value_args.get() || !value_args->IsType(Value::TYPE_LIST)) {
43 NOTREACHED() << "Invalid JSON passed to StartRequest."; 41 NOTREACHED() << "Invalid JSON passed to StartRequest.";
44 return v8::Undefined(); 42 return v8::Undefined();
45 } 43 }
46 44
47 std::string name = *v8::String::AsciiValue(args[0]); 45 std::string name = *v8::String::AsciiValue(args[0]);
48 int request_id = args[2]->Int32Value(); 46 int request_id = args[2]->Int32Value();
49 bool has_callback = args[3]->BooleanValue(); 47 bool has_callback = args[3]->BooleanValue();
50 bool for_io_thread = args[4]->BooleanValue(); 48 bool for_io_thread = args[4]->BooleanValue();
51 49
52 request_sender_->StartRequest(name, request_id, has_callback, for_io_thread, 50 request_sender_->StartRequest(name, request_id, has_callback, for_io_thread,
53 static_cast<ListValue*>(value_args.get())); 51 static_cast<ListValue*>(value_args.get()));
54 return v8::Undefined(); 52 return v8::Undefined();
55 } 53 }
56 54
57 } // namespace extensions 55 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698