Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / remoting / protocol / clipboard_echo_filter.cc
blob206f6619ea132843f181ac42ae60df443d376f28
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 #include "remoting/protocol/clipboard_echo_filter.h"
7 #include "remoting/proto/event.pb.h"
9 namespace remoting {
10 namespace protocol {
12 ClipboardEchoFilter::ClipboardEchoFilter()
13 : host_stub_(nullptr),
14 client_stub_(nullptr),
15 client_filter_(this),
16 host_filter_(this) {
19 ClipboardEchoFilter::~ClipboardEchoFilter() {
22 void ClipboardEchoFilter::set_client_stub(ClipboardStub* client_stub) {
23 client_stub_ = client_stub;
26 void ClipboardEchoFilter::set_host_stub(ClipboardStub* host_stub) {
27 host_stub_ = host_stub;
30 ClipboardStub* ClipboardEchoFilter::client_filter() {
31 return &client_filter_;
34 ClipboardStub* ClipboardEchoFilter::host_filter() {
35 return &host_filter_;
38 void ClipboardEchoFilter::InjectClipboardEventToClient(
39 const ClipboardEvent& event) {
40 if (!client_stub_) {
41 return;
43 if (event.mime_type() == client_latest_mime_type_ &&
44 event.data() == client_latest_data_) {
45 return;
47 client_stub_->InjectClipboardEvent(event);
50 void ClipboardEchoFilter::InjectClipboardEventToHost(
51 const ClipboardEvent& event) {
52 client_latest_mime_type_ = event.mime_type();
53 client_latest_data_ = event.data();
54 if (host_stub_) {
55 host_stub_->InjectClipboardEvent(event);
59 ClipboardEchoFilter::ClientFilter::ClientFilter(
60 ClipboardEchoFilter* filter) : filter_(filter) {
63 void ClipboardEchoFilter::ClientFilter::InjectClipboardEvent(
64 const ClipboardEvent& event) {
65 filter_->InjectClipboardEventToClient(event);
68 ClipboardEchoFilter::HostFilter::HostFilter(
69 ClipboardEchoFilter* filter) : filter_(filter) {
72 void ClipboardEchoFilter::HostFilter::InjectClipboardEvent(
73 const ClipboardEvent& event) {
74 filter_->InjectClipboardEventToHost(event);
77 } // namespace protocol
78 } // namespace remoting