| 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 <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 typedef BOOL (WINAPI RemoveClipboardFormatListenerFn)(HWND); | 96 typedef BOOL (WINAPI RemoveClipboardFormatListenerFn)(HWND); |
| 97 | 97 |
| 98 } // namespace | 98 } // namespace |
| 99 | 99 |
| 100 namespace remoting { | 100 namespace remoting { |
| 101 | 101 |
| 102 class ClipboardWin : public Clipboard { | 102 class ClipboardWin : public Clipboard { |
| 103 public: | 103 public: |
| 104 ClipboardWin(); | 104 ClipboardWin(); |
| 105 | 105 |
| 106 virtual void Start() OVERRIDE; | 106 virtual void Start( |
| 107 const scoped_refptr<protocol::ClipboardProxy>& client_clipboard) OVERRIDE; |
| 107 virtual void InjectClipboardEvent( | 108 virtual void InjectClipboardEvent( |
| 108 const protocol::ClipboardEvent& event) OVERRIDE; | 109 const protocol::ClipboardEvent& event) OVERRIDE; |
| 109 virtual void Stop() OVERRIDE; | 110 virtual void Stop() OVERRIDE; |
| 110 | 111 |
| 111 private: | 112 private: |
| 112 void OnClipboardUpdate(); | 113 void OnClipboardUpdate(); |
| 113 bool HaveClipboardListenerApi(); | 114 bool HaveClipboardListenerApi(); |
| 114 | 115 |
| 115 static bool RegisterWindowClass(); | 116 static bool RegisterWindowClass(); |
| 116 static LRESULT CALLBACK WndProc(HWND hwmd, UINT msg, WPARAM wParam, | 117 static LRESULT CALLBACK WndProc(HWND hwmd, UINT msg, WPARAM wParam, |
| 117 LPARAM lParam); | 118 LPARAM lParam); |
| 118 | 119 |
| 120 scoped_refptr<protocol::ClipboardProxy> client_clipboard_; |
| 119 HWND hwnd_; | 121 HWND hwnd_; |
| 120 AddClipboardFormatListenerFn* add_clipboard_format_listener_; | 122 AddClipboardFormatListenerFn* add_clipboard_format_listener_; |
| 121 RemoveClipboardFormatListenerFn* remove_clipboard_format_listener_; | 123 RemoveClipboardFormatListenerFn* remove_clipboard_format_listener_; |
| 122 bool load_functions_tried_; | 124 bool load_functions_tried_; |
| 123 | 125 |
| 124 DISALLOW_COPY_AND_ASSIGN(ClipboardWin); | 126 DISALLOW_COPY_AND_ASSIGN(ClipboardWin); |
| 125 }; | 127 }; |
| 126 | 128 |
| 127 ClipboardWin::ClipboardWin() | 129 ClipboardWin::ClipboardWin() |
| 128 : hwnd_(NULL), | 130 : hwnd_(NULL), |
| 129 add_clipboard_format_listener_(NULL), | 131 add_clipboard_format_listener_(NULL), |
| 130 remove_clipboard_format_listener_(NULL), | 132 remove_clipboard_format_listener_(NULL), |
| 131 load_functions_tried_(false) { | 133 load_functions_tried_(false) { |
| 132 } | 134 } |
| 133 | 135 |
| 134 void ClipboardWin::Start() { | 136 void ClipboardWin::Start( |
| 137 const scoped_refptr<protocol::ClipboardProxy>& client_clipboard) { |
| 138 client_clipboard_ = client_clipboard; |
| 139 |
| 135 if (!load_functions_tried_) { | 140 if (!load_functions_tried_) { |
| 136 load_functions_tried_ = true; | 141 load_functions_tried_ = true; |
| 137 HMODULE user32_module = ::GetModuleHandle(L"user32.dll"); | 142 HMODULE user32_module = ::GetModuleHandle(L"user32.dll"); |
| 138 if (!user32_module) { | 143 if (!user32_module) { |
| 139 LOG(WARNING) << "Couldn't find user32.dll."; | 144 LOG(WARNING) << "Couldn't find user32.dll."; |
| 140 } else { | 145 } else { |
| 141 add_clipboard_format_listener_ = | 146 add_clipboard_format_listener_ = |
| 142 reinterpret_cast<AddClipboardFormatListenerFn*>( | 147 reinterpret_cast<AddClipboardFormatListenerFn*>( |
| 143 ::GetProcAddress(user32_module, "AddClipboardFormatListener")); | 148 ::GetProcAddress(user32_module, "AddClipboardFormatListener")); |
| 144 remove_clipboard_format_listener_ = | 149 remove_clipboard_format_listener_ = |
| (...skipping 23 matching lines...) Expand all Loading... |
| 168 } | 173 } |
| 169 | 174 |
| 170 if (HaveClipboardListenerApi()) { | 175 if (HaveClipboardListenerApi()) { |
| 171 if (!(*add_clipboard_format_listener_)(hwnd_)) { | 176 if (!(*add_clipboard_format_listener_)(hwnd_)) { |
| 172 LOG(WARNING) << "AddClipboardFormatListener() failed: " << GetLastError(); | 177 LOG(WARNING) << "AddClipboardFormatListener() failed: " << GetLastError(); |
| 173 } | 178 } |
| 174 } | 179 } |
| 175 } | 180 } |
| 176 | 181 |
| 177 void ClipboardWin::Stop() { | 182 void ClipboardWin::Stop() { |
| 183 client_clipboard_ = NULL; |
| 184 |
| 178 if (hwnd_) { | 185 if (hwnd_) { |
| 179 if (HaveClipboardListenerApi()) { | 186 if (HaveClipboardListenerApi()) { |
| 180 (*remove_clipboard_format_listener_)(hwnd_); | 187 (*remove_clipboard_format_listener_)(hwnd_); |
| 181 } | 188 } |
| 182 ::DestroyWindow(hwnd_); | 189 ::DestroyWindow(hwnd_); |
| 183 hwnd_ = NULL; | 190 hwnd_ = NULL; |
| 184 } | 191 } |
| 185 } | 192 } |
| 186 | 193 |
| 187 void ClipboardWin::InjectClipboardEvent( | 194 void ClipboardWin::InjectClipboardEvent( |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 LOG(WARNING) << "Couldn't lock clipboard data: " << GetLastError(); | 252 LOG(WARNING) << "Couldn't lock clipboard data: " << GetLastError(); |
| 246 return; | 253 return; |
| 247 } | 254 } |
| 248 text.assign(text_lock.get()); | 255 text.assign(text_lock.get()); |
| 249 } | 256 } |
| 250 | 257 |
| 251 protocol::ClipboardEvent event; | 258 protocol::ClipboardEvent event; |
| 252 event.set_mime_type(kMimeTypeTextUtf8); | 259 event.set_mime_type(kMimeTypeTextUtf8); |
| 253 event.set_data(UTF16ToUTF8(text)); | 260 event.set_data(UTF16ToUTF8(text)); |
| 254 | 261 |
| 255 // TODO(simonmorris): Send the event to the client. | 262 if (client_clipboard_.get()) { |
| 263 client_clipboard_->InjectClipboardEvent(event); |
| 264 } |
| 256 } | 265 } |
| 257 } | 266 } |
| 258 | 267 |
| 259 bool ClipboardWin::HaveClipboardListenerApi() { | 268 bool ClipboardWin::HaveClipboardListenerApi() { |
| 260 return add_clipboard_format_listener_ && remove_clipboard_format_listener_; | 269 return add_clipboard_format_listener_ && remove_clipboard_format_listener_; |
| 261 } | 270 } |
| 262 | 271 |
| 263 bool ClipboardWin::RegisterWindowClass() { | 272 bool ClipboardWin::RegisterWindowClass() { |
| 264 // This method is only called on the UI thread, so it doesn't matter | 273 // This method is only called on the UI thread, so it doesn't matter |
| 265 // that the following test is not thread-safe. | 274 // that the following test is not thread-safe. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 return 0; | 308 return 0; |
| 300 } | 309 } |
| 301 return ::DefWindowProc(hwnd, msg, wparam, lparam); | 310 return ::DefWindowProc(hwnd, msg, wparam, lparam); |
| 302 } | 311 } |
| 303 | 312 |
| 304 scoped_ptr<Clipboard> Clipboard::Create() { | 313 scoped_ptr<Clipboard> Clipboard::Create() { |
| 305 return scoped_ptr<Clipboard>(new ClipboardWin()); | 314 return scoped_ptr<Clipboard>(new ClipboardWin()); |
| 306 } | 315 } |
| 307 | 316 |
| 308 } // namespace remoting | 317 } // namespace remoting |
| OLD | NEW |