| Index: ui/base/clipboard/clipboard_win.cc
|
| diff --git a/ui/base/clipboard/clipboard_win.cc b/ui/base/clipboard/clipboard_win.cc
|
| index 47a97d90bbcd5efbadfafba5eaa75e313cfa851e..721b1311b5a3c545fdcf411603d2d5e9324b1338 100644
|
| --- a/ui/base/clipboard/clipboard_win.cc
|
| +++ b/ui/base/clipboard/clipboard_win.cc
|
| @@ -21,6 +21,7 @@
|
| #include "base/strings/string_util.h"
|
| #include "base/strings/utf_offset_string_conversions.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| +#include "base/win/message_window.h"
|
| #include "base/win/scoped_gdi_object.h"
|
| #include "base/win/scoped_hdc.h"
|
| #include "base/win/wrapped_window_proc.h"
|
| @@ -94,37 +95,6 @@ class ScopedClipboard {
|
| bool opened_;
|
| };
|
|
|
| -LRESULT CALLBACK ClipboardOwnerWndProc(HWND hwnd,
|
| - UINT message,
|
| - WPARAM wparam,
|
| - LPARAM lparam) {
|
| - LRESULT lresult = 0;
|
| -
|
| - switch (message) {
|
| - case WM_RENDERFORMAT:
|
| - // This message comes when SetClipboardData was sent a null data handle
|
| - // and now it's come time to put the data on the clipboard.
|
| - // We always set data, so there isn't a need to actually do anything here.
|
| - break;
|
| - case WM_RENDERALLFORMATS:
|
| - // This message comes when SetClipboardData was sent a null data handle
|
| - // and now this application is about to quit, so it must put data on
|
| - // the clipboard before it exits.
|
| - // We always set data, so there isn't a need to actually do anything here.
|
| - break;
|
| - case WM_DRAWCLIPBOARD:
|
| - break;
|
| - case WM_DESTROY:
|
| - break;
|
| - case WM_CHANGECBCHAIN:
|
| - break;
|
| - default:
|
| - lresult = DefWindowProc(hwnd, message, wparam, lparam);
|
| - break;
|
| - }
|
| - return lresult;
|
| -}
|
| -
|
| template <typename charT>
|
| HGLOBAL CreateGlobalData(const std::basic_string<charT>& str) {
|
| HGLOBAL data =
|
| @@ -161,6 +131,83 @@ void MakeBitmapOpaque(const SkBitmap& bitmap) {
|
|
|
| } // namespace
|
|
|
| +// Used to create a message-only window handling clipboard-related window
|
| +// messages. It is intended to be passed to OpenClipboard() API.
|
| +class Clipboard::ClipboardWindow
|
| + : public base::win::MessageWindow::Delegate {
|
| + public:
|
| + ClipboardWindow();
|
| + virtual ~ClipboardWindow();
|
| +
|
| + // Creates the window if it is not created yat and returns its handle. Returns
|
| + // NULL if an error occurs.
|
| + HWND GetHandle();
|
| +
|
| + // Returns |true| if the window is created.
|
| + bool IsValid() const;
|
| +
|
| + private:
|
| + // base::win::MessageWindow::Delegate interface.
|
| + virtual bool HandleMessage(HWND hwnd,
|
| + UINT message,
|
| + WPARAM wparam,
|
| + LPARAM lparam,
|
| + LRESULT* result) OVERRIDE;
|
| +
|
| + base::win::MessageWindow window_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ClipboardWindow);
|
| +};
|
| +
|
| +
|
| +Clipboard::ClipboardWindow::ClipboardWindow() {
|
| +}
|
| +
|
| +Clipboard::ClipboardWindow::~ClipboardWindow() {
|
| +}
|
| +
|
| +HWND Clipboard::ClipboardWindow::GetHandle() {
|
| + if (!IsValid())
|
| + window_.Create(this);
|
| +
|
| + return window_.hwnd();
|
| +}
|
| +
|
| +bool Clipboard::ClipboardWindow::IsValid() const {
|
| + return window_.hwnd() != NULL;
|
| +}
|
| +
|
| +bool Clipboard::ClipboardWindow::HandleMessage(HWND hwnd,
|
| + UINT message,
|
| + WPARAM wparam,
|
| + LPARAM lparam,
|
| + LRESULT* result) {
|
| + switch (message) {
|
| + case WM_RENDERFORMAT:
|
| + // This message comes when SetClipboardData was sent a null data handle
|
| + // and now it's come time to put the data on the clipboard.
|
| + // We always set data, so there isn't a need to actually do anything here.
|
| + break;
|
| + case WM_RENDERALLFORMATS:
|
| + // This message comes when SetClipboardData was sent a null data handle
|
| + // and now this application is about to quit, so it must put data on
|
| + // the clipboard before it exits.
|
| + // We always set data, so there isn't a need to actually do anything here.
|
| + break;
|
| + case WM_DRAWCLIPBOARD:
|
| + break;
|
| + case WM_DESTROY:
|
| + break;
|
| + case WM_CHANGECBCHAIN:
|
| + break;
|
| + default:
|
| + return false;
|
| + }
|
| +
|
| + *result = 0;
|
| + return true;
|
| +}
|
| +
|
| Clipboard::FormatType::FormatType() : data_() {}
|
|
|
| Clipboard::FormatType::FormatType(UINT native_format) : data_() {
|
| @@ -203,26 +250,12 @@ bool Clipboard::FormatType::operator<(const FormatType& other) const {
|
| return ToUINT() < other.ToUINT();
|
| }
|
|
|
| -Clipboard::Clipboard() : create_window_(false) {
|
| - if (base::MessageLoop::current()->type() == base::MessageLoop::TYPE_UI) {
|
| - // Make a dummy HWND to be the clipboard's owner.
|
| - WNDCLASSEX window_class;
|
| - base::win::InitializeWindowClass(
|
| - L"ClipboardOwnerWindowClass",
|
| - &base::win::WrappedWindowProc<ClipboardOwnerWndProc>,
|
| - 0, 0, 0, NULL, NULL, NULL, NULL, NULL,
|
| - &window_class);
|
| - ::RegisterClassEx(&window_class);
|
| - create_window_ = true;
|
| - }
|
| -
|
| - clipboard_owner_ = NULL;
|
| +Clipboard::Clipboard() {
|
| + if (base::MessageLoop::current()->type() == base::MessageLoop::TYPE_UI)
|
| + clipboard_owner_.reset(new ClipboardWindow());
|
| }
|
|
|
| Clipboard::~Clipboard() {
|
| - if (clipboard_owner_)
|
| - ::DestroyWindow(clipboard_owner_);
|
| - clipboard_owner_ = NULL;
|
| }
|
|
|
| void Clipboard::WriteObjects(Buffer buffer, const ObjectMap& objects) {
|
| @@ -283,7 +316,7 @@ void Clipboard::WriteBookmark(const char* title_data,
|
| }
|
|
|
| void Clipboard::WriteWebSmartPaste() {
|
| - DCHECK(clipboard_owner_);
|
| + DCHECK(clipboard_owner_->IsValid());
|
| ::SetClipboardData(GetWebKitSmartPasteFormatType().ToUINT(), NULL);
|
| }
|
|
|
| @@ -378,7 +411,7 @@ void Clipboard::WriteData(const FormatType& format,
|
| }
|
|
|
| void Clipboard::WriteToClipboard(unsigned int format, HANDLE handle) {
|
| - DCHECK(clipboard_owner_);
|
| + DCHECK(clipboard_owner_->IsValid());
|
| if (handle && !::SetClipboardData(format, handle)) {
|
| DCHECK(ERROR_CLIPBOARD_NOT_OPEN != GetLastError());
|
| FreeData(format, handle);
|
| @@ -825,14 +858,7 @@ void Clipboard::FreeData(unsigned int format, HANDLE data) {
|
| }
|
|
|
| HWND Clipboard::GetClipboardWindow() const {
|
| - if (!clipboard_owner_ && create_window_) {
|
| - clipboard_owner_ = ::CreateWindow(L"ClipboardOwnerWindowClass",
|
| - L"ClipboardOwnerWindow",
|
| - 0, 0, 0, 0, 0,
|
| - HWND_MESSAGE,
|
| - 0, 0, 0);
|
| - }
|
| - return clipboard_owner_;
|
| + return clipboard_owner_ ? clipboard_owner_->GetHandle() : NULL;
|
| }
|
|
|
| } // namespace ui
|
|
|