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" | |
10 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
11 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
13 #include "content/renderer/clipboard_utils.h" | 12 #include "content/renderer/clipboard_utils.h" |
14 #include "third_party/WebKit/public/platform/WebCommon.h" | 13 #include "third_party/WebKit/public/platform/WebCommon.h" |
15 #include "third_party/WebKit/public/platform/WebDragData.h" | 14 #include "third_party/WebKit/public/platform/WebDragData.h" |
16 #include "third_party/WebKit/public/platform/WebImage.h" | 15 #include "third_party/WebKit/public/platform/WebImage.h" |
17 #include "third_party/WebKit/public/platform/WebURL.h" | 16 #include "third_party/WebKit/public/platform/WebURL.h" |
18 #include "ui/base/clipboard/clipboard.h" | 17 #include "ui/base/clipboard/clipboard.h" |
19 #include "ui/gfx/codec/png_codec.h" | 18 #include "ui/gfx/codec/png_codec.h" |
20 #include "ui/gfx/size.h" | 19 #include "ui/gfx/size.h" |
21 | 20 |
22 using blink::WebDragData; | 21 using blink::WebDragData; |
23 using blink::WebString; | 22 using blink::WebString; |
24 using blink::WebURL; | 23 using blink::WebURL; |
25 using blink::WebVector; | 24 using blink::WebVector; |
26 | 25 |
27 namespace content { | 26 namespace content { |
28 | 27 |
29 MockWebClipboardImpl::MockWebClipboardImpl() {} | 28 MockWebClipboardImpl::MockWebClipboardImpl() |
| 29 : m_sequenceNumber(0), |
| 30 m_writeSmartPaste(false) {} |
30 | 31 |
31 MockWebClipboardImpl::~MockWebClipboardImpl() {} | 32 MockWebClipboardImpl::~MockWebClipboardImpl() {} |
32 | 33 |
| 34 uint64_t MockWebClipboardImpl::sequenceNumber(Buffer) { |
| 35 return m_sequenceNumber; |
| 36 } |
| 37 |
33 bool MockWebClipboardImpl::isFormatAvailable(Format format, Buffer buffer) { | 38 bool MockWebClipboardImpl::isFormatAvailable(Format format, Buffer buffer) { |
34 switch (format) { | 39 switch (format) { |
35 case FormatPlainText: | 40 case FormatPlainText: |
36 return !m_plainText.is_null(); | 41 return !m_plainText.is_null(); |
37 | 42 |
38 case FormatHTML: | 43 case FormatHTML: |
39 return !m_htmlText.is_null(); | 44 return !m_htmlText.is_null(); |
40 | 45 |
41 case FormatSmartPaste: | 46 case FormatSmartPaste: |
42 return m_writeSmartPaste; | 47 return m_writeSmartPaste; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 128 |
124 void MockWebClipboardImpl::writeHTML(const blink::WebString& htmlText, | 129 void MockWebClipboardImpl::writeHTML(const blink::WebString& htmlText, |
125 const blink::WebURL& url, | 130 const blink::WebURL& url, |
126 const blink::WebString& plainText, | 131 const blink::WebString& plainText, |
127 bool writeSmartPaste) { | 132 bool writeSmartPaste) { |
128 clear(); | 133 clear(); |
129 | 134 |
130 m_htmlText = htmlText; | 135 m_htmlText = htmlText; |
131 m_plainText = plainText; | 136 m_plainText = plainText; |
132 m_writeSmartPaste = writeSmartPaste; | 137 m_writeSmartPaste = writeSmartPaste; |
| 138 ++m_sequenceNumber; |
133 } | 139 } |
134 | 140 |
135 void MockWebClipboardImpl::writePlainText(const blink::WebString& plain_text) { | 141 void MockWebClipboardImpl::writePlainText(const blink::WebString& plain_text) { |
136 clear(); | 142 clear(); |
137 | 143 |
138 m_plainText = plain_text; | 144 m_plainText = plain_text; |
| 145 ++m_sequenceNumber; |
139 } | 146 } |
140 | 147 |
141 void MockWebClipboardImpl::writeURL(const blink::WebURL& url, | 148 void MockWebClipboardImpl::writeURL(const blink::WebURL& url, |
142 const blink::WebString& title) { | 149 const blink::WebString& title) { |
143 clear(); | 150 clear(); |
144 | 151 |
145 m_htmlText = WebString::fromUTF8(URLToMarkup(url, title)); | 152 m_htmlText = WebString::fromUTF8(URLToMarkup(url, title)); |
146 m_plainText = url.spec().utf16(); | 153 m_plainText = url.spec().utf16(); |
| 154 ++m_sequenceNumber; |
147 } | 155 } |
148 | 156 |
149 void MockWebClipboardImpl::writeImage(const blink::WebImage& image, | 157 void MockWebClipboardImpl::writeImage(const blink::WebImage& image, |
150 const blink::WebURL& url, | 158 const blink::WebURL& url, |
151 const blink::WebString& title) { | 159 const blink::WebString& title) { |
152 if (!image.isNull()) { | 160 if (!image.isNull()) { |
153 clear(); | 161 clear(); |
154 | 162 |
155 m_plainText = m_htmlText; | 163 m_plainText = m_htmlText; |
156 m_htmlText = WebString::fromUTF8(URLToImageMarkup(url, title)); | 164 m_htmlText = WebString::fromUTF8(URLToImageMarkup(url, title)); |
157 m_image = image; | 165 m_image = image; |
| 166 ++m_sequenceNumber; |
158 } | 167 } |
159 } | 168 } |
160 | 169 |
161 void MockWebClipboardImpl::writeDataObject(const WebDragData& data) { | 170 void MockWebClipboardImpl::writeDataObject(const WebDragData& data) { |
162 clear(); | 171 clear(); |
163 | 172 |
164 const WebVector<WebDragData::Item>& itemList = data.items(); | 173 const WebVector<WebDragData::Item>& itemList = data.items(); |
165 for (size_t i = 0; i < itemList.size(); ++i) { | 174 for (size_t i = 0; i < itemList.size(); ++i) { |
166 const WebDragData::Item& item = itemList[i]; | 175 const WebDragData::Item& item = itemList[i]; |
167 switch (item.storageType) { | 176 switch (item.storageType) { |
168 case WebDragData::Item::StorageTypeString: { | 177 case WebDragData::Item::StorageTypeString: { |
| 178 ++m_sequenceNumber; |
169 if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeText)) { | 179 if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeText)) { |
170 m_plainText = item.stringData; | 180 m_plainText = item.stringData; |
171 continue; | 181 continue; |
172 } | 182 } |
173 if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeHTML)) { | 183 if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeHTML)) { |
174 m_htmlText = item.stringData; | 184 m_htmlText = item.stringData; |
175 continue; | 185 continue; |
176 } | 186 } |
177 m_customData.insert(std::make_pair(item.stringType, item.stringData)); | 187 m_customData.insert(std::make_pair(item.stringType, item.stringData)); |
178 continue; | 188 continue; |
179 } | 189 } |
180 default: | 190 default: |
181 // Currently other types are unused by the clipboard implementation. | 191 // Currently other types are unused by the clipboard implementation. |
182 NOTREACHED(); | 192 NOTREACHED(); |
183 } | 193 } |
184 } | 194 } |
185 } | 195 } |
186 | 196 |
187 void MockWebClipboardImpl::clear() { | 197 void MockWebClipboardImpl::clear() { |
188 m_plainText = base::NullableString16(); | 198 m_plainText = base::NullableString16(); |
189 m_htmlText = base::NullableString16(); | 199 m_htmlText = base::NullableString16(); |
190 m_image.reset(); | 200 m_image.reset(); |
191 m_customData.clear(); | 201 m_customData.clear(); |
192 m_writeSmartPaste = false; | 202 m_writeSmartPaste = false; |
193 } | 203 } |
194 | 204 |
195 } // namespace content | 205 } // namespace content |
OLD | NEW |