Chromium Code Reviews| 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" | |
| 22 #include "remoting/host/ipc_screen_controls.h" | 23 #include "remoting/host/ipc_screen_controls.h" |
| 23 #include "remoting/host/ipc_video_frame_capturer.h" | 24 #include "remoting/host/ipc_video_frame_capturer.h" |
| 24 #include "remoting/proto/audio.pb.h" | 25 #include "remoting/proto/audio.pb.h" |
| 25 #include "remoting/proto/control.pb.h" | 26 #include "remoting/proto/control.pb.h" |
| 26 #include "remoting/proto/event.pb.h" | 27 #include "remoting/proto/event.pb.h" |
| 27 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 28 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
| 28 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" | 29 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" |
| 30 #include "third_party/webrtc/modules/desktop_capture/mouse_cursor.h" | |
| 29 #include "third_party/webrtc/modules/desktop_capture/shared_memory.h" | 31 #include "third_party/webrtc/modules/desktop_capture/shared_memory.h" |
| 30 | 32 |
| 31 #if defined(OS_WIN) | 33 #if defined(OS_WIN) |
| 32 #include "base/win/scoped_handle.h" | 34 #include "base/win/scoped_handle.h" |
| 33 #endif // defined(OS_WIN) | 35 #endif // defined(OS_WIN) |
| 34 | 36 |
| 35 const bool kReadOnly = true; | 37 const bool kReadOnly = true; |
| 36 const char kSendInitialResolution[] = "sendInitialResolution"; | 38 const char kSendInitialResolution[] = "sendInitialResolution"; |
| 37 const char kRateLimitResizeRequests[] = "rateLimitResizeRequests"; | 39 const char kRateLimitResizeRequests[] = "rateLimitResizeRequests"; |
| 38 | 40 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 | 139 |
| 138 return scoped_ptr<ScreenControls>(new IpcScreenControls(this)); | 140 return scoped_ptr<ScreenControls>(new IpcScreenControls(this)); |
| 139 } | 141 } |
| 140 | 142 |
| 141 scoped_ptr<webrtc::ScreenCapturer> DesktopSessionProxy::CreateVideoCapturer() { | 143 scoped_ptr<webrtc::ScreenCapturer> DesktopSessionProxy::CreateVideoCapturer() { |
| 142 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 144 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 143 | 145 |
| 144 return scoped_ptr<webrtc::ScreenCapturer>(new IpcVideoFrameCapturer(this)); | 146 return scoped_ptr<webrtc::ScreenCapturer>(new IpcVideoFrameCapturer(this)); |
| 145 } | 147 } |
| 146 | 148 |
| 149 scoped_ptr<webrtc::MouseCursorMonitor> | |
| 150 DesktopSessionProxy::CreateMouseCursorMonitor() { | |
| 151 return scoped_ptr<webrtc::MouseCursorMonitor>( | |
| 152 new IpcMouseCursorMonitor(this)); | |
| 153 } | |
| 154 | |
| 147 std::string DesktopSessionProxy::GetCapabilities() const { | 155 std::string DesktopSessionProxy::GetCapabilities() const { |
| 148 std::string result = kRateLimitResizeRequests; | 156 std::string result = kRateLimitResizeRequests; |
| 149 // Ask the client to send its resolution unconditionally. | 157 // Ask the client to send its resolution unconditionally. |
| 150 if (virtual_terminal_) | 158 if (virtual_terminal_) |
| 151 result = result + " " + kSendInitialResolution; | 159 result = result + " " + kSendInitialResolution; |
| 152 return result; | 160 return result; |
| 153 } | 161 } |
| 154 | 162 |
| 155 void DesktopSessionProxy::SetCapabilities(const std::string& capabilities) { | 163 void DesktopSessionProxy::SetCapabilities(const std::string& capabilities) { |
| 156 // Delay creation of the desktop session until the client screen resolution is | 164 // Delay creation of the desktop session until the client screen resolution is |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 176 | 184 |
| 177 bool DesktopSessionProxy::OnMessageReceived(const IPC::Message& message) { | 185 bool DesktopSessionProxy::OnMessageReceived(const IPC::Message& message) { |
| 178 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 186 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 179 | 187 |
| 180 bool handled = true; | 188 bool handled = true; |
| 181 IPC_BEGIN_MESSAGE_MAP(DesktopSessionProxy, message) | 189 IPC_BEGIN_MESSAGE_MAP(DesktopSessionProxy, message) |
| 182 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_AudioPacket, | 190 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_AudioPacket, |
| 183 OnAudioPacket) | 191 OnAudioPacket) |
| 184 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_CaptureCompleted, | 192 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_CaptureCompleted, |
| 185 OnCaptureCompleted) | 193 OnCaptureCompleted) |
| 186 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_CursorShapeChanged, | 194 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_MouseCursor, |
| 187 OnCursorShapeChanged) | 195 OnMouseCursor) |
| 188 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_CreateSharedBuffer, | 196 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_CreateSharedBuffer, |
| 189 OnCreateSharedBuffer) | 197 OnCreateSharedBuffer) |
| 190 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_ReleaseSharedBuffer, | 198 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_ReleaseSharedBuffer, |
| 191 OnReleaseSharedBuffer) | 199 OnReleaseSharedBuffer) |
| 192 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_InjectClipboardEvent, | 200 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_InjectClipboardEvent, |
| 193 OnInjectClipboardEvent) | 201 OnInjectClipboardEvent) |
| 194 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_DisconnectSession, | 202 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_DisconnectSession, |
| 195 DisconnectSession); | 203 DisconnectSession); |
| 196 IPC_END_MESSAGE_MAP() | 204 IPC_END_MESSAGE_MAP() |
| 197 | 205 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 } | 318 } |
| 311 } | 319 } |
| 312 | 320 |
| 313 void DesktopSessionProxy::SetVideoCapturer( | 321 void DesktopSessionProxy::SetVideoCapturer( |
| 314 const base::WeakPtr<IpcVideoFrameCapturer> video_capturer) { | 322 const base::WeakPtr<IpcVideoFrameCapturer> video_capturer) { |
| 315 DCHECK(video_capture_task_runner_->BelongsToCurrentThread()); | 323 DCHECK(video_capture_task_runner_->BelongsToCurrentThread()); |
| 316 | 324 |
| 317 video_capturer_ = video_capturer; | 325 video_capturer_ = video_capturer; |
| 318 } | 326 } |
| 319 | 327 |
| 328 void DesktopSessionProxy::SetMouseCursorMonitor( | |
| 329 const base::WeakPtr<IpcMouseCursorMonitor>& mouse_cursor_monitor) { | |
| 330 DCHECK(video_capture_task_runner_->BelongsToCurrentThread()); | |
| 331 | |
| 332 mouse_cursor_monitor_ = mouse_cursor_monitor; | |
| 333 } | |
| 334 | |
| 320 void DesktopSessionProxy::DisconnectSession() { | 335 void DesktopSessionProxy::DisconnectSession() { |
| 321 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 336 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 322 | 337 |
| 323 // Disconnect the client session if it hasn't been disconnected yet. | 338 // Disconnect the client session if it hasn't been disconnected yet. |
| 324 if (client_session_control_.get()) | 339 if (client_session_control_.get()) |
| 325 client_session_control_->DisconnectSession(); | 340 client_session_control_->DisconnectSession(); |
| 326 } | 341 } |
| 327 | 342 |
| 328 void DesktopSessionProxy::InjectClipboardEvent( | 343 void DesktopSessionProxy::InjectClipboardEvent( |
| 329 const protocol::ClipboardEvent& event) { | 344 const protocol::ClipboardEvent& event) { |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 483 frame->set_dpi(serialized_frame.dpi); | 498 frame->set_dpi(serialized_frame.dpi); |
| 484 | 499 |
| 485 for (size_t i = 0; i < serialized_frame.dirty_region.size(); ++i) { | 500 for (size_t i = 0; i < serialized_frame.dirty_region.size(); ++i) { |
| 486 frame->mutable_updated_region()->AddRect(serialized_frame.dirty_region[i]); | 501 frame->mutable_updated_region()->AddRect(serialized_frame.dirty_region[i]); |
| 487 } | 502 } |
| 488 | 503 |
| 489 --pending_capture_frame_requests_; | 504 --pending_capture_frame_requests_; |
| 490 PostCaptureCompleted(frame.Pass()); | 505 PostCaptureCompleted(frame.Pass()); |
| 491 } | 506 } |
| 492 | 507 |
| 493 void DesktopSessionProxy::OnCursorShapeChanged( | 508 void DesktopSessionProxy::OnMouseCursor( |
| 494 const webrtc::MouseCursorShape& cursor_shape) { | 509 const SerializedMouseCursor& mouse_cursor) { |
| 495 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 510 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 496 PostCursorShape(scoped_ptr<webrtc::MouseCursorShape>( | 511 |
| 497 new webrtc::MouseCursorShape(cursor_shape))); | 512 // Sanitize IPC message. Check for overflow, and that enough data was sent. |
| 513 int cursor_width = mouse_cursor.size.width(); | |
| 514 int cursor_height = mouse_cursor.size.height(); | |
| 515 uint32 expected_total_bytes = cursor_width * cursor_height * | |
| 516 webrtc::DesktopFrame::kBytesPerPixel; | |
| 517 if (cursor_width <= 0 || cursor_width > (SHRT_MAX / 2) || | |
| 518 cursor_height <= 0 || cursor_height > (SHRT_MAX / 2) || | |
| 519 mouse_cursor.data.size() < expected_total_bytes) { | |
| 520 LOG(ERROR) << "Invalid SerializedMouseCursor:" | |
| 521 << " w=" << cursor_width << " h=" << cursor_height | |
| 522 << " data_size=" << mouse_cursor.data.size(); | |
| 523 return; | |
|
Sergey Ulanov
2013/12/03 21:47:28
bogus IPC message indicates that something went ve
dcaiafa
2013/12/10 01:32:03
Done.
| |
| 524 } | |
| 525 | |
| 526 // Rebuild a |webrtc::DesktopFrame| from the IPC message. | |
| 527 webrtc::BasicDesktopFrame* frame = | |
| 528 new webrtc::BasicDesktopFrame(mouse_cursor.size); | |
| 529 const char* source = mouse_cursor.data.data(); | |
| 530 uint8_t* target = frame->data(); | |
| 531 for (int y = 0; y < frame->size().height(); y++) { | |
| 532 int bytes_to_copy = mouse_cursor.size.width() * | |
| 533 webrtc::DesktopFrame::kBytesPerPixel; | |
| 534 memcpy(target, source, bytes_to_copy); | |
| 535 source += bytes_to_copy; | |
| 536 // N.B. |stride()| is in bytes already. | |
| 537 target += frame->stride(); | |
| 538 } | |
| 539 | |
| 540 scoped_ptr<webrtc::MouseCursor> cursor(new webrtc::MouseCursor( | |
| 541 frame, mouse_cursor.hotspot)); | |
| 542 PostMouseCursor(cursor.Pass()); | |
| 498 } | 543 } |
| 499 | 544 |
| 500 void DesktopSessionProxy::OnInjectClipboardEvent( | 545 void DesktopSessionProxy::OnInjectClipboardEvent( |
| 501 const std::string& serialized_event) { | 546 const std::string& serialized_event) { |
| 502 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 547 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 503 | 548 |
| 504 if (client_clipboard_) { | 549 if (client_clipboard_) { |
| 505 protocol::ClipboardEvent event; | 550 protocol::ClipboardEvent event; |
| 506 if (!event.ParseFromString(serialized_event)) { | 551 if (!event.ParseFromString(serialized_event)) { |
| 507 LOG(ERROR) << "Failed to parse protocol::ClipboardEvent."; | 552 LOG(ERROR) << "Failed to parse protocol::ClipboardEvent."; |
| 508 return; | 553 return; |
| 509 } | 554 } |
| 510 | 555 |
| 511 client_clipboard_->InjectClipboardEvent(event); | 556 client_clipboard_->InjectClipboardEvent(event); |
| 512 } | 557 } |
| 513 } | 558 } |
| 514 | 559 |
| 515 void DesktopSessionProxy::PostCaptureCompleted( | 560 void DesktopSessionProxy::PostCaptureCompleted( |
| 516 scoped_ptr<webrtc::DesktopFrame> frame) { | 561 scoped_ptr<webrtc::DesktopFrame> frame) { |
| 517 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 562 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 518 | 563 |
| 519 video_capture_task_runner_->PostTask( | 564 video_capture_task_runner_->PostTask( |
| 520 FROM_HERE, | 565 FROM_HERE, |
| 521 base::Bind(&IpcVideoFrameCapturer::OnCaptureCompleted, video_capturer_, | 566 base::Bind(&IpcVideoFrameCapturer::OnCaptureCompleted, video_capturer_, |
| 522 base::Passed(&frame))); | 567 base::Passed(&frame))); |
| 523 } | 568 } |
| 524 | 569 |
| 525 void DesktopSessionProxy::PostCursorShape( | 570 void DesktopSessionProxy::PostMouseCursor( |
| 526 scoped_ptr<webrtc::MouseCursorShape> cursor_shape) { | 571 scoped_ptr<webrtc::MouseCursor> mouse_cursor) { |
| 527 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 572 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 528 | 573 |
| 529 video_capture_task_runner_->PostTask( | 574 video_capture_task_runner_->PostTask( |
| 530 FROM_HERE, | 575 FROM_HERE, |
| 531 base::Bind(&IpcVideoFrameCapturer::OnCursorShapeChanged, video_capturer_, | 576 base::Bind(&IpcMouseCursorMonitor::OnMouseCursor, mouse_cursor_monitor_, |
| 532 base::Passed(&cursor_shape))); | 577 base::Passed(&mouse_cursor))); |
| 533 } | 578 } |
| 534 | 579 |
| 535 void DesktopSessionProxy::SendToDesktop(IPC::Message* message) { | 580 void DesktopSessionProxy::SendToDesktop(IPC::Message* message) { |
| 536 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 581 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 537 | 582 |
| 538 if (desktop_channel_) { | 583 if (desktop_channel_) { |
| 539 desktop_channel_->Send(message); | 584 desktop_channel_->Send(message); |
| 540 } else { | 585 } else { |
| 541 delete message; | 586 delete message; |
| 542 } | 587 } |
| 543 } | 588 } |
| 544 | 589 |
| 545 // static | 590 // static |
| 546 void DesktopSessionProxyTraits::Destruct( | 591 void DesktopSessionProxyTraits::Destruct( |
| 547 const DesktopSessionProxy* desktop_session_proxy) { | 592 const DesktopSessionProxy* desktop_session_proxy) { |
| 548 desktop_session_proxy->caller_task_runner_->DeleteSoon(FROM_HERE, | 593 desktop_session_proxy->caller_task_runner_->DeleteSoon(FROM_HERE, |
| 549 desktop_session_proxy); | 594 desktop_session_proxy); |
| 550 } | 595 } |
| 551 | 596 |
| 552 } // namespace remoting | 597 } // namespace remoting |
| OLD | NEW |