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

Side by Side Diff: ui/base/clipboard/clipboard_win.cc

Issue 8802004: Enable custom MIME types in web copy/paste. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "ui/base/clipboard/clipboard.h" 8 #include "ui/base/clipboard/clipboard.h"
9 9
10 #include <shlobj.h> 10 #include <shlobj.h>
11 #include <shellapi.h> 11 #include <shellapi.h>
12 12
13 #include "base/file_path.h" 13 #include "base/file_path.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/message_loop.h" 15 #include "base/message_loop.h"
16 #include "base/shared_memory.h" 16 #include "base/shared_memory.h"
17 #include "base/stl_util.h" 17 #include "base/stl_util.h"
18 #include "base/string_util.h" 18 #include "base/string_util.h"
19 #include "base/string_number_conversions.h" 19 #include "base/string_number_conversions.h"
20 #include "base/utf_offset_string_conversions.h" 20 #include "base/utf_offset_string_conversions.h"
21 #include "base/utf_string_conversions.h" 21 #include "base/utf_string_conversions.h"
22 #include "base/win/scoped_gdi_object.h" 22 #include "base/win/scoped_gdi_object.h"
23 #include "base/win/scoped_hdc.h" 23 #include "base/win/scoped_hdc.h"
24 #include "base/win/wrapped_window_proc.h" 24 #include "base/win/wrapped_window_proc.h"
25 #include "third_party/skia/include/core/SkBitmap.h" 25 #include "third_party/skia/include/core/SkBitmap.h"
26 #include "ui/base/clipboard/clipboard_util_win.h" 26 #include "ui/base/clipboard/clipboard_util_win.h"
27 #include "ui/base/clipboard/custom_data_helper.h"
27 #include "ui/gfx/canvas_skia.h" 28 #include "ui/gfx/canvas_skia.h"
28 #include "ui/gfx/size.h" 29 #include "ui/gfx/size.h"
29 30
30 namespace ui { 31 namespace ui {
31 32
32 namespace { 33 namespace {
33 34
34 // A scoper to manage acquiring and automatically releasing the clipboard. 35 // A scoper to manage acquiring and automatically releasing the clipboard.
35 class ScopedClipboard { 36 class ScopedClipboard {
36 public: 37 public:
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 const FORMATETC* textFormat = ClipboardUtil::GetPlainTextFormat(); 371 const FORMATETC* textFormat = ClipboardUtil::GetPlainTextFormat();
371 const FORMATETC* htmlFormat = ClipboardUtil::GetHtmlFormat(); 372 const FORMATETC* htmlFormat = ClipboardUtil::GetHtmlFormat();
372 types->clear(); 373 types->clear();
373 if (::IsClipboardFormatAvailable(textFormat->cfFormat)) 374 if (::IsClipboardFormatAvailable(textFormat->cfFormat))
374 types->push_back(UTF8ToUTF16(kMimeTypeText)); 375 types->push_back(UTF8ToUTF16(kMimeTypeText));
375 if (::IsClipboardFormatAvailable(htmlFormat->cfFormat)) 376 if (::IsClipboardFormatAvailable(htmlFormat->cfFormat))
376 types->push_back(UTF8ToUTF16(kMimeTypeHTML)); 377 types->push_back(UTF8ToUTF16(kMimeTypeHTML));
377 if (::IsClipboardFormatAvailable(CF_DIB)) 378 if (::IsClipboardFormatAvailable(CF_DIB))
378 types->push_back(UTF8ToUTF16(kMimeTypePNG)); 379 types->push_back(UTF8ToUTF16(kMimeTypePNG));
379 *contains_filenames = false; 380 *contains_filenames = false;
381
382 // Acquire the clipboard.
383 ScopedClipboard clipboard;
384 if (!clipboard.Acquire(GetClipboardWindow()))
385 return;
386
387 HANDLE hdata = ::GetClipboardData(
388 ClipboardUtil::GetWebCustomDataFormat()->cfFormat);
389 if (!hdata)
390 return;
391
392 ReadCustomDataTypes(::GlobalLock(hdata), ::GlobalSize(hdata), types);
393 ::GlobalUnlock(hdata);
380 } 394 }
381 395
382 void Clipboard::ReadText(Clipboard::Buffer buffer, string16* result) const { 396 void Clipboard::ReadText(Clipboard::Buffer buffer, string16* result) const {
383 DCHECK_EQ(buffer, BUFFER_STANDARD); 397 DCHECK_EQ(buffer, BUFFER_STANDARD);
384 if (!result) { 398 if (!result) {
385 NOTREACHED(); 399 NOTREACHED();
386 return; 400 return;
387 } 401 }
388 402
389 result->clear(); 403 result->clear();
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 MakeBitmapOpaque(device_bitmap); 554 MakeBitmapOpaque(device_bitmap);
541 } 555 }
542 } 556 }
543 557
544 return canvas.ExtractBitmap(); 558 return canvas.ExtractBitmap();
545 } 559 }
546 560
547 void Clipboard::ReadCustomData(Buffer buffer, 561 void Clipboard::ReadCustomData(Buffer buffer,
548 const string16& type, 562 const string16& type,
549 string16* result) const { 563 string16* result) const {
550 // TODO(dcheng): Implement this. 564 DCHECK_EQ(buffer, BUFFER_STANDARD);
551 NOTIMPLEMENTED(); 565
566 // Acquire the clipboard.
567 ScopedClipboard clipboard;
568 if (!clipboard.Acquire(GetClipboardWindow()))
569 return;
570
571 HANDLE hdata = ::GetClipboardData(
572 ClipboardUtil::GetWebCustomDataFormat()->cfFormat);
573 if (!hdata)
574 return;
575
576 ReadCustomDataForType(::GlobalLock(hdata), ::GlobalSize(hdata), type, result);
577 ::GlobalUnlock(hdata);
552 } 578 }
553 579
554 void Clipboard::ReadBookmark(string16* title, std::string* url) const { 580 void Clipboard::ReadBookmark(string16* title, std::string* url) const {
555 if (title) 581 if (title)
556 title->clear(); 582 title->clear();
557 583
558 if (url) 584 if (url)
559 url->clear(); 585 url->clear();
560 586
561 // Acquire the clipboard. 587 // Acquire the clipboard.
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 return base::IntToString(ClipboardUtil::GetFileContentFormatZero()->cfFormat); 752 return base::IntToString(ClipboardUtil::GetFileContentFormatZero()->cfFormat);
727 } 753 }
728 754
729 // static 755 // static
730 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() { 756 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() {
731 return base::IntToString( 757 return base::IntToString(
732 ClipboardUtil::GetWebKitSmartPasteFormat()->cfFormat); 758 ClipboardUtil::GetWebKitSmartPasteFormat()->cfFormat);
733 } 759 }
734 760
735 // static 761 // static
762 Clipboard::FormatType Clipboard::GetWebCustomDataFormatType() {
763 // TODO(dcheng): Clean up the duplicated constant.
764 // Clipboard::WritePickledData() takes a FormatType, but all the callers
765 // assume that it's a raw string. As a result, we return the format name here
766 // rather than returning a string-ified version of the registered clipboard
767 // format ID.
768 return "Chromium Web Custom MIME Data Format";
769 }
770
771 // static
736 void Clipboard::FreeData(unsigned int format, HANDLE data) { 772 void Clipboard::FreeData(unsigned int format, HANDLE data) {
737 if (format == CF_BITMAP) 773 if (format == CF_BITMAP)
738 ::DeleteObject(static_cast<HBITMAP>(data)); 774 ::DeleteObject(static_cast<HBITMAP>(data));
739 else 775 else
740 ::GlobalFree(data); 776 ::GlobalFree(data);
741 } 777 }
742 778
743 HWND Clipboard::GetClipboardWindow() const { 779 HWND Clipboard::GetClipboardWindow() const {
744 if (!clipboard_owner_ && create_window_) { 780 if (!clipboard_owner_ && create_window_) {
745 clipboard_owner_ = ::CreateWindow(L"ClipboardOwnerWindowClass", 781 clipboard_owner_ = ::CreateWindow(L"ClipboardOwnerWindowClass",
746 L"ClipboardOwnerWindow", 782 L"ClipboardOwnerWindow",
747 0, 0, 0, 0, 0, 783 0, 0, 0, 0, 0,
748 HWND_MESSAGE, 784 HWND_MESSAGE,
749 0, 0, 0); 785 0, 0, 0);
750 } 786 }
751 return clipboard_owner_; 787 return clipboard_owner_;
752 } 788 }
753 789
754 } // namespace ui 790 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698