| 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 "remoting/host/plugin/host_script_object.h" | 5 #include "remoting/host/plugin/host_script_object.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/task.h" | 9 #include "base/task.h" |
| 10 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 | 456 |
| 457 if (!host_context_.IsUIThread()) { | 457 if (!host_context_.IsUIThread()) { |
| 458 host_context_.PostToUIThread( | 458 host_context_.PostToUIThread( |
| 459 FROM_HERE, | 459 FROM_HERE, |
| 460 NewRunnableMethod(this, &HostNPScriptObject::OnStateChanged, state)); | 460 NewRunnableMethod(this, &HostNPScriptObject::OnStateChanged, state)); |
| 461 return; | 461 return; |
| 462 } | 462 } |
| 463 state_ = state; | 463 state_ = state; |
| 464 if (on_state_changed_func_) { | 464 if (on_state_changed_func_) { |
| 465 VLOG(2) << "Calling state changed " << state; | 465 VLOG(2) << "Calling state changed " << state; |
| 466 bool is_good = CallJSFunction(on_state_changed_func_, NULL, 0, NULL); | 466 bool is_good = InvokeAndIgnoreResult(on_state_changed_func_, NULL, 0); |
| 467 LOG_IF(ERROR, !is_good) << "OnStateChanged failed"; | 467 LOG_IF(ERROR, !is_good) << "OnStateChanged failed"; |
| 468 } | 468 } |
| 469 } | 469 } |
| 470 | 470 |
| 471 void HostNPScriptObject::LogDebugInfo(const std::string& message) { | 471 void HostNPScriptObject::LogDebugInfo(const std::string& message) { |
| 472 if (!host_context_.IsUIThread()) { | 472 if (!host_context_.IsUIThread()) { |
| 473 host_context_.PostToUIThread( | 473 host_context_.PostToUIThread( |
| 474 FROM_HERE, | 474 FROM_HERE, |
| 475 NewRunnableMethod(this, &HostNPScriptObject::LogDebugInfo, message)); | 475 NewRunnableMethod(this, &HostNPScriptObject::LogDebugInfo, message)); |
| 476 return; | 476 return; |
| 477 } | 477 } |
| 478 if (log_debug_info_func_) { | 478 if (log_debug_info_func_) { |
| 479 NPVariant* arg = new NPVariant(); | 479 NPVariant* arg = new NPVariant(); |
| 480 LOG(INFO) << "Logging: " << message; | 480 LOG(INFO) << "Logging: " << message; |
| 481 STRINGZ_TO_NPVARIANT(message.c_str(), *arg); | 481 STRINGZ_TO_NPVARIANT(message.c_str(), *arg); |
| 482 bool is_good = CallJSFunction(log_debug_info_func_, arg, 1, NULL); | 482 bool is_good = InvokeAndIgnoreResult(log_debug_info_func_, arg, 1); |
| 483 LOG_IF(ERROR, !is_good) << "LogDebugInfo failed"; | 483 LOG_IF(ERROR, !is_good) << "LogDebugInfo failed"; |
| 484 } | 484 } |
| 485 } | 485 } |
| 486 | 486 |
| 487 void HostNPScriptObject::SetException(const std::string& exception_string) { | 487 void HostNPScriptObject::SetException(const std::string& exception_string) { |
| 488 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); | 488 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); |
| 489 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); | 489 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); |
| 490 LogDebugInfo(exception_string); | 490 LogDebugInfo(exception_string); |
| 491 } | 491 } |
| 492 | 492 |
| 493 bool HostNPScriptObject::CallJSFunction(NPObject* func, | 493 bool HostNPScriptObject::InvokeAndIgnoreResult(NPObject* func, |
| 494 const NPVariant* args, | 494 const NPVariant* args, |
| 495 uint32_t argCount, | 495 uint32_t argCount) { |
| 496 NPVariant* result) { | |
| 497 NPVariant np_result; | 496 NPVariant np_result; |
| 498 bool is_good = func->_class->invokeDefault(func, args, argCount, &np_result); | 497 bool is_good = g_npnetscape_funcs->invokeDefault(plugin_, func, args, |
| 499 if (is_good) { | 498 argCount, &np_result); |
| 500 if (result) { | 499 if (is_good) |
| 501 *result = np_result; | |
| 502 } else { | |
| 503 g_npnetscape_funcs->releasevariantvalue(&np_result); | 500 g_npnetscape_funcs->releasevariantvalue(&np_result); |
| 504 } | |
| 505 } | |
| 506 return is_good; | 501 return is_good; |
| 507 } | 502 } |
| 508 | 503 |
| 509 void HostNPScriptObject::PostTaskToNPThread( | 504 void HostNPScriptObject::PostTaskToNPThread( |
| 510 const tracked_objects::Location& from_here, Task* task) { | 505 const tracked_objects::Location& from_here, Task* task) { |
| 511 // The NPAPI functions cannot make use of |from_here|, but this method is | 506 // The NPAPI functions cannot make use of |from_here|, but this method is |
| 512 // passed as a callback to ChromotingHostContext, so it needs to have the | 507 // passed as a callback to ChromotingHostContext, so it needs to have the |
| 513 // appropriate signature. | 508 // appropriate signature. |
| 514 | 509 |
| 515 // Can be called from any thread. | 510 // Can be called from any thread. |
| 516 g_npnetscape_funcs->pluginthreadasynccall(plugin_, | 511 g_npnetscape_funcs->pluginthreadasynccall(plugin_, |
| 517 &NPTaskSpringboard, | 512 &NPTaskSpringboard, |
| 518 task); | 513 task); |
| 519 } | 514 } |
| 520 | 515 |
| 521 void HostNPScriptObject::NPTaskSpringboard(void* task) { | 516 void HostNPScriptObject::NPTaskSpringboard(void* task) { |
| 522 Task* real_task = reinterpret_cast<Task*>(task); | 517 Task* real_task = reinterpret_cast<Task*>(task); |
| 523 real_task->Run(); | 518 real_task->Run(); |
| 524 delete real_task; | 519 delete real_task; |
| 525 } | 520 } |
| 526 | 521 |
| 527 } // namespace remoting | 522 } // namespace remoting |
| OLD | NEW |