| 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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/process_util.h" | 12 #include "base/process_util.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/threading/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
| 16 #include "base/win/message_window.h" |
| 16 #include "base/win/scoped_hglobal.h" | 17 #include "base/win/scoped_hglobal.h" |
| 17 #include "base/win/windows_version.h" | 18 #include "base/win/windows_version.h" |
| 18 #include "base/win/wrapped_window_proc.h" | 19 #include "base/win/wrapped_window_proc.h" |
| 19 #include "remoting/base/constants.h" | 20 #include "remoting/base/constants.h" |
| 20 #include "remoting/base/util.h" | 21 #include "remoting/base/util.h" |
| 21 #include "remoting/host/win/message_window.h" | |
| 22 #include "remoting/proto/event.pb.h" | 22 #include "remoting/proto/event.pb.h" |
| 23 #include "remoting/protocol/clipboard_stub.h" | 23 #include "remoting/protocol/clipboard_stub.h" |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 // A scoper class that opens and closes the clipboard. | 27 // A scoper class that opens and closes the clipboard. |
| 28 // This class was adapted from the ScopedClipboard class in | 28 // This class was adapted from the ScopedClipboard class in |
| 29 // ui/base/clipboard/clipboard_win.cc. | 29 // ui/base/clipboard/clipboard_win.cc. |
| 30 class ScopedClipboard { | 30 class ScopedClipboard { |
| 31 public: | 31 public: |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 typedef BOOL (WINAPI AddClipboardFormatListenerFn)(HWND); | 96 typedef BOOL (WINAPI AddClipboardFormatListenerFn)(HWND); |
| 97 typedef BOOL (WINAPI RemoveClipboardFormatListenerFn)(HWND); | 97 typedef BOOL (WINAPI RemoveClipboardFormatListenerFn)(HWND); |
| 98 | 98 |
| 99 } // namespace | 99 } // namespace |
| 100 | 100 |
| 101 namespace remoting { | 101 namespace remoting { |
| 102 | 102 |
| 103 class ClipboardWin : public Clipboard, | 103 class ClipboardWin : public Clipboard, |
| 104 public win::MessageWindow::Delegate { | 104 public base::win::MessageWindow::Delegate { |
| 105 public: | 105 public: |
| 106 ClipboardWin(); | 106 ClipboardWin(); |
| 107 | 107 |
| 108 virtual void Start( | 108 virtual void Start( |
| 109 scoped_ptr<protocol::ClipboardStub> client_clipboard) OVERRIDE; | 109 scoped_ptr<protocol::ClipboardStub> client_clipboard) OVERRIDE; |
| 110 virtual void InjectClipboardEvent( | 110 virtual void InjectClipboardEvent( |
| 111 const protocol::ClipboardEvent& event) OVERRIDE; | 111 const protocol::ClipboardEvent& event) OVERRIDE; |
| 112 virtual void Stop() OVERRIDE; | 112 virtual void Stop() OVERRIDE; |
| 113 | 113 |
| 114 private: | 114 private: |
| 115 void OnClipboardUpdate(); | 115 void OnClipboardUpdate(); |
| 116 | 116 |
| 117 // win::MessageWindow::Delegate interface. | 117 // base::win::MessageWindow::Delegate interface. |
| 118 virtual bool HandleMessage(HWND hwnd, | 118 virtual bool HandleMessage(HWND hwnd, |
| 119 UINT message, | 119 UINT message, |
| 120 WPARAM wparam, | 120 WPARAM wparam, |
| 121 LPARAM lparam, | 121 LPARAM lparam, |
| 122 LRESULT* result) OVERRIDE; | 122 LRESULT* result) OVERRIDE; |
| 123 | 123 |
| 124 scoped_ptr<protocol::ClipboardStub> client_clipboard_; | 124 scoped_ptr<protocol::ClipboardStub> client_clipboard_; |
| 125 AddClipboardFormatListenerFn* add_clipboard_format_listener_; | 125 AddClipboardFormatListenerFn* add_clipboard_format_listener_; |
| 126 RemoveClipboardFormatListenerFn* remove_clipboard_format_listener_; | 126 RemoveClipboardFormatListenerFn* remove_clipboard_format_listener_; |
| 127 | 127 |
| 128 // Used to subscribe to WM_CLIPBOARDUPDATE messages. | 128 // Used to subscribe to WM_CLIPBOARDUPDATE messages. |
| 129 scoped_ptr<win::MessageWindow> window_; | 129 scoped_ptr<base::win::MessageWindow> window_; |
| 130 | 130 |
| 131 DISALLOW_COPY_AND_ASSIGN(ClipboardWin); | 131 DISALLOW_COPY_AND_ASSIGN(ClipboardWin); |
| 132 }; | 132 }; |
| 133 | 133 |
| 134 ClipboardWin::ClipboardWin() | 134 ClipboardWin::ClipboardWin() |
| 135 : add_clipboard_format_listener_(NULL), | 135 : add_clipboard_format_listener_(NULL), |
| 136 remove_clipboard_format_listener_(NULL) { | 136 remove_clipboard_format_listener_(NULL) { |
| 137 } | 137 } |
| 138 | 138 |
| 139 void ClipboardWin::Start( | 139 void ClipboardWin::Start( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 155 remove_clipboard_format_listener_ = | 155 remove_clipboard_format_listener_ = |
| 156 reinterpret_cast<RemoveClipboardFormatListenerFn*>( | 156 reinterpret_cast<RemoveClipboardFormatListenerFn*>( |
| 157 GetProcAddress(user32, "RemoveClipboardFormatListener")); | 157 GetProcAddress(user32, "RemoveClipboardFormatListener")); |
| 158 // If AddClipboardFormatListener() present, RemoveClipboardFormatListener() | 158 // If AddClipboardFormatListener() present, RemoveClipboardFormatListener() |
| 159 // should be available too. | 159 // should be available too. |
| 160 CHECK(remove_clipboard_format_listener_); | 160 CHECK(remove_clipboard_format_listener_); |
| 161 } else { | 161 } else { |
| 162 LOG(WARNING) << "AddClipboardFormatListener() is not available."; | 162 LOG(WARNING) << "AddClipboardFormatListener() is not available."; |
| 163 } | 163 } |
| 164 | 164 |
| 165 window_.reset(new win::MessageWindow()); | 165 window_.reset(new base::win::MessageWindow()); |
| 166 if (!window_->Create(this)) { | 166 if (!window_->Create(this, NULL)) { |
| 167 LOG(ERROR) << "Couldn't create clipboard window."; | 167 LOG(ERROR) << "Couldn't create clipboard window."; |
| 168 window_.reset(); | 168 window_.reset(); |
| 169 return; | 169 return; |
| 170 } | 170 } |
| 171 | 171 |
| 172 if (add_clipboard_format_listener_) { | 172 if (add_clipboard_format_listener_) { |
| 173 if (!(*add_clipboard_format_listener_)(window_->hwnd())) { | 173 if (!(*add_clipboard_format_listener_)(window_->hwnd())) { |
| 174 LOG(WARNING) << "AddClipboardFormatListener() failed: " << GetLastError(); | 174 LOG(WARNING) << "AddClipboardFormatListener() failed: " << GetLastError(); |
| 175 } | 175 } |
| 176 } | 176 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 } | 272 } |
| 273 | 273 |
| 274 return false; | 274 return false; |
| 275 } | 275 } |
| 276 | 276 |
| 277 scoped_ptr<Clipboard> Clipboard::Create() { | 277 scoped_ptr<Clipboard> Clipboard::Create() { |
| 278 return scoped_ptr<Clipboard>(new ClipboardWin()); | 278 return scoped_ptr<Clipboard>(new ClipboardWin()); |
| 279 } | 279 } |
| 280 | 280 |
| 281 } // namespace remoting | 281 } // namespace remoting |
| OLD | NEW |