host_control_dispatcher.cc 3.62 KB
Newer Older
1
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 3 4 5 6
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "remoting/protocol/host_control_dispatcher.h"

7
#include "base/callback_helpers.h"
8
#include "net/socket/stream_socket.h"
9
#include "remoting/base/compound_buffer.h"
10
#include "remoting/base/constants.h"
11 12
#include "remoting/proto/control.pb.h"
#include "remoting/proto/internal.pb.h"
13
#include "remoting/protocol/clipboard_stub.h"
14
#include "remoting/protocol/host_stub.h"
15
#include "remoting/protocol/message_pipe.h"
16
#include "remoting/protocol/message_serialization.h"
17 18 19 20 21

namespace remoting {
namespace protocol {

HostControlDispatcher::HostControlDispatcher()
sergeyu's avatar
sergeyu committed
22 23
    : ChannelDispatcherBase(kControlChannelName) {}
HostControlDispatcher::~HostControlDispatcher() {}
24

25 26 27 28
void HostControlDispatcher::SetCapabilities(
    const Capabilities& capabilities) {
  ControlMessage message;
  message.mutable_capabilities()->CopyFrom(capabilities);
29
  message_pipe()->Send(&message, base::Closure());
30 31
}

32 33 34 35
void HostControlDispatcher::SetPairingResponse(
    const PairingResponse& pairing_response) {
  ControlMessage message;
  message.mutable_pairing_response()->CopyFrom(pairing_response);
36
  message_pipe()->Send(&message, base::Closure());
37 38
}

39 40 41 42
void HostControlDispatcher::DeliverHostMessage(
    const ExtensionMessage& message) {
  ControlMessage control_message;
  control_message.mutable_extension_message()->CopyFrom(message);
43
  message_pipe()->Send(&control_message, base::Closure());
44 45
}

sergeyu's avatar
sergeyu committed
46 47 48 49 50 51
void HostControlDispatcher::SetVideoLayout(const VideoLayout& layout) {
  ControlMessage message;
  message.mutable_video_layout()->CopyFrom(layout);
  message_pipe()->Send(&message, base::Closure());
}

52 53 54
void HostControlDispatcher::InjectClipboardEvent(const ClipboardEvent& event) {
  ControlMessage message;
  message.mutable_clipboard_event()->CopyFrom(event);
55
  message_pipe()->Send(&message, base::Closure());
56 57
}

58 59 60 61
void HostControlDispatcher::SetCursorShape(
    const CursorShapeInfo& cursor_shape) {
  ControlMessage message;
  message.mutable_cursor_shape()->CopyFrom(cursor_shape);
62
  message_pipe()->Send(&message, base::Closure());
63 64
}

sergeyu's avatar
sergeyu committed
65
void HostControlDispatcher::OnIncomingMessage(
66
    std::unique_ptr<CompoundBuffer> buffer) {
67
  DCHECK(clipboard_stub_);
68
  DCHECK(host_stub_);
69

70
  std::unique_ptr<ControlMessage> message =
sergeyu's avatar
sergeyu committed
71 72 73 74
      ParseMessage<ControlMessage>(buffer.get());
  if (!message)
    return;

75
  // TODO(sergeyu): Move message valudation from the message handlers here.
76 77
  if (message->has_clipboard_event()) {
    clipboard_stub_->InjectClipboardEvent(message->clipboard_event());
78
  } else if (message->has_client_resolution()) {
79 80 81 82 83 84 85
    const ClientResolution& resolution = message->client_resolution();
    if (!resolution.has_dips_width() || !resolution.has_dips_height() ||
        resolution.dips_width() <= 0 || resolution.dips_height() <= 0) {
      LOG(ERROR) << "Received invalid ClientResolution message.";
      return;
    }
    host_stub_->NotifyClientResolution(resolution);
86 87
  } else if (message->has_video_control()) {
    host_stub_->ControlVideo(message->video_control());
88 89
  } else if (message->has_audio_control()) {
    host_stub_->ControlAudio(message->audio_control());
90 91
  } else if (message->has_capabilities()) {
    host_stub_->SetCapabilities(message->capabilities());
92 93
  } else if (message->has_pairing_request()) {
    host_stub_->RequestPairing(message->pairing_request());
94 95
  } else if (message->has_extension_message()) {
    host_stub_->DeliverClientMessage(message->extension_message());
96 97 98
  } else {
    LOG(WARNING) << "Unknown control message received.";
  }
99 100 101 102
}

}  // namespace protocol
}  // namespace remoting