Revert 168224 - Update V8 to version 3.15.4.
[chromium-blink-merge.git] / remoting / client / plugin / chromoting_instance.h
blob83e712b201439c0d02a2d7b24674fbfa720addeb
1 // Copyright (c) 2012 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.
5 // TODO(ajwong): We need to come up with a better description of the
6 // responsibilities for each thread.
8 #ifndef REMOTING_CLIENT_PLUGIN_CHROMOTING_INSTANCE_H_
9 #define REMOTING_CLIENT_PLUGIN_CHROMOTING_INSTANCE_H_
11 #include <string>
13 #include "base/gtest_prod_util.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "ppapi/c/pp_instance.h"
17 #include "ppapi/c/pp_rect.h"
18 #include "ppapi/c/pp_resource.h"
19 #include "ppapi/cpp/var.h"
20 #include "third_party/skia/include/core/SkPoint.h"
21 #include "third_party/skia/include/core/SkSize.h"
23 // Windows defines 'PostMessage', so we have to undef it before we
24 // include instance_private.h
25 #if defined(PostMessage)
26 #undef PostMessage
27 #endif
29 #include "ppapi/cpp/instance.h"
30 #include "remoting/client/client_context.h"
31 #include "remoting/client/client_user_interface.h"
32 #include "remoting/client/key_event_mapper.h"
33 #include "remoting/client/plugin/mac_key_event_processor.h"
34 #include "remoting/client/plugin/pepper_input_handler.h"
35 #include "remoting/client/plugin/pepper_plugin_thread_delegate.h"
36 #include "remoting/proto/event.pb.h"
37 #include "remoting/protocol/clipboard_stub.h"
38 #include "remoting/protocol/connection_to_host.h"
39 #include "remoting/protocol/cursor_shape_stub.h"
40 #include "remoting/protocol/input_event_tracker.h"
41 #include "remoting/protocol/mouse_input_filter.h"
43 namespace base {
44 class DictionaryValue;
45 } // namespace base
47 namespace pp {
48 class InputEvent;
49 class Module;
50 } // namespace pp
52 namespace remoting {
54 class ChromotingClient;
55 class ChromotingStats;
56 class ClientContext;
57 class FrameConsumerProxy;
58 class PepperAudioPlayer;
59 class PepperView;
60 class PepperXmppProxy;
61 class RectangleUpdateDecoder;
63 struct ClientConfig;
65 class ChromotingInstance :
66 public ClientUserInterface,
67 public protocol::ClipboardStub,
68 public protocol::CursorShapeStub,
69 public pp::Instance,
70 public base::SupportsWeakPtr<ChromotingInstance> {
71 public:
72 // Plugin API version. This should be incremented whenever the API
73 // interface changes.
74 static const int kApiVersion = 7;
76 // Plugin API features. This allows orthogonal features to be supported
77 // without bumping the API version.
78 static const char kApiFeatures[];
80 // Backward-compatibility version used by for the messaging
81 // interface. Should be updated whenever we remove support for
82 // an older version of the API.
83 static const int kApiMinMessagingVersion = 5;
85 // Backward-compatibility version used by for the ScriptableObject
86 // interface. Should be updated whenever we remove support for
87 // an older version of the API.
88 static const int kApiMinScriptableVersion = 5;
90 // Helper method to parse authentication_methods parameter.
91 static bool ParseAuthMethods(const std::string& auth_methods,
92 ClientConfig* config);
94 explicit ChromotingInstance(PP_Instance instance);
95 virtual ~ChromotingInstance();
97 // pp::Instance interface.
98 virtual void DidChangeView(const pp::View& view) OVERRIDE;
99 virtual bool Init(uint32_t argc, const char* argn[],
100 const char* argv[]) OVERRIDE;
101 virtual void HandleMessage(const pp::Var& message) OVERRIDE;
102 virtual bool HandleInputEvent(const pp::InputEvent& event) OVERRIDE;
104 // ClientUserInterface interface.
105 virtual void OnConnectionState(protocol::ConnectionToHost::State state,
106 protocol::ErrorCode error) OVERRIDE;
107 virtual void OnConnectionReady(bool ready) OVERRIDE;
108 virtual protocol::ClipboardStub* GetClipboardStub() OVERRIDE;
109 virtual protocol::CursorShapeStub* GetCursorShapeStub() OVERRIDE;
111 // protocol::ClipboardStub interface.
112 virtual void InjectClipboardEvent(
113 const protocol::ClipboardEvent& event) OVERRIDE;
115 // protocol::CursorShapeStub interface.
116 virtual void SetCursorShape(
117 const protocol::CursorShapeInfo& cursor_shape) OVERRIDE;
119 // Called by PepperView.
120 void SetDesktopSize(const SkISize& size, const SkIPoint& dpi);
121 void OnFirstFrameReceived();
123 // Message handlers for messages that come from JavaScript. Called
124 // from HandleMessage().
125 void Connect(const ClientConfig& config);
126 void Disconnect();
127 void OnIncomingIq(const std::string& iq);
128 void ReleaseAllKeys();
129 void InjectKeyEvent(const protocol::KeyEvent& event);
130 void RemapKey(uint32 in_usb_keycode, uint32 out_usb_keycode);
131 void TrapKey(uint32 usb_keycode, bool trap);
132 void SendClipboardItem(const std::string& mime_type, const std::string& item);
133 void NotifyClientDimensions(int width, int height);
134 void PauseVideo(bool pause);
135 void PauseAudio(bool pause);
137 // Return statistics record by ChromotingClient.
138 // If no connection is currently active then NULL will be returned.
139 ChromotingStats* GetStats();
141 // Registers a global log message handler that redirects the log output to
142 // our plugin instance.
143 // This is called by the plugin's PPP_InitializeModule.
144 // Note that no logging will be processed unless a ChromotingInstance has been
145 // registered for logging (see RegisterLoggingInstance).
146 static void RegisterLogMessageHandler();
148 // Registers this instance so it processes messages sent by the global log
149 // message handler. This overwrites any previously registered instance.
150 void RegisterLoggingInstance();
152 // Unregisters this instance so that debug log messages will no longer be sent
153 // to it. If this instance is not the currently registered logging instance,
154 // then the currently registered instance will stay in effect.
155 void UnregisterLoggingInstance();
157 // A Log Message Handler that is called after each LOG message has been
158 // processed. This must be of type LogMessageHandlerFunction defined in
159 // base/logging.h.
160 static bool LogToUI(int severity, const char* file, int line,
161 size_t message_start, const std::string& str);
163 private:
164 FRIEND_TEST_ALL_PREFIXES(ChromotingInstanceTest, TestCaseSetup);
166 // Helper method to post messages to the webapp.
167 void PostChromotingMessage(const std::string& method,
168 scoped_ptr<base::DictionaryValue> data);
170 // Posts trapped keys to the web-app to handle.
171 void SendTrappedKey(uint32 usb_keycode, bool pressed);
173 // Callback for PepperXmppProxy.
174 void SendOutgoingIq(const std::string& iq);
176 void SendPerfStats();
178 void ProcessLogToUI(const std::string& message);
180 // Returns true if there is a ConnectionToHost and it is connected.
181 bool IsConnected();
183 bool initialized_;
185 PepperPluginThreadDelegate plugin_thread_delegate_;
186 scoped_refptr<PluginThreadTaskRunner> plugin_task_runner_;
187 ClientContext context_;
188 scoped_refptr<RectangleUpdateDecoder> rectangle_decoder_;
189 scoped_ptr<PepperView> view_;
191 scoped_ptr<protocol::ConnectionToHost> host_connection_;
192 scoped_ptr<ChromotingClient> client_;
194 // Input pipeline components, in reverse order of distance from input source.
195 protocol::MouseInputFilter mouse_input_filter_;
196 protocol::InputEventTracker input_tracker_;
197 #if defined(OS_MACOSX)
198 MacKeyEventProcessor mac_key_event_processor_;
199 #endif
200 KeyEventMapper key_mapper_;
201 PepperInputHandler input_handler_;
203 // XmppProxy is a refcounted interface used to perform thread-switching and
204 // detaching between objects whose lifetimes are controlled by pepper, and
205 // jingle_glue objects. This is used when if we start a sandboxed jingle
206 // connection.
207 scoped_refptr<PepperXmppProxy> xmpp_proxy_;
209 base::WeakPtrFactory<ChromotingInstance> weak_factory_;
211 DISALLOW_COPY_AND_ASSIGN(ChromotingInstance);
214 } // namespace remoting
216 #endif // REMOTING_CLIENT_PLUGIN_CHROMOTING_INSTANCE_H_