| Index: components/omnibox/browser/physical_web_provider.cc
|
| diff --git a/components/omnibox/browser/physical_web_provider.cc b/components/omnibox/browser/physical_web_provider.cc
|
| index 1161fe2079667b1d4723dafd8fea7b5678aa8c63..850d3e7273dc3c116349ec29fabaeef1475881bd 100644
|
| --- a/components/omnibox/browser/physical_web_provider.cc
|
| +++ b/components/omnibox/browser/physical_web_provider.cc
|
| @@ -7,7 +7,9 @@
|
| #include "base/values.h"
|
| #include "components/omnibox/browser/autocomplete_provider_client.h"
|
| #include "components/omnibox/browser/autocomplete_provider_listener.h"
|
| +#include "components/omnibox/browser/history_url_provider.h"
|
| #include "components/omnibox/browser/physical_web_provider.h"
|
| +#include "components/omnibox/browser/verbatim_match.h"
|
| #include "components/physical_web/data_source/physical_web_data_source.h"
|
| #include "components/url_formatter/url_formatter.h"
|
| #include "grit/components_strings.h"
|
| @@ -38,8 +40,9 @@ static const int kPhysicalWebUrlBaseRelevance = 700;
|
|
|
| // static
|
| PhysicalWebProvider* PhysicalWebProvider::Create(
|
| - AutocompleteProviderClient* client) {
|
| - return new PhysicalWebProvider(client);
|
| + AutocompleteProviderClient* client,
|
| + HistoryURLProvider* history_url_provider) {
|
| + return new PhysicalWebProvider(client, history_url_provider);
|
| }
|
|
|
| void PhysicalWebProvider::Start(const AutocompleteInput& input,
|
| @@ -63,6 +66,14 @@ void PhysicalWebProvider::Start(const AutocompleteInput& input,
|
| return;
|
| }
|
|
|
| + // If the omnibox is not empty, add a default match.
|
| + // This match will be opened when the user presses "Enter".
|
| + if (!input.text().empty()) {
|
| + AutocompleteMatch verbatim_match = VerbatimMatchForURL(
|
| + client_, input, input.current_url(), history_url_provider_, -1);
|
| + matches_.push_back(verbatim_match);
|
| + }
|
| +
|
| ConstructMatches(data_source->GetMetadata().get());
|
|
|
| done_ = true;
|
| @@ -73,9 +84,12 @@ void PhysicalWebProvider::Stop(bool clear_cached_results,
|
| done_ = true;
|
| }
|
|
|
| -PhysicalWebProvider::PhysicalWebProvider(AutocompleteProviderClient* client)
|
| +PhysicalWebProvider::PhysicalWebProvider(
|
| + AutocompleteProviderClient* client,
|
| + HistoryURLProvider* history_url_provider)
|
| : AutocompleteProvider(AutocompleteProvider::TYPE_PHYSICAL_WEB),
|
| - client_(client) {
|
| + client_(client),
|
| + history_url_provider_(history_url_provider) {
|
| }
|
|
|
| PhysicalWebProvider::~PhysicalWebProvider() {
|
| @@ -83,6 +97,7 @@ PhysicalWebProvider::~PhysicalWebProvider() {
|
|
|
| void PhysicalWebProvider::ConstructMatches(base::ListValue* metadata_list) {
|
| const size_t metadata_count = metadata_list->GetSize();
|
| + size_t used_slots = 0;
|
|
|
| for (size_t i = 0; i < metadata_count; ++i) {
|
| base::DictionaryValue* metadata_item = NULL;
|
| @@ -99,11 +114,11 @@ void PhysicalWebProvider::ConstructMatches(base::ListValue* metadata_list) {
|
|
|
| // Add match items with decreasing relevance to preserve the ordering in
|
| // the metadata list.
|
| - int relevance = kPhysicalWebUrlBaseRelevance - matches_.size();
|
| + int relevance = kPhysicalWebUrlBaseRelevance - used_slots;
|
|
|
| // Append an overflow item if creating a match for each metadata item would
|
| // exceed the match limit.
|
| - const size_t remaining_slots = kPhysicalWebMaxMatches - matches_.size();
|
| + const size_t remaining_slots = kPhysicalWebMaxMatches - used_slots;
|
| const size_t remaining_metadata = metadata_count - i;
|
| if ((remaining_slots == 1) && (remaining_metadata > remaining_slots)) {
|
| AppendOverflowItem(remaining_metadata, relevance);
|
| @@ -133,9 +148,8 @@ void PhysicalWebProvider::ConstructMatches(base::ListValue* metadata_list) {
|
| match.description_class.push_back(
|
| ACMatchClassification(0, ACMatchClassification::NONE));
|
|
|
| - match.allowed_to_be_default_match = matches_.empty();
|
| -
|
| matches_.push_back(match);
|
| + ++used_slots;
|
| }
|
| }
|
|
|
| @@ -164,7 +178,5 @@ void PhysicalWebProvider::AppendOverflowItem(int additional_url_count,
|
| match.description_class.push_back(
|
| ACMatchClassification(0, ACMatchClassification::NONE));
|
|
|
| - match.allowed_to_be_default_match = matches_.empty();
|
| -
|
| matches_.push_back(match);
|
| }
|
|
|