Commit 271d01c9 authored by mek@chromium.org's avatar mek@chromium.org

Platform app context menu items should not be grouped into a submenu.

BUG=141898


Review URL: https://chromiumcodereview.appspot.com/10832349

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153585 0039d316-1c4b-4281-b951-d872f2087c98
parent 9ae9c11c
...@@ -95,7 +95,7 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) { ...@@ -95,7 +95,7 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) {
// launched a window. // launched a window.
ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
// The context_menu app has one context menu item. This, along with a // The context_menu app has two context menu items. These, along with a
// separator and the developer tools, is all that should be in the menu. // separator and the developer tools, is all that should be in the menu.
WebContents* web_contents = GetFirstShellWindowWebContents(); WebContents* web_contents = GetFirstShellWindowWebContents();
ASSERT_TRUE(web_contents); ASSERT_TRUE(web_contents);
...@@ -105,6 +105,7 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) { ...@@ -105,6 +105,7 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) {
params); params);
menu->Init(); menu->Init();
ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST));
ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1));
ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
ASSERT_TRUE(menu->HasCommandWithId(IDC_RELOAD)); ASSERT_TRUE(menu->HasCommandWithId(IDC_RELOAD));
ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK));
......
...@@ -392,36 +392,42 @@ void RenderViewContextMenu::AppendExtensionItems( ...@@ -392,36 +392,42 @@ void RenderViewContextMenu::AppendExtensionItems(
if (*index == 0 && menu_model_.GetItemCount()) if (*index == 0 && menu_model_.GetItemCount())
menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
int menu_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + (*index)++; // Extensions (other than platform apps) are only allowed one top-level slot
// (and it can't be a radio or checkbox item because we are going to put the
// Extensions are only allowed one top-level slot (and it can't be a radio or // extension icon next to it).
// checkbox item because we are going to put the extension icon next to it).
// If they have more than that, we automatically push them into a submenu. // If they have more than that, we automatically push them into a submenu.
string16 title; if (extension->is_platform_app()) {
MenuItem::List submenu_items; RecursivelyAppendExtensionItems(items, can_cross_incognito, &menu_model_,
if (items.size() > 1 || items[0]->type() != MenuItem::NORMAL) { index);
title = UTF8ToUTF16(extension->name());
submenu_items = items;
} else { } else {
MenuItem* item = items[0]; int menu_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + (*index)++;
extension_item_map_[menu_id] = item->id(); string16 title;
title = item->TitleWithReplacement(PrintableSelectionText(), MenuItem::List submenu_items;
if (items.size() > 1 || items[0]->type() != MenuItem::NORMAL) {
title = UTF8ToUTF16(extension->name());
submenu_items = items;
} else {
MenuItem* item = items[0];
extension_item_map_[menu_id] = item->id();
title = item->TitleWithReplacement(PrintableSelectionText(),
kMaxExtensionItemTitleLength); kMaxExtensionItemTitleLength);
submenu_items = GetRelevantExtensionItems(item->children(), params_, submenu_items = GetRelevantExtensionItems(item->children(), params_,
profile_, can_cross_incognito); profile_, can_cross_incognito);
} }
// Now add our item(s) to the menu_model_. // Now add our item(s) to the menu_model_.
if (submenu_items.empty()) { if (submenu_items.empty()) {
menu_model_.AddItem(menu_id, title); menu_model_.AddItem(menu_id, title);
} else { } else {
ui::SimpleMenuModel* submenu = new ui::SimpleMenuModel(this); ui::SimpleMenuModel* submenu = new ui::SimpleMenuModel(this);
extension_menu_models_.push_back(submenu); extension_menu_models_.push_back(submenu);
menu_model_.AddSubMenu(menu_id, title, submenu); menu_model_.AddSubMenu(menu_id, title, submenu);
RecursivelyAppendExtensionItems(submenu_items, can_cross_incognito, submenu, RecursivelyAppendExtensionItems(submenu_items, can_cross_incognito,
index); submenu, index);
}
SetExtensionIcon(extension_id);
} }
SetExtensionIcon(extension_id);
} }
void RenderViewContextMenu::RecursivelyAppendExtensionItems( void RenderViewContextMenu::RecursivelyAppendExtensionItems(
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
// found in the LICENSE file. // found in the LICENSE file.
chrome.app.runtime.onLaunched.addListener(function() { chrome.app.runtime.onLaunched.addListener(function() {
chrome.contextMenus.create({ chrome.contextMenus.create({title: 'Extension Item 1',
id: 'id1', id: 'id1'}, function() {
title: 'Extension Item 1', chrome.contextMenus.create({title: 'Extension Item 2',
}, id: 'id2'}, function() {
function() { chrome.app.window.create('main.html', {}, function() {});
chrome.app.window.create('main.html', {}, function() {}); });
}); });
}); });
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