| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/tools/test_shell/mock_webclipboard_impl.h" | 5 #include "webkit/tools/test_shell/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/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "net/base/escape.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCommon.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCommon.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.
h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.
h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" |
| 17 #include "ui/base/clipboard/clipboard.h" |
| 17 #include "webkit/glue/webclipboard_impl.h" | 18 #include "webkit/glue/webclipboard_impl.h" |
| 18 #include "webkit/glue/webkit_glue.h" | 19 #include "webkit/glue/webkit_glue.h" |
| 19 #include "webkit/support/webkit_support_gfx.h" | 20 #include "webkit/support/webkit_support_gfx.h" |
| 20 | 21 |
| 21 #if WEBKIT_USING_CG | 22 #if WEBKIT_USING_CG |
| 22 #include <ApplicationServices/ApplicationServices.h> | 23 #include <ApplicationServices/ApplicationServices.h> |
| 23 #include <CoreFoundation/CoreFoundation.h> | 24 #include <CoreFoundation/CoreFoundation.h> |
| 24 #endif | 25 #endif |
| 25 | 26 |
| 26 using WebKit::WebDragData; | 27 using WebKit::WebDragData; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 std::vector<WebString> results; | 72 std::vector<WebString> results; |
| 72 if (!m_plainText.isEmpty()) { | 73 if (!m_plainText.isEmpty()) { |
| 73 results.push_back(WebString("text/plain")); | 74 results.push_back(WebString("text/plain")); |
| 74 } | 75 } |
| 75 if (!m_htmlText.isEmpty()) { | 76 if (!m_htmlText.isEmpty()) { |
| 76 results.push_back(WebString("text/html")); | 77 results.push_back(WebString("text/html")); |
| 77 } | 78 } |
| 78 if (!m_image.isNull()) { | 79 if (!m_image.isNull()) { |
| 79 results.push_back(WebString("image/png")); | 80 results.push_back(WebString("image/png")); |
| 80 } | 81 } |
| 81 for (size_t i = 0; i < m_customData.size(); ++i) { | 82 for (std::map<string16, string16>::const_iterator it = m_customData.begin(); |
| 82 CHECK(std::find(results.begin(), results.end(), m_customData[i].type) == | 83 it != m_customData.end(); ++it) { |
| 84 CHECK(std::find(results.begin(), results.end(), it->first) == |
| 83 results.end()); | 85 results.end()); |
| 84 results.push_back(m_customData[i].type); | 86 results.push_back(it->first); |
| 85 } | 87 } |
| 86 return results; | 88 return results; |
| 87 } | 89 } |
| 88 | 90 |
| 89 WebKit::WebString MockWebClipboardImpl::readPlainText( | 91 WebKit::WebString MockWebClipboardImpl::readPlainText( |
| 90 WebKit::WebClipboard::Buffer buffer) { | 92 WebKit::WebClipboard::Buffer buffer) { |
| 91 return m_plainText; | 93 return m_plainText; |
| 92 } | 94 } |
| 93 | 95 |
| 94 // TODO(wtc): set output argument *url. | 96 // TODO(wtc): set output argument *url. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 CFRelease(image_data_ref); | 130 CFRelease(image_data_ref); |
| 129 #endif | 131 #endif |
| 130 data.assign(reinterpret_cast<char*>(vector_as_array(&encoded_image)), | 132 data.assign(reinterpret_cast<char*>(vector_as_array(&encoded_image)), |
| 131 encoded_image.size()); | 133 encoded_image.size()); |
| 132 return data; | 134 return data; |
| 133 } | 135 } |
| 134 | 136 |
| 135 WebKit::WebString MockWebClipboardImpl::readCustomData( | 137 WebKit::WebString MockWebClipboardImpl::readCustomData( |
| 136 WebKit::WebClipboard::Buffer buffer, | 138 WebKit::WebClipboard::Buffer buffer, |
| 137 const WebKit::WebString& type) { | 139 const WebKit::WebString& type) { |
| 138 for (size_t i = 0; i < m_customData.size(); ++i) { | 140 std::map<string16, string16>::const_iterator it = m_customData.find(type); |
| 139 if (m_customData[i].type == type) { | 141 if (it != m_customData.end()) |
| 140 return m_customData[i].data; | 142 return it->second; |
| 141 } | |
| 142 } | |
| 143 return WebKit::WebString(); | 143 return WebKit::WebString(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 void MockWebClipboardImpl::writeHTML( | 146 void MockWebClipboardImpl::writeHTML( |
| 147 const WebKit::WebString& htmlText, const WebKit::WebURL& url, | 147 const WebKit::WebString& htmlText, const WebKit::WebURL& url, |
| 148 const WebKit::WebString& plainText, bool writeSmartPaste) { | 148 const WebKit::WebString& plainText, bool writeSmartPaste) { |
| 149 clear(); |
| 150 |
| 149 m_htmlText = htmlText; | 151 m_htmlText = htmlText; |
| 150 m_plainText = plainText; | 152 m_plainText = plainText; |
| 151 m_image.reset(); | |
| 152 m_customData = WebVector<WebDragData::CustomData>(); | |
| 153 m_writeSmartPaste = writeSmartPaste; | 153 m_writeSmartPaste = writeSmartPaste; |
| 154 } | 154 } |
| 155 | 155 |
| 156 void MockWebClipboardImpl::writePlainText(const WebKit::WebString& plain_text) { | 156 void MockWebClipboardImpl::writePlainText(const WebKit::WebString& plain_text) { |
| 157 m_htmlText = WebKit::WebString(); | 157 clear(); |
| 158 |
| 158 m_plainText = plain_text; | 159 m_plainText = plain_text; |
| 159 m_image.reset(); | |
| 160 m_customData = WebVector<WebDragData::CustomData>(); | |
| 161 m_writeSmartPaste = false; | |
| 162 } | 160 } |
| 163 | 161 |
| 164 void MockWebClipboardImpl::writeURL( | 162 void MockWebClipboardImpl::writeURL( |
| 165 const WebKit::WebURL& url, const WebKit::WebString& title) { | 163 const WebKit::WebURL& url, const WebKit::WebString& title) { |
| 164 clear(); |
| 165 |
| 166 m_htmlText = WebString::fromUTF8( | 166 m_htmlText = WebString::fromUTF8( |
| 167 webkit_glue::WebClipboardImpl::URLToMarkup(url, title)); | 167 webkit_glue::WebClipboardImpl::URLToMarkup(url, title)); |
| 168 m_plainText = url.spec().utf16(); | 168 m_plainText = url.spec().utf16(); |
| 169 m_image.reset(); | |
| 170 m_customData = WebVector<WebDragData::CustomData>(); | |
| 171 m_writeSmartPaste = false; | |
| 172 } | 169 } |
| 173 | 170 |
| 174 void MockWebClipboardImpl::writeImage(const WebKit::WebImage& image, | 171 void MockWebClipboardImpl::writeImage(const WebKit::WebImage& image, |
| 175 const WebKit::WebURL& url, const WebKit::WebString& title) { | 172 const WebKit::WebURL& url, const WebKit::WebString& title) { |
| 176 if (!image.isNull()) { | 173 if (!image.isNull()) { |
| 174 clear(); |
| 175 |
| 176 m_plainText = m_htmlText; |
| 177 m_htmlText = WebString::fromUTF8( | 177 m_htmlText = WebString::fromUTF8( |
| 178 webkit_glue::WebClipboardImpl::URLToImageMarkup(url, title)); | 178 webkit_glue::WebClipboardImpl::URLToImageMarkup(url, title)); |
| 179 m_plainText = m_htmlText; | |
| 180 m_image = image; | 179 m_image = image; |
| 181 m_customData = WebVector<WebDragData::CustomData>(); | |
| 182 m_writeSmartPaste = false; | |
| 183 } | 180 } |
| 184 } | 181 } |
| 185 | 182 |
| 186 void MockWebClipboardImpl::writeDataObject(const WebKit::WebDragData& data) { | 183 void MockWebClipboardImpl::writeDataObject(const WebDragData& data) { |
| 187 m_htmlText = data.htmlText(); | 184 clear(); |
| 188 m_plainText = data.plainText(); | 185 |
| 186 const WebVector<WebDragData::Item>& itemList = data.items(); |
| 187 for (size_t i = 0; i < itemList.size(); ++i) { |
| 188 const WebDragData::Item& item = itemList[i]; |
| 189 switch (item.storageType) { |
| 190 case WebDragData::Item::StorageTypeString: { |
| 191 if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeText)) { |
| 192 m_plainText = item.stringData; |
| 193 continue; |
| 194 } |
| 195 if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeHTML)) { |
| 196 m_htmlText = item.stringData; |
| 197 continue; |
| 198 } |
| 199 m_customData.insert(std::make_pair(item.stringType, item.stringData)); |
| 200 continue; |
| 201 } |
| 202 case WebDragData::Item::StorageTypeFilename: |
| 203 case WebDragData::Item::StorageTypeBinaryData: |
| 204 NOTREACHED(); // Currently unused by the clipboard implementation. |
| 205 } |
| 206 } |
| 207 } |
| 208 |
| 209 void MockWebClipboardImpl::clear() { |
| 210 m_plainText = WebString(); |
| 211 m_htmlText = WebString(); |
| 189 m_image.reset(); | 212 m_image.reset(); |
| 190 m_customData = data.customData(); | 213 m_customData.clear(); |
| 191 m_writeSmartPaste = false; | 214 m_writeSmartPaste = false; |
| 192 } | 215 } |
| OLD | NEW |