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

Side by Side Diff: content/renderer/webclipboard_impl.cc

Issue 2658573003: Use explicit WebString conversions in clipboard and drag-and-drop code (Closed)
Patch Set: Created 3 years, 11 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/renderer/drop_data_builder.cc ('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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/renderer/webclipboard_impl.h" 5 #include "content/renderer/webclipboard_impl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 return false; 73 return false;
74 } 74 }
75 75
76 WebVector<WebString> WebClipboardImpl::readAvailableTypes( 76 WebVector<WebString> WebClipboardImpl::readAvailableTypes(
77 Buffer buffer, bool* contains_filenames) { 77 Buffer buffer, bool* contains_filenames) {
78 ui::ClipboardType clipboard_type; 78 ui::ClipboardType clipboard_type;
79 std::vector<base::string16> types; 79 std::vector<base::string16> types;
80 if (ConvertBufferType(buffer, &clipboard_type)) { 80 if (ConvertBufferType(buffer, &clipboard_type)) {
81 delegate_->ReadAvailableTypes(clipboard_type, &types, contains_filenames); 81 delegate_->ReadAvailableTypes(clipboard_type, &types, contains_filenames);
82 } 82 }
83 return types; 83 WebVector<WebString> web_types(types.size());
84 std::transform(
85 types.begin(), types.end(), web_types.begin(),
86 [](const base::string16& s) { return WebString::fromUTF16(s); });
87 return web_types;
84 } 88 }
85 89
86 WebString WebClipboardImpl::readPlainText(Buffer buffer) { 90 WebString WebClipboardImpl::readPlainText(Buffer buffer) {
87 ui::ClipboardType clipboard_type; 91 ui::ClipboardType clipboard_type;
88 if (!ConvertBufferType(buffer, &clipboard_type)) 92 if (!ConvertBufferType(buffer, &clipboard_type))
89 return WebString(); 93 return WebString();
90 94
91 base::string16 text; 95 base::string16 text;
92 delegate_->ReadText(clipboard_type, &text); 96 delegate_->ReadText(clipboard_type, &text);
93 return text; 97 return WebString::fromUTF16(text);
94 } 98 }
95 99
96 WebString WebClipboardImpl::readHTML(Buffer buffer, WebURL* source_url, 100 WebString WebClipboardImpl::readHTML(Buffer buffer, WebURL* source_url,
97 unsigned* fragment_start, 101 unsigned* fragment_start,
98 unsigned* fragment_end) { 102 unsigned* fragment_end) {
99 ui::ClipboardType clipboard_type; 103 ui::ClipboardType clipboard_type;
100 if (!ConvertBufferType(buffer, &clipboard_type)) 104 if (!ConvertBufferType(buffer, &clipboard_type))
101 return WebString(); 105 return WebString();
102 106
103 base::string16 html_stdstr; 107 base::string16 html_stdstr;
104 GURL gurl; 108 GURL gurl;
105 delegate_->ReadHTML(clipboard_type, &html_stdstr, &gurl, 109 delegate_->ReadHTML(clipboard_type, &html_stdstr, &gurl,
106 static_cast<uint32_t*>(fragment_start), 110 static_cast<uint32_t*>(fragment_start),
107 static_cast<uint32_t*>(fragment_end)); 111 static_cast<uint32_t*>(fragment_end));
108 *source_url = gurl; 112 *source_url = gurl;
109 return html_stdstr; 113 return WebString::fromUTF16(html_stdstr);
110 } 114 }
111 115
112 WebString WebClipboardImpl::readRTF(Buffer buffer) { 116 WebString WebClipboardImpl::readRTF(Buffer buffer) {
113 ui::ClipboardType clipboard_type; 117 ui::ClipboardType clipboard_type;
114 if (!ConvertBufferType(buffer, &clipboard_type)) 118 if (!ConvertBufferType(buffer, &clipboard_type))
115 return WebString(); 119 return WebString();
116 120
117 std::string rtf; 121 std::string rtf;
118 delegate_->ReadRTF(clipboard_type, &rtf); 122 delegate_->ReadRTF(clipboard_type, &rtf);
119 return WebString::fromLatin1(rtf); 123 return WebString::fromLatin1(rtf);
(...skipping 14 matching lines...) Expand all
134 size); 138 size);
135 } 139 }
136 140
137 WebString WebClipboardImpl::readCustomData(Buffer buffer, 141 WebString WebClipboardImpl::readCustomData(Buffer buffer,
138 const WebString& type) { 142 const WebString& type) {
139 ui::ClipboardType clipboard_type; 143 ui::ClipboardType clipboard_type;
140 if (!ConvertBufferType(buffer, &clipboard_type)) 144 if (!ConvertBufferType(buffer, &clipboard_type))
141 return WebString(); 145 return WebString();
142 146
143 base::string16 data; 147 base::string16 data;
144 delegate_->ReadCustomData(clipboard_type, type, &data); 148 delegate_->ReadCustomData(clipboard_type, type.utf16(), &data);
145 return data; 149 return WebString::fromUTF16(data);
146 } 150 }
147 151
148 void WebClipboardImpl::writePlainText(const WebString& plain_text) { 152 void WebClipboardImpl::writePlainText(const WebString& plain_text) {
149 delegate_->WriteText(ui::CLIPBOARD_TYPE_COPY_PASTE, plain_text); 153 delegate_->WriteText(ui::CLIPBOARD_TYPE_COPY_PASTE, plain_text.utf16());
150 delegate_->CommitWrite(ui::CLIPBOARD_TYPE_COPY_PASTE); 154 delegate_->CommitWrite(ui::CLIPBOARD_TYPE_COPY_PASTE);
151 } 155 }
152 156
153 void WebClipboardImpl::writeHTML( 157 void WebClipboardImpl::writeHTML(
154 const WebString& html_text, const WebURL& source_url, 158 const WebString& html_text, const WebURL& source_url,
155 const WebString& plain_text, bool write_smart_paste) { 159 const WebString& plain_text, bool write_smart_paste) {
156 delegate_->WriteHTML(ui::CLIPBOARD_TYPE_COPY_PASTE, html_text, source_url); 160 delegate_->WriteHTML(ui::CLIPBOARD_TYPE_COPY_PASTE, html_text.utf16(),
157 delegate_->WriteText(ui::CLIPBOARD_TYPE_COPY_PASTE, plain_text); 161 source_url);
162 delegate_->WriteText(ui::CLIPBOARD_TYPE_COPY_PASTE, plain_text.utf16());
158 163
159 if (write_smart_paste) 164 if (write_smart_paste)
160 delegate_->WriteSmartPasteMarker(ui::CLIPBOARD_TYPE_COPY_PASTE); 165 delegate_->WriteSmartPasteMarker(ui::CLIPBOARD_TYPE_COPY_PASTE);
161 delegate_->CommitWrite(ui::CLIPBOARD_TYPE_COPY_PASTE); 166 delegate_->CommitWrite(ui::CLIPBOARD_TYPE_COPY_PASTE);
162 } 167 }
163 168
164 void WebClipboardImpl::writeImage(const WebImage& image, 169 void WebClipboardImpl::writeImage(const WebImage& image,
165 const WebURL& url, 170 const WebURL& url,
166 const WebString& title) { 171 const WebString& title) {
167 DCHECK(!image.isNull()); 172 DCHECK(!image.isNull());
168 const SkBitmap& bitmap = image.getSkBitmap(); 173 const SkBitmap& bitmap = image.getSkBitmap();
169 if (!delegate_->WriteImage(ui::CLIPBOARD_TYPE_COPY_PASTE, bitmap)) 174 if (!delegate_->WriteImage(ui::CLIPBOARD_TYPE_COPY_PASTE, bitmap))
170 return; 175 return;
171 176
172 if (!url.isEmpty()) { 177 if (!url.isEmpty()) {
173 delegate_->WriteBookmark(ui::CLIPBOARD_TYPE_COPY_PASTE, url, title); 178 delegate_->WriteBookmark(ui::CLIPBOARD_TYPE_COPY_PASTE, url, title.utf16());
174 #if !defined(OS_MACOSX) 179 #if !defined(OS_MACOSX)
175 // When writing the image, we also write the image markup so that pasting 180 // When writing the image, we also write the image markup so that pasting
176 // into rich text editors, such as Gmail, reveals the image. We also don't 181 // into rich text editors, such as Gmail, reveals the image. We also don't
177 // want to call writeText(), since some applications (WordPad) don't pick 182 // want to call writeText(), since some applications (WordPad) don't pick
178 // the image if there is also a text format on the clipboard. 183 // the image if there is also a text format on the clipboard.
179 // We also don't want to write HTML on a Mac, since Mail.app prefers to use 184 // We also don't want to write HTML on a Mac, since Mail.app prefers to use
180 // the image markup over attaching the actual image. See 185 // the image markup over attaching the actual image. See
181 // http://crbug.com/33016 for details. 186 // http://crbug.com/33016 for details.
182 delegate_->WriteHTML(ui::CLIPBOARD_TYPE_COPY_PASTE, 187 delegate_->WriteHTML(ui::CLIPBOARD_TYPE_COPY_PASTE,
183 base::UTF8ToUTF16(URLToImageMarkup(url, title)), 188 base::UTF8ToUTF16(URLToImageMarkup(url, title)),
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 return false; 227 return false;
223 #endif 228 #endif
224 default: 229 default:
225 NOTREACHED(); 230 NOTREACHED();
226 return false; 231 return false;
227 } 232 }
228 return true; 233 return true;
229 } 234 }
230 235
231 } // namespace content 236 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/drop_data_builder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698