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

Side by Side Diff: components/open_from_clipboard/clipboard_url_provider.cc

Issue 930323003: Upstream iOS' Open from Clipboard component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build. Created 5 years, 10 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 2015 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 "components/open_from_clipboard/clipboard_url_provider.h"
6
7 #include "base/logging.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "components/omnibox/autocomplete_input.h"
10 #include "components/open_from_clipboard/clipboard_recent_content.h"
11 #include "grit/components_strings.h"
12 #include "ui/base/l10n/l10n_util.h"
13
14 namespace {
15 // Score defining the priority of the suggestion. 1600 guarantees that the
16 // suggestion will always be first. See table in autocomplete_provider.h.
17 const int kClipboardURLProviderRelevance = 1600;
18 } // namespace
19
20 ClipboardURLProvider::ClipboardURLProvider(
21 ClipboardRecentContent* clipboard_recent_content)
22 : AutocompleteProvider(AutocompleteProvider::TYPE_SHORTCUTS),
23 clipboard_recent_content_(clipboard_recent_content) {
24 DCHECK(clipboard_recent_content_);
25 }
26
27 ClipboardURLProvider::~ClipboardURLProvider() {
28 }
29
30 void ClipboardURLProvider::Start(const AutocompleteInput& input,
31 bool minimal_changes,
32 bool called_due_to_focus) {
33 matches_.clear();
34 // Attempt to add an AutocompleteMatch only if the user has not entered
35 // anything in the omnibox.
36 if (input.cursor_position() == base::string16::npos) {
37 GURL url;
38 if (clipboard_recent_content_->GetRecentURLFromClipboard(&url)) {
39 AutocompleteMatch match(this, kClipboardURLProviderRelevance, false,
40 AutocompleteMatchType::NAVSUGGEST_PERSONALIZED);
41 match.allowed_to_be_default_match = true;
42 match.destination_url = url;
43 match.contents.assign(base::UTF8ToUTF16(url.possibly_invalid_spec()));
sdefresne 2015/02/18 15:10:07 nit: since you ensure that GetRecentURLFromClipboa
sdefresne 2015/02/18 15:10:07 nit: since you ensure that GetRecentURLFromClipboa
44 AutocompleteMatch::ClassifyLocationInString(
45 base::string16::npos, 0, match.contents.length(),
46 ACMatchClassification::URL, &match.contents_class);
47
48 match.description.assign(
49 l10n_util::GetStringUTF16(IDS_LINK_FROM_CLIPBOARD));
50 AutocompleteMatch::ClassifyLocationInString(
51 base::string16::npos, 0, match.description.length(),
52 ACMatchClassification::URL, &match.description_class);
53
54 matches_.push_back(match);
55 }
56 }
57 done_ = true;
58 }
OLDNEW
« no previous file with comments | « components/open_from_clipboard/clipboard_url_provider.h ('k') | components/open_from_clipboard_strings.grdp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698