| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/test/mock_webclipboard_impl.h" | 5 #include "content/test/mock_webclipboard_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "base/guid.h" |
| 11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 14 #include "content/renderer/clipboard_utils.h" | 15 #include "content/renderer/clipboard_utils.h" |
| 16 #include "third_party/WebKit/public/platform/Platform.h" |
| 17 #include "third_party/WebKit/public/platform/WebBlobRegistry.h" |
| 15 #include "third_party/WebKit/public/platform/WebCommon.h" | 18 #include "third_party/WebKit/public/platform/WebCommon.h" |
| 16 #include "third_party/WebKit/public/platform/WebDragData.h" | 19 #include "third_party/WebKit/public/platform/WebDragData.h" |
| 17 #include "third_party/WebKit/public/platform/WebImage.h" | 20 #include "third_party/WebKit/public/platform/WebImage.h" |
| 21 #include "third_party/WebKit/public/platform/WebThreadSafeData.h" |
| 18 #include "third_party/WebKit/public/platform/WebURL.h" | 22 #include "third_party/WebKit/public/platform/WebURL.h" |
| 19 #include "ui/base/clipboard/clipboard.h" | 23 #include "ui/base/clipboard/clipboard.h" |
| 20 #include "ui/gfx/codec/png_codec.h" | 24 #include "ui/gfx/codec/png_codec.h" |
| 21 #include "ui/gfx/geometry/size.h" | 25 #include "ui/gfx/geometry/size.h" |
| 22 | 26 |
| 23 using blink::WebDragData; | 27 using blink::WebDragData; |
| 24 using blink::WebString; | 28 using blink::WebString; |
| 25 using blink::WebURL; | 29 using blink::WebURL; |
| 26 using blink::WebVector; | 30 using blink::WebVector; |
| 27 | 31 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 blink::WebString MockWebClipboardImpl::readHTML( | 91 blink::WebString MockWebClipboardImpl::readHTML( |
| 88 blink::WebClipboard::Buffer buffer, | 92 blink::WebClipboard::Buffer buffer, |
| 89 blink::WebURL* url, | 93 blink::WebURL* url, |
| 90 unsigned* fragmentStart, | 94 unsigned* fragmentStart, |
| 91 unsigned* fragmentEnd) { | 95 unsigned* fragmentEnd) { |
| 92 *fragmentStart = 0; | 96 *fragmentStart = 0; |
| 93 *fragmentEnd = static_cast<unsigned>(m_htmlText.string().length()); | 97 *fragmentEnd = static_cast<unsigned>(m_htmlText.string().length()); |
| 94 return m_htmlText; | 98 return m_htmlText; |
| 95 } | 99 } |
| 96 | 100 |
| 97 blink::WebData MockWebClipboardImpl::readImage( | 101 blink::WebBlobInfo MockWebClipboardImpl::readImage( |
| 98 blink::WebClipboard::Buffer buffer) { | 102 blink::WebClipboard::Buffer buffer) { |
| 99 std::string data; | 103 std::vector<unsigned char> output; |
| 100 std::vector<unsigned char> encoded_image; | |
| 101 // TODO(dcheng): Verify that we can assume the image is ARGB8888. Note that | |
| 102 // for endianess reasons, it will be BGRA8888 on Windows. | |
| 103 const SkBitmap& bitmap = m_image.getSkBitmap(); | 104 const SkBitmap& bitmap = m_image.getSkBitmap(); |
| 104 SkAutoLockPixels lock(bitmap); | 105 if (!gfx::PNGCodec::FastEncodeBGRASkBitmap( |
| 105 gfx::PNGCodec::Encode(static_cast<unsigned char*>(bitmap.getPixels()), | 106 bitmap, false /* discard_transparency */, &output)) { |
| 106 #if defined(OS_ANDROID) | 107 return blink::WebBlobInfo(); |
| 107 gfx::PNGCodec::FORMAT_RGBA, | 108 } |
| 108 #else | 109 const WebString& uuid = base::ASCIIToUTF16(base::GenerateGUID()); |
| 109 gfx::PNGCodec::FORMAT_BGRA, | 110 std::unique_ptr<blink::WebBlobRegistry::Builder> blob_builder( |
| 110 #endif | 111 blink::Platform::current()->blobRegistry()->createBuilder( |
| 111 gfx::Size(bitmap.width(), bitmap.height()), | 112 uuid, blink::WebString())); |
| 112 static_cast<int>(bitmap.rowBytes()), | 113 blob_builder->appendData(blink::WebThreadSafeData( |
| 113 false /* discard_transparency */, | 114 reinterpret_cast<char*>(output.data()), output.size())); |
| 114 std::vector<gfx::PNGCodec::Comment>(), | 115 blob_builder->build(); |
| 115 &encoded_image); | 116 return blink::WebBlobInfo( |
| 116 data.assign(reinterpret_cast<char*>(encoded_image.data()), | 117 uuid, base::ASCIIToUTF16(ui::Clipboard::kMimeTypePNG), output.size()); |
| 117 encoded_image.size()); | 118 } |
| 118 return data; | 119 |
| 120 blink::WebImage MockWebClipboardImpl::readRawImage( |
| 121 blink::WebClipboard::Buffer buffer) { |
| 122 return m_image; |
| 119 } | 123 } |
| 120 | 124 |
| 121 blink::WebString MockWebClipboardImpl::readCustomData( | 125 blink::WebString MockWebClipboardImpl::readCustomData( |
| 122 blink::WebClipboard::Buffer buffer, | 126 blink::WebClipboard::Buffer buffer, |
| 123 const blink::WebString& type) { | 127 const blink::WebString& type) { |
| 124 std::map<base::string16, base::string16>::const_iterator it = | 128 std::map<base::string16, base::string16>::const_iterator it = |
| 125 m_customData.find(type); | 129 m_customData.find(type); |
| 126 if (it != m_customData.end()) | 130 if (it != m_customData.end()) |
| 127 return it->second; | 131 return it->second; |
| 128 return blink::WebString(); | 132 return blink::WebString(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 | 203 |
| 200 void MockWebClipboardImpl::clear() { | 204 void MockWebClipboardImpl::clear() { |
| 201 m_plainText = base::NullableString16(); | 205 m_plainText = base::NullableString16(); |
| 202 m_htmlText = base::NullableString16(); | 206 m_htmlText = base::NullableString16(); |
| 203 m_image.reset(); | 207 m_image.reset(); |
| 204 m_customData.clear(); | 208 m_customData.clear(); |
| 205 m_writeSmartPaste = false; | 209 m_writeSmartPaste = false; |
| 206 } | 210 } |
| 207 | 211 |
| 208 } // namespace content | 212 } // namespace content |
| OLD | NEW |