Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(561)

Side by Side Diff: remoting/host/clipboard_win.cc

Issue 10441131: [Chromoting] Handle CR-LF correctly when transferring text items to and from the clipboard on a Win… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add a static_cast to a unit test. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/base/util_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/string16.h" 13 #include "base/string16.h"
14 #include "base/threading/platform_thread.h" 14 #include "base/threading/platform_thread.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "base/win/scoped_hglobal.h" 16 #include "base/win/scoped_hglobal.h"
17 #include "base/win/windows_version.h" 17 #include "base/win/windows_version.h"
18 #include "base/win/wrapped_window_proc.h" 18 #include "base/win/wrapped_window_proc.h"
19 #include "remoting/base/constants.h" 19 #include "remoting/base/constants.h"
20 #include "remoting/base/util.h"
20 #include "remoting/proto/event.pb.h" 21 #include "remoting/proto/event.pb.h"
21 #include "remoting/protocol/clipboard_stub.h" 22 #include "remoting/protocol/clipboard_stub.h"
22 23
23 namespace { 24 namespace {
24 25
25 const WCHAR kWindowClassName[] = L"clipboardWindowClass"; 26 const WCHAR kWindowClassName[] = L"clipboardWindowClass";
26 const WCHAR kWindowName[] = L"clipboardWindow"; 27 const WCHAR kWindowName[] = L"clipboardWindow";
27 28
28 // A scoper class that opens and closes the clipboard. 29 // A scoper class that opens and closes the clipboard.
29 // This class was adapted from the ScopedClipboard class in 30 // This class was adapted from the ScopedClipboard class in
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 196
196 void ClipboardWin::InjectClipboardEvent( 197 void ClipboardWin::InjectClipboardEvent(
197 const protocol::ClipboardEvent& event) { 198 const protocol::ClipboardEvent& event) {
198 if (!hwnd_) { 199 if (!hwnd_) {
199 return; 200 return;
200 } 201 }
201 // Currently we only handle UTF-8 text. 202 // Currently we only handle UTF-8 text.
202 if (event.mime_type().compare(kMimeTypeTextUtf8)) { 203 if (event.mime_type().compare(kMimeTypeTextUtf8)) {
203 return; 204 return;
204 } 205 }
205 string16 text = UTF8ToUTF16(event.data()); 206 string16 text = UTF8ToUTF16(ReplaceLfByCrLf(event.data()));
206 207
207 ScopedClipboard clipboard; 208 ScopedClipboard clipboard;
208 if (!clipboard.Init(hwnd_)) { 209 if (!clipboard.Init(hwnd_)) {
209 LOG(WARNING) << "Couldn't open the clipboard."; 210 LOG(WARNING) << "Couldn't open the clipboard.";
210 return; 211 return;
211 } 212 }
212 213
213 clipboard.Empty(); 214 clipboard.Empty();
214 215
215 HGLOBAL text_global = 216 HGLOBAL text_global =
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 base::win::ScopedHGlobal<WCHAR> text_lock(text_global); 253 base::win::ScopedHGlobal<WCHAR> text_lock(text_global);
253 if (!text_lock.get()) { 254 if (!text_lock.get()) {
254 LOG(WARNING) << "Couldn't lock clipboard data: " << GetLastError(); 255 LOG(WARNING) << "Couldn't lock clipboard data: " << GetLastError();
255 return; 256 return;
256 } 257 }
257 text.assign(text_lock.get()); 258 text.assign(text_lock.get());
258 } 259 }
259 260
260 protocol::ClipboardEvent event; 261 protocol::ClipboardEvent event;
261 event.set_mime_type(kMimeTypeTextUtf8); 262 event.set_mime_type(kMimeTypeTextUtf8);
262 event.set_data(UTF16ToUTF8(text)); 263 event.set_data(ReplaceCrLfByLf(UTF16ToUTF8(text)));
263 264
264 if (client_clipboard_.get()) { 265 if (client_clipboard_.get()) {
265 client_clipboard_->InjectClipboardEvent(event); 266 client_clipboard_->InjectClipboardEvent(event);
266 } 267 }
267 } 268 }
268 } 269 }
269 270
270 bool ClipboardWin::HaveClipboardListenerApi() { 271 bool ClipboardWin::HaveClipboardListenerApi() {
271 return add_clipboard_format_listener_ && remove_clipboard_format_listener_; 272 return add_clipboard_format_listener_ && remove_clipboard_format_listener_;
272 } 273 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 return 0; 311 return 0;
311 } 312 }
312 return ::DefWindowProc(hwnd, msg, wparam, lparam); 313 return ::DefWindowProc(hwnd, msg, wparam, lparam);
313 } 314 }
314 315
315 scoped_ptr<Clipboard> Clipboard::Create() { 316 scoped_ptr<Clipboard> Clipboard::Create() {
316 return scoped_ptr<Clipboard>(new ClipboardWin()); 317 return scoped_ptr<Clipboard>(new ClipboardWin());
317 } 318 }
318 319
319 } // namespace remoting 320 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/base/util_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698