| 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 } | 124 } |
| 125 | 125 |
| 126 // Convert an NPVariant into an NSPObject. | 126 // Convert an NPVariant into an NSPObject. |
| 127 NPObject* ObjectFromNPVariant(const NPVariant& variant) { | 127 NPObject* ObjectFromNPVariant(const NPVariant& variant) { |
| 128 if (!NPVARIANT_IS_OBJECT(variant)) | 128 if (!NPVARIANT_IS_OBJECT(variant)) |
| 129 return NULL; | 129 return NULL; |
| 130 return NPVARIANT_TO_OBJECT(variant); | 130 return NPVARIANT_TO_OBJECT(variant); |
| 131 } | 131 } |
| 132 | 132 |
| 133 // NPAPI plugin implementation for remoting host script object. | 133 // NPAPI plugin implementation for remoting host script object. |
| 134 class HostNPScriptObject { | 134 class HostNPScriptObject : remoting::HostStatusObserver { |
| 135 public: | 135 public: |
| 136 HostNPScriptObject(NPP plugin, NPObject* parent) | 136 HostNPScriptObject(NPP plugin, NPObject* parent) |
| 137 : plugin_(plugin), | 137 : plugin_(plugin), |
| 138 parent_(parent), | 138 parent_(parent), |
| 139 state_(kDisconnected), | 139 state_(kDisconnected), |
| 140 on_state_changed_func_(NULL), | 140 on_state_changed_func_(NULL), |
| 141 np_thread_id_(base::PlatformThread::CurrentId()) { | 141 np_thread_id_(base::PlatformThread::CurrentId()) { |
| 142 LOG(INFO) << "HostNPScriptObject"; | 142 LOG(INFO) << "HostNPScriptObject"; |
| 143 } | 143 } |
| 144 | 144 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 // Disconnect. No arguments or result. | 345 // Disconnect. No arguments or result. |
| 346 bool Disconnect(const NPVariant* args, uint32_t argCount, NPVariant* result); | 346 bool Disconnect(const NPVariant* args, uint32_t argCount, NPVariant* result); |
| 347 | 347 |
| 348 // Call OnStateChanged handler if there is one. | 348 // Call OnStateChanged handler if there is one. |
| 349 void OnStateChanged(State state); | 349 void OnStateChanged(State state); |
| 350 | 350 |
| 351 // Callbacks invoked during session setup. | 351 // Callbacks invoked during session setup. |
| 352 void OnReceivedSupportID(remoting::SupportAccessVerifier* access_verifier, | 352 void OnReceivedSupportID(remoting::SupportAccessVerifier* access_verifier, |
| 353 bool success, | 353 bool success, |
| 354 const std::string& support_id); | 354 const std::string& support_id); |
| 355 void OnConnected(); | |
| 356 void OnHostShutdown(); | 355 void OnHostShutdown(); |
| 357 | 356 |
| 357 // HostStatusObserver interface. |
| 358 virtual void OnSignallingConnected(remoting::SignalStrategy* signal_strategy, |
| 359 const std::string& full_jid) {} |
| 360 virtual void OnSignallingDisconnected() {} |
| 361 virtual void OnAuthenticatedClientsChanged(int clients_connected); |
| 362 virtual void OnShutdown() {} |
| 363 |
| 358 // Call a JavaScript function wrapped as an NPObject. | 364 // Call a JavaScript function wrapped as an NPObject. |
| 359 // If result is non-null, the result of the call will be stored in it. | 365 // If result is non-null, the result of the call will be stored in it. |
| 360 // Caller is responsible for releasing result if they ask for it. | 366 // Caller is responsible for releasing result if they ask for it. |
| 361 static bool CallJSFunction(NPObject* func, | 367 static bool CallJSFunction(NPObject* func, |
| 362 const NPVariant* args, | 368 const NPVariant* args, |
| 363 uint32_t argCount, | 369 uint32_t argCount, |
| 364 NPVariant* result); | 370 NPVariant* result); |
| 365 | 371 |
| 366 // Posts a task on the main NP thread. | 372 // Posts a task on the main NP thread. |
| 367 void PostTaskToNPThread(Task* task); | 373 void PostTaskToNPThread(Task* task); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 access_verifier.get()))) { | 453 access_verifier.get()))) { |
| 448 SetException("connect: RegisterSupportHostRequest::Init failed"); | 454 SetException("connect: RegisterSupportHostRequest::Init failed"); |
| 449 return false; | 455 return false; |
| 450 } | 456 } |
| 451 | 457 |
| 452 // Create the Host. | 458 // Create the Host. |
| 453 scoped_refptr<remoting::ChromotingHost> host = | 459 scoped_refptr<remoting::ChromotingHost> host = |
| 454 remoting::ChromotingHost::Create(&host_context_, host_config, | 460 remoting::ChromotingHost::Create(&host_context_, host_config, |
| 455 access_verifier.release()); | 461 access_verifier.release()); |
| 456 host->AddStatusObserver(register_request); | 462 host->AddStatusObserver(register_request); |
| 463 host->AddStatusObserver(this); |
| 457 host->set_me2mom(true); | 464 host->set_me2mom(true); |
| 458 | 465 |
| 459 // Nothing went wrong, so lets save the host, config and request. | 466 // Nothing went wrong, so lets save the host, config and request. |
| 460 host_ = host; | 467 host_ = host; |
| 461 host_config_ = host_config; | 468 host_config_ = host_config; |
| 462 register_request_ = register_request; | 469 register_request_ = register_request; |
| 463 | 470 |
| 464 // Start the Host. | 471 // Start the Host. |
| 465 // TODO(wez): Attach to the Host for notifications of state changes. | 472 // TODO(wez): Attach to the Host for notifications of state changes. |
| 466 // It currently has no interface for that, though. | 473 // It currently has no interface for that, though. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 access_verifier->OnMe2MomHostRegistered(success, support_id); | 513 access_verifier->OnMe2MomHostRegistered(success, support_id); |
| 507 | 514 |
| 508 // Combine the Support Id with the Host Id to make the Access Code. | 515 // Combine the Support Id with the Host Id to make the Access Code. |
| 509 // TODO(wez): Locking, anyone? | 516 // TODO(wez): Locking, anyone? |
| 510 access_code_ = support_id + "-" + access_verifier->host_secret(); | 517 access_code_ = support_id + "-" + access_verifier->host_secret(); |
| 511 | 518 |
| 512 // Let the caller know that life is good. | 519 // Let the caller know that life is good. |
| 513 OnStateChanged(kReceivedAccessCode); | 520 OnStateChanged(kReceivedAccessCode); |
| 514 } | 521 } |
| 515 | 522 |
| 516 void HostNPScriptObject::OnConnected() { | |
| 517 CHECK_NE(base::PlatformThread::CurrentId(), np_thread_id_); | |
| 518 OnStateChanged(kConnected); | |
| 519 } | |
| 520 | |
| 521 void HostNPScriptObject::OnHostShutdown() { | 523 void HostNPScriptObject::OnHostShutdown() { |
| 522 CHECK_NE(base::PlatformThread::CurrentId(), np_thread_id_); | 524 CHECK_NE(base::PlatformThread::CurrentId(), np_thread_id_); |
| 523 OnStateChanged(kDisconnected); | 525 OnStateChanged(kDisconnected); |
| 524 } | 526 } |
| 525 | 527 |
| 528 void HostNPScriptObject::OnAuthenticatedClientsChanged(int clients_connected) { |
| 529 CHECK_NE(base::PlatformThread::CurrentId(), np_thread_id_); |
| 530 OnStateChanged(clients_connected ? kConnected : kDisconnected); |
| 531 } |
| 532 |
| 526 void HostNPScriptObject::OnStateChanged(State state) { | 533 void HostNPScriptObject::OnStateChanged(State state) { |
| 527 if (base::PlatformThread::CurrentId() != np_thread_id_) { | 534 if (base::PlatformThread::CurrentId() != np_thread_id_) { |
| 528 PostTaskToNPThread(NewRunnableMethod(this, | 535 PostTaskToNPThread(NewRunnableMethod(this, |
| 529 &HostNPScriptObject::OnStateChanged, | 536 &HostNPScriptObject::OnStateChanged, |
| 530 state)); | 537 state)); |
| 531 return; | 538 return; |
| 532 } | 539 } |
| 533 state_ = state; | 540 state_ = state; |
| 534 if (on_state_changed_func_) { | 541 if (on_state_changed_func_) { |
| 535 LOG(INFO) << "Calling state changed " << state; | 542 LOG(INFO) << "Calling state changed " << state; |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 947 } | 954 } |
| 948 | 955 |
| 949 EXPORT NPError API_CALL NP_GetValue(void* npp, | 956 EXPORT NPError API_CALL NP_GetValue(void* npp, |
| 950 NPPVariable variable, | 957 NPPVariable variable, |
| 951 void* value) { | 958 void* value) { |
| 952 return GetValue((NPP)npp, variable, value); | 959 return GetValue((NPP)npp, variable, value); |
| 953 } | 960 } |
| 954 #endif | 961 #endif |
| 955 | 962 |
| 956 } // extern "C" | 963 } // extern "C" |
| OLD | NEW |