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

Unified Diff: remoting/client/plugin/chromoting_instance.cc

Issue 12518027: Protocol / client plugin changes to support interactively asking for a PIN (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Changed Pin-related objects to callbacks Created 7 years, 9 months 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: remoting/client/plugin/chromoting_instance.cc
diff --git a/remoting/client/plugin/chromoting_instance.cc b/remoting/client/plugin/chromoting_instance.cc
index 92476103c15fed2b5052592e854cc5c9822c2a37..953980207a6021409ed7023d77b4bf6dddd1a224 100644
--- a/remoting/client/plugin/chromoting_instance.cc
+++ b/remoting/client/plugin/chromoting_instance.cc
@@ -134,7 +134,8 @@ logging::LogMessageHandlerFunction g_logging_old_handler = NULL;
// String sent in the "hello" message to the plugin to describe features.
const char ChromotingInstance::kApiFeatures[] =
"highQualityScaling injectKeyEvent sendClipboardItem remapKey trapKey "
- "notifyClientDimensions notifyClientResolution pauseVideo pauseAudio";
+ "notifyClientDimensions notifyClientResolution pauseVideo pauseAudio "
+ "asyncPin";
bool ChromotingInstance::ParseAuthMethods(const std::string& auth_methods_str,
ClientConfig* config) {
@@ -171,6 +172,7 @@ ChromotingInstance::ChromotingInstance(PP_Instance pp_instance)
key_mapper_(&input_tracker_),
#endif
input_handler_(&key_mapper_),
+ use_async_pin_dialog_(false),
weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL);
RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD);
@@ -270,14 +272,25 @@ void ChromotingInstance::HandleMessage(const pp::Var& message) {
if (!data->GetString("hostJid", &config.host_jid) ||
!data->GetString("hostPublicKey", &config.host_public_key) ||
!data->GetString("localJid", &config.local_jid) ||
- !data->GetString("sharedSecret", &config.shared_secret) ||
!data->GetString("authenticationMethods", &auth_methods) ||
!ParseAuthMethods(auth_methods, &config) ||
!data->GetString("authenticationTag", &config.authentication_tag)) {
LOG(ERROR) << "Invalid connect() data.";
return;
}
-
+ if (use_async_pin_dialog_) {
+ config.fetch_pin_callback =
+ base::Bind(&ChromotingInstance::FetchPinFromDialog,
+ this->AsWeakPtr());
+ } else {
+ std::string shared_secret;
+ if (!data->GetString("sharedSecret", &shared_secret)) {
+ LOG(ERROR) << "Invalid connect() data.";
+ return;
+ }
+ config.fetch_pin_callback =
+ base::Bind(&ChromotingInstance::FetchPinFromString, shared_secret);
+ }
Connect(config);
} else if (method == "disconnect") {
Disconnect();
@@ -373,6 +386,15 @@ void ChromotingInstance::HandleMessage(const pp::Var& message) {
return;
}
PauseAudio(pause);
+ } else if (method == "useAsyncPinDialog") {
+ use_async_pin_dialog_ = true;
+ } else if (method == "onPinFetched") {
+ std::string pin;
+ if (!data->GetString("pin", &pin)) {
+ LOG(ERROR) << "Invalid onPinFetched.";
+ return;
+ }
+ OnPinFetched(pin);
}
}
@@ -424,6 +446,23 @@ void ChromotingInstance::OnConnectionReady(bool ready) {
PostChromotingMessage("onConnectionReady", data.Pass());
}
+void ChromotingInstance::FetchPinFromDialog(
+ const protocol::PinFetchedCallback& pin_fetched_callback) {
+ // Once the Session object calls this function, it won't continue the
+ // authentication until the callback is called (or connection is canceled).
+ // So, it's impossible to reach this with a callback already registered.
+ DCHECK(pin_fetched_callback_.is_null());
+ pin_fetched_callback_ = pin_fetched_callback;
+ scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue());
+ PostChromotingMessage("fetchPin", data.Pass());
+}
+
+void ChromotingInstance::FetchPinFromString(
+ const std::string& shared_secret,
+ const protocol::PinFetchedCallback& pin_fetched_callback) {
+ pin_fetched_callback.Run(shared_secret);
+}
+
protocol::ClipboardStub* ChromotingInstance::GetClipboardStub() {
// TODO(sergeyu): Move clipboard handling to a separate class.
// crbug.com/138108
@@ -650,6 +689,16 @@ void ChromotingInstance::PauseAudio(bool pause) {
host_connection_->host_stub()->ControlAudio(audio_control);
}
+void ChromotingInstance::OnPinFetched(const std::string& shared_secret) {
+ if (!pin_fetched_callback_.is_null()) {
+ pin_fetched_callback_.Run(shared_secret);
+ pin_fetched_callback_.Reset();
+ } else {
+ VLOG(1) <<
+ "Ignored OnPinFetched received without a pending fetch.";
+ }
+}
+
ChromotingStats* ChromotingInstance::GetStats() {
if (!client_.get())
return NULL;

Powered by Google App Engine
This is Rietveld 408576698