| 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 #ifndef REMOTING_HOST_PLUGIN_HOST_SCRIPT_OBJECT_H_ | 5 #ifndef REMOTING_HOST_PLUGIN_HOST_SCRIPT_OBJECT_H_ |
| 6 #define REMOTING_HOST_PLUGIN_HOST_SCRIPT_OBJECT_H_ | 6 #define REMOTING_HOST_PLUGIN_HOST_SCRIPT_OBJECT_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/synchronization/cancellation_flag.h" | 14 #include "base/synchronization/cancellation_flag.h" |
| 15 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
| 16 #include "base/threading/platform_thread.h" | 16 #include "base/threading/platform_thread.h" |
| 17 #include "base/time.h" | 17 #include "base/time.h" |
| 18 #include "remoting/base/plugin_message_loop_proxy.h" |
| 18 #include "remoting/host/chromoting_host_context.h" | 19 #include "remoting/host/chromoting_host_context.h" |
| 19 #include "remoting/host/host_status_observer.h" | 20 #include "remoting/host/host_status_observer.h" |
| 20 #include "third_party/npapi/bindings/npapi.h" | 21 #include "third_party/npapi/bindings/npapi.h" |
| 21 #include "third_party/npapi/bindings/npfunctions.h" | 22 #include "third_party/npapi/bindings/npfunctions.h" |
| 22 #include "third_party/npapi/bindings/npruntime.h" | 23 #include "third_party/npapi/bindings/npruntime.h" |
| 23 | 24 |
| 24 namespace tracked_objects { | 25 namespace tracked_objects { |
| 25 class Location; | 26 class Location; |
| 26 } // namespace tracked_objects | 27 } // namespace tracked_objects |
| 27 | 28 |
| 28 namespace remoting { | 29 namespace remoting { |
| 29 | 30 |
| 30 class ChromotingHost; | 31 class ChromotingHost; |
| 31 class DesktopEnvironment; | 32 class DesktopEnvironment; |
| 32 class MutableHostConfig; | 33 class MutableHostConfig; |
| 33 class RegisterSupportHostRequest; | 34 class RegisterSupportHostRequest; |
| 34 class SignalStrategy; | 35 class SignalStrategy; |
| 35 class SupportAccessVerifier; | 36 class SupportAccessVerifier; |
| 36 | 37 |
| 37 // NPAPI plugin implementation for remoting host script object. | 38 // NPAPI plugin implementation for remoting host script object. |
| 38 // HostNPScriptObject creates threads that are required to run | 39 // HostNPScriptObject creates threads that are required to run |
| 39 // ChromotingHost and starts/stops the host on those threads. When | 40 // ChromotingHost and starts/stops the host on those threads. When |
| 40 // destroyed it sychronously shuts down the host and all threads. | 41 // destroyed it sychronously shuts down the host and all threads. |
| 41 class HostNPScriptObject : public HostStatusObserver { | 42 class HostNPScriptObject : public HostStatusObserver { |
| 42 public: | 43 public: |
| 43 HostNPScriptObject(NPP plugin, NPObject* parent); | 44 HostNPScriptObject(NPP plugin, NPObject* parent, |
| 45 PluginMessageLoopProxy::Delegate* plugin_thread_delegate); |
| 44 virtual ~HostNPScriptObject(); | 46 virtual ~HostNPScriptObject(); |
| 45 | 47 |
| 46 bool Init(); | 48 bool Init(); |
| 47 | 49 |
| 48 bool HasMethod(const std::string& method_name); | 50 bool HasMethod(const std::string& method_name); |
| 49 bool InvokeDefault(const NPVariant* args, | 51 bool InvokeDefault(const NPVariant* args, |
| 50 uint32_t argCount, | 52 uint32_t argCount, |
| 51 NPVariant* result); | 53 NPVariant* result); |
| 52 bool Invoke(const std::string& method_name, | 54 bool Invoke(const std::string& method_name, |
| 53 const NPVariant* args, | 55 const NPVariant* args, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 116 |
| 115 // Callback for ChromotingHost::Shutdown(). | 117 // Callback for ChromotingHost::Shutdown(). |
| 116 void OnShutdownFinished(); | 118 void OnShutdownFinished(); |
| 117 | 119 |
| 118 // Helper function for executing InvokeDefault on an NPObject, and ignoring | 120 // Helper function for executing InvokeDefault on an NPObject, and ignoring |
| 119 // the return value. | 121 // the return value. |
| 120 bool InvokeAndIgnoreResult(NPObject* func, | 122 bool InvokeAndIgnoreResult(NPObject* func, |
| 121 const NPVariant* args, | 123 const NPVariant* args, |
| 122 uint32_t argCount); | 124 uint32_t argCount); |
| 123 | 125 |
| 124 // Posts a task on the main NP thread. | |
| 125 void PostTaskToNPThread( | |
| 126 const tracked_objects::Location& from_here, const base::Closure& task); | |
| 127 | |
| 128 // Utility function for PostTaskToNPThread. | |
| 129 static void NPTaskSpringboard(void* task); | |
| 130 | |
| 131 // Set an exception for the current call. | 126 // Set an exception for the current call. |
| 132 void SetException(const std::string& exception_string); | 127 void SetException(const std::string& exception_string); |
| 133 | 128 |
| 134 NPP plugin_; | 129 NPP plugin_; |
| 135 NPObject* parent_; | 130 NPObject* parent_; |
| 136 int state_; | 131 int state_; |
| 137 std::string access_code_; | 132 std::string access_code_; |
| 138 std::string client_username_; | 133 std::string client_username_; |
| 139 base::TimeDelta access_code_lifetime_; | 134 base::TimeDelta access_code_lifetime_; |
| 140 NPObject* log_debug_info_func_; | 135 NPObject* log_debug_info_func_; |
| 141 NPObject* on_state_changed_func_; | 136 NPObject* on_state_changed_func_; |
| 142 base::PlatformThreadId np_thread_id_; | 137 base::PlatformThreadId np_thread_id_; |
| 138 scoped_refptr<PluginMessageLoopProxy> plugin_message_loop_proxy_; |
| 143 | 139 |
| 144 scoped_ptr<RegisterSupportHostRequest> register_request_; | 140 scoped_ptr<RegisterSupportHostRequest> register_request_; |
| 145 scoped_refptr<MutableHostConfig> host_config_; | 141 scoped_refptr<MutableHostConfig> host_config_; |
| 146 ChromotingHostContext host_context_; | 142 ChromotingHostContext host_context_; |
| 147 scoped_ptr<DesktopEnvironment> desktop_environment_; | 143 scoped_ptr<DesktopEnvironment> desktop_environment_; |
| 148 | 144 |
| 149 scoped_refptr<ChromotingHost> host_; | 145 scoped_refptr<ChromotingHost> host_; |
| 150 int failed_login_attempts_; | 146 int failed_login_attempts_; |
| 151 | 147 |
| 152 base::WaitableEvent disconnected_event_; | 148 base::WaitableEvent disconnected_event_; |
| 153 base::CancellationFlag destructing_; | |
| 154 }; | 149 }; |
| 155 | 150 |
| 156 } // namespace remoting | 151 } // namespace remoting |
| 157 | 152 |
| 158 DISABLE_RUNNABLE_METHOD_REFCOUNT(remoting::HostNPScriptObject); | 153 DISABLE_RUNNABLE_METHOD_REFCOUNT(remoting::HostNPScriptObject); |
| 159 | 154 |
| 160 #endif // REMOTING_HOST_HOST_SCRIPT_OBJECT_H_ | 155 #endif // REMOTING_HOST_HOST_SCRIPT_OBJECT_H_ |
| OLD | NEW |