diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-28 21:23:36 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-28 21:23:36 +0000 |
commit | 519b5bf5aeed0f38179fb9b3271c8c3539f47cdc (patch) | |
tree | a8dd5095efc1769f6249e1e9b32781d5831ab3fb /remoting | |
parent | 1290063b22632e0e615955e726e59204dd2bc7c0 (diff) | |
download | chromium_src-519b5bf5aeed0f38179fb9b3271c8c3539f47cdc.zip chromium_src-519b5bf5aeed0f38179fb9b3271c8c3539f47cdc.tar.gz chromium_src-519b5bf5aeed0f38179fb9b3271c8c3539f47cdc.tar.bz2 |
Chromoting pepper plugin to respond to BeginSessionResponse
Trigger loginChallenge when the client is connected or the last login attempt
has failed.
BUG=None
TEST=None
Review URL: http://codereview.chromium.org/6160001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73022 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/client/chromoting_client.cc | 14 | ||||
-rw-r--r-- | remoting/client/chromoting_view.h | 7 | ||||
-rw-r--r-- | remoting/client/extension/chromoting_tab.js | 14 | ||||
-rw-r--r-- | remoting/client/plugin/chromoting_instance.cc | 15 | ||||
-rw-r--r-- | remoting/client/plugin/chromoting_instance.h | 4 | ||||
-rw-r--r-- | remoting/client/plugin/chromoting_scriptable_object.cc | 50 | ||||
-rw-r--r-- | remoting/client/plugin/chromoting_scriptable_object.h | 23 | ||||
-rw-r--r-- | remoting/client/plugin/pepper_view.cc | 14 | ||||
-rw-r--r-- | remoting/client/plugin/pepper_view.h | 1 | ||||
-rw-r--r-- | remoting/client/plugin/pepper_view_proxy.cc | 12 | ||||
-rw-r--r-- | remoting/client/plugin/pepper_view_proxy.h | 1 | ||||
-rw-r--r-- | remoting/client/x11_view.cc | 4 | ||||
-rw-r--r-- | remoting/client/x11_view.h | 1 |
13 files changed, 132 insertions, 28 deletions
diff --git a/remoting/client/chromoting_client.cc b/remoting/client/chromoting_client.cc index 299a2cf..21911a8 100644 --- a/remoting/client/chromoting_client.cc +++ b/remoting/client/chromoting_client.cc @@ -219,11 +219,23 @@ void ChromotingClient::Initialize() { void ChromotingClient::NotifyResolution( const protocol::NotifyResolutionRequest* msg, Task* done) { NOTIMPLEMENTED(); + done->Run(); + delete done; } void ChromotingClient::BeginSessionResponse( const protocol::LocalLoginStatus* msg, Task* done) { - NOTIMPLEMENTED(); + if (message_loop() != MessageLoop::current()) { + message_loop()->PostTask( + FROM_HERE, + NewRunnableMethod(this, &ChromotingClient::BeginSessionResponse, + msg, done)); + return; + } + + view_->UpdateLoginStatus(msg->success(), msg->error_info()); + done->Run(); + delete done; } } // namespace remoting diff --git a/remoting/client/chromoting_view.h b/remoting/client/chromoting_view.h index 7d2b68a..cf2fc5a 100644 --- a/remoting/client/chromoting_view.h +++ b/remoting/client/chromoting_view.h @@ -5,6 +5,8 @@ #ifndef REMOTING_CLIENT_CHROMOTING_VIEW_H_ #define REMOTING_CLIENT_CHROMOTING_VIEW_H_ +#include <string> + #include "base/ref_counted.h" #include "media/base/video_frame.h" @@ -61,6 +63,11 @@ class ChromotingView { // Record the update the state of the connection, updating the UI as needed. virtual void SetConnectionState(ConnectionState s) = 0; + // Update the status of the last login attempt. Updating the UI as needed. + // |success| is set to true if the last login successful otherwise false. + // |info| contains the error information if available. + virtual void UpdateLoginStatus(bool success, const std::string& info) = 0; + // Reposition and resize the viewport into the backing store. If the viewport // extends past the end of the backing store, it is filled with black. virtual void SetViewport(int x, int y, int width, int height) = 0; diff --git a/remoting/client/extension/chromoting_tab.js b/remoting/client/extension/chromoting_tab.js index adf8f16..1496846 100644 --- a/remoting/client/extension/chromoting_tab.js +++ b/remoting/client/extension/chromoting_tab.js @@ -39,6 +39,7 @@ function requestListener(request, sender, sendResponse) { // has changes and the UI needs to be updated. It needs to be an object with // a 'callback' property that contains the callback function. plugin.connectionInfoUpdate = pluginCallback; + plugin.loginChallenge = pluginLoginChallenge; // TODO(garykac): Clean exit if |connect| isn't a funtion. if (typeof plugin.connect === 'function') { @@ -53,6 +54,19 @@ function requestListener(request, sender, sendResponse) { } /** + * This is the callback method that the plugin calls to request username and + * password for logging into the remote host. + */ +function pluginLoginChallenge() { + if (typeof chromoting.plugin.submitLoginInfo === 'function') { + window.setTimeout("chromoting.plugin.submitLoginInfo('hello', 'world')", + 100); + } else { + alert("Error calling methods in plugin."); + } +} + +/** * This is the callback that the plugin invokes to indicate that the host/ * client connection status has changed. */ diff --git a/remoting/client/plugin/chromoting_instance.cc b/remoting/client/plugin/chromoting_instance.cc index e7af6c0..890c478 100644 --- a/remoting/client/plugin/chromoting_instance.cc +++ b/remoting/client/plugin/chromoting_instance.cc @@ -9,6 +9,7 @@ #include "base/message_loop.h" #include "base/string_util.h" +#include "base/task.h" #include "base/threading/thread.h" #include "ppapi/c/pp_input_event.h" #include "ppapi/cpp/completion_callback.h" @@ -22,6 +23,7 @@ #include "remoting/client/plugin/pepper_view.h" #include "remoting/client/plugin/pepper_view_proxy.h" #include "remoting/jingle_glue/jingle_thread.h" +#include "remoting/proto/auth.pb.h" #include "remoting/protocol/connection_to_host.h" #include "remoting/protocol/jingle_connection_to_host.h" @@ -180,6 +182,19 @@ ChromotingScriptableObject* ChromotingInstance::GetScriptableObject() { return NULL; } +void ChromotingInstance::SubmitLoginInfo(const std::string& username, + const std::string& password) { + protocol::LocalLoginCredentials* credentials = + new protocol::LocalLoginCredentials(); + credentials->set_type(protocol::PASSWORD); + credentials->set_username(username); + credentials->set_credential(password.data(), password.length()); + + host_connection_->host_stub()->BeginSessionRequest( + credentials, + new DeleteTask<protocol::LocalLoginCredentials>(credentials)); +} + pp::Var ChromotingInstance::GetInstanceObject() { if (instance_object_.is_undefined()) { ChromotingScriptableObject* object = new ChromotingScriptableObject(this); diff --git a/remoting/client/plugin/chromoting_instance.h b/remoting/client/plugin/chromoting_instance.h index 94e4100..8a5f7f6 100644 --- a/remoting/client/plugin/chromoting_instance.h +++ b/remoting/client/plugin/chromoting_instance.h @@ -72,6 +72,10 @@ class ChromotingInstance : public pp::Instance { // Convenience wrapper to get the ChromotingScriptableObject. ChromotingScriptableObject* GetScriptableObject(); + // Called by ChromotingScriptableObject to provide username and password. + void SubmitLoginInfo(const std::string& username, + const std::string& password); + private: FRIEND_TEST_ALL_PREFIXES(ChromotingInstanceTest, TestCaseSetup); diff --git a/remoting/client/plugin/chromoting_scriptable_object.cc b/remoting/client/plugin/chromoting_scriptable_object.cc index 22016ad..c470fcd 100644 --- a/remoting/client/plugin/chromoting_scriptable_object.cc +++ b/remoting/client/plugin/chromoting_scriptable_object.cc @@ -54,6 +54,7 @@ void ChromotingScriptableObject::Init() { AddMethod("connect", &ChromotingScriptableObject::DoConnect); AddMethod("disconnect", &ChromotingScriptableObject::DoDisconnect); + AddMethod("submitLoginInfo", &ChromotingScriptableObject::DoSubmitLogin); } bool ChromotingScriptableObject::HasProperty(const Var& name, Var* exception) { @@ -183,10 +184,10 @@ void ChromotingScriptableObject::AddMethod(const std::string& name, } void ChromotingScriptableObject::SignalConnectionInfoChange() { - pp::Var exception; + Var exception; // The JavaScript callback function is the 'callback' property on the - // 'kConnectionInfoUpdate' object. + // 'connectionInfoUpdate' object. Var cb = GetProperty(Var(kConnectionInfoUpdate), &exception); // Var() means call the object directly as a function rather than calling @@ -200,22 +201,24 @@ void ChromotingScriptableObject::SignalConnectionInfoChange() { } void ChromotingScriptableObject::SignalLoginChallenge() { - pp::Var exception; + Var exception; - Var fun = GetProperty(Var(kLoginChallenge), &exception); + // The JavaScript callback function is the 'callback' property on the + // 'connectionInfoUpdate' object. + Var cb = GetProperty(Var(kLoginChallenge), &exception); - // Calls the loginChallenge() function with a callback. - fun.Call(Var(), MethodHandler(&ChromotingScriptableObject::DoLogin), - &exception); + // Var() means call the object directly as a function rather than calling + // a method in the object. + cb.Call(Var(), 0, NULL, &exception); if (!exception.is_undefined()) { - LOG(WARNING) << "Exception when calling JS callback" + LOG(WARNING) << "Exception when invoking JS callback" << exception.AsString(); } } -pp::Var ChromotingScriptableObject::DoConnect(const std::vector<Var>& args, - Var* exception) { +Var ChromotingScriptableObject::DoConnect(const std::vector<Var>& args, + Var* exception) { if (args.size() != 3) { *exception = Var("Usage: connect(username, host_jid, auth_token)"); return Var(); @@ -246,15 +249,32 @@ pp::Var ChromotingScriptableObject::DoConnect(const std::vector<Var>& args, return Var(); } -pp::Var ChromotingScriptableObject::DoDisconnect(const std::vector<Var>& args, - Var* exception) { +Var ChromotingScriptableObject::DoDisconnect(const std::vector<Var>& args, + Var* exception) { instance_->Disconnect(); return Var(); } -pp::Var ChromotingScriptableObject::DoLogin(const std::vector<pp::Var>& args, - pp::Var* exception) { - NOTIMPLEMENTED(); +Var ChromotingScriptableObject::DoSubmitLogin(const std::vector<Var>& args, + Var* exception) { + if (args.size() != 2) { + *exception = Var("Usage: login(username, password)"); + return Var(); + } + + if (!args[0].is_string()) { + *exception = Var("Username must be a string."); + return Var(); + } + std::string username = args[0].AsString(); + + if (!args[1].is_string()) { + *exception = Var("Password must be a string."); + return Var(); + } + std::string password = args[1].AsString(); + + instance_->SubmitLoginInfo(username, password); return Var(); } diff --git a/remoting/client/plugin/chromoting_scriptable_object.h b/remoting/client/plugin/chromoting_scriptable_object.h index 7153467..e265a82 100644 --- a/remoting/client/plugin/chromoting_scriptable_object.h +++ b/remoting/client/plugin/chromoting_scriptable_object.h @@ -29,12 +29,11 @@ // // status has been updated. // attribute Function connectionInfoUpdate; // -// // This function is called with a callback function as argument. The -// // signature of this function is: -// // function login(username, password); +// // This function is called when login information for the host machine is +// // needed. // // -// // The provided callback function should be called when username and -// // password is available, e.g. collected by a login prompt. +// // User of this object should respond with calling submitLoginInfo() when +// // username and password is available. // // // // This function will be called multiple times until login was successful // // or the maximum number of login attempts has been reached. In the @@ -44,6 +43,9 @@ // // Methods on the object. // void connect(string username, string host_jid, string auth_token); // void disconnect(); +// +// // Method for submitting login information. +// void submitLoginInfo(string username, string password); // } #ifndef REMOTING_CLIENT_PLUGIN_CHROMOTING_SCRIPTABLE_OBJECT_H_ @@ -101,6 +103,9 @@ class ChromotingScriptableObject : public pp::deprecated::ScriptableObject { void SetConnectionInfo(ConnectionStatus status, ConnectionQuality quality); + // This should be called to signal JS code to provide login information. + void SignalLoginChallenge(); + private: typedef std::map<std::string, int> PropertyNameMap; typedef pp::Var (ChromotingScriptableObject::*MethodHandler)( @@ -133,15 +138,11 @@ class ChromotingScriptableObject : public pp::deprecated::ScriptableObject { // changed. void SignalConnectionInfoChange(); - // This should be called to signal JS code to provide login information. - void SignalLoginChallenge(); - pp::Var DoConnect(const std::vector<pp::Var>& args, pp::Var* exception); pp::Var DoDisconnect(const std::vector<pp::Var>& args, pp::Var* exception); - // This method is called by JS to provide login information. Note that this - // method is provided as a callback. - pp::Var DoLogin(const std::vector<pp::Var>& args, pp::Var* exception); + // This method is called by JS to provide login information. + pp::Var DoSubmitLogin(const std::vector<pp::Var>& args, pp::Var* exception); PropertyNameMap property_names_; std::vector<PropertyDescriptor> properties_; diff --git a/remoting/client/plugin/pepper_view.cc b/remoting/client/plugin/pepper_view.cc index 0031439..4c58ed6 100644 --- a/remoting/client/plugin/pepper_view.cc +++ b/remoting/client/plugin/pepper_view.cc @@ -131,6 +131,7 @@ void PepperView::UnsetSolidFill() { void PepperView::SetConnectionState(ConnectionState state) { DCHECK(instance_->CurrentlyOnPluginThread()); + // TODO(hclam): Re-consider the way we communicate with Javascript. ChromotingScriptableObject* scriptable_obj = instance_->GetScriptableObject(); switch (state) { case CREATED: @@ -140,7 +141,7 @@ void PepperView::SetConnectionState(ConnectionState state) { case CONNECTED: UnsetSolidFill(); - scriptable_obj->SetConnectionInfo(STATUS_CONNECTED, QUALITY_UNKNOWN); + scriptable_obj->SignalLoginChallenge(); break; case DISCONNECTED: @@ -155,6 +156,17 @@ void PepperView::SetConnectionState(ConnectionState state) { } } +void PepperView::UpdateLoginStatus(bool success, const std::string& info) { + DCHECK(instance_->CurrentlyOnPluginThread()); + + // TODO(hclam): Re-consider the way we communicate with Javascript. + ChromotingScriptableObject* scriptable_obj = instance_->GetScriptableObject(); + if (success) + scriptable_obj->SetConnectionInfo(STATUS_CONNECTED, QUALITY_UNKNOWN); + else + scriptable_obj->SignalLoginChallenge(); +} + void PepperView::SetViewport(int x, int y, int width, int height) { DCHECK(instance_->CurrentlyOnPluginThread()); diff --git a/remoting/client/plugin/pepper_view.h b/remoting/client/plugin/pepper_view.h index f02a26b..f7822f3 100644 --- a/remoting/client/plugin/pepper_view.h +++ b/remoting/client/plugin/pepper_view.h @@ -38,6 +38,7 @@ class PepperView : public ChromotingView, virtual void SetSolidFill(uint32 color); virtual void UnsetSolidFill(); virtual void SetConnectionState(ConnectionState state); + virtual void UpdateLoginStatus(bool success, const std::string& info); virtual void SetViewport(int x, int y, int width, int height); // FrameConsumer implementation. diff --git a/remoting/client/plugin/pepper_view_proxy.cc b/remoting/client/plugin/pepper_view_proxy.cc index 4ee72d0..ce675f2 100644 --- a/remoting/client/plugin/pepper_view_proxy.cc +++ b/remoting/client/plugin/pepper_view_proxy.cc @@ -80,6 +80,18 @@ void PepperViewProxy::SetConnectionState(ConnectionState state) { view_->SetConnectionState(state); } +void PepperViewProxy::UpdateLoginStatus(bool success, const std::string& info) { + if (instance_ && !instance_->CurrentlyOnPluginThread()) { + RunTaskOnPluginThread(NewTracedMethod(this, + &PepperViewProxy::UpdateLoginStatus, + success, info)); + return; + } + + if (view_) + view_->UpdateLoginStatus(success, info); +} + void PepperViewProxy::SetViewport(int x, int y, int width, int height) { if (instance_ && !instance_->CurrentlyOnPluginThread()) { RunTaskOnPluginThread(NewTracedMethod(this, &PepperViewProxy::SetViewport, diff --git a/remoting/client/plugin/pepper_view_proxy.h b/remoting/client/plugin/pepper_view_proxy.h index 4c294e7..3d12daa 100644 --- a/remoting/client/plugin/pepper_view_proxy.h +++ b/remoting/client/plugin/pepper_view_proxy.h @@ -38,6 +38,7 @@ class PepperViewProxy : public base::RefCountedThreadSafe<PepperViewProxy>, virtual void SetSolidFill(uint32 color); virtual void UnsetSolidFill(); virtual void SetConnectionState(ConnectionState state); + virtual void UpdateLoginStatus(bool success, const std::string& info); virtual void SetViewport(int x, int y, int width, int height); // FrameConsumer implementation. diff --git a/remoting/client/x11_view.cc b/remoting/client/x11_view.cc index dc66062..2bbddd3 100644 --- a/remoting/client/x11_view.cc +++ b/remoting/client/x11_view.cc @@ -137,6 +137,10 @@ void X11View::SetConnectionState(ConnectionState s) { // TODO(garykac): Implement. } +void X11View::UpdateLoginStatus(bool success, const std::string& info) { + NOTIMPLEMENTED(); +} + void X11View::SetViewport(int x, int y, int width, int height) { // TODO(garykac): Implement. } diff --git a/remoting/client/x11_view.h b/remoting/client/x11_view.h index 7b62394..9ba7fc1 100644 --- a/remoting/client/x11_view.h +++ b/remoting/client/x11_view.h @@ -30,6 +30,7 @@ class X11View : public ChromotingView, public FrameConsumer { virtual void SetSolidFill(uint32 color); virtual void UnsetSolidFill(); virtual void SetConnectionState(ConnectionState s); + virtual void UpdateLoginStatus(bool success, const std::string& info); virtual void SetViewport(int x, int y, int width, int height); // FrameConsumer implementation. |