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

Unified Diff: chrome/renderer/extensions/send_request_natives.cc

Issue 9918006: Split SchemaGeneratedBindings up into smaller, more targetted native handlers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/renderer/extensions/send_request_natives.h ('k') | chrome/renderer/extensions/set_icon_natives.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/extensions/send_request_natives.cc
diff --git a/chrome/renderer/extensions/send_request_natives.cc b/chrome/renderer/extensions/send_request_natives.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f493828432cc42c5a5e882d3fef8bb2ca132ea50
--- /dev/null
+++ b/chrome/renderer/extensions/send_request_natives.cc
@@ -0,0 +1,57 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/renderer/extensions/send_request_natives.h"
+
+#include "base/json/json_reader.h"
+#include "chrome/renderer/extensions/extension_request_sender.h"
+
+namespace extensions {
+
+SendRequestNatives::SendRequestNatives(
+ ExtensionDispatcher* extension_dispatcher,
+ ExtensionRequestSender* request_sender)
+ : ChromeV8Extension(extension_dispatcher),
+ request_sender_(request_sender) {
+ RouteFunction("GetNextRequestId",
+ base::Bind(&SendRequestNatives::GetNextRequestId,
+ base::Unretained(this)));
+ RouteFunction("StartRequest",
+ base::Bind(&SendRequestNatives::StartRequest,
+ base::Unretained(this)));
+}
+
+v8::Handle<v8::Value> SendRequestNatives::GetNextRequestId(
+ const v8::Arguments& args) {
+ static int next_request_id = 0;
+ return v8::Integer::New(next_request_id++);
+}
+
+// Starts an API request to the browser, with an optional callback. The
+// callback will be dispatched to EventBindings::HandleResponse.
+v8::Handle<v8::Value> SendRequestNatives::StartRequest(
+ const v8::Arguments& args) {
+ std::string str_args = *v8::String::Utf8Value(args[1]);
+ base::JSONReader reader;
+ scoped_ptr<Value> value_args;
+ value_args.reset(reader.JsonToValue(str_args, false, false));
+
+ // Since we do the serialization in the v8 extension, we should always get
+ // valid JSON.
+ if (!value_args.get() || !value_args->IsType(Value::TYPE_LIST)) {
+ NOTREACHED() << "Invalid JSON passed to StartRequest.";
+ return v8::Undefined();
+ }
+
+ std::string name = *v8::String::AsciiValue(args[0]);
+ int request_id = args[2]->Int32Value();
+ bool has_callback = args[3]->BooleanValue();
+ bool for_io_thread = args[4]->BooleanValue();
+
+ request_sender_->StartRequest(name, request_id, has_callback, for_io_thread,
+ static_cast<ListValue*>(value_args.get()));
+ return v8::Undefined();
+}
+
+} // namespace extensions
« no previous file with comments | « chrome/renderer/extensions/send_request_natives.h ('k') | chrome/renderer/extensions/set_icon_natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698