OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <stdio.h> | 5 #include <stdio.h> |
6 #include <string.h> | 6 #include <string.h> |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 int state_; | 304 int state_; |
305 std::string access_code_; | 305 std::string access_code_; |
306 NPObject* on_state_changed_func_; | 306 NPObject* on_state_changed_func_; |
307 base::AtExitManager exit_manager_; | 307 base::AtExitManager exit_manager_; |
308 base::PlatformThreadId np_thread_id_; | 308 base::PlatformThreadId np_thread_id_; |
309 | 309 |
310 scoped_refptr<remoting::RegisterSupportHostRequest> register_request_; | 310 scoped_refptr<remoting::RegisterSupportHostRequest> register_request_; |
311 scoped_refptr<remoting::ChromotingHost> host_; | 311 scoped_refptr<remoting::ChromotingHost> host_; |
312 scoped_refptr<remoting::MutableHostConfig> host_config_; | 312 scoped_refptr<remoting::MutableHostConfig> host_config_; |
313 remoting::ChromotingHostContext host_context_; | 313 remoting::ChromotingHostContext host_context_; |
314 std::string host_secret_; | |
315 | 314 |
316 // Start connection. args are: | 315 // Start connection. args are: |
317 // string uid, string auth_token | 316 // string uid, string auth_token |
318 // No result. | 317 // No result. |
319 bool Connect(const NPVariant* args, uint32_t argCount, NPVariant* result); | 318 bool Connect(const NPVariant* args, uint32_t argCount, NPVariant* result); |
320 | 319 |
321 // Disconnect. No arguments or result. | 320 // Disconnect. No arguments or result. |
322 bool Disconnect(const NPVariant* args, uint32_t argCount, NPVariant* result); | 321 bool Disconnect(const NPVariant* args, uint32_t argCount, NPVariant* result); |
323 | 322 |
324 // Call OnStateChanged handler if there is one. | 323 // Call OnStateChanged handler if there is one. |
325 void OnStateChanged(State state); | 324 void OnStateChanged(State state); |
326 | 325 |
327 // Currently just mock methods to verify that everything is working | 326 // Callbacks invoked during session setup. |
328 void OnReceivedSupportID(bool success, const std::string& support_id); | 327 void OnReceivedSupportID(remoting::SupportAccessVerifier* access_verifier, |
| 328 bool success, |
| 329 const std::string& support_id); |
329 void OnConnected(); | 330 void OnConnected(); |
330 void OnHostShutdown(); | 331 void OnHostShutdown(); |
331 | 332 |
332 // Call a JavaScript function wrapped as an NPObject. | 333 // Call a JavaScript function wrapped as an NPObject. |
333 // If result is non-null, the result of the call will be stored in it. | 334 // If result is non-null, the result of the call will be stored in it. |
334 // Caller is responsible for releasing result if they ask for it. | 335 // Caller is responsible for releasing result if they ask for it. |
335 static bool CallJSFunction(NPObject* func, | 336 static bool CallJSFunction(NPObject* func, |
336 const NPVariant* args, | 337 const NPVariant* args, |
337 uint32_t argCount, | 338 uint32_t argCount, |
338 NPVariant* result); | 339 NPVariant* result); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 host_config->SetString(remoting::kXmppLoginConfigPath, uid); | 393 host_config->SetString(remoting::kXmppLoginConfigPath, uid); |
393 host_config->SetString(remoting::kXmppAuthTokenConfigPath, auth_token); | 394 host_config->SetString(remoting::kXmppAuthTokenConfigPath, auth_token); |
394 | 395 |
395 // Create an access verifier and fetch the host secret. | 396 // Create an access verifier and fetch the host secret. |
396 scoped_ptr<remoting::SupportAccessVerifier> access_verifier; | 397 scoped_ptr<remoting::SupportAccessVerifier> access_verifier; |
397 access_verifier.reset(new remoting::SupportAccessVerifier); | 398 access_verifier.reset(new remoting::SupportAccessVerifier); |
398 if (!access_verifier->Init()) { | 399 if (!access_verifier->Init()) { |
399 SetException("connect: SupportAccessVerifier::Init failed"); | 400 SetException("connect: SupportAccessVerifier::Init failed"); |
400 return false; | 401 return false; |
401 } | 402 } |
402 host_secret_ = access_verifier->host_secret(); | |
403 | 403 |
404 // Generate a key pair for the Host to use. | 404 // Generate a key pair for the Host to use. |
405 // TODO(wez): Move this to the worker thread. | 405 // TODO(wez): Move this to the worker thread. |
406 remoting::HostKeyPair host_key_pair; | 406 remoting::HostKeyPair host_key_pair; |
407 host_key_pair.Generate(); | 407 host_key_pair.Generate(); |
408 host_key_pair.Save(host_config); | 408 host_key_pair.Save(host_config); |
409 | 409 |
410 // Create the Host. | |
411 scoped_refptr<remoting::ChromotingHost> host = | |
412 remoting::ChromotingHost::Create(&host_context_, host_config, | |
413 access_verifier.release()); | |
414 | |
415 // Request registration of the host for support. | 410 // Request registration of the host for support. |
416 scoped_refptr<remoting::RegisterSupportHostRequest> register_request = | 411 scoped_refptr<remoting::RegisterSupportHostRequest> register_request = |
417 new remoting::RegisterSupportHostRequest(); | 412 new remoting::RegisterSupportHostRequest(); |
418 if (!register_request->Init( | 413 if (!register_request->Init( |
419 host_config.get(), | 414 host_config.get(), |
420 base::Bind(&HostNPScriptObject::OnReceivedSupportID, | 415 base::Bind(&HostNPScriptObject::OnReceivedSupportID, |
421 base::Unretained(this)))) { | 416 base::Unretained(this), |
| 417 access_verifier.get()))) { |
422 SetException("connect: RegisterSupportHostRequest::Init failed"); | 418 SetException("connect: RegisterSupportHostRequest::Init failed"); |
423 return false; | 419 return false; |
424 } | 420 } |
| 421 |
| 422 // Create the Host. |
| 423 scoped_refptr<remoting::ChromotingHost> host = |
| 424 remoting::ChromotingHost::Create(&host_context_, host_config, |
| 425 access_verifier.release()); |
425 host->AddStatusObserver(register_request); | 426 host->AddStatusObserver(register_request); |
426 | 427 |
| 428 // TODO(wez): Improve our authentication framework. |
| 429 host->set_preauthenticated(true); |
| 430 |
427 // Nothing went wrong, so lets save the host, config and request. | 431 // Nothing went wrong, so lets save the host, config and request. |
428 host_ = host; | 432 host_ = host; |
429 host_config_ = host_config; | 433 host_config_ = host_config; |
430 register_request_ = register_request; | 434 register_request_ = register_request; |
431 | 435 |
432 // Start the Host. | 436 // Start the Host. |
433 // TODO(wez): Attach to the Host for notifications of state changes. | 437 // TODO(wez): Attach to the Host for notifications of state changes. |
434 // It currently has no interface for that, though. | 438 // It currently has no interface for that, though. |
435 host_->Start(NewRunnableMethod(this, &HostNPScriptObject::OnHostShutdown)); | 439 host_->Start(NewRunnableMethod(this, &HostNPScriptObject::OnHostShutdown)); |
436 | 440 |
437 OnStateChanged(kRequestedAccessCode); | 441 OnStateChanged(kRequestedAccessCode); |
438 return true; | 442 return true; |
439 } | 443 } |
440 | 444 |
441 bool HostNPScriptObject::Disconnect(const NPVariant* args, | 445 bool HostNPScriptObject::Disconnect(const NPVariant* args, |
442 uint32_t arg_count, | 446 uint32_t arg_count, |
443 NPVariant* result) { | 447 NPVariant* result) { |
444 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); | 448 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); |
445 if (arg_count != 0) { | 449 if (arg_count != 0) { |
446 SetException("disconnect: bad number of arguments"); | 450 SetException("disconnect: bad number of arguments"); |
447 return false; | 451 return false; |
448 } | 452 } |
449 | 453 |
450 if (host_.get()) { | 454 if (host_.get()) { |
451 host_->Shutdown(); | 455 host_->Shutdown(); |
452 host_ = NULL; | 456 host_ = NULL; |
453 } | 457 } |
454 register_request_ = NULL; | 458 register_request_ = NULL; |
455 host_config_ = NULL; | 459 host_config_ = NULL; |
456 host_secret_.clear(); | |
457 | 460 |
458 OnStateChanged(kDisconnected); | 461 OnStateChanged(kDisconnected); |
459 return true; | 462 return true; |
460 } | 463 } |
461 | 464 |
462 void HostNPScriptObject::OnReceivedSupportID(bool success, | 465 void HostNPScriptObject::OnReceivedSupportID( |
463 const std::string& support_id) { | 466 remoting::SupportAccessVerifier* access_verifier, |
| 467 bool success, |
| 468 const std::string& support_id) { |
464 CHECK_NE(base::PlatformThread::CurrentId(), np_thread_id_); | 469 CHECK_NE(base::PlatformThread::CurrentId(), np_thread_id_); |
465 | 470 |
466 if (!success) { | 471 if (!success) { |
467 // TODO(wez): Replace the success/fail flag with full error reporting. | 472 // TODO(wez): Replace the success/fail flag with full error reporting. |
468 OnHostShutdown(); | 473 OnHostShutdown(); |
469 return; | 474 return; |
470 } | 475 } |
471 | 476 |
472 // Combine the Support Id with the Host Id to make the Access Code | 477 // Inform the AccessVerifier of our Support-Id, for authentication. |
| 478 access_verifier->OnMe2MomHostRegistered(success, support_id); |
| 479 |
| 480 // Combine the Support Id with the Host Id to make the Access Code. |
473 // TODO(wez): Locking, anyone? | 481 // TODO(wez): Locking, anyone? |
474 access_code_ = support_id + "-" + host_secret_; | 482 access_code_ = support_id + "-" + access_verifier->host_secret(); |
475 host_secret_ = std::string(); | |
476 | 483 |
477 // Let the caller know that life is good. | 484 // Let the caller know that life is good. |
478 OnStateChanged(kReceivedAccessCode); | 485 OnStateChanged(kReceivedAccessCode); |
479 } | 486 } |
480 | 487 |
481 void HostNPScriptObject::OnConnected() { | 488 void HostNPScriptObject::OnConnected() { |
482 CHECK_NE(base::PlatformThread::CurrentId(), np_thread_id_); | 489 CHECK_NE(base::PlatformThread::CurrentId(), np_thread_id_); |
483 OnStateChanged(kConnected); | 490 OnStateChanged(kConnected); |
484 } | 491 } |
485 | 492 |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
864 return STRINGIZE(HOST_PLUGIN_MIME_TYPE) ":" | 871 return STRINGIZE(HOST_PLUGIN_MIME_TYPE) ":" |
865 HOST_PLUGIN_NAME ":" | 872 HOST_PLUGIN_NAME ":" |
866 HOST_PLUGIN_DESCRIPTION; | 873 HOST_PLUGIN_DESCRIPTION; |
867 } | 874 } |
868 | 875 |
869 OSCALL NPError NP_GetValue(void* npp, NPPVariable variable, void* value) { | 876 OSCALL NPError NP_GetValue(void* npp, NPPVariable variable, void* value) { |
870 return GetValue((NPP)npp, variable, value); | 877 return GetValue((NPP)npp, variable, value); |
871 } | 878 } |
872 | 879 |
873 } // extern "C" | 880 } // extern "C" |
OLD | NEW |