summaryrefslogtreecommitdiffstats
path: root/remoting/client
diff options
context:
space:
mode:
authorajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-03 15:56:57 +0000
committerajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-03 15:56:57 +0000
commite05eb1d621ca0a26e0b33c650d4dbf456dba6863 (patch)
tree97322432de7e2381eb065cc3af19d53abba6e2f3 /remoting/client
parentfbc94a82c898c17dffbb7bad4f2ed70ffc15b133 (diff)
downloadchromium_src-e05eb1d621ca0a26e0b33c650d4dbf456dba6863.zip
chromium_src-e05eb1d621ca0a26e0b33c650d4dbf456dba6863.tar.gz
chromium_src-e05eb1d621ca0a26e0b33c650d4dbf456dba6863.tar.bz2
Refactor JingleClient to support thunking the xmpp signaling into Javascript.
We do this so that we may make HTTP requests using the javascript libraries available to Google Talk. This is required to allow us to sandbox. BUG=none TEST=none Review URL: http://codereview.chromium.org/6597092 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76746 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/client')
-rw-r--r--remoting/client/plugin/chromoting_scriptable_object.cc14
-rw-r--r--remoting/client/plugin/chromoting_scriptable_object.h15
-rw-r--r--remoting/client/plugin/pepper_xmpp_proxy.cc57
-rw-r--r--remoting/client/plugin/pepper_xmpp_proxy.h42
4 files changed, 126 insertions, 2 deletions
diff --git a/remoting/client/plugin/chromoting_scriptable_object.cc b/remoting/client/plugin/chromoting_scriptable_object.cc
index 497e803..b45b822 100644
--- a/remoting/client/plugin/chromoting_scriptable_object.cc
+++ b/remoting/client/plugin/chromoting_scriptable_object.cc
@@ -9,6 +9,7 @@
#include "ppapi/cpp/var.h"
#include "remoting/client/client_config.h"
#include "remoting/client/plugin/chromoting_instance.h"
+#include "remoting/client/plugin/pepper_xmpp_proxy.h"
using pp::Var;
@@ -250,6 +251,19 @@ void ChromotingScriptableObject::SignalLoginChallenge() {
LogDebugInfo("Exception when invoking loginChallenge JS callback.");
}
+void ChromotingScriptableObject::AttachXmppProxy(XmppProxy* xmpp_proxy) {
+ xmpp_proxy_ = xmpp_proxy;
+}
+
+void ChromotingScriptableObject::SendIq(const std::string& iq_request_xml) {
+ // TODO(ajwong): Do something smart here.
+ NOTIMPLEMENTED();
+}
+
+void ChromotingScriptableObject::ReceiveIq(const std::string& iq_response_xml) {
+ xmpp_proxy_->ReceiveIq(iq_response_xml);
+}
+
Var ChromotingScriptableObject::DoConnect(const std::vector<Var>& args,
Var* exception) {
if (args.size() != 3) {
diff --git a/remoting/client/plugin/chromoting_scriptable_object.h b/remoting/client/plugin/chromoting_scriptable_object.h
index aec9c23..b8b848e62 100644
--- a/remoting/client/plugin/chromoting_scriptable_object.h
+++ b/remoting/client/plugin/chromoting_scriptable_object.h
@@ -65,12 +65,15 @@
#include <string>
#include <vector>
+#include "base/weak_ptr.h"
+
#include "ppapi/cpp/dev/scriptable_object_deprecated.h"
#include "ppapi/cpp/var.h"
namespace remoting {
class ChromotingInstance;
+class XmppProxy;
extern const char kStatusAttribute[];
@@ -91,7 +94,9 @@ enum ConnectionQuality {
QUALITY_BAD,
};
-class ChromotingScriptableObject : public pp::deprecated::ScriptableObject {
+class ChromotingScriptableObject
+ : public pp::deprecated::ScriptableObject,
+ public base::SupportsWeakPtr<ChromotingScriptableObject> {
public:
explicit ChromotingScriptableObject(ChromotingInstance* instance);
virtual ~ChromotingScriptableObject();
@@ -118,6 +123,12 @@ class ChromotingScriptableObject : public pp::deprecated::ScriptableObject {
// This should be called to signal JS code to provide login information.
void SignalLoginChallenge();
+ // Handles a Request/Response for a Javascript IQ stanza used to initiate a
+ // jingle connection.
+ void AttachXmppProxy(XmppProxy* xmpp_proxy);
+ void SendIq(const std::string& iq_request_xml);
+ void ReceiveIq(const std::string& iq_response_xml);
+
private:
typedef std::map<std::string, int> PropertyNameMap;
typedef pp::Var (ChromotingScriptableObject::*MethodHandler)(
@@ -141,7 +152,6 @@ class ChromotingScriptableObject : public pp::deprecated::ScriptableObject {
MethodHandler method;
};
-
// Routines to add new attribute, method properties.
void AddAttribute(const std::string& name, pp::Var attribute);
void AddMethod(const std::string& name, MethodHandler handler);
@@ -158,6 +168,7 @@ class ChromotingScriptableObject : public pp::deprecated::ScriptableObject {
PropertyNameMap property_names_;
std::vector<PropertyDescriptor> properties_;
+ scoped_refptr<XmppProxy> xmpp_proxy_;
ChromotingInstance* instance_;
};
diff --git a/remoting/client/plugin/pepper_xmpp_proxy.cc b/remoting/client/plugin/pepper_xmpp_proxy.cc
new file mode 100644
index 0000000..7e4c26c
--- /dev/null
+++ b/remoting/client/plugin/pepper_xmpp_proxy.cc
@@ -0,0 +1,57 @@
+// Copyright (c) 2011 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 "remoting/client/plugin/pepper_xmpp_proxy.h"
+
+namespace remoting {
+
+PepperXmppProxy::PepperXmppProxy(MessageLoop* jingle_message_loop,
+ MessageLoop* pepper_message_loop)
+ : jingle_message_loop_(jingle_message_loop),
+ pepper_message_loop_(pepper_message_loop) {
+}
+
+void PepperXmppProxy::AttachScriptableObject(
+ ChromotingScriptableObject* scriptable_object,
+ Task* done) {
+ DCHECK_EQ(jingle_message_loop_, MessageLoop::Current());
+ scriptable_object_ = scriptable_object;
+ scriptable_object_->AttachXmppProxy(this);
+}
+
+void PepperXmppProxy::AttachJavascriptIqRequest(
+ JavascriptIqRequest* javascript_iq_request) {
+ DCHECK_EQ(pepper_message_loop_, MessageLoop::Current());
+ javascript_iq_request_ = javascript_iq_request;
+}
+
+void PepperXmppProxy::SendIq(const std::string& iq_request_xml) {
+ if (MessageLoop::Current() != pepper_message_loop_) {
+ pepper_message_loop_->PostTask(
+ NewRunnableMethod(this,
+ &PepperXmppProxy::SendIq,
+ iq_request_xml));
+ return;
+ }
+
+ if (scriptable_object_) {
+ scriptable_object_->SendIq(iq_request_xml, this);
+ }
+}
+
+void PepperXmppProxy::ReceiveIq(const std::string& iq_response_xml) {
+ if (MessageLoop::Current() != jingle_message_loop_) {
+ jingle_message_loop_->PostTask(
+ NewRunnableMethod(this,
+ &PepperXmppProxy::ReceiveIq,
+ iq_response_xml));
+ return;
+ }
+
+ if (javascript_iq_request_) {
+ javascript_iq_request_->handleIqResponse(iq_response_xml);
+ }
+}
+
+} // namespace remoting
diff --git a/remoting/client/plugin/pepper_xmpp_proxy.h b/remoting/client/plugin/pepper_xmpp_proxy.h
new file mode 100644
index 0000000..6c6c553
--- /dev/null
+++ b/remoting/client/plugin/pepper_xmpp_proxy.h
@@ -0,0 +1,42 @@
+// Copyright (c) 2011 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.
+
+#ifndef REMOTING_CLIENT_PLUGIN_PEPPER_XMPP_PROXY_H_
+#define REMOTING_CLIENT_PLUGIN_PEPPER_XMPP_PROXY_H_
+
+#include "base/weak_ptr.h"
+#include "remoting/jingle_glue/iq_request.h"
+
+namespace remoting {
+
+class PepperXmppProxy : public XmppProxy {
+ public:
+ PepperXmppProxy(MessageLoop* jingle_message_loop,
+ MessageLoop* pepper_message_loop);
+
+ // Must be run on pepper thread.
+ void AttachScriptableObject(ChromotingScriptableObject* scriptable_object);
+
+ // Must be run on jingle thread.
+ void AttachJavascriptIqRequest(JavascriptIqRequest* javascript_iq_request);
+
+ void SendIq(const std::string& iq_request_xml);
+ void ReceiveIq(const std::string& iq_response_xml);
+
+ private:
+ ~PepperXmppProxy();
+
+ MessageLoop* jingle_message_loop_;
+ MessageLoop* pepper_message_loop_;
+
+ base::WeakPtr<ChromotingScriptableObject> scriptable_object_;
+ base::WeakPtr<JavascriptIqRequest> javascript_iq_request_;
+ std::string iq_response_xml_;
+
+ DISALLOW_COPY_AND_ASSIGN(PepperXmppProxy);
+};
+
+} // namespace remoting
+
+#endif // REMOTING_CLIENT_PLUGIN_PEPPER_XMPP_PROXY_H_