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

Side by Side Diff: ui/base/dragdrop/drag_and_drop_url_utils.cc

Issue 2322253004: Drag and dropping text, parsable as url (Closed)
Patch Set: Moving url logic out of os_exchange_data 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/base/dragdrop/drag_and_drop_url_utils.h"
6
7 #include "base/macros.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "components/url_formatter/url_fixer.h"
10 #include "net/base/filename_util.h"
11 #include "ui/base/dragdrop/os_exchange_data.h"
12 #include "url/gurl.h"
13
14 namespace ui {
15
16 namespace {
17
18 base::Optional<GURL> TryToExtractPlainTextURL(const ui::OSExchangeData& data) {
19 base::string16 text;
20 if (!data.GetString(&text))
21 return {};
22 auto res = url_formatter::FixupURL(base::UTF16ToUTF8(text), "");
sky 2016/09/15 21:32:50 ""->std::string in all of these.
23 if (!res.is_valid())
24 return {};
25 return res;
26 }
27
28 } // namespace
29
30 bool CanBeInterpretedAsURL(const ui::OSExchangeData& data,
31 ui::OSExchangeData::FilenameToURLPolicy policy) {
32 if (data.HasURL(policy))
33 return true;
34 return static_cast<bool>(TryToExtractPlainTextURL(data));
35 }
36
37 base::Optional<std::pair<GURL, base::string16>> TryToInterpretAsURL(
38 const ui::OSExchangeData& data,
39 ui::OSExchangeData::FilenameToURLPolicy policy) {
40 std::pair<GURL, base::string16> res;
41 if (data.GetURLAndTitle(policy, &res.first, &res.second))
42 return res;
43
44 auto opt_url = TryToExtractPlainTextURL(data);
45 if (!opt_url)
46 return {};
47 res.first = std::move(*opt_url);
48 res.second = net::GetSuggestedFilename(res.first, "", "", "", "", {});
49 return res;
50 }
51
52 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698