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/clipboard.h" | 5 #include "remoting/host/clipboard.h" |
| 6 | 6 |
| 7 #include <X11/Xlib.h> | |
| 8 | |
| 9 #include "base/bind.h" | |
| 7 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop.h" | |
| 12 #include "base/message_pump_libevent.h" | |
|
Sergey Ulanov
2012/09/14 19:35:01
don't need this include. See my comment below.
Lambros
2012/09/14 21:35:13
Done.
| |
| 13 #include "remoting/host/x_server_clipboard.h" | |
| 14 #include "remoting/proto/event.pb.h" | |
| 15 #include "remoting/protocol/clipboard_stub.h" | |
| 8 | 16 |
| 9 namespace remoting { | 17 namespace remoting { |
| 10 | 18 |
| 11 class ClipboardLinux : public Clipboard { | 19 class ClipboardLinux : public Clipboard, base::MessagePumpLibevent::Watcher { |
|
Sergey Ulanov
2012/09/14 19:35:01
It's better to use MessageLoopForIO::Watcher here.
Sergey Ulanov
2012/09/14 19:35:01
Add comment to exmplain that we expect this code t
Lambros
2012/09/14 21:35:13
Done.
Lambros
2012/09/14 21:35:13
Done.
| |
| 12 public: | 20 public: |
| 13 ClipboardLinux(); | 21 ClipboardLinux(); |
| 22 virtual ~ClipboardLinux(); | |
| 14 | 23 |
| 15 // Must be called on the UI thread. | |
| 16 virtual void Start( | 24 virtual void Start( |
|
Sergey Ulanov
2012/09/14 19:35:01
// Clipboard interface.
Lambros
2012/09/14 21:35:13
Done.
| |
| 17 scoped_ptr<protocol::ClipboardStub> client_clipboard) OVERRIDE; | 25 scoped_ptr<protocol::ClipboardStub> client_clipboard) OVERRIDE; |
| 18 virtual void InjectClipboardEvent( | 26 virtual void InjectClipboardEvent( |
| 19 const protocol::ClipboardEvent& event) OVERRIDE; | 27 const protocol::ClipboardEvent& event) OVERRIDE; |
| 20 virtual void Stop() OVERRIDE; | 28 virtual void Stop() OVERRIDE; |
| 21 | 29 |
| 22 private: | 30 private: |
| 31 void OnClipboardChanged(const std::string& mime_type, | |
| 32 const std::string& data); | |
| 33 void PumpEvents(); | |
| 34 | |
| 35 // base::MessagePumpLibevent::Watcher interface | |
|
Sergey Ulanov
2012/09/14 19:35:01
nit: period at the end of the comment. MessageLoop
Lambros
2012/09/14 21:35:13
Done.
| |
| 36 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; | |
|
Sergey Ulanov
2012/09/14 19:35:01
Per style guide interface implementation must alwa
Lambros
2012/09/14 21:35:13
Done.
Lambros
2012/09/14 21:35:13
Done (and moved the implementations so they match
| |
| 37 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; | |
| 38 | |
| 39 scoped_ptr<protocol::ClipboardStub> client_clipboard_; | |
| 40 | |
| 41 XServerClipboard x_server_clipboard_; | |
| 42 Display* display_; | |
| 43 | |
| 44 base::MessagePumpLibevent::FileDescriptorWatcher x_connection_watcher_; | |
| 45 | |
| 23 DISALLOW_COPY_AND_ASSIGN(ClipboardLinux); | 46 DISALLOW_COPY_AND_ASSIGN(ClipboardLinux); |
| 24 }; | 47 }; |
| 25 | 48 |
| 49 ClipboardLinux::ClipboardLinux() : display_(NULL) { | |
|
Sergey Ulanov
2012/09/14 19:35:01
nit: better to place initializer on a separate lin
Lambros
2012/09/14 21:35:13
Done.
| |
| 50 } | |
| 51 | |
| 52 ClipboardLinux::~ClipboardLinux() { | |
| 53 Stop(); | |
| 54 } | |
| 55 | |
| 26 void ClipboardLinux::Start( | 56 void ClipboardLinux::Start( |
| 27 scoped_ptr<protocol::ClipboardStub> client_clipboard) { | 57 scoped_ptr<protocol::ClipboardStub> client_clipboard) { |
| 28 NOTIMPLEMENTED(); | 58 display_ = XOpenDisplay(NULL); |
|
Sergey Ulanov
2012/09/14 19:35:01
Please add TODO to share X connection with the eve
Lambros
2012/09/14 21:35:13
Done.
| |
| 59 if (!display_) { | |
| 60 LOG(ERROR) << "Couldn't open X display"; | |
| 61 return; | |
| 62 } | |
| 63 client_clipboard_.swap(client_clipboard); | |
| 64 | |
| 65 x_server_clipboard_.Init(display_, | |
| 66 base::Bind(&ClipboardLinux::OnClipboardChanged, | |
| 67 base::Unretained(this))); | |
| 68 | |
| 69 MessageLoopForIO::current()->WatchFileDescriptor( | |
| 70 ConnectionNumber(display_), true, MessageLoopForIO::WATCH_READ, | |
| 71 &x_connection_watcher_, this); | |
| 72 PumpEvents(); | |
| 29 } | 73 } |
| 30 | 74 |
| 31 void ClipboardLinux::InjectClipboardEvent( | 75 void ClipboardLinux::InjectClipboardEvent( |
| 32 const protocol::ClipboardEvent& event) { | 76 const protocol::ClipboardEvent& event) { |
| 33 NOTIMPLEMENTED(); | 77 x_server_clipboard_.SetClipboard(event.mime_type(), event.data()); |
| 34 } | 78 } |
| 35 | 79 |
| 36 void ClipboardLinux::Stop() { | 80 void ClipboardLinux::Stop() { |
| 37 NOTIMPLEMENTED(); | 81 client_clipboard_.reset(); |
| 82 x_connection_watcher_.StopWatchingFileDescriptor(); | |
| 83 | |
| 84 if (display_) { | |
| 85 XCloseDisplay(display_); | |
| 86 display_ = NULL; | |
| 87 } | |
| 88 } | |
| 89 | |
| 90 void ClipboardLinux::OnClipboardChanged(const std::string& mime_type, | |
| 91 const std::string& data) { | |
| 92 protocol::ClipboardEvent event; | |
| 93 event.set_mime_type(mime_type); | |
| 94 event.set_data(data); | |
| 95 | |
| 96 if (client_clipboard_.get()) { | |
| 97 client_clipboard_->InjectClipboardEvent(event); | |
| 98 } | |
| 99 } | |
| 100 | |
| 101 void ClipboardLinux::PumpEvents() { | |
| 102 DCHECK(display_); | |
| 103 | |
| 104 while (XPending(display_)) { | |
| 105 XEvent event; | |
| 106 XNextEvent(display_, &event); | |
| 107 x_server_clipboard_.ProcessXEvent(&event); | |
| 108 } | |
| 109 } | |
| 110 | |
| 111 void ClipboardLinux::OnFileCanReadWithoutBlocking(int fd) { | |
| 112 PumpEvents(); | |
| 113 } | |
| 114 | |
| 115 void ClipboardLinux::OnFileCanWriteWithoutBlocking(int fd) { | |
| 38 } | 116 } |
| 39 | 117 |
| 40 scoped_ptr<Clipboard> Clipboard::Create() { | 118 scoped_ptr<Clipboard> Clipboard::Create() { |
| 41 return scoped_ptr<Clipboard>(new ClipboardLinux()); | 119 return scoped_ptr<Clipboard>(new ClipboardLinux()); |
| 42 } | 120 } |
| 43 | 121 |
| 44 } // namespace remoting | 122 } // namespace remoting |
| OLD | NEW |