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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "content/renderer/clipboard_utils.h" | 13 #include "content/renderer/clipboard_utils.h" |
14 #include "third_party/WebKit/public/platform/WebCommon.h" | 14 #include "third_party/WebKit/public/platform/WebCommon.h" |
15 #include "third_party/WebKit/public/platform/WebDragData.h" | 15 #include "third_party/WebKit/public/platform/WebDragData.h" |
16 #include "third_party/WebKit/public/platform/WebImage.h" | 16 #include "third_party/WebKit/public/platform/WebImage.h" |
17 #include "third_party/WebKit/public/platform/WebURL.h" | 17 #include "third_party/WebKit/public/platform/WebURL.h" |
18 #include "ui/base/clipboard/clipboard.h" | 18 #include "ui/base/clipboard/clipboard.h" |
19 #include "ui/gfx/codec/png_codec.h" | 19 #include "ui/gfx/codec/png_codec.h" |
20 #include "ui/gfx/size.h" | 20 #include "ui/gfx/size.h" |
21 #include "webkit/glue/webkit_glue.h" | 21 #include "webkit/glue/webkit_glue.h" |
22 | 22 |
23 using WebKit::WebDragData; | 23 using blink::WebDragData; |
24 using WebKit::WebString; | 24 using blink::WebString; |
25 using WebKit::WebURL; | 25 using blink::WebURL; |
26 using WebKit::WebVector; | 26 using blink::WebVector; |
27 | 27 |
28 namespace content { | 28 namespace content { |
29 | 29 |
30 MockWebClipboardImpl::MockWebClipboardImpl() {} | 30 MockWebClipboardImpl::MockWebClipboardImpl() {} |
31 | 31 |
32 MockWebClipboardImpl::~MockWebClipboardImpl() {} | 32 MockWebClipboardImpl::~MockWebClipboardImpl() {} |
33 | 33 |
34 bool MockWebClipboardImpl::isFormatAvailable(Format format, Buffer buffer) { | 34 bool MockWebClipboardImpl::isFormatAvailable(Format format, Buffer buffer) { |
35 switch (format) { | 35 switch (format) { |
36 case FormatPlainText: | 36 case FormatPlainText: |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 for (std::map<base::string16, base::string16>::const_iterator it = | 79 for (std::map<base::string16, base::string16>::const_iterator it = |
80 m_customData.begin(); | 80 m_customData.begin(); |
81 it != m_customData.end(); ++it) { | 81 it != m_customData.end(); ++it) { |
82 CHECK(std::find(results.begin(), results.end(), it->first) == | 82 CHECK(std::find(results.begin(), results.end(), it->first) == |
83 results.end()); | 83 results.end()); |
84 results.push_back(it->first); | 84 results.push_back(it->first); |
85 } | 85 } |
86 return results; | 86 return results; |
87 } | 87 } |
88 | 88 |
89 WebKit::WebString MockWebClipboardImpl::readPlainText( | 89 blink::WebString MockWebClipboardImpl::readPlainText( |
90 WebKit::WebClipboard::Buffer buffer) { | 90 blink::WebClipboard::Buffer buffer) { |
91 return m_plainText; | 91 return m_plainText; |
92 } | 92 } |
93 | 93 |
94 // TODO(wtc): set output argument *url. | 94 // TODO(wtc): set output argument *url. |
95 WebKit::WebString MockWebClipboardImpl::readHTML( | 95 blink::WebString MockWebClipboardImpl::readHTML( |
96 WebKit::WebClipboard::Buffer buffer, | 96 blink::WebClipboard::Buffer buffer, |
97 WebKit::WebURL* url, | 97 blink::WebURL* url, |
98 unsigned* fragmentStart, | 98 unsigned* fragmentStart, |
99 unsigned* fragmentEnd) { | 99 unsigned* fragmentEnd) { |
100 *fragmentStart = 0; | 100 *fragmentStart = 0; |
101 *fragmentEnd = static_cast<unsigned>(m_htmlText.length()); | 101 *fragmentEnd = static_cast<unsigned>(m_htmlText.length()); |
102 return m_htmlText; | 102 return m_htmlText; |
103 } | 103 } |
104 | 104 |
105 WebKit::WebData MockWebClipboardImpl::readImage( | 105 blink::WebData MockWebClipboardImpl::readImage( |
106 WebKit::WebClipboard::Buffer buffer) { | 106 blink::WebClipboard::Buffer buffer) { |
107 std::string data; | 107 std::string data; |
108 std::vector<unsigned char> encoded_image; | 108 std::vector<unsigned char> encoded_image; |
109 // TODO(dcheng): Verify that we can assume the image is ARGB8888. Note that | 109 // TODO(dcheng): Verify that we can assume the image is ARGB8888. Note that |
110 // for endianess reasons, it will be BGRA8888 on Windows. | 110 // for endianess reasons, it will be BGRA8888 on Windows. |
111 const SkBitmap& bitmap = m_image.getSkBitmap(); | 111 const SkBitmap& bitmap = m_image.getSkBitmap(); |
112 SkAutoLockPixels lock(bitmap); | 112 SkAutoLockPixels lock(bitmap); |
113 gfx::PNGCodec::Encode(static_cast<unsigned char*>(bitmap.getPixels()), | 113 gfx::PNGCodec::Encode(static_cast<unsigned char*>(bitmap.getPixels()), |
114 #if defined(OS_ANDROID) | 114 #if defined(OS_ANDROID) |
115 gfx::PNGCodec::FORMAT_RGBA, | 115 gfx::PNGCodec::FORMAT_RGBA, |
116 #else | 116 #else |
117 gfx::PNGCodec::FORMAT_BGRA, | 117 gfx::PNGCodec::FORMAT_BGRA, |
118 #endif | 118 #endif |
119 gfx::Size(bitmap.width(), bitmap.height()), | 119 gfx::Size(bitmap.width(), bitmap.height()), |
120 bitmap.rowBytes(), | 120 bitmap.rowBytes(), |
121 false /* discard_transparency */, | 121 false /* discard_transparency */, |
122 std::vector<gfx::PNGCodec::Comment>(), | 122 std::vector<gfx::PNGCodec::Comment>(), |
123 &encoded_image); | 123 &encoded_image); |
124 data.assign(reinterpret_cast<char*>(vector_as_array(&encoded_image)), | 124 data.assign(reinterpret_cast<char*>(vector_as_array(&encoded_image)), |
125 encoded_image.size()); | 125 encoded_image.size()); |
126 return data; | 126 return data; |
127 } | 127 } |
128 | 128 |
129 WebKit::WebString MockWebClipboardImpl::readCustomData( | 129 blink::WebString MockWebClipboardImpl::readCustomData( |
130 WebKit::WebClipboard::Buffer buffer, | 130 blink::WebClipboard::Buffer buffer, |
131 const WebKit::WebString& type) { | 131 const blink::WebString& type) { |
132 std::map<base::string16, base::string16>::const_iterator it = | 132 std::map<base::string16, base::string16>::const_iterator it = |
133 m_customData.find(type); | 133 m_customData.find(type); |
134 if (it != m_customData.end()) | 134 if (it != m_customData.end()) |
135 return it->second; | 135 return it->second; |
136 return WebKit::WebString(); | 136 return blink::WebString(); |
137 } | 137 } |
138 | 138 |
139 void MockWebClipboardImpl::writeHTML(const WebKit::WebString& htmlText, | 139 void MockWebClipboardImpl::writeHTML(const blink::WebString& htmlText, |
140 const WebKit::WebURL& url, | 140 const blink::WebURL& url, |
141 const WebKit::WebString& plainText, | 141 const blink::WebString& plainText, |
142 bool writeSmartPaste) { | 142 bool writeSmartPaste) { |
143 clear(); | 143 clear(); |
144 | 144 |
145 m_htmlText = htmlText; | 145 m_htmlText = htmlText; |
146 m_plainText = plainText; | 146 m_plainText = plainText; |
147 m_writeSmartPaste = writeSmartPaste; | 147 m_writeSmartPaste = writeSmartPaste; |
148 } | 148 } |
149 | 149 |
150 void MockWebClipboardImpl::writePlainText(const WebKit::WebString& plain_text) { | 150 void MockWebClipboardImpl::writePlainText(const blink::WebString& plain_text) { |
151 clear(); | 151 clear(); |
152 | 152 |
153 m_plainText = plain_text; | 153 m_plainText = plain_text; |
154 } | 154 } |
155 | 155 |
156 void MockWebClipboardImpl::writeURL(const WebKit::WebURL& url, | 156 void MockWebClipboardImpl::writeURL(const blink::WebURL& url, |
157 const WebKit::WebString& title) { | 157 const blink::WebString& title) { |
158 clear(); | 158 clear(); |
159 | 159 |
160 m_htmlText = WebString::fromUTF8(URLToMarkup(url, title)); | 160 m_htmlText = WebString::fromUTF8(URLToMarkup(url, title)); |
161 m_plainText = url.spec().utf16(); | 161 m_plainText = url.spec().utf16(); |
162 } | 162 } |
163 | 163 |
164 void MockWebClipboardImpl::writeImage(const WebKit::WebImage& image, | 164 void MockWebClipboardImpl::writeImage(const blink::WebImage& image, |
165 const WebKit::WebURL& url, | 165 const blink::WebURL& url, |
166 const WebKit::WebString& title) { | 166 const blink::WebString& title) { |
167 if (!image.isNull()) { | 167 if (!image.isNull()) { |
168 clear(); | 168 clear(); |
169 | 169 |
170 m_plainText = m_htmlText; | 170 m_plainText = m_htmlText; |
171 m_htmlText = WebString::fromUTF8(URLToImageMarkup(url, title)); | 171 m_htmlText = WebString::fromUTF8(URLToImageMarkup(url, title)); |
172 m_image = image; | 172 m_image = image; |
173 } | 173 } |
174 } | 174 } |
175 | 175 |
176 void MockWebClipboardImpl::writeDataObject(const WebDragData& data) { | 176 void MockWebClipboardImpl::writeDataObject(const WebDragData& data) { |
(...skipping 24 matching lines...) Expand all Loading... |
201 | 201 |
202 void MockWebClipboardImpl::clear() { | 202 void MockWebClipboardImpl::clear() { |
203 m_plainText = WebString(); | 203 m_plainText = WebString(); |
204 m_htmlText = WebString(); | 204 m_htmlText = WebString(); |
205 m_image.reset(); | 205 m_image.reset(); |
206 m_customData.clear(); | 206 m_customData.clear(); |
207 m_writeSmartPaste = false; | 207 m_writeSmartPaste = false; |
208 } | 208 } |
209 | 209 |
210 } // namespace content | 210 } // namespace content |
OLD | NEW |