| 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 "remoting/host/plugin/host_plugin_utils.h" | 21 #include "remoting/host/plugin/host_plugin_utils.h" |
| 21 #include "third_party/npapi/bindings/npapi.h" | 22 #include "third_party/npapi/bindings/npapi.h" |
| 22 #include "third_party/npapi/bindings/npfunctions.h" | 23 #include "third_party/npapi/bindings/npfunctions.h" |
| 23 #include "third_party/npapi/bindings/npruntime.h" | 24 #include "third_party/npapi/bindings/npruntime.h" |
| 24 | 25 |
| 25 namespace tracked_objects { | 26 namespace tracked_objects { |
| 26 class Location; | 27 class Location; |
| 27 } // namespace tracked_objects | 28 } // namespace tracked_objects |
| (...skipping 10 matching lines...) Expand all Loading... |
| 38 namespace policy_hack { | 39 namespace policy_hack { |
| 39 class NatPolicy; | 40 class NatPolicy; |
| 40 } // namespace policy_hack | 41 } // namespace policy_hack |
| 41 | 42 |
| 42 // NPAPI plugin implementation for remoting host script object. | 43 // NPAPI plugin implementation for remoting host script object. |
| 43 // HostNPScriptObject creates threads that are required to run | 44 // HostNPScriptObject creates threads that are required to run |
| 44 // ChromotingHost and starts/stops the host on those threads. When | 45 // ChromotingHost and starts/stops the host on those threads. When |
| 45 // destroyed it sychronously shuts down the host and all threads. | 46 // destroyed it sychronously shuts down the host and all threads. |
| 46 class HostNPScriptObject : public HostStatusObserver { | 47 class HostNPScriptObject : public HostStatusObserver { |
| 47 public: | 48 public: |
| 48 HostNPScriptObject(NPP plugin, NPObject* parent); | 49 HostNPScriptObject(NPP plugin, NPObject* parent, |
| 50 PluginMessageLoopProxy::Delegate* plugin_thread_delegate); |
| 49 virtual ~HostNPScriptObject(); | 51 virtual ~HostNPScriptObject(); |
| 50 | 52 |
| 51 bool Init(); | 53 bool Init(); |
| 52 | 54 |
| 53 bool HasMethod(const std::string& method_name); | 55 bool HasMethod(const std::string& method_name); |
| 54 bool InvokeDefault(const NPVariant* args, | 56 bool InvokeDefault(const NPVariant* args, |
| 55 uint32_t argCount, | 57 uint32_t argCount, |
| 56 NPVariant* result); | 58 NPVariant* result); |
| 57 bool Invoke(const std::string& method_name, | 59 bool Invoke(const std::string& method_name, |
| 58 const NPVariant* args, | 60 const NPVariant* args, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 // unchanged and returns false on failure. | 137 // unchanged and returns false on failure. |
| 136 bool LocalizeString(const char* tag, const char* substitution, | 138 bool LocalizeString(const char* tag, const char* substitution, |
| 137 std::string* result); | 139 std::string* result); |
| 138 | 140 |
| 139 // Helper function for executing InvokeDefault on an NPObject, and ignoring | 141 // Helper function for executing InvokeDefault on an NPObject, and ignoring |
| 140 // the return value. | 142 // the return value. |
| 141 bool InvokeAndIgnoreResult(NPObject* func, | 143 bool InvokeAndIgnoreResult(NPObject* func, |
| 142 const NPVariant* args, | 144 const NPVariant* args, |
| 143 uint32_t argCount); | 145 uint32_t argCount); |
| 144 | 146 |
| 145 // Posts a task on the main NP thread. | |
| 146 void PostTaskToNPThread( | |
| 147 const tracked_objects::Location& from_here, const base::Closure& task); | |
| 148 | |
| 149 // Utility function for PostTaskToNPThread. | |
| 150 static void NPTaskSpringboard(void* task); | |
| 151 | |
| 152 // Set an exception for the current call. | 147 // Set an exception for the current call. |
| 153 void SetException(const std::string& exception_string); | 148 void SetException(const std::string& exception_string); |
| 154 | 149 |
| 155 NPP plugin_; | 150 NPP plugin_; |
| 156 NPObject* parent_; | 151 NPObject* parent_; |
| 157 int state_; | 152 int state_; |
| 158 std::string access_code_; | 153 std::string access_code_; |
| 159 std::string client_username_; | 154 std::string client_username_; |
| 160 base::TimeDelta access_code_lifetime_; | 155 base::TimeDelta access_code_lifetime_; |
| 161 ScopedRefNPObject localize_func_; | 156 ScopedRefNPObject localize_func_; |
| 162 ScopedRefNPObject log_debug_info_func_; | 157 ScopedRefNPObject log_debug_info_func_; |
| 163 ScopedRefNPObject on_state_changed_func_; | 158 ScopedRefNPObject on_state_changed_func_; |
| 164 base::PlatformThreadId np_thread_id_; | 159 base::PlatformThreadId np_thread_id_; |
| 160 scoped_refptr<PluginMessageLoopProxy> plugin_message_loop_proxy_; |
| 165 | 161 |
| 166 scoped_ptr<RegisterSupportHostRequest> register_request_; | 162 scoped_ptr<RegisterSupportHostRequest> register_request_; |
| 167 scoped_refptr<MutableHostConfig> host_config_; | 163 scoped_refptr<MutableHostConfig> host_config_; |
| 168 ChromotingHostContext host_context_; | 164 ChromotingHostContext host_context_; |
| 169 scoped_ptr<DesktopEnvironment> desktop_environment_; | 165 scoped_ptr<DesktopEnvironment> desktop_environment_; |
| 170 | 166 |
| 171 scoped_refptr<ChromotingHost> host_; | 167 scoped_refptr<ChromotingHost> host_; |
| 172 int failed_login_attempts_; | 168 int failed_login_attempts_; |
| 173 | 169 |
| 174 base::WaitableEvent disconnected_event_; | 170 base::WaitableEvent disconnected_event_; |
| 175 base::CancellationFlag destructing_; | |
| 176 | 171 |
| 177 scoped_ptr<policy_hack::NatPolicy> nat_policy_; | 172 scoped_ptr<policy_hack::NatPolicy> nat_policy_; |
| 178 | 173 |
| 179 // Host the current nat traversal policy setting. | 174 // Host the current nat traversal policy setting. |
| 180 bool nat_traversal_enabled_; | 175 bool nat_traversal_enabled_; |
| 181 | 176 |
| 182 // Indiciates whether or not a policy has ever been read. This is to ensure | 177 // Indiciates whether or not a policy has ever been read. This is to ensure |
| 183 // that on startup, we do not accidentally start a connection before we have | 178 // that on startup, we do not accidentally start a connection before we have |
| 184 // queried our policy restrictions. | 179 // queried our policy restrictions. |
| 185 bool policy_received_; | 180 bool policy_received_; |
| 186 | 181 |
| 187 // On startup, it is possible to have Connect() called before the policy read | 182 // On startup, it is possible to have Connect() called before the policy read |
| 188 // is completed. Rather than just failing, we thunk the connection call so | 183 // is completed. Rather than just failing, we thunk the connection call so |
| 189 // it can be executed after at least one successful policy read. This | 184 // it can be executed after at least one successful policy read. This |
| 190 // variable contains the thunk if it is necessary. | 185 // variable contains the thunk if it is necessary. |
| 191 base::Closure pending_connect_; | 186 base::Closure pending_connect_; |
| 192 }; | 187 }; |
| 193 | 188 |
| 194 } // namespace remoting | 189 } // namespace remoting |
| 195 | 190 |
| 196 DISABLE_RUNNABLE_METHOD_REFCOUNT(remoting::HostNPScriptObject); | 191 DISABLE_RUNNABLE_METHOD_REFCOUNT(remoting::HostNPScriptObject); |
| 197 | 192 |
| 198 #endif // REMOTING_HOST_HOST_SCRIPT_OBJECT_H_ | 193 #endif // REMOTING_HOST_HOST_SCRIPT_OBJECT_H_ |
| OLD | NEW |