| 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 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 } | 68 } |
| 69 if (!m_htmlText.string().empty()) { | 69 if (!m_htmlText.string().empty()) { |
| 70 results.push_back(WebString("text/html")); | 70 results.push_back(WebString("text/html")); |
| 71 } | 71 } |
| 72 if (!m_image.isNull()) { | 72 if (!m_image.isNull()) { |
| 73 results.push_back(WebString("image/png")); | 73 results.push_back(WebString("image/png")); |
| 74 } | 74 } |
| 75 for (std::map<base::string16, base::string16>::const_iterator it = | 75 for (std::map<base::string16, base::string16>::const_iterator it = |
| 76 m_customData.begin(); | 76 m_customData.begin(); |
| 77 it != m_customData.end(); ++it) { | 77 it != m_customData.end(); ++it) { |
| 78 CHECK(std::find(results.begin(), results.end(), it->first) == | 78 CHECK(std::find(results.begin(), results.end(), |
| 79 results.end()); | 79 WebString::fromUTF16(it->first)) == results.end()); |
| 80 results.push_back(it->first); | 80 results.push_back(WebString::fromUTF16(it->first)); |
| 81 } | 81 } |
| 82 return results; | 82 return results; |
| 83 } | 83 } |
| 84 | 84 |
| 85 blink::WebString MockWebClipboardImpl::readPlainText( | 85 blink::WebString MockWebClipboardImpl::readPlainText( |
| 86 blink::WebClipboard::Buffer buffer) { | 86 blink::WebClipboard::Buffer buffer) { |
| 87 return m_plainText; | 87 return WebString::fromUTF16(m_plainText); |
| 88 } | 88 } |
| 89 | 89 |
| 90 // TODO(wtc): set output argument *url. | 90 // TODO(wtc): set output argument *url. |
| 91 blink::WebString MockWebClipboardImpl::readHTML( | 91 blink::WebString MockWebClipboardImpl::readHTML( |
| 92 blink::WebClipboard::Buffer buffer, | 92 blink::WebClipboard::Buffer buffer, |
| 93 blink::WebURL* url, | 93 blink::WebURL* url, |
| 94 unsigned* fragmentStart, | 94 unsigned* fragmentStart, |
| 95 unsigned* fragmentEnd) { | 95 unsigned* fragmentEnd) { |
| 96 *fragmentStart = 0; | 96 *fragmentStart = 0; |
| 97 *fragmentEnd = static_cast<unsigned>(m_htmlText.string().length()); | 97 *fragmentEnd = static_cast<unsigned>(m_htmlText.string().length()); |
| 98 return m_htmlText; | 98 return WebString::fromUTF16(m_htmlText); |
| 99 } | 99 } |
| 100 | 100 |
| 101 blink::WebBlobInfo MockWebClipboardImpl::readImage( | 101 blink::WebBlobInfo MockWebClipboardImpl::readImage( |
| 102 blink::WebClipboard::Buffer buffer) { | 102 blink::WebClipboard::Buffer buffer) { |
| 103 std::vector<unsigned char> output; | 103 std::vector<unsigned char> output; |
| 104 const SkBitmap& bitmap = m_image.getSkBitmap(); | 104 const SkBitmap& bitmap = m_image.getSkBitmap(); |
| 105 if (!gfx::PNGCodec::FastEncodeBGRASkBitmap( | 105 if (!gfx::PNGCodec::FastEncodeBGRASkBitmap( |
| 106 bitmap, false /* discard_transparency */, &output)) { | 106 bitmap, false /* discard_transparency */, &output)) { |
| 107 return blink::WebBlobInfo(); | 107 return blink::WebBlobInfo(); |
| 108 } | 108 } |
| 109 const WebString& uuid = base::ASCIIToUTF16(base::GenerateGUID()); | 109 const WebString& uuid = WebString::fromASCII(base::GenerateGUID()); |
| 110 std::unique_ptr<blink::WebBlobRegistry::Builder> blob_builder( | 110 std::unique_ptr<blink::WebBlobRegistry::Builder> blob_builder( |
| 111 blink::Platform::current()->getBlobRegistry()->createBuilder( | 111 blink::Platform::current()->getBlobRegistry()->createBuilder( |
| 112 uuid, blink::WebString())); | 112 uuid, blink::WebString())); |
| 113 blob_builder->appendData(blink::WebThreadSafeData( | 113 blob_builder->appendData(blink::WebThreadSafeData( |
| 114 reinterpret_cast<char*>(output.data()), output.size())); | 114 reinterpret_cast<char*>(output.data()), output.size())); |
| 115 blob_builder->build(); | 115 blob_builder->build(); |
| 116 return blink::WebBlobInfo( | 116 return blink::WebBlobInfo( |
| 117 uuid, base::ASCIIToUTF16(ui::Clipboard::kMimeTypePNG), output.size()); | 117 uuid, WebString::fromASCII(ui::Clipboard::kMimeTypePNG), output.size()); |
| 118 } | 118 } |
| 119 | 119 |
| 120 blink::WebImage MockWebClipboardImpl::readRawImage( | 120 blink::WebImage MockWebClipboardImpl::readRawImage( |
| 121 blink::WebClipboard::Buffer buffer) { | 121 blink::WebClipboard::Buffer buffer) { |
| 122 return m_image; | 122 return m_image; |
| 123 } | 123 } |
| 124 | 124 |
| 125 blink::WebString MockWebClipboardImpl::readCustomData( | 125 blink::WebString MockWebClipboardImpl::readCustomData( |
| 126 blink::WebClipboard::Buffer buffer, | 126 blink::WebClipboard::Buffer buffer, |
| 127 const blink::WebString& type) { | 127 const blink::WebString& type) { |
| 128 std::map<base::string16, base::string16>::const_iterator it = | 128 std::map<base::string16, base::string16>::const_iterator it = |
| 129 m_customData.find(type); | 129 m_customData.find(type.utf16()); |
| 130 if (it != m_customData.end()) | 130 if (it != m_customData.end()) |
| 131 return it->second; | 131 return WebString::fromUTF16(it->second); |
| 132 return blink::WebString(); | 132 return blink::WebString(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void MockWebClipboardImpl::writeHTML(const blink::WebString& htmlText, | 135 void MockWebClipboardImpl::writeHTML(const blink::WebString& htmlText, |
| 136 const blink::WebURL& url, | 136 const blink::WebURL& url, |
| 137 const blink::WebString& plainText, | 137 const blink::WebString& plainText, |
| 138 bool writeSmartPaste) { | 138 bool writeSmartPaste) { |
| 139 clear(); | 139 clear(); |
| 140 | 140 |
| 141 m_htmlText = htmlText; | 141 m_htmlText = WebString::toNullableString16(htmlText); |
| 142 m_plainText = plainText; | 142 m_plainText = WebString::toNullableString16(plainText); |
| 143 m_writeSmartPaste = writeSmartPaste; | 143 m_writeSmartPaste = writeSmartPaste; |
| 144 ++m_sequenceNumber; | 144 ++m_sequenceNumber; |
| 145 } | 145 } |
| 146 | 146 |
| 147 void MockWebClipboardImpl::writePlainText(const blink::WebString& plain_text) { | 147 void MockWebClipboardImpl::writePlainText(const blink::WebString& plain_text) { |
| 148 clear(); | 148 clear(); |
| 149 | 149 |
| 150 m_plainText = plain_text; | 150 m_plainText = WebString::toNullableString16(plain_text); |
| 151 ++m_sequenceNumber; | 151 ++m_sequenceNumber; |
| 152 } | 152 } |
| 153 | 153 |
| 154 void MockWebClipboardImpl::writeURL(const blink::WebURL& url, | 154 void MockWebClipboardImpl::writeURL(const blink::WebURL& url, |
| 155 const blink::WebString& title) { | 155 const blink::WebString& title) { |
| 156 clear(); | 156 clear(); |
| 157 | 157 |
| 158 m_htmlText = WebString::fromUTF8(URLToMarkup(url, title)); | 158 m_htmlText = base::NullableString16( |
| 159 m_plainText = url.string(); | 159 base::UTF8ToUTF16(URLToMarkup(url, title)), false /* is_null */); |
| 160 m_plainText = WebString::toNullableString16(url.string()); |
| 160 ++m_sequenceNumber; | 161 ++m_sequenceNumber; |
| 161 } | 162 } |
| 162 | 163 |
| 163 void MockWebClipboardImpl::writeImage(const blink::WebImage& image, | 164 void MockWebClipboardImpl::writeImage(const blink::WebImage& image, |
| 164 const blink::WebURL& url, | 165 const blink::WebURL& url, |
| 165 const blink::WebString& title) { | 166 const blink::WebString& title) { |
| 166 if (!image.isNull()) { | 167 if (!image.isNull()) { |
| 167 clear(); | 168 clear(); |
| 168 | 169 |
| 169 m_plainText = m_htmlText; | 170 m_plainText = m_htmlText; |
| 170 m_htmlText = WebString::fromUTF8(URLToImageMarkup(url, title)); | 171 m_htmlText = base::NullableString16( |
| 172 base::UTF8ToUTF16(URLToImageMarkup(url, title)), false /* is_null */); |
| 171 m_image = image; | 173 m_image = image; |
| 172 ++m_sequenceNumber; | 174 ++m_sequenceNumber; |
| 173 } | 175 } |
| 174 } | 176 } |
| 175 | 177 |
| 176 void MockWebClipboardImpl::writeDataObject(const WebDragData& data) { | 178 void MockWebClipboardImpl::writeDataObject(const WebDragData& data) { |
| 177 clear(); | 179 clear(); |
| 178 | 180 |
| 179 const WebVector<WebDragData::Item>& itemList = data.items(); | 181 const WebVector<WebDragData::Item>& itemList = data.items(); |
| 180 for (size_t i = 0; i < itemList.size(); ++i) { | 182 for (size_t i = 0; i < itemList.size(); ++i) { |
| 181 const WebDragData::Item& item = itemList[i]; | 183 const WebDragData::Item& item = itemList[i]; |
| 182 switch (item.storageType) { | 184 switch (item.storageType) { |
| 183 case WebDragData::Item::StorageTypeString: { | 185 case WebDragData::Item::StorageTypeString: { |
| 184 ++m_sequenceNumber; | 186 ++m_sequenceNumber; |
| 185 base::string16 type(item.stringType); | 187 base::string16 type(item.stringType.utf16()); |
| 186 if (base::EqualsASCII(type, ui::Clipboard::kMimeTypeText)) { | 188 if (base::EqualsASCII(type, ui::Clipboard::kMimeTypeText)) { |
| 187 m_plainText = item.stringData; | 189 m_plainText = WebString::toNullableString16(item.stringData); |
| 188 continue; | 190 continue; |
| 189 } | 191 } |
| 190 if (base::EqualsASCII(type, ui::Clipboard::kMimeTypeHTML)) { | 192 if (base::EqualsASCII(type, ui::Clipboard::kMimeTypeHTML)) { |
| 191 m_htmlText = item.stringData; | 193 m_htmlText = WebString::toNullableString16(item.stringData); |
| 192 continue; | 194 continue; |
| 193 } | 195 } |
| 194 m_customData.insert(std::make_pair(type, item.stringData)); | 196 m_customData.insert(std::make_pair(type, item.stringData.utf16())); |
| 195 continue; | 197 continue; |
| 196 } | 198 } |
| 197 default: | 199 default: |
| 198 // Currently other types are unused by the clipboard implementation. | 200 // Currently other types are unused by the clipboard implementation. |
| 199 NOTREACHED(); | 201 NOTREACHED(); |
| 200 } | 202 } |
| 201 } | 203 } |
| 202 } | 204 } |
| 203 | 205 |
| 204 void MockWebClipboardImpl::clear() { | 206 void MockWebClipboardImpl::clear() { |
| 205 m_plainText = base::NullableString16(); | 207 m_plainText = base::NullableString16(); |
| 206 m_htmlText = base::NullableString16(); | 208 m_htmlText = base::NullableString16(); |
| 207 m_image.reset(); | 209 m_image.reset(); |
| 208 m_customData.clear(); | 210 m_customData.clear(); |
| 209 m_writeSmartPaste = false; | 211 m_writeSmartPaste = false; |
| 210 } | 212 } |
| 211 | 213 |
| 212 } // namespace content | 214 } // namespace content |
| OLD | NEW |