OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/desktop_session_proxy.h" | 5 #include "remoting/host/desktop_session_proxy.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/platform_file.h" | 9 #include "base/platform_file.h" |
10 #include "base/process/process_handle.h" | 10 #include "base/process/process_handle.h" |
11 #include "base/memory/shared_memory.h" | 11 #include "base/memory/shared_memory.h" |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "ipc/ipc_channel_proxy.h" | 13 #include "ipc/ipc_channel_proxy.h" |
14 #include "ipc/ipc_message_macros.h" | 14 #include "ipc/ipc_message_macros.h" |
15 #include "remoting/base/capabilities.h" | 15 #include "remoting/base/capabilities.h" |
16 #include "remoting/host/chromoting_messages.h" | 16 #include "remoting/host/chromoting_messages.h" |
17 #include "remoting/host/client_session.h" | 17 #include "remoting/host/client_session.h" |
18 #include "remoting/host/client_session_control.h" | 18 #include "remoting/host/client_session_control.h" |
19 #include "remoting/host/desktop_session_connector.h" | 19 #include "remoting/host/desktop_session_connector.h" |
20 #include "remoting/host/ipc_audio_capturer.h" | 20 #include "remoting/host/ipc_audio_capturer.h" |
21 #include "remoting/host/ipc_input_injector.h" | 21 #include "remoting/host/ipc_input_injector.h" |
22 #include "remoting/host/ipc_mouse_cursor_monitor.h" | |
23 #include "remoting/host/ipc_screen_controls.h" | 22 #include "remoting/host/ipc_screen_controls.h" |
24 #include "remoting/host/ipc_video_frame_capturer.h" | 23 #include "remoting/host/ipc_video_frame_capturer.h" |
25 #include "remoting/proto/audio.pb.h" | 24 #include "remoting/proto/audio.pb.h" |
26 #include "remoting/proto/control.pb.h" | 25 #include "remoting/proto/control.pb.h" |
27 #include "remoting/proto/event.pb.h" | 26 #include "remoting/proto/event.pb.h" |
28 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 27 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
29 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" | 28 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" |
30 #include "third_party/webrtc/modules/desktop_capture/mouse_cursor.h" | |
31 #include "third_party/webrtc/modules/desktop_capture/shared_memory.h" | 29 #include "third_party/webrtc/modules/desktop_capture/shared_memory.h" |
32 | 30 |
33 #if defined(OS_WIN) | 31 #if defined(OS_WIN) |
34 #include "base/win/scoped_handle.h" | 32 #include "base/win/scoped_handle.h" |
35 #endif // defined(OS_WIN) | 33 #endif // defined(OS_WIN) |
36 | 34 |
37 const bool kReadOnly = true; | 35 const bool kReadOnly = true; |
38 const char kSendInitialResolution[] = "sendInitialResolution"; | 36 const char kSendInitialResolution[] = "sendInitialResolution"; |
39 const char kRateLimitResizeRequests[] = "rateLimitResizeRequests"; | 37 const char kRateLimitResizeRequests[] = "rateLimitResizeRequests"; |
40 | 38 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 | 137 |
140 return scoped_ptr<ScreenControls>(new IpcScreenControls(this)); | 138 return scoped_ptr<ScreenControls>(new IpcScreenControls(this)); |
141 } | 139 } |
142 | 140 |
143 scoped_ptr<webrtc::ScreenCapturer> DesktopSessionProxy::CreateVideoCapturer() { | 141 scoped_ptr<webrtc::ScreenCapturer> DesktopSessionProxy::CreateVideoCapturer() { |
144 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 142 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
145 | 143 |
146 return scoped_ptr<webrtc::ScreenCapturer>(new IpcVideoFrameCapturer(this)); | 144 return scoped_ptr<webrtc::ScreenCapturer>(new IpcVideoFrameCapturer(this)); |
147 } | 145 } |
148 | 146 |
149 scoped_ptr<webrtc::MouseCursorMonitor> | |
150 DesktopSessionProxy::CreateMouseCursorMonitor() { | |
151 return scoped_ptr<webrtc::MouseCursorMonitor>( | |
152 new IpcMouseCursorMonitor(this)); | |
153 } | |
154 | |
155 std::string DesktopSessionProxy::GetCapabilities() const { | 147 std::string DesktopSessionProxy::GetCapabilities() const { |
156 std::string result = kRateLimitResizeRequests; | 148 std::string result = kRateLimitResizeRequests; |
157 // Ask the client to send its resolution unconditionally. | 149 // Ask the client to send its resolution unconditionally. |
158 if (virtual_terminal_) | 150 if (virtual_terminal_) |
159 result = result + " " + kSendInitialResolution; | 151 result = result + " " + kSendInitialResolution; |
160 return result; | 152 return result; |
161 } | 153 } |
162 | 154 |
163 void DesktopSessionProxy::SetCapabilities(const std::string& capabilities) { | 155 void DesktopSessionProxy::SetCapabilities(const std::string& capabilities) { |
164 // Delay creation of the desktop session until the client screen resolution is | 156 // Delay creation of the desktop session until the client screen resolution is |
(...skipping 19 matching lines...) Expand all Loading... |
184 | 176 |
185 bool DesktopSessionProxy::OnMessageReceived(const IPC::Message& message) { | 177 bool DesktopSessionProxy::OnMessageReceived(const IPC::Message& message) { |
186 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 178 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
187 | 179 |
188 bool handled = true; | 180 bool handled = true; |
189 IPC_BEGIN_MESSAGE_MAP(DesktopSessionProxy, message) | 181 IPC_BEGIN_MESSAGE_MAP(DesktopSessionProxy, message) |
190 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_AudioPacket, | 182 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_AudioPacket, |
191 OnAudioPacket) | 183 OnAudioPacket) |
192 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_CaptureCompleted, | 184 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_CaptureCompleted, |
193 OnCaptureCompleted) | 185 OnCaptureCompleted) |
194 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_MouseCursor, | 186 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_CursorShapeChanged, |
195 OnMouseCursor) | 187 OnCursorShapeChanged) |
196 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_CreateSharedBuffer, | 188 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_CreateSharedBuffer, |
197 OnCreateSharedBuffer) | 189 OnCreateSharedBuffer) |
198 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_ReleaseSharedBuffer, | 190 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_ReleaseSharedBuffer, |
199 OnReleaseSharedBuffer) | 191 OnReleaseSharedBuffer) |
200 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_InjectClipboardEvent, | 192 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_InjectClipboardEvent, |
201 OnInjectClipboardEvent) | 193 OnInjectClipboardEvent) |
202 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_DisconnectSession, | 194 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_DisconnectSession, |
203 DisconnectSession); | 195 DisconnectSession); |
204 IPC_END_MESSAGE_MAP() | 196 IPC_END_MESSAGE_MAP() |
205 | 197 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 } | 311 } |
320 } | 312 } |
321 | 313 |
322 void DesktopSessionProxy::SetVideoCapturer( | 314 void DesktopSessionProxy::SetVideoCapturer( |
323 const base::WeakPtr<IpcVideoFrameCapturer> video_capturer) { | 315 const base::WeakPtr<IpcVideoFrameCapturer> video_capturer) { |
324 DCHECK(video_capture_task_runner_->BelongsToCurrentThread()); | 316 DCHECK(video_capture_task_runner_->BelongsToCurrentThread()); |
325 | 317 |
326 video_capturer_ = video_capturer; | 318 video_capturer_ = video_capturer; |
327 } | 319 } |
328 | 320 |
329 void DesktopSessionProxy::SetMouseCursorMonitor( | |
330 const base::WeakPtr<IpcMouseCursorMonitor>& mouse_cursor_monitor) { | |
331 DCHECK(video_capture_task_runner_->BelongsToCurrentThread()); | |
332 | |
333 mouse_cursor_monitor_ = mouse_cursor_monitor; | |
334 } | |
335 | |
336 void DesktopSessionProxy::DisconnectSession() { | 321 void DesktopSessionProxy::DisconnectSession() { |
337 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 322 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
338 | 323 |
339 // Disconnect the client session if it hasn't been disconnected yet. | 324 // Disconnect the client session if it hasn't been disconnected yet. |
340 if (client_session_control_.get()) | 325 if (client_session_control_.get()) |
341 client_session_control_->DisconnectSession(); | 326 client_session_control_->DisconnectSession(); |
342 } | 327 } |
343 | 328 |
344 void DesktopSessionProxy::InjectClipboardEvent( | 329 void DesktopSessionProxy::InjectClipboardEvent( |
345 const protocol::ClipboardEvent& event) { | 330 const protocol::ClipboardEvent& event) { |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 frame->set_dpi(serialized_frame.dpi); | 484 frame->set_dpi(serialized_frame.dpi); |
500 | 485 |
501 for (size_t i = 0; i < serialized_frame.dirty_region.size(); ++i) { | 486 for (size_t i = 0; i < serialized_frame.dirty_region.size(); ++i) { |
502 frame->mutable_updated_region()->AddRect(serialized_frame.dirty_region[i]); | 487 frame->mutable_updated_region()->AddRect(serialized_frame.dirty_region[i]); |
503 } | 488 } |
504 | 489 |
505 --pending_capture_frame_requests_; | 490 --pending_capture_frame_requests_; |
506 PostCaptureCompleted(frame.Pass()); | 491 PostCaptureCompleted(frame.Pass()); |
507 } | 492 } |
508 | 493 |
509 void DesktopSessionProxy::OnMouseCursor( | 494 void DesktopSessionProxy::OnCursorShapeChanged( |
510 const webrtc::MouseCursor& mouse_cursor) { | 495 const webrtc::MouseCursorShape& cursor_shape) { |
511 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 496 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
512 scoped_ptr<webrtc::MouseCursor> cursor( | 497 PostCursorShape(scoped_ptr<webrtc::MouseCursorShape>( |
513 webrtc::MouseCursor::CopyOf(mouse_cursor)); | 498 new webrtc::MouseCursorShape(cursor_shape))); |
514 PostMouseCursor(cursor.Pass()); | |
515 } | 499 } |
516 | 500 |
517 void DesktopSessionProxy::OnInjectClipboardEvent( | 501 void DesktopSessionProxy::OnInjectClipboardEvent( |
518 const std::string& serialized_event) { | 502 const std::string& serialized_event) { |
519 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 503 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
520 | 504 |
521 if (client_clipboard_) { | 505 if (client_clipboard_) { |
522 protocol::ClipboardEvent event; | 506 protocol::ClipboardEvent event; |
523 if (!event.ParseFromString(serialized_event)) { | 507 if (!event.ParseFromString(serialized_event)) { |
524 LOG(ERROR) << "Failed to parse protocol::ClipboardEvent."; | 508 LOG(ERROR) << "Failed to parse protocol::ClipboardEvent."; |
525 return; | 509 return; |
526 } | 510 } |
527 | 511 |
528 client_clipboard_->InjectClipboardEvent(event); | 512 client_clipboard_->InjectClipboardEvent(event); |
529 } | 513 } |
530 } | 514 } |
531 | 515 |
532 void DesktopSessionProxy::PostCaptureCompleted( | 516 void DesktopSessionProxy::PostCaptureCompleted( |
533 scoped_ptr<webrtc::DesktopFrame> frame) { | 517 scoped_ptr<webrtc::DesktopFrame> frame) { |
534 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 518 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
535 | 519 |
536 video_capture_task_runner_->PostTask( | 520 video_capture_task_runner_->PostTask( |
537 FROM_HERE, | 521 FROM_HERE, |
538 base::Bind(&IpcVideoFrameCapturer::OnCaptureCompleted, video_capturer_, | 522 base::Bind(&IpcVideoFrameCapturer::OnCaptureCompleted, video_capturer_, |
539 base::Passed(&frame))); | 523 base::Passed(&frame))); |
540 } | 524 } |
541 | 525 |
542 void DesktopSessionProxy::PostMouseCursor( | 526 void DesktopSessionProxy::PostCursorShape( |
543 scoped_ptr<webrtc::MouseCursor> mouse_cursor) { | 527 scoped_ptr<webrtc::MouseCursorShape> cursor_shape) { |
544 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 528 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
545 | 529 |
546 video_capture_task_runner_->PostTask( | 530 video_capture_task_runner_->PostTask( |
547 FROM_HERE, | 531 FROM_HERE, |
548 base::Bind(&IpcMouseCursorMonitor::OnMouseCursor, mouse_cursor_monitor_, | 532 base::Bind(&IpcVideoFrameCapturer::OnCursorShapeChanged, video_capturer_, |
549 base::Passed(&mouse_cursor))); | 533 base::Passed(&cursor_shape))); |
550 } | 534 } |
551 | 535 |
552 void DesktopSessionProxy::SendToDesktop(IPC::Message* message) { | 536 void DesktopSessionProxy::SendToDesktop(IPC::Message* message) { |
553 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 537 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
554 | 538 |
555 if (desktop_channel_) { | 539 if (desktop_channel_) { |
556 desktop_channel_->Send(message); | 540 desktop_channel_->Send(message); |
557 } else { | 541 } else { |
558 delete message; | 542 delete message; |
559 } | 543 } |
560 } | 544 } |
561 | 545 |
562 // static | 546 // static |
563 void DesktopSessionProxyTraits::Destruct( | 547 void DesktopSessionProxyTraits::Destruct( |
564 const DesktopSessionProxy* desktop_session_proxy) { | 548 const DesktopSessionProxy* desktop_session_proxy) { |
565 desktop_session_proxy->caller_task_runner_->DeleteSoon(FROM_HERE, | 549 desktop_session_proxy->caller_task_runner_->DeleteSoon(FROM_HERE, |
566 desktop_session_proxy); | 550 desktop_session_proxy); |
567 } | 551 } |
568 | 552 |
569 } // namespace remoting | 553 } // namespace remoting |
OLD | NEW |