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

Unified Diff: components/omnibox/browser/physical_web_provider.cc

Issue 2266083002: Avoid DCHECK failure for chrome:// URLs in autocomplete suggestions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: changes for pkasting@ Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
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..caac80699f9eb5b5d6fc59fc55ad2c0eea390ffb 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,
@@ -65,6 +68,16 @@ void PhysicalWebProvider::Start(const AutocompleteInput& input,
ConstructMatches(data_source->GetMetadata().get());
+ // Physical Web matches should never be default. If the omnibox input is
+ // non-empty and we have at least one Physical Web match, add the current URL
+ // as the default so that hitting enter after focusing the omnibox causes the
+ // current page to reload. If the input field is empty, no default match is
+ // required.
+ if (!matches_.empty() && !input.text().empty()) {
+ matches_.push_back(VerbatimMatchForURL(client_, input, input.current_url(),
+ history_url_provider_, -1));
+ }
+
done_ = true;
}
@@ -73,16 +86,19 @@ 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() {
}
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 +115,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 +149,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 +179,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);
}
« no previous file with comments | « components/omnibox/browser/physical_web_provider.h ('k') | components/omnibox/browser/physical_web_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698