Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 402 RenderViewContextMenu::RenderViewContextMenu( | 403 RenderViewContextMenu::RenderViewContextMenu( |
| 403 content::RenderFrameHost* render_frame_host, | 404 content::RenderFrameHost* render_frame_host, |
| 404 const content::ContextMenuParams& params) | 405 const content::ContextMenuParams& params) |
| 405 : params_(params), | 406 : params_(params), |
| 406 source_web_contents_(WebContents::FromRenderFrameHost(render_frame_host)), | 407 source_web_contents_(WebContents::FromRenderFrameHost(render_frame_host)), |
| 407 render_process_id_(render_frame_host->GetProcess()->GetID()), | 408 render_process_id_(render_frame_host->GetProcess()->GetID()), |
| 408 render_frame_id_(render_frame_host->GetRoutingID()), | 409 render_frame_id_(render_frame_host->GetRoutingID()), |
| 409 profile_(Profile::FromBrowserContext( | 410 profile_(Profile::FromBrowserContext( |
| 410 source_web_contents_->GetBrowserContext())), | 411 source_web_contents_->GetBrowserContext())), |
| 411 menu_model_(this), | 412 menu_model_(this), |
| 412 extension_items_(profile_, this, &menu_model_, | 413 extension_items_(profile_, |
| 413 base::Bind(MenuItemMatchesParams, params_)), | 414 this, |
| 415 &menu_model_, | |
| 416 base::Bind(MenuItemMatchesParams, params_)), | |
| 414 speech_input_submenu_model_(this), | 417 speech_input_submenu_model_(this), |
| 415 protocol_handler_submenu_model_(this), | 418 protocol_handler_submenu_model_(this), |
| 416 protocol_handler_registry_( | 419 protocol_handler_registry_( |
| 417 ProtocolHandlerRegistryFactory::GetForProfile(profile_)), | 420 ProtocolHandlerRegistryFactory::GetForProfile(profile_)), |
| 418 command_executed_(false) { | 421 command_executed_(false) { |
| 419 content_type_.reset(ContextMenuContentTypeFactory::Create( | 422 content_type_.reset(ContextMenuContentTypeFactory::Create( |
| 420 source_web_contents_, | 423 source_web_contents_, |
| 421 render_frame_host, params)); | 424 render_frame_host, params)); |
| 422 } | 425 } |
| 423 | 426 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 493 contexts.Contains(MenuItem::PAGE)) | 496 contexts.Contains(MenuItem::PAGE)) |
| 494 return true; | 497 return true; |
| 495 | 498 |
| 496 return false; | 499 return false; |
| 497 } | 500 } |
| 498 | 501 |
| 499 static const GURL& GetDocumentURL(const content::ContextMenuParams& params) { | 502 static const GURL& GetDocumentURL(const content::ContextMenuParams& params) { |
| 500 return params.frame_url.is_empty() ? params.page_url : params.frame_url; | 503 return params.frame_url.is_empty() ? params.page_url : params.frame_url; |
| 501 } | 504 } |
| 502 | 505 |
| 503 // static | 506 // static. |
|
Fady Samuel
2014/03/05 17:54:10
This change seems unnecesary.
lazyboy
2014/03/05 18:27:59
Done.
| |
| 504 bool RenderViewContextMenu::MenuItemMatchesParams( | 507 bool RenderViewContextMenu::MenuItemMatchesParams( |
| 505 const content::ContextMenuParams& params, | 508 const content::ContextMenuParams& params, |
| 506 const extensions::MenuItem* item) { | 509 const extensions::MenuItem* item) { |
| 507 bool match = ExtensionContextAndPatternMatch(params, item->contexts(), | 510 bool match = ExtensionContextAndPatternMatch(params, item->contexts(), |
| 508 item->target_url_patterns()); | 511 item->target_url_patterns()); |
| 509 if (!match) | 512 if (!match) |
| 510 return false; | 513 return false; |
| 511 | 514 |
| 512 const GURL& document_url = GetDocumentURL(params); | 515 const GURL& document_url = GetDocumentURL(params); |
| 513 return ExtensionPatternMatch(item->document_url_patterns(), document_url); | 516 return ExtensionPatternMatch(item->document_url_patterns(), document_url); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 530 // Get a list of extension id's that have context menu items, and sort by the | 533 // Get a list of extension id's that have context menu items, and sort by the |
| 531 // top level context menu title of the extension. | 534 // top level context menu title of the extension. |
| 532 std::set<std::string> ids = menu_manager->ExtensionIds(); | 535 std::set<std::string> ids = menu_manager->ExtensionIds(); |
| 533 std::vector<base::string16> sorted_menu_titles; | 536 std::vector<base::string16> sorted_menu_titles; |
| 534 std::map<base::string16, std::string> map_ids; | 537 std::map<base::string16, std::string> map_ids; |
| 535 for (std::set<std::string>::iterator i = ids.begin(); i != ids.end(); ++i) { | 538 for (std::set<std::string>::iterator i = ids.begin(); i != ids.end(); ++i) { |
| 536 const Extension* extension = service->GetExtensionById(*i, false); | 539 const Extension* extension = service->GetExtensionById(*i, false); |
| 537 // Platform apps have their context menus created directly in | 540 // Platform apps have their context menus created directly in |
| 538 // AppendPlatformAppItems. | 541 // AppendPlatformAppItems. |
| 539 if (extension && !extension->is_platform_app()) { | 542 if (extension && !extension->is_platform_app()) { |
| 543 const MenuItem::ExtensionKey& key(*i); | |
| 540 base::string16 menu_title = extension_items_.GetTopLevelContextMenuTitle( | 544 base::string16 menu_title = extension_items_.GetTopLevelContextMenuTitle( |
| 541 *i, printable_selection_text); | 545 key, printable_selection_text); |
| 542 map_ids[menu_title] = *i; | 546 map_ids[menu_title] = *i; |
| 543 sorted_menu_titles.push_back(menu_title); | 547 sorted_menu_titles.push_back(menu_title); |
| 544 } | 548 } |
| 545 } | 549 } |
| 546 if (sorted_menu_titles.empty()) | 550 if (sorted_menu_titles.empty()) |
| 547 return; | 551 return; |
| 548 | 552 |
| 549 const std::string app_locale = g_browser_process->GetApplicationLocale(); | 553 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
| 550 l10n_util::SortStrings16(app_locale, &sorted_menu_titles); | 554 l10n_util::SortStrings16(app_locale, &sorted_menu_titles); |
| 551 | 555 |
| 552 int index = 0; | 556 int index = 0; |
| 553 base::TimeTicks begin = base::TimeTicks::Now(); | 557 base::TimeTicks begin = base::TimeTicks::Now(); |
| 554 for (size_t i = 0; i < sorted_menu_titles.size(); ++i) { | 558 for (size_t i = 0; i < sorted_menu_titles.size(); ++i) { |
| 555 const std::string& id = map_ids[sorted_menu_titles[i]]; | 559 const std::string& id = map_ids[sorted_menu_titles[i]]; |
| 556 extension_items_.AppendExtensionItems(id, printable_selection_text, | 560 const MenuItem::ExtensionKey& extension_key = MenuItem::ExtensionKey(id); |
|
Fady Samuel
2014/03/05 17:54:10
This doesn't look right. You're constructing a tem
lazyboy
2014/03/05 18:27:59
Ou, don't know how it got there, fixed, thanks.
| |
| 557 &index); | 561 extension_items_.AppendExtensionItems( |
| 562 extension_key, printable_selection_text, &index); | |
| 558 } | 563 } |
| 559 | 564 |
| 560 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", | 565 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", |
| 561 base::TimeTicks::Now() - begin); | 566 base::TimeTicks::Now() - begin); |
| 562 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); | 567 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); |
| 563 } | 568 } |
| 564 | 569 |
| 565 void RenderViewContextMenu::AppendCurrentExtensionItems() { | 570 void RenderViewContextMenu::AppendCurrentExtensionItems() { |
| 566 // Avoid appending extension related items when |extension| is null. | 571 // Avoid appending extension related items when |extension| is null. |
| 567 // For Panel, this happens when the panel is navigated to a url outside of the | 572 // For Panel, this happens when the panel is navigated to a url outside of the |
| 568 // extension's package. | 573 // extension's package. |
| 569 const Extension* extension = GetExtension(); | 574 const Extension* extension = GetExtension(); |
| 570 if (extension) { | 575 if (extension) { |
| 571 // Only add extension items from this extension. | 576 // Only add extension items from this extension. |
| 572 int index = 0; | 577 int index = 0; |
| 573 extension_items_.AppendExtensionItems(extension->id(), | 578 const MenuItem::ExtensionKey key( |
| 574 PrintableSelectionText(), &index); | 579 extension->id(), WebViewGuest::GetViewInstanceId(source_web_contents_)); |
| 580 extension_items_.AppendExtensionItems( | |
| 581 key, PrintableSelectionText(), &index); | |
| 575 } | 582 } |
| 576 } | 583 } |
| 577 | 584 |
| 578 void RenderViewContextMenu::InitMenu() { | 585 void RenderViewContextMenu::InitMenu() { |
| 579 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_CUSTOM)) { | 586 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_CUSTOM)) { |
| 580 AppendCustomItems(); | 587 AppendCustomItems(); |
| 581 | 588 |
| 582 const bool has_selection = !params_.selection_text.empty(); | 589 const bool has_selection = !params_.selection_text.empty(); |
| 583 if (has_selection) { | 590 if (has_selection) { |
| 584 // We will add more items if there's a selection, so add a separator. | 591 // We will add more items if there's a selection, so add a separator. |
| (...skipping 1460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2045 source_web_contents_->GetRenderViewHost()-> | 2052 source_web_contents_->GetRenderViewHost()-> |
| 2046 ExecuteMediaPlayerActionAtLocation(location, action); | 2053 ExecuteMediaPlayerActionAtLocation(location, action); |
| 2047 } | 2054 } |
| 2048 | 2055 |
| 2049 void RenderViewContextMenu::PluginActionAt( | 2056 void RenderViewContextMenu::PluginActionAt( |
| 2050 const gfx::Point& location, | 2057 const gfx::Point& location, |
| 2051 const WebPluginAction& action) { | 2058 const WebPluginAction& action) { |
| 2052 source_web_contents_->GetRenderViewHost()-> | 2059 source_web_contents_->GetRenderViewHost()-> |
| 2053 ExecutePluginActionAtLocation(location, action); | 2060 ExecutePluginActionAtLocation(location, action); |
| 2054 } | 2061 } |
| OLD | NEW |