OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef REMOTING_HOST_HOST_SCRIPT_OBJECT_H_ |
| 6 #define REMOTING_HOST_HOST_SCRIPT_OBJECT_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/synchronization/cancellation_flag.h" |
| 15 #include "base/synchronization/waitable_event.h" |
| 16 #include "base/threading/platform_thread.h" |
| 17 #include "remoting/host/chromoting_host_context.h" |
| 18 #include "remoting/host/host_status_observer.h" |
| 19 #include "third_party/npapi/bindings/npapi.h" |
| 20 #include "third_party/npapi/bindings/npfunctions.h" |
| 21 #include "third_party/npapi/bindings/npruntime.h" |
| 22 |
| 23 class Task; |
| 24 |
| 25 namespace tracked_objects { |
| 26 class Location; |
| 27 } // namespace tracked_objects |
| 28 |
| 29 namespace remoting { |
| 30 |
| 31 class ChromotingHost; |
| 32 class MutableHostConfig; |
| 33 class RegisterSupportHostRequest; |
| 34 class SignalStrategy; |
| 35 class SupportAccessVerifier; |
| 36 |
| 37 // NPAPI plugin implementation for remoting host script object. |
| 38 // HostNPScriptObject creates threads that are required to run |
| 39 // ChromotingHost and starts/stops the host on those threads. When |
| 40 // destroyed it sychronously shuts down the host and all threads. |
| 41 class HostNPScriptObject : public HostStatusObserver { |
| 42 public: |
| 43 HostNPScriptObject(NPP plugin, NPObject* parent); |
| 44 virtual ~HostNPScriptObject(); |
| 45 |
| 46 bool Init(); |
| 47 |
| 48 bool HasMethod(const std::string& method_name); |
| 49 bool InvokeDefault(const NPVariant* args, |
| 50 uint32_t argCount, |
| 51 NPVariant* result); |
| 52 bool Invoke(const std::string& method_name, |
| 53 const NPVariant* args, |
| 54 uint32_t argCount, |
| 55 NPVariant* result); |
| 56 bool HasProperty(const std::string& property_name); |
| 57 bool GetProperty(const std::string& property_name, NPVariant* result); |
| 58 bool SetProperty(const std::string& property_name, const NPVariant* value); |
| 59 bool RemoveProperty(const std::string& property_name); |
| 60 bool Enumerate(std::vector<std::string>* values); |
| 61 |
| 62 // remoting::HostStatusObserver implementation. |
| 63 virtual void OnSignallingConnected(remoting::SignalStrategy* signal_strategy, |
| 64 const std::string& full_jid) OVERRIDE; |
| 65 virtual void OnSignallingDisconnected() OVERRIDE; |
| 66 virtual void OnAccessDenied() OVERRIDE; |
| 67 virtual void OnShutdown() OVERRIDE; |
| 68 |
| 69 private: |
| 70 enum State { |
| 71 kDisconnected, |
| 72 kRequestedAccessCode, |
| 73 kReceivedAccessCode, |
| 74 kConnected, |
| 75 kAffirmingConnection, |
| 76 kError |
| 77 }; |
| 78 |
| 79 // Start connection. args are: |
| 80 // string uid, string auth_token |
| 81 // No result. |
| 82 bool Connect(const NPVariant* args, uint32_t argCount, NPVariant* result); |
| 83 |
| 84 // Disconnect. No arguments or result. |
| 85 bool Disconnect(const NPVariant* args, uint32_t argCount, NPVariant* result); |
| 86 |
| 87 // Call LogDebugInfo handler if there is one. |
| 88 void LogDebugInfo(const std::string& message); |
| 89 |
| 90 // Call OnStateChanged handler if there is one. |
| 91 void OnStateChanged(State state); |
| 92 |
| 93 // Callbacks invoked during session setup. |
| 94 void OnReceivedSupportID(remoting::SupportAccessVerifier* access_verifier, |
| 95 bool success, |
| 96 const std::string& support_id); |
| 97 |
| 98 // Helper functions that run on main thread. Can be called on any |
| 99 // other thread. |
| 100 void ConnectInternal(const std::string& uid, |
| 101 const std::string& auth_token, |
| 102 const std::string& auth_service); |
| 103 void DisconnectInternal(); |
| 104 |
| 105 // Callback for ChromotingHost::Shutdown(). |
| 106 void OnShutdownFinished(); |
| 107 |
| 108 // Call a JavaScript function wrapped as an NPObject. |
| 109 // If result is non-null, the result of the call will be stored in it. |
| 110 // Caller is responsible for releasing result if they ask for it. |
| 111 static bool CallJSFunction(NPObject* func, |
| 112 const NPVariant* args, |
| 113 uint32_t argCount, |
| 114 NPVariant* result); |
| 115 |
| 116 // Posts a task on the main NP thread. |
| 117 void PostTaskToNPThread(const tracked_objects::Location& from_here, |
| 118 Task* task); |
| 119 |
| 120 // Utility function for PostTaskToNPThread. |
| 121 static void NPTaskSpringboard(void* task); |
| 122 |
| 123 // Set an exception for the current call. |
| 124 void SetException(const std::string& exception_string); |
| 125 |
| 126 NPP plugin_; |
| 127 NPObject* parent_; |
| 128 int state_; |
| 129 std::string access_code_; |
| 130 NPObject* log_debug_info_func_; |
| 131 NPObject* on_state_changed_func_; |
| 132 base::PlatformThreadId np_thread_id_; |
| 133 |
| 134 scoped_ptr<RegisterSupportHostRequest> register_request_; |
| 135 scoped_refptr<ChromotingHost> host_; |
| 136 scoped_refptr<MutableHostConfig> host_config_; |
| 137 ChromotingHostContext host_context_; |
| 138 int failed_login_attempts_; |
| 139 |
| 140 base::WaitableEvent disconnected_event_; |
| 141 base::CancellationFlag destructing_; |
| 142 }; |
| 143 |
| 144 } // namespace remoting |
| 145 |
| 146 DISABLE_RUNNABLE_METHOD_REFCOUNT(remoting::HostNPScriptObject); |
| 147 |
| 148 #endif // REMOTING_HOST_HOST_SCRIPT_OBJECT_H_ |
OLD | NEW |