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