Chromium Code Reviews| 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/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 } | 68 } |
| 69 | 69 |
| 70 physical_web::PhysicalWebDataSource* data_source = | 70 physical_web::PhysicalWebDataSource* data_source = |
| 71 client_->GetPhysicalWebDataSource(); | 71 client_->GetPhysicalWebDataSource(); |
| 72 if (!data_source) { | 72 if (!data_source) { |
| 73 done_ = true; | 73 done_ = true; |
| 74 nearby_url_count_ = 0; | 74 nearby_url_count_ = 0; |
| 75 return; | 75 return; |
| 76 } | 76 } |
| 77 | 77 |
| 78 if (input.from_omnibox_focus()) { | 78 bool input_from_focus = input.from_omnibox_focus(); |
|
Mark P
2017/01/25 20:19:47
nit: both const
mattreynolds
2017/01/25 22:01:52
Done.
| |
| 79 bool empty_input_from_user = !input_from_focus && input.text().empty(); | |
| 80 | |
| 81 if (input_from_focus || empty_input_from_user) { | |
| 79 ConstructZeroSuggestMatches(data_source->GetMetadataList()); | 82 ConstructZeroSuggestMatches(data_source->GetMetadataList()); |
| 80 | 83 |
| 81 if (!matches_.empty()) { | 84 if (!matches_.empty()) { |
| 82 had_physical_web_suggestions_ = true; | 85 had_physical_web_suggestions_ = true; |
| 83 had_physical_web_suggestions_at_focus_or_later_ = true; | 86 had_physical_web_suggestions_at_focus_or_later_ = true; |
| 84 } | 87 } |
| 85 | 88 |
| 86 if (!zero_suggest_enabled_) { | 89 // Don't show zero-suggest suggestions unless the PhysicalWebZeroSuggest |
| 90 // omnibox experiment parameter is enabled. If the omnibox input is empty | |
| 91 // because the user cleared it, also require that PhysicalWebAfterTyping is | |
| 92 // enabled. | |
| 93 if (!zero_suggest_enabled_ || | |
| 94 (empty_input_from_user && !after_typing_enabled_)) { | |
| 87 matches_.clear(); | 95 matches_.clear(); |
| 88 } | 96 } |
| 89 | 97 |
| 90 // In zero-suggest, Physical Web matches should never be default. If the | 98 // In zero-suggest, Physical Web matches should never be default. If the |
| 91 // omnibox input is non-empty and we have at least one Physical Web match, | 99 // omnibox input is non-empty and we have at least one Physical Web match, |
| 92 // add the current URL as the default so that hitting enter after focusing | 100 // add the current URL as the default so that hitting enter after focusing |
| 93 // the omnibox causes the current page to reload. If the input field is | 101 // the omnibox causes the current page to reload. If the input field is |
| 94 // empty, no default match is required. | 102 // empty, no default match is required. |
| 95 if (!matches_.empty() && !input.text().empty()) { | 103 if (!matches_.empty() && !input.text().empty()) { |
| 96 matches_.push_back(VerbatimMatchForURL( | 104 matches_.push_back(VerbatimMatchForURL( |
| 97 client_, input, input.current_url(), history_url_provider_, -1)); | 105 client_, input, input.current_url(), history_url_provider_, -1)); |
| 98 } | 106 } |
| 99 } else { | 107 } else { |
| 100 ConstructQuerySuggestMatches(data_source->GetMetadataList(), input); | 108 ConstructQuerySuggestMatches(data_source->GetMetadataList(), input); |
| 101 | 109 |
| 102 if (!matches_.empty()) { | 110 if (!matches_.empty()) { |
| 103 had_physical_web_suggestions_ = true; | 111 had_physical_web_suggestions_ = true; |
| 104 had_physical_web_suggestions_at_focus_or_later_ = true; | 112 had_physical_web_suggestions_at_focus_or_later_ = true; |
| 105 } | 113 } |
| 106 | 114 |
| 115 // Don't show Physical Web suggestions after the user starts typing unless | |
| 116 // the PhysicalWebAfterTyping omnibox experiment parameter is enabled. | |
| 107 if (!after_typing_enabled_) { | 117 if (!after_typing_enabled_) { |
| 108 matches_.clear(); | 118 matches_.clear(); |
| 109 } | 119 } |
| 110 } | 120 } |
| 111 | 121 |
| 112 done_ = true; | 122 done_ = true; |
| 113 } | 123 } |
| 114 | 124 |
| 115 void PhysicalWebProvider::Stop(bool clear_cached_results, | 125 void PhysicalWebProvider::Stop(bool clear_cached_results, |
| 116 bool due_to_user_inactivity) { | 126 bool due_to_user_inactivity) { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 AutocompleteInput::FormattedStringWithEquivalentMeaning( | 283 AutocompleteInput::FormattedStringWithEquivalentMeaning( |
| 274 url, match.contents, client_->GetSchemeClassifier()); | 284 url, match.contents, client_->GetSchemeClassifier()); |
| 275 | 285 |
| 276 match.description = | 286 match.description = |
| 277 l10n_util::GetStringUTF16(IDS_PHYSICAL_WEB_OVERFLOW_DESCRIPTION); | 287 l10n_util::GetStringUTF16(IDS_PHYSICAL_WEB_OVERFLOW_DESCRIPTION); |
| 278 match.description_class.push_back( | 288 match.description_class.push_back( |
| 279 ACMatchClassification(0, ACMatchClassification::NONE)); | 289 ACMatchClassification(0, ACMatchClassification::NONE)); |
| 280 | 290 |
| 281 matches_.push_back(match); | 291 matches_.push_back(match); |
| 282 } | 292 } |
| OLD | NEW |