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

Unified Diff: content/test/mock_webclipboard_impl.cc

Issue 1876653003: Register clipboard image blob in the browser process to copy data less. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/test/mock_webclipboard_impl.h ('k') | third_party/WebKit/Source/core/clipboard/DataObjectItem.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/test/mock_webclipboard_impl.cc
diff --git a/content/test/mock_webclipboard_impl.cc b/content/test/mock_webclipboard_impl.cc
index 02b5ba96336a655de8d1cf73ddebf8dc170ac267..f5ca0a9f1b4f8d1713f83d766fc943d6e63ef8ec 100644
--- a/content/test/mock_webclipboard_impl.cc
+++ b/content/test/mock_webclipboard_impl.cc
@@ -8,13 +8,17 @@
#include <algorithm>
+#include "base/guid.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "content/renderer/clipboard_utils.h"
+#include "third_party/WebKit/public/platform/Platform.h"
+#include "third_party/WebKit/public/platform/WebBlobRegistry.h"
#include "third_party/WebKit/public/platform/WebCommon.h"
#include "third_party/WebKit/public/platform/WebDragData.h"
#include "third_party/WebKit/public/platform/WebImage.h"
+#include "third_party/WebKit/public/platform/WebThreadSafeData.h"
#include "third_party/WebKit/public/platform/WebURL.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/gfx/codec/png_codec.h"
@@ -94,28 +98,28 @@ blink::WebString MockWebClipboardImpl::readHTML(
return m_htmlText;
}
-blink::WebData MockWebClipboardImpl::readImage(
+blink::WebBlobInfo MockWebClipboardImpl::readImage(
blink::WebClipboard::Buffer buffer) {
- std::string data;
- std::vector<unsigned char> encoded_image;
- // TODO(dcheng): Verify that we can assume the image is ARGB8888. Note that
- // for endianess reasons, it will be BGRA8888 on Windows.
+ std::vector<unsigned char> output;
const SkBitmap& bitmap = m_image.getSkBitmap();
- SkAutoLockPixels lock(bitmap);
- gfx::PNGCodec::Encode(static_cast<unsigned char*>(bitmap.getPixels()),
-#if defined(OS_ANDROID)
- gfx::PNGCodec::FORMAT_RGBA,
-#else
- gfx::PNGCodec::FORMAT_BGRA,
-#endif
- gfx::Size(bitmap.width(), bitmap.height()),
- static_cast<int>(bitmap.rowBytes()),
- false /* discard_transparency */,
- std::vector<gfx::PNGCodec::Comment>(),
- &encoded_image);
- data.assign(reinterpret_cast<char*>(encoded_image.data()),
- encoded_image.size());
- return data;
+ if (!gfx::PNGCodec::FastEncodeBGRASkBitmap(
+ bitmap, false /* discard_transparency */, &output)) {
+ return blink::WebBlobInfo();
+ }
+ const WebString& uuid = base::ASCIIToUTF16(base::GenerateGUID());
+ std::unique_ptr<blink::WebBlobRegistry::Builder> blob_builder(
+ blink::Platform::current()->blobRegistry()->createBuilder(
+ uuid, blink::WebString()));
+ blob_builder->appendData(blink::WebThreadSafeData(
+ reinterpret_cast<char*>(output.data()), output.size()));
+ blob_builder->build();
+ return blink::WebBlobInfo(
+ uuid, base::ASCIIToUTF16(ui::Clipboard::kMimeTypePNG), output.size());
+}
+
+blink::WebImage MockWebClipboardImpl::readRawImage(
+ blink::WebClipboard::Buffer buffer) {
+ return m_image;
}
blink::WebString MockWebClipboardImpl::readCustomData(
« no previous file with comments | « content/test/mock_webclipboard_impl.h ('k') | third_party/WebKit/Source/core/clipboard/DataObjectItem.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698