OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <algorithm> | 5 #include <algorithm> |
6 #include <set> | 6 #include <set> |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 9 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
10 | 10 |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 GetRelevantExtensionItems(*all_items, params_, profile_, | 385 GetRelevantExtensionItems(*all_items, params_, profile_, |
386 can_cross_incognito); | 386 can_cross_incognito); |
387 if (items.empty()) | 387 if (items.empty()) |
388 return; | 388 return; |
389 | 389 |
390 // If this is the first extension-provided menu item, and there are other | 390 // If this is the first extension-provided menu item, and there are other |
391 // items in the menu, add a separator. | 391 // items in the menu, add a separator. |
392 if (*index == 0 && menu_model_.GetItemCount()) | 392 if (*index == 0 && menu_model_.GetItemCount()) |
393 menu_model_.AddSeparator(); | 393 menu_model_.AddSeparator(); |
394 | 394 |
395 int menu_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + (*index)++; | 395 // Extensions (other than platform apps) are only allowed one top-level slot |
| 396 // (and it can't be a radio or checkbox item because we are going to put the |
| 397 // extension icon next to it). |
| 398 // If they have more than that, we automatically push them into a submenu. |
| 399 if (extension->is_platform_app()) { |
| 400 RecursivelyAppendExtensionItems(items, can_cross_incognito, &menu_model_, |
| 401 index); |
| 402 } else { |
| 403 int menu_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + (*index)++; |
| 404 string16 title; |
| 405 MenuItem::List submenu_items; |
396 | 406 |
397 // Extensions are only allowed one top-level slot (and it can't be a radio or | 407 if (items.size() > 1 || items[0]->type() != MenuItem::NORMAL) { |
398 // checkbox item because we are going to put the extension icon next to it). | 408 title = UTF8ToUTF16(extension->name()); |
399 // If they have more than that, we automatically push them into a submenu. | 409 submenu_items = items; |
400 string16 title; | 410 } else { |
401 MenuItem::List submenu_items; | 411 MenuItem* item = items[0]; |
402 if (items.size() > 1 || items[0]->type() != MenuItem::NORMAL) { | 412 extension_item_map_[menu_id] = item->id(); |
403 title = UTF8ToUTF16(extension->name()); | 413 title = item->TitleWithReplacement(PrintableSelectionText(), |
404 submenu_items = items; | |
405 } else { | |
406 MenuItem* item = items[0]; | |
407 extension_item_map_[menu_id] = item->id(); | |
408 title = item->TitleWithReplacement(PrintableSelectionText(), | |
409 kMaxExtensionItemTitleLength); | 414 kMaxExtensionItemTitleLength); |
410 submenu_items = GetRelevantExtensionItems(item->children(), params_, | 415 submenu_items = GetRelevantExtensionItems(item->children(), params_, |
411 profile_, can_cross_incognito); | 416 profile_, can_cross_incognito); |
| 417 } |
| 418 |
| 419 // Now add our item(s) to the menu_model_. |
| 420 if (submenu_items.empty()) { |
| 421 menu_model_.AddItem(menu_id, title); |
| 422 } else { |
| 423 ui::SimpleMenuModel* submenu = new ui::SimpleMenuModel(this); |
| 424 extension_menu_models_.push_back(submenu); |
| 425 menu_model_.AddSubMenu(menu_id, title, submenu); |
| 426 RecursivelyAppendExtensionItems(submenu_items, can_cross_incognito, |
| 427 submenu, index); |
| 428 } |
| 429 SetExtensionIcon(extension_id); |
412 } | 430 } |
413 | |
414 // Now add our item(s) to the menu_model_. | |
415 if (submenu_items.empty()) { | |
416 menu_model_.AddItem(menu_id, title); | |
417 } else { | |
418 ui::SimpleMenuModel* submenu = new ui::SimpleMenuModel(this); | |
419 extension_menu_models_.push_back(submenu); | |
420 menu_model_.AddSubMenu(menu_id, title, submenu); | |
421 RecursivelyAppendExtensionItems(submenu_items, can_cross_incognito, submenu, | |
422 index); | |
423 } | |
424 SetExtensionIcon(extension_id); | |
425 } | 431 } |
426 | 432 |
427 void RenderViewContextMenu::RecursivelyAppendExtensionItems( | 433 void RenderViewContextMenu::RecursivelyAppendExtensionItems( |
428 const MenuItem::List& items, | 434 const MenuItem::List& items, |
429 bool can_cross_incognito, | 435 bool can_cross_incognito, |
430 ui::SimpleMenuModel* menu_model, | 436 ui::SimpleMenuModel* menu_model, |
431 int* index) { | 437 int* index) { |
432 string16 selection_text = PrintableSelectionText(); | 438 string16 selection_text = PrintableSelectionText(); |
433 MenuItem::Type last_type = MenuItem::NORMAL; | 439 MenuItem::Type last_type = MenuItem::NORMAL; |
434 int radio_group_id = 1; | 440 int radio_group_id = 1; |
(...skipping 1574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2009 source_web_contents_->GetRenderViewHost()-> | 2015 source_web_contents_->GetRenderViewHost()-> |
2010 ExecuteMediaPlayerActionAtLocation(location, action); | 2016 ExecuteMediaPlayerActionAtLocation(location, action); |
2011 } | 2017 } |
2012 | 2018 |
2013 void RenderViewContextMenu::PluginActionAt( | 2019 void RenderViewContextMenu::PluginActionAt( |
2014 const gfx::Point& location, | 2020 const gfx::Point& location, |
2015 const WebPluginAction& action) { | 2021 const WebPluginAction& action) { |
2016 source_web_contents_->GetRenderViewHost()-> | 2022 source_web_contents_->GetRenderViewHost()-> |
2017 ExecutePluginActionAtLocation(location, action); | 2023 ExecutePluginActionAtLocation(location, action); |
2018 } | 2024 } |
OLD | NEW |