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. 4 5 #include "remoting/protocol/clipboard_echo_filter.h" 6 7 #include "remoting/proto/event.pb.h" 8 9 namespace remoting { 10 namespace protocol { 11 ClipboardEchoFilter()12ClipboardEchoFilter::ClipboardEchoFilter() 13 : host_stub_(NULL), 14 client_stub_(NULL), 15 client_filter_(this), 16 host_filter_(this) { 17 } 18 ~ClipboardEchoFilter()19ClipboardEchoFilter::~ClipboardEchoFilter() { 20 } 21 set_client_stub(ClipboardStub * client_stub)22void ClipboardEchoFilter::set_client_stub(ClipboardStub* client_stub) { 23 client_stub_ = client_stub; 24 } 25 set_host_stub(ClipboardStub * host_stub)26void ClipboardEchoFilter::set_host_stub(ClipboardStub* host_stub) { 27 host_stub_ = host_stub; 28 } 29 client_filter()30ClipboardStub* ClipboardEchoFilter::client_filter() { 31 return &client_filter_; 32 } 33 host_filter()34ClipboardStub* ClipboardEchoFilter::host_filter() { 35 return &host_filter_; 36 } 37 InjectClipboardEventToClient(const ClipboardEvent & event)38void ClipboardEchoFilter::InjectClipboardEventToClient( 39 const ClipboardEvent& event) { 40 if (!client_stub_) { 41 return; 42 } 43 if (event.mime_type() == client_latest_mime_type_ && 44 event.data() == client_latest_data_) { 45 return; 46 } 47 client_stub_->InjectClipboardEvent(event); 48 } 49 InjectClipboardEventToHost(const ClipboardEvent & event)50void 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); 56 } 57 } 58 ClientFilter(ClipboardEchoFilter * filter)59ClipboardEchoFilter::ClientFilter::ClientFilter( 60 ClipboardEchoFilter* filter) : filter_(filter) { 61 } 62 InjectClipboardEvent(const ClipboardEvent & event)63void ClipboardEchoFilter::ClientFilter::InjectClipboardEvent( 64 const ClipboardEvent& event) { 65 filter_->InjectClipboardEventToClient(event); 66 } 67 HostFilter(ClipboardEchoFilter * filter)68ClipboardEchoFilter::HostFilter::HostFilter( 69 ClipboardEchoFilter* filter) : filter_(filter) { 70 } 71 InjectClipboardEvent(const ClipboardEvent & event)72void ClipboardEchoFilter::HostFilter::InjectClipboardEvent( 73 const ClipboardEvent& event) { 74 filter_->InjectClipboardEventToHost(event); 75 } 76 77 } // namespace protocol 78 } // namespace remoting 79