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

Unified Diff: ui/base/dragdrop/os_exchange_data.cc

Issue 2322253004: Drag and dropping text, parsable as url (Closed)
Patch Set: initial patch for windows Created 4 years, 3 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
Index: ui/base/dragdrop/os_exchange_data.cc
diff --git a/ui/base/dragdrop/os_exchange_data.cc b/ui/base/dragdrop/os_exchange_data.cc
index bae9df1a8bbac41320474e70d632227d21f0a5bf..17fca9ccb938c9193ea4b87752e60df10c6dc01f 100644
--- a/ui/base/dragdrop/os_exchange_data.cc
+++ b/ui/base/dragdrop/os_exchange_data.cc
@@ -6,6 +6,7 @@
#include "base/pickle.h"
#include "build/build_config.h"
+#include "net/base/filename_util.h"
#include "ui/base/dragdrop/os_exchange_data_provider_factory.h"
#include "url/gurl.h"
@@ -65,10 +66,23 @@ bool OSExchangeData::GetString(base::string16* data) const {
return provider_->GetString(data);
}
-bool OSExchangeData::GetURLAndTitle(FilenameToURLPolicy policy,
+bool OSExchangeData::GetURLAndTitle(FilenameToURLPolicy filename_policy,
+ URLTextParsePolicy text_parse_policy,
GURL* url,
base::string16* title) const {
- return provider_->GetURLAndTitle(policy, url, title);
+ if (provider_->GetURLAndTitle(filename_policy, url, title))
+ return true;
+ if (text_parse_policy == DO_NOT_PARSE_TEXT_AS_URL)
+ return false;
+ base::string16 url_str;
+ if (!provider_->GetString(&url_str))
+ return false;
+ GURL test(url_str);
+ if (!test.is_valid())
+ return false;
+ *url = std::move(test);
dcheng 2016/09/13 19:53:26 GURL isn't actually movable, so this doesn't do an
+ *title = net::GetSuggestedFilename(*url, "", "", "", "", std::string());
+ return true;
}
bool OSExchangeData::GetFilename(base::FilePath* path) const {
@@ -88,8 +102,16 @@ bool OSExchangeData::HasString() const {
return provider_->HasString();
}
-bool OSExchangeData::HasURL(FilenameToURLPolicy policy) const {
- return provider_->HasURL(policy);
+bool OSExchangeData::HasURL(FilenameToURLPolicy filename_policy,
+ URLTextParsePolicy text_parse_policy) const {
+ if (provider_->HasURL(filename_policy))
+ return true;
+ if (text_parse_policy == DO_NOT_PARSE_TEXT_AS_URL)
+ return false;
+ base::string16 url_str;
+ if (provider_->GetString(&url_str))
+ return false;
+ return GURL(url_str).is_valid();
}
bool OSExchangeData::HasFile() const {
@@ -106,7 +128,7 @@ bool OSExchangeData::HasAnyFormat(
const std::set<Clipboard::FormatType>& format_types) const {
if ((formats & STRING) != 0 && HasString())
return true;
- if ((formats & URL) != 0 && HasURL(CONVERT_FILENAMES))
+ if ((formats & URL) != 0 && HasURL(CONVERT_FILENAMES, PARSE_TEXT_AS_URL))
return true;
#if defined(OS_WIN)
if ((formats & FILE_CONTENTS) != 0 && provider_->HasFileContents())

Powered by Google App Engine
This is Rietveld 408576698