summaryrefslogtreecommitdiffstats
path: root/remoting/client/plugin/chromoting_plugin.cc
diff options
context:
space:
mode:
Diffstat (limited to 'remoting/client/plugin/chromoting_plugin.cc')
-rw-r--r--remoting/client/plugin/chromoting_plugin.cc87
1 files changed, 22 insertions, 65 deletions
diff --git a/remoting/client/plugin/chromoting_plugin.cc b/remoting/client/plugin/chromoting_plugin.cc
index 160bf3a..bb1aa80 100644
--- a/remoting/client/plugin/chromoting_plugin.cc
+++ b/remoting/client/plugin/chromoting_plugin.cc
@@ -10,18 +10,18 @@
#include "base/message_loop.h"
#include "base/string_util.h"
#include "base/thread.h"
+#include "remoting/client/client_config.h"
+#include "remoting/client/client_util.h"
#include "remoting/client/chromoting_client.h"
#include "remoting/client/host_connection.h"
#include "remoting/client/jingle_host_connection.h"
+#include "remoting/client/plugin/pepper_input_handler.h"
#include "remoting/client/plugin/pepper_view.h"
#include "remoting/jingle_glue/jingle_thread.h"
#include "third_party/ppapi/c/pp_event.h"
#include "third_party/ppapi/c/pp_rect.h"
#include "third_party/ppapi/cpp/completion_callback.h"
-using std::string;
-using std::vector;
-
namespace remoting {
const char* ChromotingPlugin::kMimeType = "pepper-application/x-chromoting";
@@ -32,18 +32,17 @@ ChromotingPlugin::ChromotingPlugin(PP_Instance pp_instance)
}
ChromotingPlugin::~ChromotingPlugin() {
- if (host_connection_.get())
- host_connection_->Disconnect();
+ if (client_.get()) {
+ client_->Stop();
+ }
// TODO(ajwong): We need to ensure all objects have actually stopped posting
// to the message loop before this point. Right now, we don't have a well
// defined stop for the plugin process, and the thread shutdown is likely a
// race condition.
- if (network_thread_.get())
- network_thread_->Stop();
-
- if (main_thread_.get())
- main_thread_->Stop();
+ if (context_.get()) {
+ context_->Stop();
+ }
}
bool ChromotingPlugin::Init(uint32_t argc,
@@ -77,34 +76,29 @@ bool ChromotingPlugin::Init(uint32_t argc,
return false;
}
- string user_id;
- string auth_token;
- string host_jid;
- if (!ParseUrl(url, &user_id, &auth_token, &host_jid)) {
+ ClientConfig config;
+ if (!GetLoginInfoFromUrlParams(url, &config)) {
LOG(WARNING) << "Could not parse URL: " << url;
return false;
}
- // Start the threads.
- main_thread_.reset(new base::Thread("ChromoClientMain"));
- if (!main_thread_->Start()) {
- LOG(ERROR) << "Main thread failed to start.";
- return false;
- }
- network_thread_.reset(new JingleThread());
- network_thread_->Start();
-
- // Create the chromting objects.
- host_connection_.reset(new JingleHostConnection(network_thread_.get()));
+ // Create the chromoting objects.
+ host_connection_.reset(new JingleHostConnection(context_.get()));
view_.reset(new PepperView(this));
- client_.reset(new ChromotingClient(main_thread_->message_loop(),
- host_connection_.get(), view_.get()));
+ input_handler_.reset(new PepperInputHandler());
+ client_.reset(new ChromotingClient(&config,
+ context_.get(),
+ host_connection_.get(),
+ view_.get(),
+ input_handler_.get(),
+ NULL));
// Default to a medium grey.
view_->SetSolidFill(0xFFCDCDCD);
// Kick off the connection.
- host_connection_->Connect(user_id, auth_token, host_jid, client_.get());
+ context_->Start();
+ client_->Start();
return true;
}
@@ -153,41 +147,4 @@ bool ChromotingPlugin::HandleEvent(const PP_Event& event) {
return false;
}
-bool ChromotingPlugin::ParseUrl(const std::string& url,
- string* user_id,
- string* auth_token,
- string* host_jid) {
- // TODO(ajwong): We should use GURL or something. Don't parse this by hand!
-
- // The Url should be of the form:
- //
- // chromotocol://<hostid>?user=<userid>&auth=<authtoken>&jid=<hostjid>
- //
- vector<string> parts;
- SplitString(url, '&', &parts);
- if (parts.size() != 3) {
- return false;
- }
-
- size_t pos = parts[0].rfind('=');
- if (pos == string::npos && (pos + 1) != string::npos) {
- return false;
- }
- user_id->assign(parts[0].substr(pos + 1));
-
- pos = parts[1].rfind('=');
- if (pos == string::npos && (pos + 1) != string::npos) {
- return false;
- }
- auth_token->assign(parts[1].substr(pos + 1));
-
- pos = parts[2].rfind('=');
- if (pos == string::npos && (pos + 1) != string::npos) {
- return false;
- }
- host_jid->assign(parts[2].substr(pos + 1));
-
- return true;
-}
-
} // namespace remoting