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 12 ClipboardEchoFilter::ClipboardEchoFilter() 13 : host_stub_(NULL), 14 client_stub_(NULL), 15 client_filter_(this), 16 host_filter_(this) { 17 } 18 19 ClipboardEchoFilter::~ClipboardEchoFilter() { 20 } 21 22 void ClipboardEchoFilter::set_client_stub(ClipboardStub* client_stub) { 23 client_stub_ = client_stub; 24 } 25 26 void ClipboardEchoFilter::set_host_stub(ClipboardStub* host_stub) { 27 host_stub_ = host_stub; 28 } 29 30 ClipboardStub* ClipboardEchoFilter::client_filter() { 31 return &client_filter_; 32 } 33 34 ClipboardStub* ClipboardEchoFilter::host_filter() { 35 return &host_filter_; 36 } 37 38 void 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 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); 56 } 57 } 58 59 ClipboardEchoFilter::ClientFilter::ClientFilter( 60 ClipboardEchoFilter* filter) : filter_(filter) { 61 } 62 63 void ClipboardEchoFilter::ClientFilter::InjectClipboardEvent( 64 const ClipboardEvent& event) { 65 filter_->InjectClipboardEventToClient(event); 66 } 67 68 ClipboardEchoFilter::HostFilter::HostFilter( 69 ClipboardEchoFilter* filter) : filter_(filter) { 70 } 71 72 void ClipboardEchoFilter::HostFilter::InjectClipboardEvent( 73 const ClipboardEvent& event) { 74 filter_->InjectClipboardEventToHost(event); 75 } 76 77 } // namespace protocol 78 } // namespace remoting 79