diff options
author | dcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-21 00:53:12 +0000 |
---|---|---|
committer | dcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-21 00:53:12 +0000 |
commit | e4c5cf49eccde08b693cb9a957a03938a691a18c (patch) | |
tree | 512154771b2e482410d26e4d77f1de92b8cd80f4 /app | |
parent | dc79d22fcb5ad4eb11db86a78f67516030e9b5c3 (diff) | |
download | chromium_src-e4c5cf49eccde08b693cb9a957a03938a691a18c.zip chromium_src-e4c5cf49eccde08b693cb9a957a03938a691a18c.tar.gz chromium_src-e4c5cf49eccde08b693cb9a957a03938a691a18c.tar.bz2 |
Don't populate WebDropData with file URLs when dragging files.
This is the Windows patch. There will be separate patches for Mac and Linux.
BUG=42685
TEST=none
Review URL: http://codereview.chromium.org/2126010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47870 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r-- | app/clipboard/clipboard_util_win.cc | 103 | ||||
-rw-r--r-- | app/clipboard/clipboard_util_win.h | 2 | ||||
-rw-r--r-- | app/os_exchange_data_provider_win.cc | 2 |
3 files changed, 59 insertions, 48 deletions
diff --git a/app/clipboard/clipboard_util_win.cc b/app/clipboard/clipboard_util_win.cc index 355e8d9..2ed7241 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, diff --git a/app/clipboard/clipboard_util_win.h b/app/clipboard/clipboard_util_win.h index 5bbe8f0..7bedb51 100644 --- a/app/clipboard/clipboard_util_win.h +++ b/app/clipboard/clipboard_util_win.h @@ -44,7 +44,7 @@ class ClipboardUtil { // Helper methods to extract information from an IDataObject. These methods // return true if the requested data type is found in |data_object|. static bool GetUrl(IDataObject* data_object, - std::wstring* url, std::wstring* title); + std::wstring* url, std::wstring* title, bool convert_filenames); static bool GetFilenames(IDataObject* data_object, std::vector<std::wstring>* filenames); static bool GetPlainText(IDataObject* data_object, std::wstring* plain_text); diff --git a/app/os_exchange_data_provider_win.cc b/app/os_exchange_data_provider_win.cc index 6e11714..b977252 100644 --- a/app/os_exchange_data_provider_win.cc +++ b/app/os_exchange_data_provider_win.cc @@ -370,7 +370,7 @@ bool OSExchangeDataProviderWin::GetString(std::wstring* data) const { bool OSExchangeDataProviderWin::GetURLAndTitle(GURL* url, std::wstring* title) const { std::wstring url_str; - bool success = ClipboardUtil::GetUrl(source_object_, &url_str, title); + bool success = ClipboardUtil::GetUrl(source_object_, &url_str, title, true); if (success) { GURL test_url(url_str); if (test_url.is_valid()) { |