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

Side by Side Diff: components/omnibox/browser/clipboard_url_provider.cc

Issue 2738003002: Add title to current page in zero suggest. (Closed)
Patch Set: Include description for other providers. Created 3 years, 8 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 "components/omnibox/browser/clipboard_url_provider.h" 5 #include "components/omnibox/browser/clipboard_url_provider.h"
6 6
7 #include "base/feature_list.h"
7 #include "base/logging.h" 8 #include "base/logging.h"
8 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
9 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
10 #include "components/omnibox/browser/autocomplete_input.h" 11 #include "components/omnibox/browser/autocomplete_input.h"
11 #include "components/omnibox/browser/autocomplete_provider_client.h" 12 #include "components/omnibox/browser/autocomplete_provider_client.h"
12 #include "components/omnibox/browser/verbatim_match.h" 13 #include "components/omnibox/browser/verbatim_match.h"
13 #include "components/open_from_clipboard/clipboard_recent_content.h" 14 #include "components/open_from_clipboard/clipboard_recent_content.h"
14 #include "components/strings/grit/components_strings.h" 15 #include "components/strings/grit/components_strings.h"
15 #include "components/url_formatter/url_formatter.h" 16 #include "components/url_formatter/url_formatter.h"
16 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
Mark P 2017/04/18 21:05:10 Please include omnibox_field_trial.
gcomanici 2017/04/19 02:53:07 Done.
17 18
18 ClipboardURLProvider::ClipboardURLProvider( 19 ClipboardURLProvider::ClipboardURLProvider(
19 AutocompleteProviderClient* client, 20 AutocompleteProviderClient* client,
20 HistoryURLProvider* history_url_provider, 21 HistoryURLProvider* history_url_provider,
21 ClipboardRecentContent* clipboard_content) 22 ClipboardRecentContent* clipboard_content)
22 : AutocompleteProvider(AutocompleteProvider::TYPE_CLIPBOARD_URL), 23 : AutocompleteProvider(AutocompleteProvider::TYPE_CLIPBOARD_URL),
23 client_(client), 24 client_(client),
24 clipboard_content_(clipboard_content), 25 clipboard_content_(clipboard_content),
25 history_url_provider_(history_url_provider) { 26 history_url_provider_(history_url_provider) {
26 DCHECK(clipboard_content_); 27 DCHECK(clipboard_content_);
(...skipping 13 matching lines...) Expand all
40 // If the clipboard does not contain any URL, or the URL on the page is the 41 // If the clipboard does not contain any URL, or the URL on the page is the
41 // same as the URL in the clipboard, early return. 42 // same as the URL in the clipboard, early return.
42 if (!clipboard_content_->GetRecentURLFromClipboard(&url) || 43 if (!clipboard_content_->GetRecentURLFromClipboard(&url) ||
43 url == input.current_url()) 44 url == input.current_url())
44 return; 45 return;
45 46
46 DCHECK(url.is_valid()); 47 DCHECK(url.is_valid());
47 // If the omnibox is not empty, add a default match. 48 // If the omnibox is not empty, add a default match.
48 // This match will be opened when the user presses "Enter". 49 // This match will be opened when the user presses "Enter".
49 if (!input.text().empty()) { 50 if (!input.text().empty()) {
50 AutocompleteMatch verbatim_match = VerbatimMatchForURL( 51 const base::string16 description =
51 client_, input, input.current_url(), history_url_provider_, -1); 52 (base::FeatureList::IsEnabled(omnibox::kDisplayTitleForCurrentUrl))
53 ? input.current_title()
54 : base::string16();
55 AutocompleteMatch verbatim_match =
56 VerbatimMatchForURL(client_, input, input.current_url(), description,
57 history_url_provider_, -1);
52 matches_.push_back(verbatim_match); 58 matches_.push_back(verbatim_match);
53 } 59 }
54 UMA_HISTOGRAM_BOOLEAN("Omnibox.ClipboardSuggestionShownWithCurrentURL", 60 UMA_HISTOGRAM_BOOLEAN("Omnibox.ClipboardSuggestionShownWithCurrentURL",
55 !matches_.empty()); 61 !matches_.empty());
56 UMA_HISTOGRAM_LONG_TIMES_100("Omnibox.ClipboardSuggestionShownAge", 62 UMA_HISTOGRAM_LONG_TIMES_100("Omnibox.ClipboardSuggestionShownAge",
57 clipboard_content_->GetClipboardContentAge()); 63 clipboard_content_->GetClipboardContentAge());
58 64
59 // Add the clipboard match. The relevance is 800 to beat ZeroSuggest results. 65 // Add the clipboard match. The relevance is 800 to beat ZeroSuggest results.
60 AutocompleteMatch match(this, 800, false, AutocompleteMatchType::CLIPBOARD); 66 AutocompleteMatch match(this, 800, false, AutocompleteMatchType::CLIPBOARD);
61 match.destination_url = url; 67 match.destination_url = url;
62 match.contents.assign(url_formatter::FormatUrl( 68 match.contents.assign(url_formatter::FormatUrl(
63 url, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::SPACES, 69 url, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::SPACES,
64 nullptr, nullptr, nullptr)); 70 nullptr, nullptr, nullptr));
65 AutocompleteMatch::ClassifyLocationInString( 71 AutocompleteMatch::ClassifyLocationInString(
66 base::string16::npos, 0, match.contents.length(), 72 base::string16::npos, 0, match.contents.length(),
67 ACMatchClassification::URL, &match.contents_class); 73 ACMatchClassification::URL, &match.contents_class);
68 74
69 match.description.assign(l10n_util::GetStringUTF16(IDS_LINK_FROM_CLIPBOARD)); 75 match.description.assign(l10n_util::GetStringUTF16(IDS_LINK_FROM_CLIPBOARD));
70 AutocompleteMatch::ClassifyLocationInString( 76 AutocompleteMatch::ClassifyLocationInString(
71 base::string16::npos, 0, match.description.length(), 77 base::string16::npos, 0, match.description.length(),
72 ACMatchClassification::NONE, &match.description_class); 78 ACMatchClassification::NONE, &match.description_class);
73 79
74 matches_.push_back(match); 80 matches_.push_back(match);
75 } 81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698