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

Side by Side Diff: app/clipboard/clipboard_util_win.cc

Issue 2126010: Don't populate WebDropData with file URLs when dragging files. (Closed)
Patch Set: . Created 10 years, 7 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 | « app/clipboard/clipboard_util_win.h ('k') | app/os_exchange_data_provider_win.cc » ('j') | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "app/clipboard/clipboard_util_win.h" 5 #include "app/clipboard/clipboard_util_win.h"
6 6
7 #include <shellapi.h> 7 #include <shellapi.h>
8 #include <shlwapi.h> 8 #include <shlwapi.h>
9 #include <wininet.h> 9 #include <wininet.h>
10 10
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 size_t newline_pos = str.find('\n'); 57 size_t newline_pos = str.find('\n');
58 if (newline_pos != std::wstring::npos) { 58 if (newline_pos != std::wstring::npos) {
59 url->assign(str, 0, newline_pos); 59 url->assign(str, 0, newline_pos);
60 title->assign(str, newline_pos + 1, std::wstring::npos); 60 title->assign(str, newline_pos + 1, std::wstring::npos);
61 } else { 61 } else {
62 url->assign(str); 62 url->assign(str);
63 title->assign(str); 63 title->assign(str);
64 } 64 }
65 } 65 }
66 66
67 bool GetFileUrl(IDataObject* data_object, std::wstring* url,
68 std::wstring* title) {
69 STGMEDIUM store;
70 if (SUCCEEDED(data_object->GetData(ClipboardUtil::GetFilenameWFormat(),
71 &store))) {
72 bool success = false;
73 {
74 // filename using unicode
75 ScopedHGlobal<wchar_t> data(store.hGlobal);
76 if (data.get() && data.get()[0] &&
77 (PathFileExists(data.get()) || PathIsUNC(data.get()))) {
78 wchar_t file_url[INTERNET_MAX_URL_LENGTH];
79 DWORD file_url_len = arraysize(file_url);
80 if (SUCCEEDED(::UrlCreateFromPathW(data.get(), file_url, &file_url_len,
81 0))) {
82 url->assign(file_url);
83 title->assign(file_url);
84 success = true;
85 }
86 }
87 }
88 ReleaseStgMedium(&store);
89 if (success)
90 return true;
91 }
92
93 if (SUCCEEDED(data_object->GetData(ClipboardUtil::GetFilenameFormat(),
94 &store))) {
95 bool success = false;
96 {
97 // filename using ascii
98 ScopedHGlobal<char> data(store.hGlobal);
99 if (data.get() && data.get()[0] && (PathFileExistsA(data.get()) ||
100 PathIsUNCA(data.get()))) {
101 char file_url[INTERNET_MAX_URL_LENGTH];
102 DWORD file_url_len = arraysize(file_url);
103 if (SUCCEEDED(::UrlCreateFromPathA(data.get(), file_url, &file_url_len,
104 0))) {
105 url->assign(UTF8ToWide(file_url));
106 title->assign(*url);
107 success = true;
108 }
109 }
110 }
111 ReleaseStgMedium(&store);
112 if (success)
113 return true;
114 }
115 return false;
116 }
117
67 } // namespace 118 } // namespace
68 119
69 120
70 FORMATETC* ClipboardUtil::GetUrlFormat() { 121 FORMATETC* ClipboardUtil::GetUrlFormat() {
71 static UINT cf = RegisterClipboardFormat(CFSTR_INETURLA); 122 static UINT cf = RegisterClipboardFormat(CFSTR_INETURLA);
72 static FORMATETC format = {cf, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; 123 static FORMATETC format = {cf, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
73 return &format; 124 return &format;
74 } 125 }
75 126
76 FORMATETC* ClipboardUtil::GetUrlWFormat() { 127 FORMATETC* ClipboardUtil::GetUrlWFormat() {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 } 226 }
176 227
177 bool ClipboardUtil::HasPlainText(IDataObject* data_object) { 228 bool ClipboardUtil::HasPlainText(IDataObject* data_object) {
178 DCHECK(data_object); 229 DCHECK(data_object);
179 return SUCCEEDED(data_object->QueryGetData(GetPlainTextWFormat())) || 230 return SUCCEEDED(data_object->QueryGetData(GetPlainTextWFormat())) ||
180 SUCCEEDED(data_object->QueryGetData(GetPlainTextFormat())); 231 SUCCEEDED(data_object->QueryGetData(GetPlainTextFormat()));
181 } 232 }
182 233
183 234
184 bool ClipboardUtil::GetUrl(IDataObject* data_object, 235 bool ClipboardUtil::GetUrl(IDataObject* data_object,
185 std::wstring* url, std::wstring* title) { 236 std::wstring* url, std::wstring* title, bool convert_filenames) {
186 DCHECK(data_object && url && title); 237 DCHECK(data_object && url && title);
187 if (!HasUrl(data_object)) 238 if (!HasUrl(data_object))
188 return false; 239 return false;
189 240
190 // Try to extract a URL from |data_object| in a variety of formats. 241 // Try to extract a URL from |data_object| in a variety of formats.
191 STGMEDIUM store; 242 STGMEDIUM store;
192 if (GetUrlFromHDrop(data_object, url, title)) 243 if (GetUrlFromHDrop(data_object, url, title))
193 return true; 244 return true;
194 245
195 if (SUCCEEDED(data_object->GetData(GetMozUrlFormat(), &store)) || 246 if (SUCCEEDED(data_object->GetData(GetMozUrlFormat(), &store)) ||
(...skipping 10 matching lines...) Expand all
206 if (SUCCEEDED(data_object->GetData(GetUrlFormat(), &store))) { 257 if (SUCCEEDED(data_object->GetData(GetUrlFormat(), &store))) {
207 { 258 {
208 // URL using ascii 259 // URL using ascii
209 ScopedHGlobal<char> data(store.hGlobal); 260 ScopedHGlobal<char> data(store.hGlobal);
210 SplitUrlAndTitle(UTF8ToWide(data.get()), url, title); 261 SplitUrlAndTitle(UTF8ToWide(data.get()), url, title);
211 } 262 }
212 ReleaseStgMedium(&store); 263 ReleaseStgMedium(&store);
213 return true; 264 return true;
214 } 265 }
215 266
216 if (SUCCEEDED(data_object->GetData(GetFilenameWFormat(), &store))) { 267 if (convert_filenames) {
217 bool success = false; 268 return GetFileUrl(data_object, url, title);
218 { 269 } else {
219 // filename using unicode 270 return false;
220 ScopedHGlobal<wchar_t> data(store.hGlobal);
221 if (data.get() && data.get()[0] &&
222 (PathFileExists(data.get()) || PathIsUNC(data.get()))) {
223 wchar_t file_url[INTERNET_MAX_URL_LENGTH];
224 DWORD file_url_len = arraysize(file_url);
225 if (SUCCEEDED(::UrlCreateFromPathW(data.get(), file_url, &file_url_len,
226 0))) {
227 url->assign(file_url);
228 title->assign(file_url);
229 success = true;
230 }
231 }
232 }
233 ReleaseStgMedium(&store);
234 if (success)
235 return true;
236 } 271 }
237
238 if (SUCCEEDED(data_object->GetData(GetFilenameFormat(), &store))) {
239 bool success = false;
240 {
241 // filename using ascii
242 ScopedHGlobal<char> data(store.hGlobal);
243 if (data.get() && data.get()[0] && (PathFileExistsA(data.get()) ||
244 PathIsUNCA(data.get()))) {
245 char file_url[INTERNET_MAX_URL_LENGTH];
246 DWORD file_url_len = arraysize(file_url);
247 if (SUCCEEDED(::UrlCreateFromPathA(data.get(), file_url, &file_url_len,
248 0))) {
249 url->assign(UTF8ToWide(file_url));
250 title->assign(*url);
251 success = true;
252 }
253 }
254 }
255 ReleaseStgMedium(&store);
256 if (success)
257 return true;
258 }
259
260 return false;
261 } 272 }
262 273
263 bool ClipboardUtil::GetFilenames(IDataObject* data_object, 274 bool ClipboardUtil::GetFilenames(IDataObject* data_object,
264 std::vector<std::wstring>* filenames) { 275 std::vector<std::wstring>* filenames) {
265 DCHECK(data_object && filenames); 276 DCHECK(data_object && filenames);
266 if (!HasFilenames(data_object)) 277 if (!HasFilenames(data_object))
267 return false; 278 return false;
268 279
269 STGMEDIUM medium; 280 STGMEDIUM medium;
270 if (FAILED(data_object->GetData(GetCFHDropFormat(), &medium))) 281 if (FAILED(data_object->GetData(GetCFHDropFormat(), &medium)))
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 ScopedHGlobal<char> data(store.hGlobal); 324 ScopedHGlobal<char> data(store.hGlobal);
314 plain_text->assign(UTF8ToWide(data.get())); 325 plain_text->assign(UTF8ToWide(data.get()));
315 } 326 }
316 ReleaseStgMedium(&store); 327 ReleaseStgMedium(&store);
317 return true; 328 return true;
318 } 329 }
319 330
320 // If a file is dropped on the window, it does not provide either of the 331 // If a file is dropped on the window, it does not provide either of the
321 // plain text formats, so here we try to forcibly get a url. 332 // plain text formats, so here we try to forcibly get a url.
322 std::wstring title; 333 std::wstring title;
323 return GetUrl(data_object, plain_text, &title); 334 return GetUrl(data_object, plain_text, &title, false);
324 } 335 }
325 336
326 bool ClipboardUtil::GetHtml(IDataObject* data_object, 337 bool ClipboardUtil::GetHtml(IDataObject* data_object,
327 std::wstring* html, std::string* base_url) { 338 std::wstring* html, std::string* base_url) {
328 DCHECK(data_object && html && base_url); 339 DCHECK(data_object && html && base_url);
329 340
330 STGMEDIUM store; 341 STGMEDIUM store;
331 if (SUCCEEDED(data_object->QueryGetData(GetHtmlFormat())) && 342 if (SUCCEEDED(data_object->QueryGetData(GetHtmlFormat())) &&
332 SUCCEEDED(data_object->GetData(GetHtmlFormat(), &store))) { 343 SUCCEEDED(data_object->GetData(GetHtmlFormat(), &store))) {
333 { 344 {
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 size_t tag_end = cf_html.rfind("<!--EndFragment", std::string::npos); 530 size_t tag_end = cf_html.rfind("<!--EndFragment", std::string::npos);
520 fragment_end = cf_html.rfind('<', tag_end); 531 fragment_end = cf_html.rfind('<', tag_end);
521 } 532 }
522 if (fragment_start != std::string::npos && 533 if (fragment_start != std::string::npos &&
523 fragment_end != std::string::npos) { 534 fragment_end != std::string::npos) {
524 *html = cf_html.substr(fragment_start, fragment_end - fragment_start); 535 *html = cf_html.substr(fragment_start, fragment_end - fragment_start);
525 TrimWhitespace(*html, TRIM_ALL, html); 536 TrimWhitespace(*html, TRIM_ALL, html);
526 } 537 }
527 } 538 }
528 } 539 }
OLDNEW
« no previous file with comments | « app/clipboard/clipboard_util_win.h ('k') | app/os_exchange_data_provider_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698