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

Side by Side Diff: base/clipboard_win.cc

Issue 11398: Lazily create the clipboard owner window. CreateWindow can take ~.5ms, and w... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 1 month 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
« base/clipboard.h ('K') | « base/clipboard.h ('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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 // Many of these functions are based on those found in 5 // Many of these functions are based on those found in
6 // webkit/port/platform/PasteboardWin.cpp 6 // webkit/port/platform/PasteboardWin.cpp
7 7
8 #include <shlobj.h> 8 #include <shlobj.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 10
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 124
125 Clipboard::Clipboard() { 125 Clipboard::Clipboard() {
126 // make a dummy HWND to be the clipboard's owner 126 // make a dummy HWND to be the clipboard's owner
127 WNDCLASSEX wcex = {0}; 127 WNDCLASSEX wcex = {0};
128 wcex.cbSize = sizeof(WNDCLASSEX); 128 wcex.cbSize = sizeof(WNDCLASSEX);
129 wcex.lpfnWndProc = ClipboardOwnerWndProc; 129 wcex.lpfnWndProc = ClipboardOwnerWndProc;
130 wcex.hInstance = GetModuleHandle(NULL); 130 wcex.hInstance = GetModuleHandle(NULL);
131 wcex.lpszClassName = L"ClipboardOwnerWindowClass"; 131 wcex.lpszClassName = L"ClipboardOwnerWindowClass";
132 ::RegisterClassEx(&wcex); 132 ::RegisterClassEx(&wcex);
133 133
134 clipboard_owner_ = ::CreateWindow(L"ClipboardOwnerWindowClass", 134 clipboard_owner_ = NULL;
135 L"ClipboardOwnerWindow",
136 0, 0, 0, 0, 0,
137 HWND_MESSAGE,
138 0, 0, 0);
139 } 135 }
140 136
141 Clipboard::~Clipboard() { 137 Clipboard::~Clipboard() {
142 ::DestroyWindow(clipboard_owner_); 138 if (clipboard_owner_)
139 ::DestroyWindow(clipboard_owner_);
143 clipboard_owner_ = NULL; 140 clipboard_owner_ = NULL;
144 } 141 }
145 142
146 void Clipboard::WriteObjects(const ObjectMap& objects) { 143 void Clipboard::WriteObjects(const ObjectMap& objects) {
147 WriteObjects(objects, NULL); 144 WriteObjects(objects, NULL);
148 } 145 }
149 146
150 void Clipboard::WriteObjects(const ObjectMap& objects, 147 void Clipboard::WriteObjects(const ObjectMap& objects,
151 base::ProcessHandle process) { 148 base::ProcessHandle process) {
152 ScopedClipboard clipboard; 149 ScopedClipboard clipboard;
153 if (!clipboard.Acquire(clipboard_owner_)) 150 if (!clipboard.Acquire(GetClipboardWindow()))
154 return; 151 return;
155 152
156 ::EmptyClipboard(); 153 ::EmptyClipboard();
157 154
158 for (ObjectMap::const_iterator iter = objects.begin(); 155 for (ObjectMap::const_iterator iter = objects.begin();
159 iter != objects.end(); ++iter) { 156 iter != objects.end(); ++iter) {
160 if (iter->first == CBF_SMBITMAP) 157 if (iter->first == CBF_SMBITMAP)
161 WriteBitmapFromSharedMemory(&(iter->second[0].front()), 158 WriteBitmapFromSharedMemory(&(iter->second[0].front()),
162 &(iter->second[1].front()), 159 &(iter->second[1].front()),
163 process); 160 process);
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 void Clipboard::ReadText(std::wstring* result) const { 375 void Clipboard::ReadText(std::wstring* result) const {
379 if (!result) { 376 if (!result) {
380 NOTREACHED(); 377 NOTREACHED();
381 return; 378 return;
382 } 379 }
383 380
384 result->clear(); 381 result->clear();
385 382
386 // Acquire the clipboard. 383 // Acquire the clipboard.
387 ScopedClipboard clipboard; 384 ScopedClipboard clipboard;
388 if (!clipboard.Acquire(clipboard_owner_)) 385 if (!clipboard.Acquire(GetClipboardWindow()))
389 return; 386 return;
390 387
391 HANDLE data = ::GetClipboardData(CF_UNICODETEXT); 388 HANDLE data = ::GetClipboardData(CF_UNICODETEXT);
392 if (!data) 389 if (!data)
393 return; 390 return;
394 391
395 result->assign(static_cast<const wchar_t*>(::GlobalLock(data))); 392 result->assign(static_cast<const wchar_t*>(::GlobalLock(data)));
396 ::GlobalUnlock(data); 393 ::GlobalUnlock(data);
397 } 394 }
398 395
399 void Clipboard::ReadAsciiText(std::string* result) const { 396 void Clipboard::ReadAsciiText(std::string* result) const {
400 if (!result) { 397 if (!result) {
401 NOTREACHED(); 398 NOTREACHED();
402 return; 399 return;
403 } 400 }
404 401
405 result->clear(); 402 result->clear();
406 403
407 // Acquire the clipboard. 404 // Acquire the clipboard.
408 ScopedClipboard clipboard; 405 ScopedClipboard clipboard;
409 if (!clipboard.Acquire(clipboard_owner_)) 406 if (!clipboard.Acquire(GetClipboardWindow()))
410 return; 407 return;
411 408
412 HANDLE data = ::GetClipboardData(CF_TEXT); 409 HANDLE data = ::GetClipboardData(CF_TEXT);
413 if (!data) 410 if (!data)
414 return; 411 return;
415 412
416 result->assign(static_cast<const char*>(::GlobalLock(data))); 413 result->assign(static_cast<const char*>(::GlobalLock(data)));
417 ::GlobalUnlock(data); 414 ::GlobalUnlock(data);
418 } 415 }
419 416
420 void Clipboard::ReadHTML(std::wstring* markup, std::string* src_url) const { 417 void Clipboard::ReadHTML(std::wstring* markup, std::string* src_url) const {
421 if (markup) 418 if (markup)
422 markup->clear(); 419 markup->clear();
423 420
424 if (src_url) 421 if (src_url)
425 src_url->clear(); 422 src_url->clear();
426 423
427 // Acquire the clipboard. 424 // Acquire the clipboard.
428 ScopedClipboard clipboard; 425 ScopedClipboard clipboard;
429 if (!clipboard.Acquire(clipboard_owner_)) 426 if (!clipboard.Acquire(GetClipboardWindow()))
430 return; 427 return;
431 428
432 HANDLE data = ::GetClipboardData(GetHtmlFormatType()); 429 HANDLE data = ::GetClipboardData(GetHtmlFormatType());
433 if (!data) 430 if (!data)
434 return; 431 return;
435 432
436 std::string html_fragment(static_cast<const char*>(::GlobalLock(data))); 433 std::string html_fragment(static_cast<const char*>(::GlobalLock(data)));
437 ::GlobalUnlock(data); 434 ::GlobalUnlock(data);
438 435
439 std::string markup_utf8; 436 std::string markup_utf8;
440 ClipboardUtil::CFHtmlToHtml(html_fragment, &markup_utf8, src_url); 437 ClipboardUtil::CFHtmlToHtml(html_fragment, &markup_utf8, src_url);
441 markup->assign(UTF8ToWide(markup_utf8)); 438 markup->assign(UTF8ToWide(markup_utf8));
442 } 439 }
443 440
444 void Clipboard::ReadBookmark(std::wstring* title, std::string* url) const { 441 void Clipboard::ReadBookmark(std::wstring* title, std::string* url) const {
445 if (title) 442 if (title)
446 title->clear(); 443 title->clear();
447 444
448 if (url) 445 if (url)
449 url->clear(); 446 url->clear();
450 447
451 // Acquire the clipboard. 448 // Acquire the clipboard.
452 ScopedClipboard clipboard; 449 ScopedClipboard clipboard;
453 if (!clipboard.Acquire(clipboard_owner_)) 450 if (!clipboard.Acquire(GetClipboardWindow()))
454 return; 451 return;
455 452
456 HANDLE data = ::GetClipboardData(GetUrlWFormatType()); 453 HANDLE data = ::GetClipboardData(GetUrlWFormatType());
457 if (!data) 454 if (!data)
458 return; 455 return;
459 456
460 std::wstring bookmark(static_cast<const wchar_t*>(::GlobalLock(data))); 457 std::wstring bookmark(static_cast<const wchar_t*>(::GlobalLock(data)));
461 ::GlobalUnlock(data); 458 ::GlobalUnlock(data);
462 459
463 ParseBookmarkClipboardFormat(bookmark, title, url); 460 ParseBookmarkClipboardFormat(bookmark, title, url);
(...skipping 18 matching lines...) Expand all
482 // Read a set of files in HDROP format from the clipboard. 479 // Read a set of files in HDROP format from the clipboard.
483 void Clipboard::ReadFiles(std::vector<std::wstring>* files) const { 480 void Clipboard::ReadFiles(std::vector<std::wstring>* files) const {
484 if (!files) { 481 if (!files) {
485 NOTREACHED(); 482 NOTREACHED();
486 return; 483 return;
487 } 484 }
488 485
489 files->clear(); 486 files->clear();
490 487
491 ScopedClipboard clipboard; 488 ScopedClipboard clipboard;
492 if (!clipboard.Acquire(clipboard_owner_)) 489 if (!clipboard.Acquire(GetClipboardWindow()))
493 return; 490 return;
494 491
495 HDROP drop = static_cast<HDROP>(::GetClipboardData(CF_HDROP)); 492 HDROP drop = static_cast<HDROP>(::GetClipboardData(CF_HDROP));
496 if (!drop) 493 if (!drop)
497 return; 494 return;
498 495
499 // Count of files in the HDROP. 496 // Count of files in the HDROP.
500 int count = ::DragQueryFile(drop, 0xffffffff, NULL, 0); 497 int count = ::DragQueryFile(drop, 0xffffffff, NULL, 0);
501 498
502 if (count) { 499 if (count) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 return ClipboardUtil::GetWebKitSmartPasteFormat()->cfFormat; 595 return ClipboardUtil::GetWebKitSmartPasteFormat()->cfFormat;
599 } 596 }
600 597
601 // static 598 // static
602 void Clipboard::FreeData(FormatType format, HANDLE data) { 599 void Clipboard::FreeData(FormatType format, HANDLE data) {
603 if (format == CF_BITMAP) 600 if (format == CF_BITMAP)
604 ::DeleteObject(static_cast<HBITMAP>(data)); 601 ::DeleteObject(static_cast<HBITMAP>(data));
605 else 602 else
606 ::GlobalFree(data); 603 ::GlobalFree(data);
607 } 604 }
605
606 HWND Clipboard::GetClipboardWindow() const {
607 if (!clipboard_owner_) {
608 clipboard_owner_ = ::CreateWindow(L"ClipboardOwnerWindowClass",
609 L"ClipboardOwnerWindow",
610 0, 0, 0, 0, 0,
611 HWND_MESSAGE,
612 0, 0, 0);
613 }
614 return clipboard_owner_;
615 }
OLDNEW
« base/clipboard.h ('K') | « base/clipboard.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698