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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/client/plugin/chromoting_instance.h" 5 #include "remoting/client/plugin/chromoting_instance.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 16 matching lines...) Expand all
27 #include "ppapi/cpp/input_event.h" 27 #include "ppapi/cpp/input_event.h"
28 #include "ppapi/cpp/mouse_cursor.h" 28 #include "ppapi/cpp/mouse_cursor.h"
29 #include "ppapi/cpp/rect.h" 29 #include "ppapi/cpp/rect.h"
30 #include "remoting/base/constants.h" 30 #include "remoting/base/constants.h"
31 #include "remoting/base/util.h" 31 #include "remoting/base/util.h"
32 #include "remoting/client/chromoting_client.h" 32 #include "remoting/client/chromoting_client.h"
33 #include "remoting/client/client_config.h" 33 #include "remoting/client/client_config.h"
34 #include "remoting/client/frame_consumer_proxy.h" 34 #include "remoting/client/frame_consumer_proxy.h"
35 #include "remoting/client/plugin/pepper_audio_player.h" 35 #include "remoting/client/plugin/pepper_audio_player.h"
36 #include "remoting/client/plugin/pepper_input_handler.h" 36 #include "remoting/client/plugin/pepper_input_handler.h"
37 #include "remoting/client/plugin/pepper_pin_fetcher.h"
37 #include "remoting/client/plugin/pepper_port_allocator.h" 38 #include "remoting/client/plugin/pepper_port_allocator.h"
38 #include "remoting/client/plugin/pepper_view.h" 39 #include "remoting/client/plugin/pepper_view.h"
39 #include "remoting/client/plugin/pepper_xmpp_proxy.h" 40 #include "remoting/client/plugin/pepper_xmpp_proxy.h"
40 #include "remoting/client/rectangle_update_decoder.h" 41 #include "remoting/client/rectangle_update_decoder.h"
41 #include "remoting/protocol/connection_to_host.h" 42 #include "remoting/protocol/connection_to_host.h"
42 #include "remoting/protocol/host_stub.h" 43 #include "remoting/protocol/host_stub.h"
43 #include "remoting/protocol/libjingle_transport_factory.h" 44 #include "remoting/protocol/libjingle_transport_factory.h"
44 45
45 // Windows defines 'PostMessage', so we have to undef it. 46 // Windows defines 'PostMessage', so we have to undef it.
46 #if defined(PostMessage) 47 #if defined(PostMessage)
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 g_logging_instance = LAZY_INSTANCE_INITIALIZER; 128 g_logging_instance = LAZY_INSTANCE_INITIALIZER;
128 base::LazyInstance<base::Lock>::Leaky 129 base::LazyInstance<base::Lock>::Leaky
129 g_logging_lock = LAZY_INSTANCE_INITIALIZER; 130 g_logging_lock = LAZY_INSTANCE_INITIALIZER;
130 logging::LogMessageHandlerFunction g_logging_old_handler = NULL; 131 logging::LogMessageHandlerFunction g_logging_old_handler = NULL;
131 132
132 } // namespace 133 } // namespace
133 134
134 // String sent in the "hello" message to the plugin to describe features. 135 // String sent in the "hello" message to the plugin to describe features.
135 const char ChromotingInstance::kApiFeatures[] = 136 const char ChromotingInstance::kApiFeatures[] =
136 "highQualityScaling injectKeyEvent sendClipboardItem remapKey trapKey " 137 "highQualityScaling injectKeyEvent sendClipboardItem remapKey trapKey "
137 "notifyClientDimensions notifyClientResolution pauseVideo pauseAudio"; 138 "notifyClientDimensions notifyClientResolution pauseVideo pauseAudio "
139 "onPinFetched useAsyncPinDialog";
Sergey Ulanov 2013/03/17 21:29:21 Don't need two separate features
rmsousa 2013/03/18 21:07:26 Done.
138 140
139 bool ChromotingInstance::ParseAuthMethods(const std::string& auth_methods_str, 141 bool ChromotingInstance::ParseAuthMethods(const std::string& auth_methods_str,
140 ClientConfig* config) { 142 ClientConfig* config) {
141 std::vector<std::string> auth_methods; 143 std::vector<std::string> auth_methods;
142 base::SplitString(auth_methods_str, ',', &auth_methods); 144 base::SplitString(auth_methods_str, ',', &auth_methods);
143 for (std::vector<std::string>::iterator it = auth_methods.begin(); 145 for (std::vector<std::string>::iterator it = auth_methods.begin();
144 it != auth_methods.end(); ++it) { 146 it != auth_methods.end(); ++it) {
145 protocol::AuthenticationMethod authentication_method = 147 protocol::AuthenticationMethod authentication_method =
146 protocol::AuthenticationMethod::FromString(*it); 148 protocol::AuthenticationMethod::FromString(*it);
147 if (authentication_method.is_valid()) 149 if (authentication_method.is_valid())
(...skipping 16 matching lines...) Expand all
164 input_tracker_(&mouse_input_filter_), 166 input_tracker_(&mouse_input_filter_),
165 #if defined(OS_MACOSX) 167 #if defined(OS_MACOSX)
166 // On Mac we need an extra filter to inject missing keyup events. 168 // On Mac we need an extra filter to inject missing keyup events.
167 // See remoting/client/plugin/mac_key_event_processor.h for more details. 169 // See remoting/client/plugin/mac_key_event_processor.h for more details.
168 mac_key_event_processor_(&input_tracker_), 170 mac_key_event_processor_(&input_tracker_),
169 key_mapper_(&mac_key_event_processor_), 171 key_mapper_(&mac_key_event_processor_),
170 #else 172 #else
171 key_mapper_(&input_tracker_), 173 key_mapper_(&input_tracker_),
172 #endif 174 #endif
173 input_handler_(&key_mapper_), 175 input_handler_(&key_mapper_),
176 use_async_pin_dialog_(false),
174 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 177 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
175 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL); 178 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL);
176 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); 179 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD);
177 180
178 // Resister this instance to handle debug log messsages. 181 // Resister this instance to handle debug log messsages.
179 RegisterLoggingInstance(); 182 RegisterLoggingInstance();
180 183
181 // Send hello message. 184 // Send hello message.
182 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); 185 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue());
183 data->SetInteger("apiVersion", kApiVersion); 186 data->SetInteger("apiVersion", kApiVersion);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 if (!data->GetString("hostJid", &config.host_jid) || 273 if (!data->GetString("hostJid", &config.host_jid) ||
271 !data->GetString("hostPublicKey", &config.host_public_key) || 274 !data->GetString("hostPublicKey", &config.host_public_key) ||
272 !data->GetString("localJid", &config.local_jid) || 275 !data->GetString("localJid", &config.local_jid) ||
273 !data->GetString("sharedSecret", &config.shared_secret) || 276 !data->GetString("sharedSecret", &config.shared_secret) ||
274 !data->GetString("authenticationMethods", &auth_methods) || 277 !data->GetString("authenticationMethods", &auth_methods) ||
275 !ParseAuthMethods(auth_methods, &config) || 278 !ParseAuthMethods(auth_methods, &config) ||
276 !data->GetString("authenticationTag", &config.authentication_tag)) { 279 !data->GetString("authenticationTag", &config.authentication_tag)) {
277 LOG(ERROR) << "Invalid connect() data."; 280 LOG(ERROR) << "Invalid connect() data.";
278 return; 281 return;
279 } 282 }
280
281 Connect(config); 283 Connect(config);
282 } else if (method == "disconnect") { 284 } else if (method == "disconnect") {
283 Disconnect(); 285 Disconnect();
284 } else if (method == "incomingIq") { 286 } else if (method == "incomingIq") {
285 std::string iq; 287 std::string iq;
286 if (!data->GetString("iq", &iq)) { 288 if (!data->GetString("iq", &iq)) {
287 LOG(ERROR) << "Invalid onIq() data."; 289 LOG(ERROR) << "Invalid onIq() data.";
288 return; 290 return;
289 } 291 }
290 OnIncomingIq(iq); 292 OnIncomingIq(iq);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 return; 368 return;
367 } 369 }
368 PauseVideo(pause); 370 PauseVideo(pause);
369 } else if (method == "pauseAudio") { 371 } else if (method == "pauseAudio") {
370 bool pause = false; 372 bool pause = false;
371 if (!data->GetBoolean("pause", &pause)) { 373 if (!data->GetBoolean("pause", &pause)) {
372 LOG(ERROR) << "Invalid pauseAudio."; 374 LOG(ERROR) << "Invalid pauseAudio.";
373 return; 375 return;
374 } 376 }
375 PauseAudio(pause); 377 PauseAudio(pause);
378 } else if (method == "useAsyncPinDialog") {
379 use_async_pin_dialog_ = true;
380 } else if (method == "onPinFetched") {
381 std::string pin;
382 if (!data->GetString("pin", &pin)) {
383 LOG(ERROR) << "Invalid onPinFetched.";
384 return;
385 }
386 OnPinFetched(pin);
376 } 387 }
377 } 388 }
378 389
379 void ChromotingInstance::DidChangeView(const pp::View& view) { 390 void ChromotingInstance::DidChangeView(const pp::View& view) {
380 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 391 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
381 392
382 plugin_view_ = view; 393 plugin_view_ = view;
383 if (view_) { 394 if (view_) {
384 view_->SetView(view); 395 view_->SetView(view);
385 mouse_input_filter_.set_input_size(view_->get_view_size_dips()); 396 mouse_input_filter_.set_input_size(view_->get_view_size_dips());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 data->SetString("error", ConnectionErrorToString(error)); 428 data->SetString("error", ConnectionErrorToString(error));
418 PostChromotingMessage("onConnectionStatus", data.Pass()); 429 PostChromotingMessage("onConnectionStatus", data.Pass());
419 } 430 }
420 431
421 void ChromotingInstance::OnConnectionReady(bool ready) { 432 void ChromotingInstance::OnConnectionReady(bool ready) {
422 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); 433 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue());
423 data->SetBoolean("ready", ready); 434 data->SetBoolean("ready", ready);
424 PostChromotingMessage("onConnectionReady", data.Pass()); 435 PostChromotingMessage("onConnectionReady", data.Pass());
425 } 436 }
426 437
438 scoped_ptr<protocol::PinFetcher> ChromotingInstance::CreatePinFetcher() {
439 return scoped_ptr<protocol::PinFetcher>(new PepperPinFetcher(AsWeakPtr()));
440 }
441
442 void ChromotingInstance::FetchPin(base::WeakPtr<PepperPinFetcher> pin_fetcher) {
443 // Once the Session object calls this function, it won't continue the
444 // authentication until the callback is called (or connection is canceled).
445 // So, it's impossible to reach this with a pin fetcher already registered.
446 DCHECK(!pin_fetcher_);
447 pin_fetcher_ = pin_fetcher;
448 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue());
449 PostChromotingMessage("fetchPin", data.Pass());
450 }
451
427 protocol::ClipboardStub* ChromotingInstance::GetClipboardStub() { 452 protocol::ClipboardStub* ChromotingInstance::GetClipboardStub() {
428 // TODO(sergeyu): Move clipboard handling to a separate class. 453 // TODO(sergeyu): Move clipboard handling to a separate class.
429 // crbug.com/138108 454 // crbug.com/138108
430 return this; 455 return this;
431 } 456 }
432 457
433 protocol::CursorShapeStub* ChromotingInstance::GetCursorShapeStub() { 458 protocol::CursorShapeStub* ChromotingInstance::GetCursorShapeStub() {
434 // TODO(sergeyu): Move cursor shape code to a separate class. 459 // TODO(sergeyu): Move cursor shape code to a separate class.
435 // crbug.com/138108 460 // crbug.com/138108
436 return this; 461 return this;
437 } 462 }
438 463
464 protocol::PinFetcherFactory* ChromotingInstance::GetPinFetcherFactory() {
465 // TODO(rmsousa): Move pin fetcher code to a separate class.
Sergey Ulanov 2013/03/17 21:29:21 Isn't it already in a separate class?
rmsousa 2013/03/18 21:07:26 Done.
466 if (use_async_pin_dialog_) {
467 return this;
468 } else {
469 return NULL;
470 }
471 }
472
439 void ChromotingInstance::InjectClipboardEvent( 473 void ChromotingInstance::InjectClipboardEvent(
440 const protocol::ClipboardEvent& event) { 474 const protocol::ClipboardEvent& event) {
441 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); 475 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue());
442 data->SetString("mimeType", event.mime_type()); 476 data->SetString("mimeType", event.mime_type());
443 data->SetString("item", event.data()); 477 data->SetString("item", event.data());
444 PostChromotingMessage("injectClipboardItem", data.Pass()); 478 PostChromotingMessage("injectClipboardItem", data.Pass());
445 } 479 }
446 480
447 void ChromotingInstance::SetCursorShape( 481 void ChromotingInstance::SetCursorShape(
448 const protocol::CursorShapeInfo& cursor_shape) { 482 const protocol::CursorShapeInfo& cursor_shape) {
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 677
644 void ChromotingInstance::PauseAudio(bool pause) { 678 void ChromotingInstance::PauseAudio(bool pause) {
645 if (!IsConnected()) { 679 if (!IsConnected()) {
646 return; 680 return;
647 } 681 }
648 protocol::AudioControl audio_control; 682 protocol::AudioControl audio_control;
649 audio_control.set_enable(!pause); 683 audio_control.set_enable(!pause);
650 host_connection_->host_stub()->ControlAudio(audio_control); 684 host_connection_->host_stub()->ControlAudio(audio_control);
651 } 685 }
652 686
687 void ChromotingInstance::OnPinFetched(const std::string& shared_secret) {
688 if (pin_fetcher_) {
689 pin_fetcher_->OnPinFetched(shared_secret);
690 pin_fetcher_.reset();
691 } else {
692 VLOG(1) <<
693 "Ignored OnPinFetched received without a pending fetch.";
694 }
695 }
696
653 ChromotingStats* ChromotingInstance::GetStats() { 697 ChromotingStats* ChromotingInstance::GetStats() {
654 if (!client_.get()) 698 if (!client_.get())
655 return NULL; 699 return NULL;
656 return client_->GetStats(); 700 return client_->GetStats();
657 } 701 }
658 702
659 void ChromotingInstance::PostChromotingMessage( 703 void ChromotingInstance::PostChromotingMessage(
660 const std::string& method, 704 const std::string& method,
661 scoped_ptr<base::DictionaryValue> data) { 705 scoped_ptr<base::DictionaryValue> data) {
662 scoped_ptr<base::DictionaryValue> message(new base::DictionaryValue()); 706 scoped_ptr<base::DictionaryValue> message(new base::DictionaryValue());
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 url_components.scheme.len); 863 url_components.scheme.len);
820 return url_scheme == kChromeExtensionUrlScheme; 864 return url_scheme == kChromeExtensionUrlScheme;
821 } 865 }
822 866
823 bool ChromotingInstance::IsConnected() { 867 bool ChromotingInstance::IsConnected() {
824 return host_connection_.get() && 868 return host_connection_.get() &&
825 (host_connection_->state() == protocol::ConnectionToHost::CONNECTED); 869 (host_connection_->state() == protocol::ConnectionToHost::CONNECTED);
826 } 870 }
827 871
828 } // namespace remoting 872 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698