Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(511)

Side by Side Diff: chrome/browser/renderer_context_menu/render_view_context_menu.cc

Issue 186213003: <webview>: Context menu API implementation CL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync @tott Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/renderer_context_menu/render_view_context_menu.h" 5 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 18 matching lines...) Expand all
29 #include "chrome/browser/chrome_notification_types.h" 29 #include "chrome/browser/chrome_notification_types.h"
30 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" 30 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
31 #include "chrome/browser/devtools/devtools_window.h" 31 #include "chrome/browser/devtools/devtools_window.h"
32 #include "chrome/browser/download/download_service.h" 32 #include "chrome/browser/download/download_service.h"
33 #include "chrome/browser/download/download_service_factory.h" 33 #include "chrome/browser/download/download_service_factory.h"
34 #include "chrome/browser/download/download_stats.h" 34 #include "chrome/browser/download/download_stats.h"
35 #include "chrome/browser/extensions/devtools_util.h" 35 #include "chrome/browser/extensions/devtools_util.h"
36 #include "chrome/browser/extensions/extension_host.h" 36 #include "chrome/browser/extensions/extension_host.h"
37 #include "chrome/browser/extensions/extension_service.h" 37 #include "chrome/browser/extensions/extension_service.h"
38 #include "chrome/browser/google/google_util.h" 38 #include "chrome/browser/google/google_util.h"
39 #include "chrome/browser/guestview/webview/webview_guest.h"
39 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" 40 #include "chrome/browser/plugins/chrome_plugin_service_filter.h"
40 #include "chrome/browser/prefs/incognito_mode_prefs.h" 41 #include "chrome/browser/prefs/incognito_mode_prefs.h"
41 #include "chrome/browser/profiles/profile.h" 42 #include "chrome/browser/profiles/profile.h"
42 #include "chrome/browser/profiles/profile_io_data.h" 43 #include "chrome/browser/profiles/profile_io_data.h"
43 #include "chrome/browser/renderer_context_menu/context_menu_content_type_factory .h" 44 #include "chrome/browser/renderer_context_menu/context_menu_content_type_factory .h"
44 #include "chrome/browser/renderer_context_menu/spellchecker_submenu_observer.h" 45 #include "chrome/browser/renderer_context_menu/spellchecker_submenu_observer.h"
45 #include "chrome/browser/renderer_context_menu/spelling_menu_observer.h" 46 #include "chrome/browser/renderer_context_menu/spelling_menu_observer.h"
46 #include "chrome/browser/search/search.h" 47 #include "chrome/browser/search/search.h"
47 #include "chrome/browser/search_engines/search_terms_data.h" 48 #include "chrome/browser/search_engines/search_terms_data.h"
48 #include "chrome/browser/search_engines/template_url.h" 49 #include "chrome/browser/search_engines/template_url.h"
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 RenderViewContextMenu::RenderViewContextMenu( 399 RenderViewContextMenu::RenderViewContextMenu(
399 content::RenderFrameHost* render_frame_host, 400 content::RenderFrameHost* render_frame_host,
400 const content::ContextMenuParams& params) 401 const content::ContextMenuParams& params)
401 : params_(params), 402 : params_(params),
402 source_web_contents_(WebContents::FromRenderFrameHost(render_frame_host)), 403 source_web_contents_(WebContents::FromRenderFrameHost(render_frame_host)),
403 render_process_id_(render_frame_host->GetProcess()->GetID()), 404 render_process_id_(render_frame_host->GetProcess()->GetID()),
404 render_frame_id_(render_frame_host->GetRoutingID()), 405 render_frame_id_(render_frame_host->GetRoutingID()),
405 profile_(Profile::FromBrowserContext( 406 profile_(Profile::FromBrowserContext(
406 source_web_contents_->GetBrowserContext())), 407 source_web_contents_->GetBrowserContext())),
407 menu_model_(this), 408 menu_model_(this),
408 extension_items_(profile_, this, &menu_model_, 409 extension_items_(profile_,
409 base::Bind(MenuItemMatchesParams, params_)), 410 this,
411 &menu_model_,
412 base::Bind(MenuItemMatchesParams, params_)),
410 speech_input_submenu_model_(this), 413 speech_input_submenu_model_(this),
411 protocol_handler_submenu_model_(this), 414 protocol_handler_submenu_model_(this),
412 protocol_handler_registry_( 415 protocol_handler_registry_(
413 ProtocolHandlerRegistryFactory::GetForProfile(profile_)), 416 ProtocolHandlerRegistryFactory::GetForProfile(profile_)),
414 command_executed_(false) { 417 command_executed_(false) {
415 content_type_.reset(ContextMenuContentTypeFactory::Create( 418 content_type_.reset(ContextMenuContentTypeFactory::Create(
416 source_web_contents_, 419 source_web_contents_,
417 render_frame_host, params)); 420 render_frame_host, params));
418 } 421 }
419 422
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 521
519 MenuManager* menu_manager = MenuManager::Get(profile_); 522 MenuManager* menu_manager = MenuManager::Get(profile_);
520 if (!menu_manager) 523 if (!menu_manager)
521 return; 524 return;
522 525
523 base::string16 printable_selection_text = PrintableSelectionText(); 526 base::string16 printable_selection_text = PrintableSelectionText();
524 EscapeAmpersands(&printable_selection_text); 527 EscapeAmpersands(&printable_selection_text);
525 528
526 // Get a list of extension id's that have context menu items, and sort by the 529 // Get a list of extension id's that have context menu items, and sort by the
527 // top level context menu title of the extension. 530 // top level context menu title of the extension.
528 std::set<std::string> ids = menu_manager->ExtensionIds(); 531 std::set<MenuItem::ExtensionKey> ids = menu_manager->ExtensionIds();
529 std::vector<base::string16> sorted_menu_titles; 532 std::vector<base::string16> sorted_menu_titles;
530 std::map<base::string16, std::string> map_ids; 533 std::map<base::string16, std::string> map_ids;
531 for (std::set<std::string>::iterator i = ids.begin(); i != ids.end(); ++i) { 534 for (std::set<MenuItem::ExtensionKey>::iterator i = ids.begin();
532 const Extension* extension = service->GetExtensionById(*i, false); 535 i != ids.end();
536 ++i) {
537 const Extension* extension =
538 service->GetExtensionById(i->extension_id, false);
533 // Platform apps have their context menus created directly in 539 // Platform apps have their context menus created directly in
534 // AppendPlatformAppItems. 540 // AppendPlatformAppItems.
535 if (extension && !extension->is_platform_app()) { 541 if (extension && !extension->is_platform_app()) {
536 base::string16 menu_title = extension_items_.GetTopLevelContextMenuTitle( 542 base::string16 menu_title = extension_items_.GetTopLevelContextMenuTitle(
537 *i, printable_selection_text); 543 *i, printable_selection_text);
538 map_ids[menu_title] = *i; 544 map_ids[menu_title] = i->extension_id;
539 sorted_menu_titles.push_back(menu_title); 545 sorted_menu_titles.push_back(menu_title);
540 } 546 }
541 } 547 }
542 if (sorted_menu_titles.empty()) 548 if (sorted_menu_titles.empty())
543 return; 549 return;
544 550
545 const std::string app_locale = g_browser_process->GetApplicationLocale(); 551 const std::string app_locale = g_browser_process->GetApplicationLocale();
546 l10n_util::SortStrings16(app_locale, &sorted_menu_titles); 552 l10n_util::SortStrings16(app_locale, &sorted_menu_titles);
547 553
548 int index = 0; 554 int index = 0;
549 base::TimeTicks begin = base::TimeTicks::Now(); 555 base::TimeTicks begin = base::TimeTicks::Now();
550 for (size_t i = 0; i < sorted_menu_titles.size(); ++i) { 556 for (size_t i = 0; i < sorted_menu_titles.size(); ++i) {
551 const std::string& id = map_ids[sorted_menu_titles[i]]; 557 const std::string& id = map_ids[sorted_menu_titles[i]];
552 extension_items_.AppendExtensionItems(id, printable_selection_text, 558 const MenuItem::ExtensionKey extension_key(id);
553 &index); 559 extension_items_.AppendExtensionItems(
560 extension_key, printable_selection_text, &index);
554 } 561 }
555 562
556 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", 563 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime",
557 base::TimeTicks::Now() - begin); 564 base::TimeTicks::Now() - begin);
558 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); 565 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index);
559 } 566 }
560 567
561 void RenderViewContextMenu::AppendCurrentExtensionItems() { 568 void RenderViewContextMenu::AppendCurrentExtensionItems() {
562 // Avoid appending extension related items when |extension| is null. 569 // Avoid appending extension related items when |extension| is null.
563 // For Panel, this happens when the panel is navigated to a url outside of the 570 // For Panel, this happens when the panel is navigated to a url outside of the
564 // extension's package. 571 // extension's package.
565 const Extension* extension = GetExtension(); 572 const Extension* extension = GetExtension();
566 if (extension) { 573 if (extension) {
567 // Only add extension items from this extension. 574 // Only add extension items from this extension.
568 int index = 0; 575 int index = 0;
569 extension_items_.AppendExtensionItems(extension->id(), 576 const MenuItem::ExtensionKey key(
570 PrintableSelectionText(), &index); 577 extension->id(), WebViewGuest::GetViewInstanceId(source_web_contents_));
578 extension_items_.AppendExtensionItems(
579 key, PrintableSelectionText(), &index);
571 } 580 }
572 } 581 }
573 582
574 void RenderViewContextMenu::InitMenu() { 583 void RenderViewContextMenu::InitMenu() {
575 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_CUSTOM)) { 584 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_CUSTOM)) {
576 AppendCustomItems(); 585 AppendCustomItems();
577 586
578 const bool has_selection = !params_.selection_text.empty(); 587 const bool has_selection = !params_.selection_text.empty();
579 if (has_selection) { 588 if (has_selection) {
580 // We will add more items if there's a selection, so add a separator. 589 // We will add more items if there's a selection, so add a separator.
(...skipping 1471 matching lines...) Expand 10 before | Expand all | Expand 10 after
2052 source_web_contents_->GetRenderViewHost()-> 2061 source_web_contents_->GetRenderViewHost()->
2053 ExecuteMediaPlayerActionAtLocation(location, action); 2062 ExecuteMediaPlayerActionAtLocation(location, action);
2054 } 2063 }
2055 2064
2056 void RenderViewContextMenu::PluginActionAt( 2065 void RenderViewContextMenu::PluginActionAt(
2057 const gfx::Point& location, 2066 const gfx::Point& location,
2058 const WebPluginAction& action) { 2067 const WebPluginAction& action) {
2059 source_web_contents_->GetRenderViewHost()-> 2068 source_web_contents_->GetRenderViewHost()->
2060 ExecutePluginActionAtLocation(location, action); 2069 ExecutePluginActionAtLocation(location, action);
2061 } 2070 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698