summaryrefslogtreecommitdiffstats
path: root/webkit/tools/test_shell/mock_webclipboard_impl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'webkit/tools/test_shell/mock_webclipboard_impl.cc')
-rw-r--r--webkit/tools/test_shell/mock_webclipboard_impl.cc48
1 files changed, 47 insertions, 1 deletions
diff --git a/webkit/tools/test_shell/mock_webclipboard_impl.cc b/webkit/tools/test_shell/mock_webclipboard_impl.cc
index 1e00f70..f7c19d9 100644
--- a/webkit/tools/test_shell/mock_webclipboard_impl.cc
+++ b/webkit/tools/test_shell/mock_webclipboard_impl.cc
@@ -1,16 +1,24 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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/tools/test_shell/mock_webclipboard_impl.h"
#include "base/logging.h"
+#include "base/stl_util-inl.h"
#include "base/string_util.h"
#include "net/base/escape.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebCommon.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
#include "webkit/glue/webclipboard_impl.h"
#include "webkit/glue/webkit_glue.h"
+#include "webkit/support/webkit_support_gfx.h"
+
+#if WEBKIT_USING_CG
+#include <ApplicationServices/ApplicationServices.h>
+#include <CoreFoundation/CoreFoundation.h>
+#endif
using WebKit::WebString;
using WebKit::WebURL;
@@ -58,17 +66,50 @@ WebKit::WebString MockWebClipboardImpl::readHTML(
return m_htmlText;
}
+WebKit::WebData MockWebClipboardImpl::readImage(
+ WebKit::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.
+#if WEBKIT_USING_SKIA
+ const SkBitmap& bitmap = m_image.getSkBitmap();
+ SkAutoLockPixels lock(bitmap);
+ webkit_support::EncodeBGRAPNG(static_cast<unsigned char*>(bitmap.getPixels()),
+ bitmap.width(),
+ bitmap.height(),
+ bitmap.rowBytes(),
+ false,
+ &encoded_image);
+#elif WEBKIT_USING_CG
+ CGImageRef image = m_image.getCGImageRef();
+ CFDataRef image_data_ref =
+ CGDataProviderCopyData(CGImageGetDataProvider(image));
+ webkit_support::EncodeRGBAPNG(CFDataGetBytePtr(image_data_ref),
+ CGImageGetWidth(image),
+ CGImageGetHeight(image),
+ CGImageGetBytesPerRow(image),
+ &encoded_image);
+ CFRelease(image_data_ref);
+#endif
+ data.assign(reinterpret_cast<char*>(vector_as_array(&encoded_image)),
+ encoded_image.size());
+ return data;
+}
+
void MockWebClipboardImpl::writeHTML(
const WebKit::WebString& htmlText, const WebKit::WebURL& url,
const WebKit::WebString& plainText, bool writeSmartPaste) {
m_htmlText = htmlText;
m_plainText = plainText;
+ m_image.reset();
m_writeSmartPaste = writeSmartPaste;
}
void MockWebClipboardImpl::writePlainText(const WebKit::WebString& plain_text) {
m_htmlText = WebKit::WebString();
m_plainText = plain_text;
+ m_image.reset();
m_writeSmartPaste = false;
}
@@ -77,6 +118,7 @@ void MockWebClipboardImpl::writeURL(
m_htmlText = WebString::fromUTF8(
webkit_glue::WebClipboardImpl::URLToMarkup(url, title));
m_plainText = url.spec().utf16();
+ m_image.reset();
m_writeSmartPaste = false;
}
@@ -86,6 +128,7 @@ void MockWebClipboardImpl::writeImage(const WebKit::WebImage& image,
m_htmlText = WebString::fromUTF8(
webkit_glue::WebClipboardImpl::URLToImageMarkup(url, title));
m_plainText = m_htmlText;
+ m_image = image;
m_writeSmartPaste = false;
}
}
@@ -100,5 +143,8 @@ WebVector<WebString> MockWebClipboardImpl::readAvailableTypes(
if (!m_htmlText.isEmpty()) {
results.push_back(WebString("text/html"));
}
+ if (!m_image.isNull()) {
+ results.push_back(WebString("image/png"));
+ }
return results;
}