| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 #include "content/public/browser/download_manager.h" | 93 #include "content/public/browser/download_manager.h" |
| 94 #include "content/public/browser/download_save_info.h" | 94 #include "content/public/browser/download_save_info.h" |
| 95 #include "content/public/browser/download_url_parameters.h" | 95 #include "content/public/browser/download_url_parameters.h" |
| 96 #include "content/public/browser/navigation_details.h" | 96 #include "content/public/browser/navigation_details.h" |
| 97 #include "content/public/browser/navigation_entry.h" | 97 #include "content/public/browser/navigation_entry.h" |
| 98 #include "content/public/browser/notification_service.h" | 98 #include "content/public/browser/notification_service.h" |
| 99 #include "content/public/browser/render_frame_host.h" | 99 #include "content/public/browser/render_frame_host.h" |
| 100 #include "content/public/browser/render_process_host.h" | 100 #include "content/public/browser/render_process_host.h" |
| 101 #include "content/public/browser/render_view_host.h" | 101 #include "content/public/browser/render_view_host.h" |
| 102 #include "content/public/browser/render_widget_host_view.h" | 102 #include "content/public/browser/render_widget_host_view.h" |
| 103 #include "content/public/browser/storage_partition.h" |
| 103 #include "content/public/browser/user_metrics.h" | 104 #include "content/public/browser/user_metrics.h" |
| 104 #include "content/public/browser/web_contents.h" | 105 #include "content/public/browser/web_contents.h" |
| 105 #include "content/public/common/browser_plugin_guest_mode.h" | 106 #include "content/public/common/browser_plugin_guest_mode.h" |
| 106 #include "content/public/common/menu_item.h" | 107 #include "content/public/common/menu_item.h" |
| 107 #include "content/public/common/ssl_status.h" | 108 #include "content/public/common/ssl_status.h" |
| 108 #include "content/public/common/url_utils.h" | 109 #include "content/public/common/url_utils.h" |
| 109 #include "extensions/browser/extension_host.h" | 110 #include "extensions/browser/extension_host.h" |
| 110 #include "extensions/browser/extension_system.h" | 111 #include "extensions/browser/extension_system.h" |
| 111 #include "extensions/browser/guest_view/web_view/web_view_guest.h" | 112 #include "extensions/browser/guest_view/web_view/web_view_guest.h" |
| 112 #include "extensions/browser/view_type_utils.h" | 113 #include "extensions/browser/view_type_utils.h" |
| (...skipping 1631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1744 | 1745 |
| 1745 return false; | 1746 return false; |
| 1746 } | 1747 } |
| 1747 | 1748 |
| 1748 void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) { | 1749 void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) { |
| 1749 RenderViewContextMenuBase::ExecuteCommand(id, event_flags); | 1750 RenderViewContextMenuBase::ExecuteCommand(id, event_flags); |
| 1750 if (command_executed_) | 1751 if (command_executed_) |
| 1751 return; | 1752 return; |
| 1752 command_executed_ = true; | 1753 command_executed_ = true; |
| 1753 | 1754 |
| 1755 // MAY BE NULL. Check before using. The frame under the cursor could have |
| 1756 // been asynchronously destroyed while the context menu was open, but many |
| 1757 // context menu commands should continue to function in this situation (e.g. |
| 1758 // "Reload"). |
| 1759 RenderFrameHost* render_frame_host = GetRenderFrameHost(); |
| 1760 |
| 1754 // Process extension menu items. | 1761 // Process extension menu items. |
| 1755 if (ContextMenuMatcher::IsExtensionsCustomCommandId(id)) { | 1762 if (ContextMenuMatcher::IsExtensionsCustomCommandId(id)) { |
| 1756 extension_items_.ExecuteCommand(id, source_web_contents_, | 1763 if (render_frame_host) { |
| 1757 GetRenderFrameHost(), params_); | 1764 extension_items_.ExecuteCommand(id, source_web_contents_, |
| 1765 render_frame_host, params_); |
| 1766 } |
| 1758 return; | 1767 return; |
| 1759 } | 1768 } |
| 1760 | 1769 |
| 1761 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && | 1770 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && |
| 1762 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { | 1771 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { |
| 1763 ProtocolHandlerRegistry::ProtocolHandlerList handlers = | 1772 ProtocolHandlerRegistry::ProtocolHandlerList handlers = |
| 1764 GetHandlersForLinkUrl(); | 1773 GetHandlersForLinkUrl(); |
| 1765 if (handlers.empty()) | 1774 if (handlers.empty()) |
| 1766 return; | 1775 return; |
| 1767 | 1776 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1822 GetDocumentURL(params_), | 1831 GetDocumentURL(params_), |
| 1823 NEW_WINDOW, | 1832 NEW_WINDOW, |
| 1824 ui::PAGE_TRANSITION_LINK); | 1833 ui::PAGE_TRANSITION_LINK); |
| 1825 break; | 1834 break; |
| 1826 | 1835 |
| 1827 case IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD: | 1836 case IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD: |
| 1828 OpenURL(params_.link_url, GURL(), OFF_THE_RECORD, | 1837 OpenURL(params_.link_url, GURL(), OFF_THE_RECORD, |
| 1829 ui::PAGE_TRANSITION_LINK); | 1838 ui::PAGE_TRANSITION_LINK); |
| 1830 break; | 1839 break; |
| 1831 | 1840 |
| 1832 case IDC_CONTENT_CONTEXT_SAVELINKAS: { | 1841 case IDC_CONTENT_CONTEXT_SAVELINKAS: |
| 1833 RecordDownloadSource(DOWNLOAD_INITIATED_BY_CONTEXT_MENU); | 1842 SaveLinkAs(); |
| 1834 const GURL& url = params_.link_url; | |
| 1835 content::Referrer referrer = CreateReferrer(url, params_); | |
| 1836 DownloadManager* dlm = | |
| 1837 BrowserContext::GetDownloadManager(browser_context_); | |
| 1838 std::unique_ptr<DownloadUrlParameters> dl_params( | |
| 1839 DownloadUrlParameters::FromWebContents(source_web_contents_, url)); | |
| 1840 dl_params->set_referrer(referrer); | |
| 1841 dl_params->set_referrer_encoding(params_.frame_charset); | |
| 1842 dl_params->set_suggested_name(params_.suggested_filename); | |
| 1843 dl_params->set_prompt(true); | |
| 1844 dlm->DownloadUrl(std::move(dl_params)); | |
| 1845 break; | 1843 break; |
| 1846 } | |
| 1847 | 1844 |
| 1848 case IDC_CONTENT_CONTEXT_SAVEAVAS: | 1845 case IDC_CONTENT_CONTEXT_SAVEAVAS: |
| 1849 case IDC_CONTENT_CONTEXT_SAVEIMAGEAS: { | 1846 case IDC_CONTENT_CONTEXT_SAVEIMAGEAS: { |
| 1850 bool is_large_data_url = params_.has_image_contents && | 1847 bool is_large_data_url = params_.has_image_contents && |
| 1851 params_.src_url.is_empty(); | 1848 params_.src_url.is_empty(); |
| 1852 if (params_.media_type == WebContextMenuData::MediaTypeCanvas || | 1849 if (params_.media_type == WebContextMenuData::MediaTypeCanvas || |
| 1853 (params_.media_type == WebContextMenuData::MediaTypeImage && | 1850 (params_.media_type == WebContextMenuData::MediaTypeImage && |
| 1854 is_large_data_url)) { | 1851 is_large_data_url)) { |
| 1855 source_web_contents_->GetRenderViewHost()->SaveImageAt( | 1852 source_web_contents_->GetRenderViewHost()->SaveImageAt( |
| 1856 params_.x, params_.y); | 1853 params_.x, params_.y); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2005 DCHECK(platform_app->is_platform_app()); | 2002 DCHECK(platform_app->is_platform_app()); |
| 2006 | 2003 |
| 2007 apps::AppLoadService::Get(GetProfile()) | 2004 apps::AppLoadService::Get(GetProfile()) |
| 2008 ->RestartApplication(platform_app->id()); | 2005 ->RestartApplication(platform_app->id()); |
| 2009 break; | 2006 break; |
| 2010 } | 2007 } |
| 2011 | 2008 |
| 2012 case IDC_PRINT: { | 2009 case IDC_PRINT: { |
| 2013 #if defined(ENABLE_PRINTING) | 2010 #if defined(ENABLE_PRINTING) |
| 2014 if (params_.media_type != WebContextMenuData::MediaTypeNone) { | 2011 if (params_.media_type != WebContextMenuData::MediaTypeNone) { |
| 2015 RenderFrameHost* render_frame_host = GetRenderFrameHost(); | |
| 2016 if (render_frame_host) { | 2012 if (render_frame_host) { |
| 2017 render_frame_host->Send(new PrintMsg_PrintNodeUnderContextMenu( | 2013 render_frame_host->Send(new PrintMsg_PrintNodeUnderContextMenu( |
| 2018 render_frame_host->GetRoutingID())); | 2014 render_frame_host->GetRoutingID())); |
| 2019 } | 2015 } |
| 2020 break; | 2016 break; |
| 2021 } | 2017 } |
| 2022 | 2018 |
| 2023 printing::StartPrint( | 2019 printing::StartPrint( |
| 2024 source_web_contents_, | 2020 source_web_contents_, |
| 2025 GetPrefs(browser_context_)->GetBoolean(prefs::kPrintPreviewDisabled), | 2021 GetPrefs(browser_context_)->GetBoolean(prefs::kPrintPreviewDisabled), |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2292 } | 2288 } |
| 2293 | 2289 |
| 2294 void RenderViewContextMenu::Inspect(int x, int y) { | 2290 void RenderViewContextMenu::Inspect(int x, int y) { |
| 2295 content::RecordAction(UserMetricsAction("DevTools_InspectElement")); | 2291 content::RecordAction(UserMetricsAction("DevTools_InspectElement")); |
| 2296 RenderFrameHost* render_frame_host = GetRenderFrameHost(); | 2292 RenderFrameHost* render_frame_host = GetRenderFrameHost(); |
| 2297 if (!render_frame_host) | 2293 if (!render_frame_host) |
| 2298 return; | 2294 return; |
| 2299 DevToolsWindow::InspectElement(render_frame_host, x, y); | 2295 DevToolsWindow::InspectElement(render_frame_host, x, y); |
| 2300 } | 2296 } |
| 2301 | 2297 |
| 2298 void RenderViewContextMenu::SaveLinkAs() { |
| 2299 RenderFrameHost* render_frame_host = GetRenderFrameHost(); |
| 2300 if (!render_frame_host) |
| 2301 return; |
| 2302 |
| 2303 RecordDownloadSource(DOWNLOAD_INITIATED_BY_CONTEXT_MENU); |
| 2304 |
| 2305 const GURL& url = params_.link_url; |
| 2306 content::StoragePartition* storage_partition = |
| 2307 BrowserContext::GetStoragePartition( |
| 2308 source_web_contents_->GetBrowserContext(), |
| 2309 render_frame_host->GetSiteInstance()); |
| 2310 |
| 2311 std::unique_ptr<DownloadUrlParameters> dl_params( |
| 2312 new DownloadUrlParameters( |
| 2313 url, render_frame_host->GetProcess()->GetID(), |
| 2314 render_frame_host->GetRenderViewHost()->GetRoutingID(), |
| 2315 render_frame_host->GetRoutingID(), |
| 2316 storage_partition->GetURLRequestContext())); |
| 2317 dl_params->set_referrer(CreateReferrer(url, params_)); |
| 2318 dl_params->set_referrer_encoding(params_.frame_charset); |
| 2319 dl_params->set_suggested_name(params_.suggested_filename); |
| 2320 dl_params->set_prompt(true); |
| 2321 |
| 2322 BrowserContext::GetDownloadManager(browser_context_)->DownloadUrl( |
| 2323 std::move(dl_params)); |
| 2324 } |
| 2325 |
| 2302 void RenderViewContextMenu::WriteURLToClipboard(const GURL& url) { | 2326 void RenderViewContextMenu::WriteURLToClipboard(const GURL& url) { |
| 2303 ::WriteURLToClipboard(url); | 2327 ::WriteURLToClipboard(url); |
| 2304 } | 2328 } |
| 2305 | 2329 |
| 2306 void RenderViewContextMenu::MediaPlayerActionAt( | 2330 void RenderViewContextMenu::MediaPlayerActionAt( |
| 2307 const gfx::Point& location, | 2331 const gfx::Point& location, |
| 2308 const WebMediaPlayerAction& action) { | 2332 const WebMediaPlayerAction& action) { |
| 2309 source_web_contents_->GetRenderViewHost()-> | 2333 source_web_contents_->GetRenderViewHost()-> |
| 2310 ExecuteMediaPlayerActionAtLocation(location, action); | 2334 ExecuteMediaPlayerActionAtLocation(location, action); |
| 2311 } | 2335 } |
| 2312 | 2336 |
| 2313 void RenderViewContextMenu::PluginActionAt( | 2337 void RenderViewContextMenu::PluginActionAt( |
| 2314 const gfx::Point& location, | 2338 const gfx::Point& location, |
| 2315 const WebPluginAction& action) { | 2339 const WebPluginAction& action) { |
| 2316 source_web_contents_->GetRenderViewHost()-> | 2340 source_web_contents_->GetRenderViewHost()-> |
| 2317 ExecutePluginActionAtLocation(location, action); | 2341 ExecutePluginActionAtLocation(location, action); |
| 2318 } | 2342 } |
| OLD | NEW |