diff options
Diffstat (limited to 'remoting/client')
-rw-r--r-- | remoting/client/chromoting_client.cc | 42 | ||||
-rw-r--r-- | remoting/client/chromoting_client.h | 20 | ||||
-rw-r--r-- | remoting/client/client_config.h | 3 | ||||
-rw-r--r-- | remoting/client/client_user_interface.h | 7 | ||||
-rw-r--r-- | remoting/client/plugin/chromoting_instance.cc | 23 | ||||
-rw-r--r-- | remoting/client/plugin/chromoting_instance.h | 10 |
6 files changed, 99 insertions, 6 deletions
diff --git a/remoting/client/chromoting_client.cc b/remoting/client/chromoting_client.cc index 28d5154..c9208ff 100644 --- a/remoting/client/chromoting_client.cc +++ b/remoting/client/chromoting_client.cc @@ -5,6 +5,7 @@ #include "remoting/client/chromoting_client.h" #include "base/bind.h" +#include "remoting/base/capabilities.h" #include "remoting/client/audio_decode_scheduler.h" #include "remoting/client/audio_player.h" #include "remoting/client/client_context.h" @@ -14,6 +15,7 @@ #include "remoting/proto/video.pb.h" #include "remoting/protocol/authentication_method.h" #include "remoting/protocol/connection_to_host.h" +#include "remoting/protocol/host_stub.h" #include "remoting/protocol/negotiating_client_authenticator.h" #include "remoting/protocol/session_config.h" #include "remoting/protocol/transport.h" @@ -33,6 +35,7 @@ ChromotingClient::ChromotingClient( task_runner_(client_context->main_task_runner()), connection_(connection), user_interface_(user_interface), + host_capabilities_received_(false), weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { rectangle_decoder_ = new RectangleUpdateDecoder(client_context->main_task_runner(), @@ -88,14 +91,39 @@ ChromotingStats* ChromotingClient::GetStats() { return rectangle_decoder_->GetStats(); } +void ChromotingClient::SetCapabilities( + const protocol::Capabilities& capabilities) { + DCHECK(task_runner_->BelongsToCurrentThread()); + + // Only accept the first |protocol::Capabilities| message. + if (host_capabilities_received_) { + LOG(WARNING) << "protocol::Capabilities has been received already."; + return; + } + + host_capabilities_received_ = true; + if (capabilities.has_capabilities()) + host_capabilities_ = capabilities.capabilities(); + + VLOG(1) << "Host capabilities: " << host_capabilities_; + + // Calculate the set of capabilities enabled by both client and host and pass + // it to the webapp. + user_interface_->SetCapabilities( + IntersectCapabilities(config_.capabilities, host_capabilities_)); +} + void ChromotingClient::InjectClipboardEvent( const protocol::ClipboardEvent& event) { DCHECK(task_runner_->BelongsToCurrentThread()); + user_interface_->GetClipboardStub()->InjectClipboardEvent(event); } void ChromotingClient::SetCursorShape( const protocol::CursorShapeInfo& cursor_shape) { + DCHECK(task_runner_->BelongsToCurrentThread()); + user_interface_->GetCursorShapeStub()->SetCursorShape(cursor_shape); } @@ -121,6 +149,20 @@ void ChromotingClient::Initialize() { rectangle_decoder_->Initialize(connection_->config()); if (connection_->config().is_audio_enabled()) audio_decode_scheduler_->Initialize(connection_->config()); + + // Negotiate capabilities with the host. + if (connection_->config().SupportsCapabilities()) { + VLOG(1) << "Client capabilities: " << config_.capabilities; + + protocol::Capabilities capabilities; + capabilities.set_capabilities(config_.capabilities); + connection_->host_stub()->SetCapabilities(capabilities); + } else { + VLOG(1) << "The host does not support any capabilities."; + + host_capabilities_received_ = true; + user_interface_->SetCapabilities(host_capabilities_); + } } } // namespace remoting diff --git a/remoting/client/chromoting_client.h b/remoting/client/chromoting_client.h index d6fc09b..a04606e 100644 --- a/remoting/client/chromoting_client.h +++ b/remoting/client/chromoting_client.h @@ -7,7 +7,7 @@ #ifndef REMOTING_CLIENT_CHROMOTING_CLIENT_H_ #define REMOTING_CLIENT_CHROMOTING_CLIENT_H_ -#include <list> +#include <string> #include "base/callback.h" #include "base/memory/scoped_ptr.h" @@ -61,13 +61,17 @@ class ChromotingClient : public protocol::ConnectionToHost::HostEventCallback, // Return the stats recorded by this client. ChromotingStats* GetStats(); + // ClientStub implementation. + virtual void SetCapabilities( + const protocol::Capabilities& capabilities) OVERRIDE; + // ClipboardStub implementation for receiving clipboard data from host. - virtual void InjectClipboardEvent(const protocol::ClipboardEvent& event) - OVERRIDE; + virtual void InjectClipboardEvent( + const protocol::ClipboardEvent& event) OVERRIDE; // CursorShapeStub implementation for receiving cursor shape updates. - virtual void SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) - OVERRIDE; + virtual void SetCursorShape( + const protocol::CursorShapeInfo& cursor_shape) OVERRIDE; // ConnectionToHost::HostEventCallback implementation. virtual void OnConnectionState( @@ -93,6 +97,12 @@ class ChromotingClient : public protocol::ConnectionToHost::HostEventCallback, // If non-NULL, this is called when the client is done. base::Closure client_done_; + // The set of all capabilities supported by the host. + std::string host_capabilities_; + + // True if |protocol::Capabilities| message has been received. + bool host_capabilities_received_; + // Record the statistics of the connection. ChromotingStats stats_; diff --git a/remoting/client/client_config.h b/remoting/client/client_config.h index 9b954d1..35f7286 100644 --- a/remoting/client/client_config.h +++ b/remoting/client/client_config.h @@ -27,6 +27,9 @@ struct ClientConfig { std::vector<protocol::AuthenticationMethod> authentication_methods; std::string authentication_tag; + + // The set of all capabilities supported by the webapp. + std::string capabilities; }; } // namespace remoting diff --git a/remoting/client/client_user_interface.h b/remoting/client/client_user_interface.h index 646c7c8..59460f1 100644 --- a/remoting/client/client_user_interface.h +++ b/remoting/client/client_user_interface.h @@ -5,7 +5,10 @@ #ifndef REMOTING_CLIENT_CLIENT_USER_INTERFACE_H_ #define REMOTING_CLIENT_CLIENT_USER_INTERFACE_H_ +#include <string> + #include "base/basictypes.h" +#include "base/memory/scoped_ptr.h" #include "remoting/protocol/connection_to_host.h" #include "remoting/protocol/third_party_client_authenticator.h" @@ -30,6 +33,10 @@ class ClientUserInterface { protocol::ErrorCode error) = 0; virtual void OnConnectionReady(bool ready) = 0; + // Passes the final set of capabilities negotiated between the client and host + // to the application. + virtual void SetCapabilities(const std::string& capabilities) = 0; + // Get the view's ClipboardStub implementation. virtual protocol::ClipboardStub* GetClipboardStub() = 0; diff --git a/remoting/client/plugin/chromoting_instance.cc b/remoting/client/plugin/chromoting_instance.cc index 45671e4..bc204ca 100644 --- a/remoting/client/plugin/chromoting_instance.cc +++ b/remoting/client/plugin/chromoting_instance.cc @@ -137,12 +137,15 @@ logging::LogMessageHandlerFunction g_logging_old_handler = NULL; } // namespace -// String sent in the "hello" message to the plugin to describe features. +// String sent in the "hello" message to the webapp to describe features. const char ChromotingInstance::kApiFeatures[] = "highQualityScaling injectKeyEvent sendClipboardItem remapKey trapKey " "notifyClientDimensions notifyClientResolution pauseVideo pauseAudio " "asyncPin thirdPartyAuth"; +const char ChromotingInstance::kRequestedCapabilities[] = ""; +const char ChromotingInstance::kSupportedCapabilities[] = ""; + bool ChromotingInstance::ParseAuthMethods(const std::string& auth_methods_str, ClientConfig* config) { std::vector<std::string> auth_methods; @@ -191,6 +194,9 @@ ChromotingInstance::ChromotingInstance(PP_Instance pp_instance) data->SetInteger("apiVersion", kApiVersion); data->SetString("apiFeatures", kApiFeatures); data->SetInteger("apiMinVersion", kApiMinMessagingVersion); + data->SetString("requestedCapabilities", kRequestedCapabilities); + data->SetString("supportedCapabilities", kSupportedCapabilities); + PostChromotingMessage("hello", data.Pass()); } @@ -297,6 +303,15 @@ void ChromotingInstance::HandleMessage(const pp::Var& message) { config.fetch_secret_callback = base::Bind(&ChromotingInstance::FetchSecretFromString, shared_secret); } + + // Read the list of capabilities, if any. + if (data->HasKey("capabilities")) { + if (!data->GetString("capabilities", &config.capabilities)) { + LOG(ERROR) << "Invalid connect() data."; + return; + } + } + Connect(config); } else if (method == "disconnect") { Disconnect(); @@ -478,6 +493,12 @@ void ChromotingInstance::OnConnectionReady(bool ready) { PostChromotingMessage("onConnectionReady", data.Pass()); } +void ChromotingInstance::SetCapabilities(const std::string& capabilities) { + scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); + data->SetString("capabilities", capabilities); + PostChromotingMessage("setCapabilities", data.Pass()); +} + void ChromotingInstance::FetchSecretFromDialog( const protocol::SecretFetchedCallback& secret_fetched_callback) { // Once the Session object calls this function, it won't continue the diff --git a/remoting/client/plugin/chromoting_instance.h b/remoting/client/plugin/chromoting_instance.h index c6c8f578f..dd19cc1 100644 --- a/remoting/client/plugin/chromoting_instance.h +++ b/remoting/client/plugin/chromoting_instance.h @@ -34,6 +34,7 @@ #include "remoting/client/plugin/pepper_input_handler.h" #include "remoting/client/plugin/pepper_plugin_thread_delegate.h" #include "remoting/proto/event.pb.h" +#include "remoting/protocol/client_stub.h" #include "remoting/protocol/clipboard_stub.h" #include "remoting/protocol/connection_to_host.h" #include "remoting/protocol/cursor_shape_stub.h" @@ -80,6 +81,14 @@ class ChromotingInstance : // without bumping the API version. static const char kApiFeatures[]; + // Capabilities supported by the plugin that should also be supported by the + // webapp to be enabled. + static const char kRequestedCapabilities[]; + + // Capabilities supported by the plugin that do not need to be supported by + // the webapp to be enabled. + static const char kSupportedCapabilities[]; + // Backward-compatibility version used by for the messaging // interface. Should be updated whenever we remove support for // an older version of the API. @@ -108,6 +117,7 @@ class ChromotingInstance : virtual void OnConnectionState(protocol::ConnectionToHost::State state, protocol::ErrorCode error) OVERRIDE; virtual void OnConnectionReady(bool ready) OVERRIDE; + virtual void SetCapabilities(const std::string& capabilities) OVERRIDE; virtual protocol::ClipboardStub* GetClipboardStub() OVERRIDE; virtual protocol::CursorShapeStub* GetCursorShapeStub() OVERRIDE; virtual scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher> |