OLD | NEW |
---|---|
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 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 | 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/physical_web_provider.h" | 5 #include "components/omnibox/browser/physical_web_provider.h" |
6 | 6 |
7 #include "base/feature_list.h" | |
7 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
8 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
9 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
11 #include "components/bookmarks/browser/titled_url_index.h" | 12 #include "components/bookmarks/browser/titled_url_index.h" |
12 #include "components/bookmarks/browser/titled_url_node_sorter.h" | 13 #include "components/bookmarks/browser/titled_url_node_sorter.h" |
13 #include "components/omnibox/browser/autocomplete_provider_client.h" | 14 #include "components/omnibox/browser/autocomplete_provider_client.h" |
14 #include "components/omnibox/browser/autocomplete_provider_listener.h" | 15 #include "components/omnibox/browser/autocomplete_provider_listener.h" |
15 #include "components/omnibox/browser/history_url_provider.h" | 16 #include "components/omnibox/browser/history_url_provider.h" |
16 #include "components/omnibox/browser/omnibox_field_trial.h" | 17 #include "components/omnibox/browser/omnibox_field_trial.h" |
17 #include "components/omnibox/browser/physical_web_node.h" | 18 #include "components/omnibox/browser/physical_web_node.h" |
18 #include "components/omnibox/browser/titled_url_match_utils.h" | 19 #include "components/omnibox/browser/titled_url_match_utils.h" |
19 #include "components/omnibox/browser/url_prefix.h" | 20 #include "components/omnibox/browser/url_prefix.h" |
20 #include "components/omnibox/browser/verbatim_match.h" | 21 #include "components/omnibox/browser/verbatim_match.h" |
21 #include "components/physical_web/data_source/physical_web_data_source.h" | 22 #include "components/physical_web/data_source/physical_web_data_source.h" |
22 #include "components/strings/grit/components_strings.h" | 23 #include "components/strings/grit/components_strings.h" |
23 #include "components/url_formatter/url_formatter.h" | 24 #include "components/url_formatter/url_formatter.h" |
24 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
25 #include "ui/gfx/text_elider.h" | 26 #include "ui/gfx/text_elider.h" |
26 #include "url/gurl.h" | 27 #include "url/gurl.h" |
27 | 28 |
Mark P
2017/04/18 21:05:10
Please include omnibox_field_trial.
gcomanici
2017/04/19 02:53:07
There already.
| |
28 namespace { | 29 namespace { |
29 | 30 |
30 // The maximum length of the page title's part of the overflow item's | 31 // The maximum length of the page title's part of the overflow item's |
31 // description. Longer titles will be truncated to this length. In a normal | 32 // description. Longer titles will be truncated to this length. In a normal |
32 // Physical Web match item (non-overflow item) we allow the omnibox display to | 33 // Physical Web match item (non-overflow item) we allow the omnibox display to |
33 // truncate the title instead. | 34 // truncate the title instead. |
34 static const size_t kMaxTitleLengthInOverflow = 15; | 35 static const size_t kMaxTitleLengthInOverflow = 15; |
35 | 36 |
36 // The maximum number of Physical Web URLs to retrieve from the index. | 37 // The maximum number of Physical Web URLs to retrieve from the index. |
37 static const size_t kPhysicalWebIndexMaxMatches = 50; | 38 static const size_t kPhysicalWebIndexMaxMatches = 50; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 (empty_input_from_user && !after_typing_enabled_)) { | 96 (empty_input_from_user && !after_typing_enabled_)) { |
96 matches_.clear(); | 97 matches_.clear(); |
97 } | 98 } |
98 | 99 |
99 // In zero-suggest, Physical Web matches should never be default. If the | 100 // In zero-suggest, Physical Web matches should never be default. If the |
100 // omnibox input is non-empty and we have at least one Physical Web match, | 101 // omnibox input is non-empty and we have at least one Physical Web match, |
101 // add the current URL as the default so that hitting enter after focusing | 102 // add the current URL as the default so that hitting enter after focusing |
102 // the omnibox causes the current page to reload. If the input field is | 103 // the omnibox causes the current page to reload. If the input field is |
103 // empty, no default match is required. | 104 // empty, no default match is required. |
104 if (!matches_.empty() && !input.text().empty()) { | 105 if (!matches_.empty() && !input.text().empty()) { |
105 matches_.push_back(VerbatimMatchForURL( | 106 const base::string16 description = |
106 client_, input, input.current_url(), history_url_provider_, -1)); | 107 (base::FeatureList::IsEnabled(omnibox::kDisplayTitleForCurrentUrl)) |
108 ? input.current_title() | |
109 : base::string16(); | |
110 matches_.push_back(VerbatimMatchForURL(client_, input, | |
111 input.current_url(), description, | |
112 history_url_provider_, -1)); | |
107 } | 113 } |
108 } else { | 114 } else { |
109 ConstructQuerySuggestMatches(std::move(metadata_list), input); | 115 ConstructQuerySuggestMatches(std::move(metadata_list), input); |
110 | 116 |
111 if (!matches_.empty()) { | 117 if (!matches_.empty()) { |
112 had_physical_web_suggestions_ = true; | 118 had_physical_web_suggestions_ = true; |
113 had_physical_web_suggestions_at_focus_or_later_ = true; | 119 had_physical_web_suggestions_at_focus_or_later_ = true; |
114 } | 120 } |
115 | 121 |
116 // Don't show Physical Web suggestions after the user starts typing unless | 122 // Don't show Physical Web suggestions after the user starts typing unless |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 AutocompleteInput::FormattedStringWithEquivalentMeaning( | 315 AutocompleteInput::FormattedStringWithEquivalentMeaning( |
310 url, match.contents, client_->GetSchemeClassifier()); | 316 url, match.contents, client_->GetSchemeClassifier()); |
311 | 317 |
312 match.description = | 318 match.description = |
313 l10n_util::GetStringUTF16(IDS_PHYSICAL_WEB_OVERFLOW_DESCRIPTION); | 319 l10n_util::GetStringUTF16(IDS_PHYSICAL_WEB_OVERFLOW_DESCRIPTION); |
314 match.description_class.push_back( | 320 match.description_class.push_back( |
315 ACMatchClassification(0, ACMatchClassification::NONE)); | 321 ACMatchClassification(0, ACMatchClassification::NONE)); |
316 | 322 |
317 matches_.push_back(match); | 323 matches_.push_back(match); |
318 } | 324 } |
OLD | NEW |