Commit 01ef913d authored by Ghazale Hosseinabadi's avatar Ghazale Hosseinabadi Committed by Commit Bot

[Extensions] Call HasVisibleItems only if submenu_model is not null

In this CL, we add a check in IsCommandIdVisible in order to call
HasVisibleItems only if submenu_model is not null.

Bug: 1101726
Change-Id: I248daaeca3ac67777c00020c81d7f08e2433fae1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2285388Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Commit-Queue: Ghazale Hosseinabadi <ghazale@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786086}
parent ed0c1c64
...@@ -205,17 +205,18 @@ bool ContextMenuMatcher::IsCommandIdVisible(int command_id) const { ...@@ -205,17 +205,18 @@ bool ContextMenuMatcher::IsCommandIdVisible(int command_id) const {
// extension's name, that is a container of an extension's menu items. This // extension's name, that is a container of an extension's menu items. This
// top-level menu item is not added to the context menu, so checking its // top-level menu item is not added to the context menu, so checking its
// visibility is a special case handled below. This top-level menu item should // visibility is a special case handled below. This top-level menu item should
// always be displayed. // be displayed only if it has an invisible submenu item.
if (!item && ContextMenuMatcher::IsExtensionsCustomCommandId(command_id)) { if (!item && ContextMenuMatcher::IsExtensionsCustomCommandId(command_id)) {
ui::MenuModel* model = menu_model_; ui::MenuModel* model = menu_model_;
int index = 0; int index = 0;
if (ui::MenuModel::GetModelAndIndexForCommandId(command_id, &model, if (ui::MenuModel::GetModelAndIndexForCommandId(command_id, &model,
&index)) { &index)) {
ui::MenuModel* submenu_model = model->GetSubmenuModelAt(index); ui::MenuModel* submenu_model = model->GetSubmenuModelAt(index);
// The only way for this to be an extensions command ID without an // TODO(ghazale): Find out why submenu_model might be null. In other
// associated menu item is for it to be the generated menu. // words, in which circumstance it can be an extensions custom command ID
DCHECK(submenu_model); // which does not have an associated item, but it's submenu_model is null.
return HasVisibleItems(submenu_model); if (submenu_model)
return HasVisibleItems(submenu_model);
} }
return false; return false;
} else if (item) { } else if (item) {
......
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