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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: app/clipboard/clipboard_util_win.cc
diff --git a/app/clipboard/clipboard_util_win.cc b/app/clipboard/clipboard_util_win.cc
index 355e8d93e65adfdfdea529ea1c92a8ecc7a3389a..2ed724128880e23272078bc3be04d265a7944ef7 100644
--- a/app/clipboard/clipboard_util_win.cc
+++ b/app/clipboard/clipboard_util_win.cc
@@ -64,6 +64,57 @@ void SplitUrlAndTitle(const std::wstring& str,
}
}
+bool GetFileUrl(IDataObject* data_object, std::wstring* url,
+ std::wstring* title) {
+ STGMEDIUM store;
+ if (SUCCEEDED(data_object->GetData(ClipboardUtil::GetFilenameWFormat(),
+ &store))) {
+ bool success = false;
+ {
+ // filename using unicode
+ ScopedHGlobal<wchar_t> data(store.hGlobal);
+ if (data.get() && data.get()[0] &&
+ (PathFileExists(data.get()) || PathIsUNC(data.get()))) {
+ wchar_t file_url[INTERNET_MAX_URL_LENGTH];
+ DWORD file_url_len = arraysize(file_url);
+ if (SUCCEEDED(::UrlCreateFromPathW(data.get(), file_url, &file_url_len,
+ 0))) {
+ url->assign(file_url);
+ title->assign(file_url);
+ success = true;
+ }
+ }
+ }
+ ReleaseStgMedium(&store);
+ if (success)
+ return true;
+ }
+
+ if (SUCCEEDED(data_object->GetData(ClipboardUtil::GetFilenameFormat(),
+ &store))) {
+ bool success = false;
+ {
+ // filename using ascii
+ ScopedHGlobal<char> data(store.hGlobal);
+ if (data.get() && data.get()[0] && (PathFileExistsA(data.get()) ||
+ PathIsUNCA(data.get()))) {
+ char file_url[INTERNET_MAX_URL_LENGTH];
+ DWORD file_url_len = arraysize(file_url);
+ if (SUCCEEDED(::UrlCreateFromPathA(data.get(), file_url, &file_url_len,
+ 0))) {
+ url->assign(UTF8ToWide(file_url));
+ title->assign(*url);
+ success = true;
+ }
+ }
+ }
+ ReleaseStgMedium(&store);
+ if (success)
+ return true;
+ }
+ return false;
+}
+
} // namespace
@@ -182,7 +233,7 @@ bool ClipboardUtil::HasPlainText(IDataObject* data_object) {
bool ClipboardUtil::GetUrl(IDataObject* data_object,
- std::wstring* url, std::wstring* title) {
+ std::wstring* url, std::wstring* title, bool convert_filenames) {
DCHECK(data_object && url && title);
if (!HasUrl(data_object))
return false;
@@ -213,51 +264,11 @@ bool ClipboardUtil::GetUrl(IDataObject* data_object,
return true;
}
- if (SUCCEEDED(data_object->GetData(GetFilenameWFormat(), &store))) {
- bool success = false;
- {
- // filename using unicode
- ScopedHGlobal<wchar_t> data(store.hGlobal);
- if (data.get() && data.get()[0] &&
- (PathFileExists(data.get()) || PathIsUNC(data.get()))) {
- wchar_t file_url[INTERNET_MAX_URL_LENGTH];
- DWORD file_url_len = arraysize(file_url);
- if (SUCCEEDED(::UrlCreateFromPathW(data.get(), file_url, &file_url_len,
- 0))) {
- url->assign(file_url);
- title->assign(file_url);
- success = true;
- }
- }
- }
- ReleaseStgMedium(&store);
- if (success)
- return true;
- }
-
- if (SUCCEEDED(data_object->GetData(GetFilenameFormat(), &store))) {
- bool success = false;
- {
- // filename using ascii
- ScopedHGlobal<char> data(store.hGlobal);
- if (data.get() && data.get()[0] && (PathFileExistsA(data.get()) ||
- PathIsUNCA(data.get()))) {
- char file_url[INTERNET_MAX_URL_LENGTH];
- DWORD file_url_len = arraysize(file_url);
- if (SUCCEEDED(::UrlCreateFromPathA(data.get(), file_url, &file_url_len,
- 0))) {
- url->assign(UTF8ToWide(file_url));
- title->assign(*url);
- success = true;
- }
- }
- }
- ReleaseStgMedium(&store);
- if (success)
- return true;
+ if (convert_filenames) {
+ return GetFileUrl(data_object, url, title);
+ } else {
+ return false;
}
-
- return false;
}
bool ClipboardUtil::GetFilenames(IDataObject* data_object,
@@ -320,7 +331,7 @@ bool ClipboardUtil::GetPlainText(IDataObject* data_object,
// If a file is dropped on the window, it does not provide either of the
// plain text formats, so here we try to forcibly get a url.
std::wstring title;
- return GetUrl(data_object, plain_text, &title);
+ return GetUrl(data_object, plain_text, &title, false);
}
bool ClipboardUtil::GetHtml(IDataObject* data_object,
« 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