Index: content/renderer/webclipboard_impl.cc |
diff --git a/content/renderer/webclipboard_impl.cc b/content/renderer/webclipboard_impl.cc |
index e248c517a06a67d52c683b2af78d12a7d2c1d834..ceb2d06a05055f12ca20e64a4093c370b8fd1145 100644 |
--- a/content/renderer/webclipboard_impl.cc |
+++ b/content/renderer/webclipboard_impl.cc |
@@ -5,14 +5,13 @@ |
#include "content/renderer/webclipboard_impl.h" |
#include "base/logging.h" |
-#include "base/pickle.h" |
#include "base/strings/string_util.h" |
#include "base/strings/utf_string_conversions.h" |
#include "content/common/clipboard_format.h" |
#include "content/public/common/drop_data.h" |
#include "content/renderer/clipboard_utils.h" |
#include "content/renderer/drop_data_builder.h" |
-#include "content/renderer/scoped_clipboard_writer_glue.h" |
+#include "content/renderer/renderer_clipboard_client.h" |
#include "third_party/WebKit/public/platform/WebData.h" |
#include "third_party/WebKit/public/platform/WebDragData.h" |
#include "third_party/WebKit/public/platform/WebImage.h" |
@@ -20,9 +19,6 @@ |
#include "third_party/WebKit/public/platform/WebString.h" |
#include "third_party/WebKit/public/platform/WebURL.h" |
#include "third_party/WebKit/public/platform/WebVector.h" |
-#include "third_party/skia/include/core/SkBitmap.h" |
-#include "ui/base/clipboard/clipboard.h" |
-#include "ui/base/clipboard/custom_data_helper.h" |
#include "url/gurl.h" |
using blink::WebClipboard; |
@@ -35,8 +31,9 @@ using blink::WebVector; |
namespace content { |
-WebClipboardImpl::WebClipboardImpl(ClipboardClient* client) |
+WebClipboardImpl::WebClipboardImpl(RendererClipboardClient* client) |
: client_(client) { |
+ DCHECK(client); |
} |
WebClipboardImpl::~WebClipboardImpl() { |
@@ -133,41 +130,31 @@ WebString WebClipboardImpl::readCustomData(Buffer buffer, |
} |
void WebClipboardImpl::writePlainText(const WebString& plain_text) { |
- ScopedClipboardWriterGlue scw(client_); |
- scw.WriteText(plain_text); |
+ client_->WriteText(ui::CLIPBOARD_TYPE_COPY_PASTE, plain_text); |
+ client_->CommitWrite(ui::CLIPBOARD_TYPE_COPY_PASTE); |
} |
void WebClipboardImpl::writeHTML( |
const WebString& html_text, const WebURL& source_url, |
const WebString& plain_text, bool write_smart_paste) { |
- ScopedClipboardWriterGlue scw(client_); |
- scw.WriteHTML(html_text, source_url.spec()); |
- scw.WriteText(plain_text); |
+ client_->WriteHTML(ui::CLIPBOARD_TYPE_COPY_PASTE, html_text, source_url); |
+ client_->WriteText(ui::CLIPBOARD_TYPE_COPY_PASTE, plain_text); |
if (write_smart_paste) |
- scw.WriteWebSmartPaste(); |
+ client_->WriteSmartPasteMarker(ui::CLIPBOARD_TYPE_COPY_PASTE); |
+ client_->CommitWrite(ui::CLIPBOARD_TYPE_COPY_PASTE); |
} |
void WebClipboardImpl::writeImage(const WebImage& image, |
const WebURL& url, |
const WebString& title) { |
- ScopedClipboardWriterGlue scw(client_); |
- |
- if (!image.isNull()) { |
- const SkBitmap& bitmap = image.getSkBitmap(); |
- // WriteBitmapFromPixels expects 32-bit data. |
- DCHECK_EQ(bitmap.colorType(), kN32_SkColorType); |
- |
- SkAutoLockPixels locked(bitmap); |
- void *pixels = bitmap.getPixels(); |
- // TODO(piman): this should not be NULL, but it is. crbug.com/369621 |
- if (!pixels) |
- return; |
- scw.WriteBitmapFromPixels(pixels, image.size()); |
- } |
+ DCHECK(!image.isNull()); |
dcheng
2014/09/18 17:02:22
I'm not really sure if we need this check. It's wo
|
+ const SkBitmap& bitmap = image.getSkBitmap(); |
+ if (!client_->WriteImage(ui::CLIPBOARD_TYPE_COPY_PASTE, bitmap)) |
+ return; |
if (!url.isEmpty()) { |
- scw.WriteBookmark(title, url.spec()); |
+ client_->WriteBookmark(ui::CLIPBOARD_TYPE_COPY_PASTE, url, title); |
#if !defined(OS_MACOSX) |
// When writing the image, we also write the image markup so that pasting |
// into rich text editors, such as Gmail, reveals the image. We also don't |
@@ -176,31 +163,30 @@ void WebClipboardImpl::writeImage(const WebImage& image, |
// We also don't want to write HTML on a Mac, since Mail.app prefers to use |
// the image markup over attaching the actual image. See |
// http://crbug.com/33016 for details. |
- scw.WriteHTML(base::UTF8ToUTF16(URLToImageMarkup(url, title)), |
- std::string()); |
+ client_->WriteHTML(ui::CLIPBOARD_TYPE_COPY_PASTE, |
+ base::UTF8ToUTF16(URLToImageMarkup(url, title)), |
+ GURL()); |
#endif |
} |
+ client_->CommitWrite(ui::CLIPBOARD_TYPE_COPY_PASTE); |
} |
void WebClipboardImpl::writeDataObject(const WebDragData& data) { |
- ScopedClipboardWriterGlue scw(client_); |
- |
const DropData& data_object = DropDataBuilder::Build(data); |
// TODO(dcheng): Properly support text/uri-list here. |
+ // Avoid calling the WriteFoo functions if there is no data associated with a |
+ // type. This prevents stomping on clipboard contents that might have been |
+ // written by extension functions such as chrome.bookmarkManagerPrivate.copy. |
if (!data_object.text.is_null()) |
- scw.WriteText(data_object.text.string()); |
+ client_->WriteText(ui::CLIPBOARD_TYPE_COPY_PASTE, |
+ data_object.text.string()); |
if (!data_object.html.is_null()) |
- scw.WriteHTML(data_object.html.string(), std::string()); |
- // If there is no custom data, avoid calling WritePickledData. This ensures |
- // that ScopedClipboardWriterGlue's dtor remains a no-op if the page didn't |
- // modify the DataTransfer object, which is important to avoid stomping on |
- // any clipboard contents written by extension functions such as |
- // chrome.bookmarkManagerPrivate.copy. |
- if (!data_object.custom_data.empty()) { |
- Pickle pickle; |
- ui::WriteCustomDataToPickle(data_object.custom_data, &pickle); |
- scw.WritePickledData(pickle, ui::Clipboard::GetWebCustomDataFormatType()); |
- } |
+ client_->WriteHTML( |
+ ui::CLIPBOARD_TYPE_COPY_PASTE, data_object.html.string(), GURL()); |
+ if (!data_object.custom_data.empty()) |
+ client_->WriteCustomData(ui::CLIPBOARD_TYPE_COPY_PASTE, |
+ data_object.custom_data); |
+ client_->CommitWrite(ui::CLIPBOARD_TYPE_COPY_PASTE); |
} |
bool WebClipboardImpl::ConvertBufferType(Buffer buffer, |