Commit 1a9e9ccd authored by Tommy Li's avatar Tommy Li Committed by Commit Bot

[omnibox] Fix a bug with OmniboxPopupModel::TriggerSelectionAction

OmniboxPopupModel::TriggerSelectionAction will definitely crash in the
no-default-match edge case, which can definitely happen with certain
enterprise policies.

Additionally, it's possible that UI callers will pass in an invalid
|selection|, as they are an external class that could potentially be
stale. In practice, it doesn't SEEM possible for this to occur with
Views, but I'm not sure.

Philosophically, I think crashing when the UI code gets out of date
isn't a good thing, and this code should be a bit more tolerant.

Bug: 1085407, 1078183, 1052522
Change-Id: Ibe5a2b09340679d3bfb86c234bc799f0823fdaaf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2216605Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Commit-Queue: Tommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772420}
parent d8373820
...@@ -563,9 +563,14 @@ void OmniboxPopupModel::SetSelection(Selection selection) { ...@@ -563,9 +563,14 @@ void OmniboxPopupModel::SetSelection(Selection selection) {
} }
bool OmniboxPopupModel::TriggerSelectionAction(Selection selection) { bool OmniboxPopupModel::TriggerSelectionAction(Selection selection) {
// Early exit for the kNoMatch case. Also exits if the calling UI passes in
// an invalid |selection|.
if (selection.line >= result().size())
return false;
auto& match = result().match_at(selection.line); auto& match = result().match_at(selection.line);
if (selection.state == HEADER_BUTTON_FOCUSED) { if (selection.state == HEADER_BUTTON_FOCUSED &&
DCHECK(match.suggestion_group_id.has_value()); match.suggestion_group_id.has_value()) {
omnibox::ToggleSuggestionGroupIdVisibility( omnibox::ToggleSuggestionGroupIdVisibility(
pref_service_, match.suggestion_group_id.value()); pref_service_, match.suggestion_group_id.value());
return true; return true;
......
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