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

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

Issue 61383003: Pass pepper apps API calls through the existing js apps API bindings. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years 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
Index: chrome/renderer/extensions/pepper_request_proxy.cc
diff --git a/chrome/renderer/extensions/pepper_request_proxy.cc b/chrome/renderer/extensions/pepper_request_proxy.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5291c0305b18d9c937dd31a8de29b8d1c903c633
--- /dev/null
+++ b/chrome/renderer/extensions/pepper_request_proxy.cc
@@ -0,0 +1,78 @@
+// Copyright 2013 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/pepper_request_proxy.h"
+
+#include "base/values.h"
+#include "chrome/renderer/extensions/chrome_v8_context.h"
+#include "content/public/renderer/v8_value_converter.h"
+
+namespace extensions {
+
+PepperRequestProxy::PepperRequestProxy(ChromeV8Context* context)
+ : context_(context), next_request_id_(0) {}
+
+PepperRequestProxy::~PepperRequestProxy() {}
+
+bool PepperRequestProxy::StartCall(const ResponseCallback& callback,
+ const std::string& request_name,
+ base::ListValue* args,
+ int* request_id,
+ std::string* error) {
+ *request_id = next_request_id_++;
+ pending_request_map_[*request_id] = callback;
+ args->Insert(0, new base::FundamentalValue(*request_id));
+
+ bool result =
+ StartRequest(request_name, "callMethod", args, error);
+ if (!result)
+ pending_request_map_.erase(*request_id);
+ return result;
+}
+
+bool PepperRequestProxy::StartPost(const std::string& request_name,
+ base::ListValue* args,
+ std::string* error) {
+ return StartRequest(request_name, "postMethod", args, error);
+}
+
+bool PepperRequestProxy::StartRequest(const std::string& request_name,
+ const std::string& method_name,
+ base::ListValue* args,
+ std::string* error) {
+ args->Insert(0, new base::StringValue(request_name));
not at google - send to devlin 2013/12/03 17:32:50 it seems like you can avoid this weirdness of modi
Sam McNally 2013/12/04 00:01:36 Done.
+
+ // TODO(sammc): Converting from base::Value to v8::Value and then back to
+ // base::Value is not optimal. For most API calls the JS code doesn't do much.
+ // http://crbug.com/324115.
+ v8::HandleScope scope(v8::Isolate::GetCurrent());
+ scoped_ptr<content::V8ValueConverter> converter(
+ content::V8ValueConverter::create());
+ std::vector<v8::Handle<v8::Value> > v8_args;
+ for (base::ListValue::const_iterator it = args->begin(); it != args->end();
+ ++it) {
+ v8_args.push_back(converter->ToV8Value(*it, context_->v8_context()));
+ }
+ v8::Handle<v8::Value> v8_error = context_->module_system()->CallModuleMethod(
+ "pepper_request", method_name, &v8_args);
+ if (v8_error->IsString()) {
+ if (error)
+ *error = *v8::String::Utf8Value(v8_error);
+ return false;
+ }
+
+ return true;
+}
+
+void PepperRequestProxy::OnResponseReceived(int request_id,
+ bool success,
+ const base::ListValue& args,
+ const std::string& error) {
+ PendingRequestMap::iterator it = pending_request_map_.find(request_id);
+ DCHECK(it != pending_request_map_.end());
+ it->second.Run(request_id, success, args, error);
+ pending_request_map_.erase(it);
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698