Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: content/test/mock_webclipboard_impl.cc

Issue 135853010: Fix the WebStrings leak in MockWebClipboardImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use NullableString16 Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/test/mock_webclipboard_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 15 matching lines...) Expand all
26 26
27 namespace content { 27 namespace content {
28 28
29 MockWebClipboardImpl::MockWebClipboardImpl() {} 29 MockWebClipboardImpl::MockWebClipboardImpl() {}
30 30
31 MockWebClipboardImpl::~MockWebClipboardImpl() {} 31 MockWebClipboardImpl::~MockWebClipboardImpl() {}
32 32
33 bool MockWebClipboardImpl::isFormatAvailable(Format format, Buffer buffer) { 33 bool MockWebClipboardImpl::isFormatAvailable(Format format, Buffer buffer) {
34 switch (format) { 34 switch (format) {
35 case FormatPlainText: 35 case FormatPlainText:
36 return !m_plainText.isNull(); 36 return !m_plainText.is_null();
37 37
38 case FormatHTML: 38 case FormatHTML:
39 return !m_htmlText.isNull(); 39 return !m_htmlText.is_null();
40 40
41 case FormatSmartPaste: 41 case FormatSmartPaste:
42 return m_writeSmartPaste; 42 return m_writeSmartPaste;
43 43
44 default: 44 default:
45 NOTREACHED(); 45 NOTREACHED();
46 return false; 46 return false;
47 } 47 }
48 48
49 switch (buffer) { 49 switch (buffer) {
50 case BufferStandard: 50 case BufferStandard:
51 break; 51 break;
52 case BufferSelection: 52 case BufferSelection:
53 #if defined(OS_POSIX) && !defined(OS_MACOSX) 53 #if defined(OS_POSIX) && !defined(OS_MACOSX)
54 break; 54 break;
55 #endif 55 #endif
56 default: 56 default:
57 NOTREACHED(); 57 NOTREACHED();
58 return false; 58 return false;
59 } 59 }
60 60
61 return true; 61 return true;
62 } 62 }
63 63
64 WebVector<WebString> MockWebClipboardImpl::readAvailableTypes( 64 WebVector<WebString> MockWebClipboardImpl::readAvailableTypes(
65 Buffer buffer, 65 Buffer buffer,
66 bool* containsFilenames) { 66 bool* containsFilenames) {
67 *containsFilenames = false; 67 *containsFilenames = false;
68 std::vector<WebString> results; 68 std::vector<WebString> results;
69 if (!m_plainText.isEmpty()) { 69 if (!m_plainText.string().empty()) {
70 results.push_back(WebString("text/plain")); 70 results.push_back(WebString("text/plain"));
71 } 71 }
72 if (!m_htmlText.isEmpty()) { 72 if (!m_htmlText.string().empty()) {
73 results.push_back(WebString("text/html")); 73 results.push_back(WebString("text/html"));
74 } 74 }
75 if (!m_image.isNull()) { 75 if (!m_image.isNull()) {
76 results.push_back(WebString("image/png")); 76 results.push_back(WebString("image/png"));
77 } 77 }
78 for (std::map<base::string16, base::string16>::const_iterator it = 78 for (std::map<base::string16, base::string16>::const_iterator it =
79 m_customData.begin(); 79 m_customData.begin();
80 it != m_customData.end(); ++it) { 80 it != m_customData.end(); ++it) {
81 CHECK(std::find(results.begin(), results.end(), it->first) == 81 CHECK(std::find(results.begin(), results.end(), it->first) ==
82 results.end()); 82 results.end());
83 results.push_back(it->first); 83 results.push_back(it->first);
84 } 84 }
85 return results; 85 return results;
86 } 86 }
87 87
88 blink::WebString MockWebClipboardImpl::readPlainText( 88 blink::WebString MockWebClipboardImpl::readPlainText(
89 blink::WebClipboard::Buffer buffer) { 89 blink::WebClipboard::Buffer buffer) {
90 return m_plainText; 90 return m_plainText;
91 } 91 }
92 92
93 // TODO(wtc): set output argument *url. 93 // TODO(wtc): set output argument *url.
94 blink::WebString MockWebClipboardImpl::readHTML( 94 blink::WebString MockWebClipboardImpl::readHTML(
95 blink::WebClipboard::Buffer buffer, 95 blink::WebClipboard::Buffer buffer,
96 blink::WebURL* url, 96 blink::WebURL* url,
97 unsigned* fragmentStart, 97 unsigned* fragmentStart,
98 unsigned* fragmentEnd) { 98 unsigned* fragmentEnd) {
99 *fragmentStart = 0; 99 *fragmentStart = 0;
100 *fragmentEnd = static_cast<unsigned>(m_htmlText.length()); 100 *fragmentEnd = static_cast<unsigned>(m_htmlText.string().length());
101 return m_htmlText; 101 return m_htmlText;
102 } 102 }
103 103
104 blink::WebData MockWebClipboardImpl::readImage( 104 blink::WebData MockWebClipboardImpl::readImage(
105 blink::WebClipboard::Buffer buffer) { 105 blink::WebClipboard::Buffer buffer) {
106 std::string data; 106 std::string data;
107 std::vector<unsigned char> encoded_image; 107 std::vector<unsigned char> encoded_image;
108 // TODO(dcheng): Verify that we can assume the image is ARGB8888. Note that 108 // TODO(dcheng): Verify that we can assume the image is ARGB8888. Note that
109 // for endianess reasons, it will be BGRA8888 on Windows. 109 // for endianess reasons, it will be BGRA8888 on Windows.
110 const SkBitmap& bitmap = m_image.getSkBitmap(); 110 const SkBitmap& bitmap = m_image.getSkBitmap();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 continue; 192 continue;
193 } 193 }
194 case WebDragData::Item::StorageTypeFilename: 194 case WebDragData::Item::StorageTypeFilename:
195 case WebDragData::Item::StorageTypeBinaryData: 195 case WebDragData::Item::StorageTypeBinaryData:
196 NOTREACHED(); // Currently unused by the clipboard implementation. 196 NOTREACHED(); // Currently unused by the clipboard implementation.
197 } 197 }
198 } 198 }
199 } 199 }
200 200
201 void MockWebClipboardImpl::clear() { 201 void MockWebClipboardImpl::clear() {
202 m_plainText = WebString(); 202 m_plainText = base::NullableString16();
203 m_htmlText = WebString(); 203 m_htmlText = base::NullableString16();
204 m_image.reset(); 204 m_image.reset();
205 m_customData.clear(); 205 m_customData.clear();
206 m_writeSmartPaste = false; 206 m_writeSmartPaste = false;
207 } 207 }
208 208
209 } // namespace content 209 } // namespace content
OLDNEW
« no previous file with comments | « content/test/mock_webclipboard_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698