Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/base/dragdrop/os_exchange_data.h" | 5 #include "ui/base/dragdrop/os_exchange_data.h" |
| 6 | 6 |
| 7 #include "base/pickle.h" | 7 #include "base/pickle.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "net/base/filename_util.h" | |
| 9 #include "ui/base/dragdrop/os_exchange_data_provider_factory.h" | 10 #include "ui/base/dragdrop/os_exchange_data_provider_factory.h" |
| 10 #include "url/gurl.h" | 11 #include "url/gurl.h" |
| 11 | 12 |
| 12 namespace ui { | 13 namespace ui { |
| 13 | 14 |
| 14 OSExchangeData::DownloadFileInfo::DownloadFileInfo( | 15 OSExchangeData::DownloadFileInfo::DownloadFileInfo( |
| 15 const base::FilePath& filename, | 16 const base::FilePath& filename, |
| 16 DownloadFileProvider* downloader) | 17 DownloadFileProvider* downloader) |
| 17 : filename(filename), | 18 : filename(filename), |
| 18 downloader(downloader) { | 19 downloader(downloader) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 | 59 |
| 59 void OSExchangeData::SetPickledData(const Clipboard::FormatType& format, | 60 void OSExchangeData::SetPickledData(const Clipboard::FormatType& format, |
| 60 const base::Pickle& data) { | 61 const base::Pickle& data) { |
| 61 provider_->SetPickledData(format, data); | 62 provider_->SetPickledData(format, data); |
| 62 } | 63 } |
| 63 | 64 |
| 64 bool OSExchangeData::GetString(base::string16* data) const { | 65 bool OSExchangeData::GetString(base::string16* data) const { |
| 65 return provider_->GetString(data); | 66 return provider_->GetString(data); |
| 66 } | 67 } |
| 67 | 68 |
| 68 bool OSExchangeData::GetURLAndTitle(FilenameToURLPolicy policy, | 69 bool OSExchangeData::GetURLAndTitle(FilenameToURLPolicy filename_policy, |
| 70 URLTextParsePolicy text_parse_policy, | |
| 69 GURL* url, | 71 GURL* url, |
| 70 base::string16* title) const { | 72 base::string16* title) const { |
| 71 return provider_->GetURLAndTitle(policy, url, title); | 73 if (provider_->GetURLAndTitle(filename_policy, url, title)) |
| 74 return true; | |
| 75 if (text_parse_policy == DO_NOT_PARSE_TEXT_AS_URL) | |
| 76 return false; | |
| 77 base::string16 url_str; | |
| 78 if (!provider_->GetString(&url_str)) | |
| 79 return false; | |
| 80 GURL test(url_str); | |
| 81 if (!test.is_valid()) | |
| 82 return false; | |
| 83 *url = std::move(test); | |
|
dcheng
2016/09/13 19:53:26
GURL isn't actually movable, so this doesn't do an
| |
| 84 *title = net::GetSuggestedFilename(*url, "", "", "", "", std::string()); | |
| 85 return true; | |
| 72 } | 86 } |
| 73 | 87 |
| 74 bool OSExchangeData::GetFilename(base::FilePath* path) const { | 88 bool OSExchangeData::GetFilename(base::FilePath* path) const { |
| 75 return provider_->GetFilename(path); | 89 return provider_->GetFilename(path); |
| 76 } | 90 } |
| 77 | 91 |
| 78 bool OSExchangeData::GetFilenames(std::vector<FileInfo>* filenames) const { | 92 bool OSExchangeData::GetFilenames(std::vector<FileInfo>* filenames) const { |
| 79 return provider_->GetFilenames(filenames); | 93 return provider_->GetFilenames(filenames); |
| 80 } | 94 } |
| 81 | 95 |
| 82 bool OSExchangeData::GetPickledData(const Clipboard::FormatType& format, | 96 bool OSExchangeData::GetPickledData(const Clipboard::FormatType& format, |
| 83 base::Pickle* data) const { | 97 base::Pickle* data) const { |
| 84 return provider_->GetPickledData(format, data); | 98 return provider_->GetPickledData(format, data); |
| 85 } | 99 } |
| 86 | 100 |
| 87 bool OSExchangeData::HasString() const { | 101 bool OSExchangeData::HasString() const { |
| 88 return provider_->HasString(); | 102 return provider_->HasString(); |
| 89 } | 103 } |
| 90 | 104 |
| 91 bool OSExchangeData::HasURL(FilenameToURLPolicy policy) const { | 105 bool OSExchangeData::HasURL(FilenameToURLPolicy filename_policy, |
| 92 return provider_->HasURL(policy); | 106 URLTextParsePolicy text_parse_policy) const { |
| 107 if (provider_->HasURL(filename_policy)) | |
| 108 return true; | |
| 109 if (text_parse_policy == DO_NOT_PARSE_TEXT_AS_URL) | |
| 110 return false; | |
| 111 base::string16 url_str; | |
| 112 if (provider_->GetString(&url_str)) | |
| 113 return false; | |
| 114 return GURL(url_str).is_valid(); | |
| 93 } | 115 } |
| 94 | 116 |
| 95 bool OSExchangeData::HasFile() const { | 117 bool OSExchangeData::HasFile() const { |
| 96 return provider_->HasFile(); | 118 return provider_->HasFile(); |
| 97 } | 119 } |
| 98 | 120 |
| 99 bool OSExchangeData::HasCustomFormat( | 121 bool OSExchangeData::HasCustomFormat( |
| 100 const Clipboard::FormatType& format) const { | 122 const Clipboard::FormatType& format) const { |
| 101 return provider_->HasCustomFormat(format); | 123 return provider_->HasCustomFormat(format); |
| 102 } | 124 } |
| 103 | 125 |
| 104 bool OSExchangeData::HasAnyFormat( | 126 bool OSExchangeData::HasAnyFormat( |
| 105 int formats, | 127 int formats, |
| 106 const std::set<Clipboard::FormatType>& format_types) const { | 128 const std::set<Clipboard::FormatType>& format_types) const { |
| 107 if ((formats & STRING) != 0 && HasString()) | 129 if ((formats & STRING) != 0 && HasString()) |
| 108 return true; | 130 return true; |
| 109 if ((formats & URL) != 0 && HasURL(CONVERT_FILENAMES)) | 131 if ((formats & URL) != 0 && HasURL(CONVERT_FILENAMES, PARSE_TEXT_AS_URL)) |
| 110 return true; | 132 return true; |
| 111 #if defined(OS_WIN) | 133 #if defined(OS_WIN) |
| 112 if ((formats & FILE_CONTENTS) != 0 && provider_->HasFileContents()) | 134 if ((formats & FILE_CONTENTS) != 0 && provider_->HasFileContents()) |
| 113 return true; | 135 return true; |
| 114 #endif | 136 #endif |
| 115 #if defined(USE_AURA) | 137 #if defined(USE_AURA) |
| 116 if ((formats & HTML) != 0 && provider_->HasHtml()) | 138 if ((formats & HTML) != 0 && provider_->HasHtml()) |
| 117 return true; | 139 return true; |
| 118 #endif | 140 #endif |
| 119 if ((formats & FILE_NAME) != 0 && provider_->HasFile()) | 141 if ((formats & FILE_NAME) != 0 && provider_->HasFile()) |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 145 void OSExchangeData::SetHtml(const base::string16& html, const GURL& base_url) { | 167 void OSExchangeData::SetHtml(const base::string16& html, const GURL& base_url) { |
| 146 provider_->SetHtml(html, base_url); | 168 provider_->SetHtml(html, base_url); |
| 147 } | 169 } |
| 148 | 170 |
| 149 bool OSExchangeData::GetHtml(base::string16* html, GURL* base_url) const { | 171 bool OSExchangeData::GetHtml(base::string16* html, GURL* base_url) const { |
| 150 return provider_->GetHtml(html, base_url); | 172 return provider_->GetHtml(html, base_url); |
| 151 } | 173 } |
| 152 #endif | 174 #endif |
| 153 | 175 |
| 154 } // namespace ui | 176 } // namespace ui |
| OLD | NEW |