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

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

Issue 1977623002: Updates to DownloadUrlParameters in preparation for OOPIF changes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 4 years, 7 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <set> 10 #include <set>
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 #include "content/public/browser/download_manager.h" 92 #include "content/public/browser/download_manager.h"
93 #include "content/public/browser/download_save_info.h" 93 #include "content/public/browser/download_save_info.h"
94 #include "content/public/browser/download_url_parameters.h" 94 #include "content/public/browser/download_url_parameters.h"
95 #include "content/public/browser/navigation_details.h" 95 #include "content/public/browser/navigation_details.h"
96 #include "content/public/browser/navigation_entry.h" 96 #include "content/public/browser/navigation_entry.h"
97 #include "content/public/browser/notification_service.h" 97 #include "content/public/browser/notification_service.h"
98 #include "content/public/browser/render_frame_host.h" 98 #include "content/public/browser/render_frame_host.h"
99 #include "content/public/browser/render_process_host.h" 99 #include "content/public/browser/render_process_host.h"
100 #include "content/public/browser/render_view_host.h" 100 #include "content/public/browser/render_view_host.h"
101 #include "content/public/browser/render_widget_host_view.h" 101 #include "content/public/browser/render_widget_host_view.h"
102 #include "content/public/browser/storage_partition.h"
102 #include "content/public/browser/user_metrics.h" 103 #include "content/public/browser/user_metrics.h"
103 #include "content/public/browser/web_contents.h" 104 #include "content/public/browser/web_contents.h"
104 #include "content/public/common/browser_plugin_guest_mode.h" 105 #include "content/public/common/browser_plugin_guest_mode.h"
105 #include "content/public/common/menu_item.h" 106 #include "content/public/common/menu_item.h"
106 #include "content/public/common/ssl_status.h" 107 #include "content/public/common/ssl_status.h"
107 #include "content/public/common/url_utils.h" 108 #include "content/public/common/url_utils.h"
108 #include "extensions/browser/extension_host.h" 109 #include "extensions/browser/extension_host.h"
109 #include "extensions/browser/extension_system.h" 110 #include "extensions/browser/extension_system.h"
110 #include "extensions/browser/guest_view/web_view/web_view_guest.h" 111 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
111 #include "extensions/browser/view_type_utils.h" 112 #include "extensions/browser/view_type_utils.h"
(...skipping 1622 matching lines...) Expand 10 before | Expand all | Expand 10 after
1734 1735
1735 return false; 1736 return false;
1736 } 1737 }
1737 1738
1738 void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) { 1739 void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) {
1739 RenderViewContextMenuBase::ExecuteCommand(id, event_flags); 1740 RenderViewContextMenuBase::ExecuteCommand(id, event_flags);
1740 if (command_executed_) 1741 if (command_executed_)
1741 return; 1742 return;
1742 command_executed_ = true; 1743 command_executed_ = true;
1743 1744
1745 // MAY BE NULL. Check before using. The frame under the cursor could have
1746 // been asynchronously destroyed while the context menu was open, but many
1747 // context menu commands should continue to function in this situation (e.g.
1748 // "Reload").
1749 RenderFrameHost* render_frame_host = GetRenderFrameHost();
1750
1744 // Process extension menu items. 1751 // Process extension menu items.
1745 if (ContextMenuMatcher::IsExtensionsCustomCommandId(id)) { 1752 if (ContextMenuMatcher::IsExtensionsCustomCommandId(id)) {
1746 extension_items_.ExecuteCommand(id, source_web_contents_, 1753 if (render_frame_host) {
1747 GetRenderFrameHost(), params_); 1754 extension_items_.ExecuteCommand(id, source_web_contents_,
1755 render_frame_host, params_);
1756 }
1748 return; 1757 return;
1749 } 1758 }
1750 1759
1751 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && 1760 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST &&
1752 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { 1761 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) {
1753 ProtocolHandlerRegistry::ProtocolHandlerList handlers = 1762 ProtocolHandlerRegistry::ProtocolHandlerList handlers =
1754 GetHandlersForLinkUrl(); 1763 GetHandlersForLinkUrl();
1755 if (handlers.empty()) 1764 if (handlers.empty())
1756 return; 1765 return;
1757 1766
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1812 GetDocumentURL(params_), 1821 GetDocumentURL(params_),
1813 NEW_WINDOW, 1822 NEW_WINDOW,
1814 ui::PAGE_TRANSITION_LINK); 1823 ui::PAGE_TRANSITION_LINK);
1815 break; 1824 break;
1816 1825
1817 case IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD: 1826 case IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD:
1818 OpenURL(params_.link_url, GURL(), OFF_THE_RECORD, 1827 OpenURL(params_.link_url, GURL(), OFF_THE_RECORD,
1819 ui::PAGE_TRANSITION_LINK); 1828 ui::PAGE_TRANSITION_LINK);
1820 break; 1829 break;
1821 1830
1822 case IDC_CONTENT_CONTEXT_SAVELINKAS: { 1831 case IDC_CONTENT_CONTEXT_SAVELINKAS:
1823 RecordDownloadSource(DOWNLOAD_INITIATED_BY_CONTEXT_MENU); 1832 SaveLinkAs();
1824 const GURL& url = params_.link_url;
1825 content::Referrer referrer = CreateReferrer(url, params_);
1826 DownloadManager* dlm =
1827 BrowserContext::GetDownloadManager(browser_context_);
1828 std::unique_ptr<DownloadUrlParameters> dl_params(
1829 DownloadUrlParameters::FromWebContents(source_web_contents_, url));
1830 dl_params->set_referrer(referrer);
1831 dl_params->set_referrer_encoding(params_.frame_charset);
1832 dl_params->set_suggested_name(params_.suggested_filename);
1833 dl_params->set_prompt(true);
1834 dlm->DownloadUrl(std::move(dl_params));
1835 break; 1833 break;
1836 }
1837 1834
1838 case IDC_CONTENT_CONTEXT_SAVEAVAS: 1835 case IDC_CONTENT_CONTEXT_SAVEAVAS:
1839 case IDC_CONTENT_CONTEXT_SAVEIMAGEAS: { 1836 case IDC_CONTENT_CONTEXT_SAVEIMAGEAS: {
1840 bool is_large_data_url = params_.has_image_contents && 1837 bool is_large_data_url = params_.has_image_contents &&
1841 params_.src_url.is_empty(); 1838 params_.src_url.is_empty();
1842 if (params_.media_type == WebContextMenuData::MediaTypeCanvas || 1839 if (params_.media_type == WebContextMenuData::MediaTypeCanvas ||
1843 (params_.media_type == WebContextMenuData::MediaTypeImage && 1840 (params_.media_type == WebContextMenuData::MediaTypeImage &&
1844 is_large_data_url)) { 1841 is_large_data_url)) {
1845 source_web_contents_->GetRenderViewHost()->SaveImageAt( 1842 source_web_contents_->GetRenderViewHost()->SaveImageAt(
1846 params_.x, params_.y); 1843 params_.x, params_.y);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1995 DCHECK(platform_app->is_platform_app()); 1992 DCHECK(platform_app->is_platform_app());
1996 1993
1997 apps::AppLoadService::Get(GetProfile()) 1994 apps::AppLoadService::Get(GetProfile())
1998 ->RestartApplication(platform_app->id()); 1995 ->RestartApplication(platform_app->id());
1999 break; 1996 break;
2000 } 1997 }
2001 1998
2002 case IDC_PRINT: { 1999 case IDC_PRINT: {
2003 #if defined(ENABLE_PRINTING) 2000 #if defined(ENABLE_PRINTING)
2004 if (params_.media_type != WebContextMenuData::MediaTypeNone) { 2001 if (params_.media_type != WebContextMenuData::MediaTypeNone) {
2005 RenderFrameHost* render_frame_host = GetRenderFrameHost();
2006 if (render_frame_host) { 2002 if (render_frame_host) {
2007 render_frame_host->Send(new PrintMsg_PrintNodeUnderContextMenu( 2003 render_frame_host->Send(new PrintMsg_PrintNodeUnderContextMenu(
2008 render_frame_host->GetRoutingID())); 2004 render_frame_host->GetRoutingID()));
2009 } 2005 }
2010 break; 2006 break;
2011 } 2007 }
2012 2008
2013 printing::StartPrint( 2009 printing::StartPrint(
2014 source_web_contents_, 2010 source_web_contents_,
2015 GetPrefs(browser_context_)->GetBoolean(prefs::kPrintPreviewDisabled), 2011 GetPrefs(browser_context_)->GetBoolean(prefs::kPrintPreviewDisabled),
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
2262 } 2258 }
2263 2259
2264 void RenderViewContextMenu::Inspect(int x, int y) { 2260 void RenderViewContextMenu::Inspect(int x, int y) {
2265 content::RecordAction(UserMetricsAction("DevTools_InspectElement")); 2261 content::RecordAction(UserMetricsAction("DevTools_InspectElement"));
2266 RenderFrameHost* render_frame_host = GetRenderFrameHost(); 2262 RenderFrameHost* render_frame_host = GetRenderFrameHost();
2267 if (!render_frame_host) 2263 if (!render_frame_host)
2268 return; 2264 return;
2269 DevToolsWindow::InspectElement(render_frame_host, x, y); 2265 DevToolsWindow::InspectElement(render_frame_host, x, y);
2270 } 2266 }
2271 2267
2268 void RenderViewContextMenu::SaveLinkAs() {
2269 RenderFrameHost* render_frame_host = GetRenderFrameHost();
2270 if (!render_frame_host)
2271 return;
2272
2273 RecordDownloadSource(DOWNLOAD_INITIATED_BY_CONTEXT_MENU);
2274
2275 const GURL& url = params_.link_url;
2276 content::StoragePartition* storage_partition =
2277 BrowserContext::GetStoragePartition(
2278 source_web_contents_->GetBrowserContext(),
2279 render_frame_host->GetSiteInstance());
2280
2281 std::unique_ptr<DownloadUrlParameters> dl_params(
2282 new DownloadUrlParameters(
2283 url, render_frame_host->GetProcess()->GetID(),
2284 render_frame_host->GetRenderViewHost()->GetRoutingID(),
2285 render_frame_host->GetRoutingID(),
2286 storage_partition->GetURLRequestContext()));
2287 dl_params->set_referrer(CreateReferrer(url, params_));
2288 dl_params->set_referrer_encoding(params_.frame_charset);
2289 dl_params->set_suggested_name(params_.suggested_filename);
2290 dl_params->set_prompt(true);
2291
2292 BrowserContext::GetDownloadManager(browser_context_)->DownloadUrl(
2293 std::move(dl_params));
2294 }
2295
2272 void RenderViewContextMenu::WriteURLToClipboard(const GURL& url) { 2296 void RenderViewContextMenu::WriteURLToClipboard(const GURL& url) {
2273 ::WriteURLToClipboard(url); 2297 ::WriteURLToClipboard(url);
2274 } 2298 }
2275 2299
2276 void RenderViewContextMenu::MediaPlayerActionAt( 2300 void RenderViewContextMenu::MediaPlayerActionAt(
2277 const gfx::Point& location, 2301 const gfx::Point& location,
2278 const WebMediaPlayerAction& action) { 2302 const WebMediaPlayerAction& action) {
2279 source_web_contents_->GetRenderViewHost()-> 2303 source_web_contents_->GetRenderViewHost()->
2280 ExecuteMediaPlayerActionAtLocation(location, action); 2304 ExecuteMediaPlayerActionAtLocation(location, action);
2281 } 2305 }
2282 2306
2283 void RenderViewContextMenu::PluginActionAt( 2307 void RenderViewContextMenu::PluginActionAt(
2284 const gfx::Point& location, 2308 const gfx::Point& location,
2285 const WebPluginAction& action) { 2309 const WebPluginAction& action) {
2286 source_web_contents_->GetRenderViewHost()-> 2310 source_web_contents_->GetRenderViewHost()->
2287 ExecutePluginActionAtLocation(location, action); 2311 ExecutePluginActionAtLocation(location, action);
2288 } 2312 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698