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 13 matching lines...) Expand all Loading... |
24 RouteFunction("StartRequest", | 24 RouteFunction("StartRequest", |
25 base::Bind(&SendRequestNatives::StartRequest, | 25 base::Bind(&SendRequestNatives::StartRequest, |
26 base::Unretained(this))); | 26 base::Unretained(this))); |
27 RouteFunction("GetGlobal", | 27 RouteFunction("GetGlobal", |
28 base::Bind(&SendRequestNatives::GetGlobal, | 28 base::Bind(&SendRequestNatives::GetGlobal, |
29 base::Unretained(this))); | 29 base::Unretained(this))); |
30 } | 30 } |
31 | 31 |
32 v8::Handle<v8::Value> SendRequestNatives::GetNextRequestId( | 32 v8::Handle<v8::Value> SendRequestNatives::GetNextRequestId( |
33 const v8::Arguments& args) { | 33 const v8::Arguments& args) { |
34 static int next_request_id = 0; | 34 return v8::Integer::New(request_sender_->GetNextRequestId()); |
35 return v8::Integer::New(next_request_id++); | |
36 } | 35 } |
37 | 36 |
38 // Starts an API request to the browser, with an optional callback. The | 37 // Starts an API request to the browser, with an optional callback. The |
39 // callback will be dispatched to EventBindings::HandleResponse. | 38 // callback will be dispatched to EventBindings::HandleResponse. |
40 v8::Handle<v8::Value> SendRequestNatives::StartRequest( | 39 v8::Handle<v8::Value> SendRequestNatives::StartRequest( |
41 const v8::Arguments& args) { | 40 const v8::Arguments& args) { |
42 std::string name = *v8::String::AsciiValue(args[0]); | 41 std::string name = *v8::String::AsciiValue(args[0]); |
43 int request_id = args[2]->Int32Value(); | 42 int request_id = args[2]->Int32Value(); |
44 bool has_callback = args[3]->BooleanValue(); | 43 bool has_callback = args[3]->BooleanValue(); |
45 bool for_io_thread = args[4]->BooleanValue(); | 44 bool for_io_thread = args[4]->BooleanValue(); |
(...skipping 20 matching lines...) Expand all Loading... |
66 return v8::Undefined(); | 65 return v8::Undefined(); |
67 } | 66 } |
68 | 67 |
69 v8::Handle<v8::Value> SendRequestNatives::GetGlobal(const v8::Arguments& args) { | 68 v8::Handle<v8::Value> SendRequestNatives::GetGlobal(const v8::Arguments& args) { |
70 CHECK_EQ(1, args.Length()); | 69 CHECK_EQ(1, args.Length()); |
71 CHECK(args[0]->IsObject()); | 70 CHECK(args[0]->IsObject()); |
72 return v8::Handle<v8::Object>::Cast(args[0])->CreationContext()->Global(); | 71 return v8::Handle<v8::Object>::Cast(args[0])->CreationContext()->Global(); |
73 } | 72 } |
74 | 73 |
75 } // namespace extensions | 74 } // namespace extensions |
OLD | NEW |