Commit d202eefd authored by manuk's avatar manuk Committed by Commit Bot

[omnibox] Null check default search provider for shortcut prov and deletion URLs

Setting the DefaultSearchProviderEnabled policy to false means
TemplateURLService::GetDefaultSearchProvider returns null. This CL adds 2 null
checks for this case.

Firstly, when the user selects a keyword match e.g. 'yahoo.com world', a
shortcut is created for the input 'world'. If the user then begins typing
'world', the shortcut provider determines whether the shortcut suggestion
requires a keyword based on whether it's search engine (yahoo) differs from the
default search engine (e.g. google). This CL short circuits this check and adds
the keyword if there is no default search engine.

Secondly, to determine the deletion URL of a search result, the omnibox queries
the default search engine. This CL skips setting the deletion URL when there is
no default search engine.

Bug: 871898
Change-Id: I5b008121c0ce6afd019463070507718ebf86b8dc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1778642
Commit-Queue: manuk hovanesian <manukh@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#692098}
parent cb13cfb2
...@@ -445,7 +445,8 @@ void BaseSearchProvider::SetDeletionURL(const std::string& deletion_url, ...@@ -445,7 +445,8 @@ void BaseSearchProvider::SetDeletionURL(const std::string& deletion_url,
return; return;
TemplateURLService* template_url_service = client_->GetTemplateURLService(); TemplateURLService* template_url_service = client_->GetTemplateURLService();
if (!template_url_service) if (!template_url_service ||
!template_url_service->GetDefaultSearchProvider())
return; return;
GURL url = GURL url =
template_url_service->GetDefaultSearchProvider()->GenerateSearchURL( template_url_service->GetDefaultSearchProvider()->GenerateSearchURL(
......
...@@ -298,13 +298,15 @@ AutocompleteMatch ShortcutsProvider::ShortcutToACMatch( ...@@ -298,13 +298,15 @@ AutocompleteMatch ShortcutsProvider::ShortcutToACMatch(
base::StrCat({base::UTF16ToUTF8(match.keyword), " "}), base::StrCat({base::UTF16ToUTF8(match.keyword), " "}),
base::CompareCase::INSENSITIVE_ASCII); base::CompareCase::INSENSITIVE_ASCII);
if (is_search_type) { if (is_search_type) {
const TemplateURL* template_url =
client_->GetTemplateURLService()->GetDefaultSearchProvider();
match.from_keyword = match.from_keyword =
// Either the match is not from the default search provider: // Either the default search provider is disabled,
match.keyword != client_->GetTemplateURLService() !template_url ||
->GetDefaultSearchProvider() // or the match is not from the default search provider,
->keyword() || match.keyword != template_url->keyword() ||
// Or it is, but keyword mode was invoked explicitly and the keyword // or keyword mode was invoked explicitly and the keyword in the input
// in the input is also of the default search provider. // is also of the default search provider.
(input.prefer_keyword() && keyword_matches); (input.prefer_keyword() && keyword_matches);
} }
// True if input is in keyword mode and the match is a URL suggestion or the // True if input is in keyword mode and the match is a URL suggestion or the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment