diff options
author | piman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-22 03:48:52 +0000 |
---|---|---|
committer | piman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-22 03:48:52 +0000 |
commit | 0de5d8609abf9961228c2a12031fc5354688345a (patch) | |
tree | e11e8fc9ac695dc41f999a62b88e95e3b6d780d8 /webkit/glue | |
parent | 66d22164c2aded1403643b52a9763f492acbbdcc (diff) | |
download | chromium_src-0de5d8609abf9961228c2a12031fc5354688345a.zip chromium_src-0de5d8609abf9961228c2a12031fc5354688345a.tar.gz chromium_src-0de5d8609abf9961228c2a12031fc5354688345a.tar.bz2 |
Move clipboard-related webkit_glue embedder functions into a ClipboardClient interface.
This moves the functions into a pattern that is component-friendly.
BUG=98755
TEST=Chrome, DRT, test_shell
Review URL: http://codereview.chromium.org/8591030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111097 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue')
-rw-r--r-- | webkit/glue/clipboard_client.h | 68 | ||||
-rw-r--r-- | webkit/glue/scoped_clipboard_writer_glue.cc | 25 | ||||
-rw-r--r-- | webkit/glue/scoped_clipboard_writer_glue.h | 12 | ||||
-rw-r--r-- | webkit/glue/webclipboard_impl.cc | 36 | ||||
-rw-r--r-- | webkit/glue/webclipboard_impl.h | 4 | ||||
-rw-r--r-- | webkit/glue/webkit_glue.gypi | 1 | ||||
-rw-r--r-- | webkit/glue/webkit_glue.h | 38 |
7 files changed, 121 insertions, 63 deletions
diff --git a/webkit/glue/clipboard_client.h b/webkit/glue/clipboard_client.h new file mode 100644 index 0000000..92e8c88 --- /dev/null +++ b/webkit/glue/clipboard_client.h @@ -0,0 +1,68 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WEBKIT_GLUE_CLIPBOARD_CLIENT_H_ +#define WEBKIT_GLUE_CLIPBOARD_CLIENT_H_ + +#include "ui/base/clipboard/clipboard.h" + +class GURL; + +namespace webkit_glue { + +// Interface for the webkit glue embedder to implement to support clipboard. +class ClipboardClient { + public: + class WriteContext { + public: + virtual ~WriteContext() { } + + // Writes bitmap data into the context, updating the ObjectMap. + virtual void WriteBitmapFromPixels(ui::Clipboard::ObjectMap* objects, + const void* pixels, + const gfx::Size& size) = 0; + + // Flushes all gathered data, and destroys the context. + virtual void FlushAndDestroy(const ui::Clipboard::ObjectMap& objects) = 0; + }; + + virtual ~ClipboardClient() { } + + // Get a clipboard that can be used to construct a ScopedClipboardWriterGlue. + virtual ui::Clipboard* GetClipboard() = 0; + + // Get a sequence number which uniquely identifies clipboard state. + virtual uint64 GetSequenceNumber(ui::Clipboard::Buffer buffer) = 0; + + // Tests whether the clipboard contains a certain format + virtual bool IsFormatAvailable(const ui::Clipboard::FormatType& format, + ui::Clipboard::Buffer buffer) = 0; + + // Reads the available types from the clipboard, if available. + virtual void ReadAvailableTypes(ui::Clipboard::Buffer buffer, + std::vector<string16>* types, + bool* contains_filenames) = 0; + + // Reads UNICODE text from the clipboard, if available. + virtual void ReadText(ui::Clipboard::Buffer buffer, string16* result) = 0; + + // Reads ASCII text from the clipboard, if available. + virtual void ReadAsciiText(ui::Clipboard::Buffer buffer, + std::string* result) = 0; + + // Reads HTML from the clipboard, if available. + virtual void ReadHTML(ui::Clipboard::Buffer buffer, string16* markup, + GURL* url, uint32* fragment_start, + uint32* fragment_end) = 0; + + // Reads and image from the clipboard, if available. + virtual void ReadImage(ui::Clipboard::Buffer buffer, std::string* data) = 0; + + // Creates a context to write clipboard data. May return NULL. + virtual WriteContext* CreateWriteContext() = 0; +}; + +} // namespace webkit_glue + +#endif // WEBKIT_GLUE_CLIPBOARD_CLIENT_H_ diff --git a/webkit/glue/scoped_clipboard_writer_glue.cc b/webkit/glue/scoped_clipboard_writer_glue.cc new file mode 100644 index 0000000..be4ccac --- /dev/null +++ b/webkit/glue/scoped_clipboard_writer_glue.cc @@ -0,0 +1,25 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "webkit/glue/scoped_clipboard_writer_glue.h" + +ScopedClipboardWriterGlue::ScopedClipboardWriterGlue( + webkit_glue::ClipboardClient* client) + : ui::ScopedClipboardWriter(client->GetClipboard()), + context_(client->CreateWriteContext()) { +} + +ScopedClipboardWriterGlue::~ScopedClipboardWriterGlue() { + if (context_) + context_->FlushAndDestroy(objects_); +} + +void ScopedClipboardWriterGlue::WriteBitmapFromPixels(const void* pixels, + const gfx::Size& size) { + if (context_) { + context_->WriteBitmapFromPixels(&objects_, pixels, size); + } else { + ScopedClipboardWriter::WriteBitmapFromPixels(pixels, size); + } +} diff --git a/webkit/glue/scoped_clipboard_writer_glue.h b/webkit/glue/scoped_clipboard_writer_glue.h index 9b331fc..cee1669 100644 --- a/webkit/glue/scoped_clipboard_writer_glue.h +++ b/webkit/glue/scoped_clipboard_writer_glue.h @@ -6,24 +6,18 @@ #define WEBKIT_GLUE_SCOPED_CLIPBOARD_WRITER_GLUE_H_ #include "ui/base/clipboard/scoped_clipboard_writer.h" - -namespace base { -class SharedMemory; -} +#include "webkit/glue/clipboard_client.h" class ScopedClipboardWriterGlue : public ui::ScopedClipboardWriter { public: - explicit ScopedClipboardWriterGlue(ui::Clipboard* clipboard) - : ui::ScopedClipboardWriter(clipboard), - shared_buf_(NULL) { - } + explicit ScopedClipboardWriterGlue(webkit_glue::ClipboardClient* client); ~ScopedClipboardWriterGlue(); void WriteBitmapFromPixels(const void* pixels, const gfx::Size& size); private: - base::SharedMemory* shared_buf_; + webkit_glue::ClipboardClient::WriteContext* context_; DISALLOW_COPY_AND_ASSIGN(ScopedClipboardWriterGlue); }; diff --git a/webkit/glue/webclipboard_impl.cc b/webkit/glue/webclipboard_impl.cc index 80b2ae9..42b76cf 100644 --- a/webkit/glue/webclipboard_impl.cc +++ b/webkit/glue/webclipboard_impl.cc @@ -62,6 +62,10 @@ std::string WebClipboardImpl::URLToImageMarkup(const WebURL& url, return markup; } +WebClipboardImpl::WebClipboardImpl(ClipboardClient* client) + : client_(client) { +} + WebClipboardImpl::~WebClipboardImpl() { } @@ -74,7 +78,7 @@ uint64 WebClipboardImpl::sequenceNumber(Buffer buffer) { if (!ConvertBufferType(buffer, &buffer_type)) return 0; - return ClipboardGetSequenceNumber(buffer_type); + return client_->GetSequenceNumber(buffer_type); } bool WebClipboardImpl::isFormatAvailable(Format format, Buffer buffer) { @@ -86,9 +90,9 @@ bool WebClipboardImpl::isFormatAvailable(Format format, Buffer buffer) { switch (format) { case FormatPlainText: - return ClipboardIsFormatAvailable(ui::Clipboard::GetPlainTextFormatType(), + return client_->IsFormatAvailable(ui::Clipboard::GetPlainTextFormatType(), buffer_type) || - ClipboardIsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(), + client_->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(), buffer_type); case FormatHTML: format_type = ui::Clipboard::GetHtmlFormatType(); @@ -106,7 +110,7 @@ bool WebClipboardImpl::isFormatAvailable(Format format, Buffer buffer) { return false; } - return ClipboardIsFormatAvailable(format_type, buffer_type); + return client_->IsFormatAvailable(format_type, buffer_type); } WebVector<WebString> WebClipboardImpl::readAvailableTypes( @@ -114,7 +118,7 @@ WebVector<WebString> WebClipboardImpl::readAvailableTypes( ui::Clipboard::Buffer buffer_type; std::vector<string16> types; if (ConvertBufferType(buffer, &buffer_type)) { - ClipboardReadAvailableTypes(buffer_type, &types, contains_filenames); + client_->ReadAvailableTypes(buffer_type, &types, contains_filenames); } return types; } @@ -124,18 +128,18 @@ WebString WebClipboardImpl::readPlainText(Buffer buffer) { if (!ConvertBufferType(buffer, &buffer_type)) return WebString(); - if (ClipboardIsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(), + if (client_->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(), buffer_type)) { string16 text; - ClipboardReadText(buffer_type, &text); + client_->ReadText(buffer_type, &text); if (!text.empty()) return text; } - if (ClipboardIsFormatAvailable(ui::Clipboard::GetPlainTextFormatType(), + if (client_->IsFormatAvailable(ui::Clipboard::GetPlainTextFormatType(), buffer_type)) { std::string text; - ClipboardReadAsciiText(buffer_type, &text); + client_->ReadAsciiText(buffer_type, &text); if (!text.empty()) return ASCIIToUTF16(text); } @@ -152,7 +156,7 @@ WebString WebClipboardImpl::readHTML(Buffer buffer, WebURL* source_url, string16 html_stdstr; GURL gurl; - ClipboardReadHTML(buffer_type, &html_stdstr, &gurl, + client_->ReadHTML(buffer_type, &html_stdstr, &gurl, static_cast<uint32*>(fragment_start), static_cast<uint32*>(fragment_end)); *source_url = gurl; @@ -165,14 +169,14 @@ WebData WebClipboardImpl::readImage(Buffer buffer) { return WebData(); std::string png_data; - ClipboardReadImage(buffer_type, &png_data); + client_->ReadImage(buffer_type, &png_data); return WebData(png_data); } void WebClipboardImpl::writeHTML( const WebString& html_text, const WebURL& source_url, const WebString& plain_text, bool write_smart_paste) { - ScopedClipboardWriterGlue scw(ClipboardGetClipboard()); + ScopedClipboardWriterGlue scw(client_); scw.WriteHTML(html_text, source_url.spec()); scw.WriteText(plain_text); @@ -181,12 +185,12 @@ void WebClipboardImpl::writeHTML( } void WebClipboardImpl::writePlainText(const WebString& plain_text) { - ScopedClipboardWriterGlue scw(ClipboardGetClipboard()); + ScopedClipboardWriterGlue scw(client_); scw.WriteText(plain_text); } void WebClipboardImpl::writeURL(const WebURL& url, const WebString& title) { - ScopedClipboardWriterGlue scw(ClipboardGetClipboard()); + ScopedClipboardWriterGlue scw(client_); scw.WriteBookmark(title, url.spec()); scw.WriteHTML(UTF8ToUTF16(URLToMarkup(url, title)), ""); @@ -195,7 +199,7 @@ void WebClipboardImpl::writeURL(const WebURL& url, const WebString& title) { void WebClipboardImpl::writeImage( const WebImage& image, const WebURL& url, const WebString& title) { - ScopedClipboardWriterGlue scw(ClipboardGetClipboard()); + ScopedClipboardWriterGlue scw(client_); if (!image.isNull()) { #if WEBKIT_USING_SKIA @@ -226,7 +230,7 @@ void WebClipboardImpl::writeDataObject(const WebDragData& data) { // TODO(dcheng): This actually results in a double clear of the clipboard. // Once in WebKit, and once here when the clipboard writer goes out of scope. // The same is true of the other WebClipboard::write* methods. - ScopedClipboardWriterGlue scw(ClipboardGetClipboard()); + ScopedClipboardWriterGlue scw(client_); // TODO(dcheng): Properly support text/uri-list here. scw.WriteText(data.plainText()); diff --git a/webkit/glue/webclipboard_impl.h b/webkit/glue/webclipboard_impl.h index b4ac1e4..c1514f2 100644 --- a/webkit/glue/webclipboard_impl.h +++ b/webkit/glue/webclipboard_impl.h @@ -11,6 +11,7 @@ #include <string> namespace webkit_glue { +class ClipboardClient; class WebClipboardImpl : public WebKit::WebClipboard { public: @@ -19,6 +20,8 @@ class WebClipboardImpl : public WebKit::WebClipboard { static std::string URLToImageMarkup(const WebKit::WebURL& url, const WebKit::WebString& title); + explicit WebClipboardImpl(ClipboardClient* client); + virtual ~WebClipboardImpl(); // WebClipboard methods: @@ -51,6 +54,7 @@ class WebClipboardImpl : public WebKit::WebClipboard { private: bool ConvertBufferType(Buffer, ui::Clipboard::Buffer*); + ClipboardClient* client_; }; } // namespace webkit_glue diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi index 95a7f84..1c6a8c2 100644 --- a/webkit/glue/webkit_glue.gypi +++ b/webkit/glue/webkit_glue.gypi @@ -373,6 +373,7 @@ 'resource_loader_bridge.h', 'resource_type.cc', 'resource_type.h', + 'scoped_clipboard_writer_glue.cc', 'scoped_clipboard_writer_glue.h', 'simple_webmimeregistry_impl.cc', 'simple_webmimeregistry_impl.h', diff --git a/webkit/glue/webkit_glue.h b/webkit/glue/webkit_glue.h index 53d6d9c..ddbc3a3 100644 --- a/webkit/glue/webkit_glue.h +++ b/webkit/glue/webkit_glue.h @@ -19,7 +19,6 @@ #include "base/string16.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebCanvas.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileError.h" -#include "ui/base/clipboard/clipboard.h" class GURL; class SkBitmap; @@ -167,47 +166,10 @@ string16 GetLocalizedString(int message_id); // specified as BINDATA in the relevant .rc file. base::StringPiece GetDataResource(int resource_id); -// Glue to access the clipboard. - -// Get a clipboard that can be used to construct a ScopedClipboardWriterGlue. -ui::Clipboard* ClipboardGetClipboard(); - -// Get a sequence number which uniquely identifies clipboard state. -uint64 ClipboardGetSequenceNumber(ui::Clipboard::Buffer buffer); - -// Tests whether the clipboard contains a certain format -bool ClipboardIsFormatAvailable(const ui::Clipboard::FormatType& format, - ui::Clipboard::Buffer buffer); - -// Reads the available types from the clipboard, if available. -void ClipboardReadAvailableTypes(ui::Clipboard::Buffer buffer, - std::vector<string16>* types, - bool* contains_filenames); - -// Reads UNICODE text from the clipboard, if available. -void ClipboardReadText(ui::Clipboard::Buffer buffer, string16* result); - -// Reads ASCII text from the clipboard, if available. -void ClipboardReadAsciiText(ui::Clipboard::Buffer buffer, std::string* result); - -// Reads HTML from the clipboard, if available. -void ClipboardReadHTML(ui::Clipboard::Buffer buffer, string16* markup, - GURL* url, uint32* fragment_start, - uint32* fragment_end); - -void ClipboardReadImage(ui::Clipboard::Buffer buffer, std::string* data); - // Embedders implement this function to return the list of plugins to Webkit. void GetPlugins(bool refresh, std::vector<webkit::WebPluginInfo>* plugins); -// Returns the locale that this instance of webkit is running as. This is of -// the form language-country (e.g., en-US or pt-BR). -std::string GetWebKitLocale(); - -// Returns true if the embedder is running in single process mode. -bool IsSingleProcess(); - // ---- END FUNCTIONS IMPLEMENTED BY EMBEDDER --------------------------------- |