Commit 65d22828 authored by Jochen Eisinger's avatar Jochen Eisinger Committed by Commit Bot

Use internal API to start downloads from download page

Otherwise, the renderer will turn cross-origin downloads into
navigations

BUG=857441
R=asanka@chromium.org

Change-Id: I7a584951d794d22a6c417d06bd80d6de0db53236
Reviewed-on: https://chromium-review.googlesource.com/1120818
Commit-Queue: Jochen Eisinger <jochen@chromium.org>
Reviewed-by: default avatarMartin Šrámek <msramek@chromium.org>
Reviewed-by: default avatarAsanka Herath <asanka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#572205}
parent a6dcc165
...@@ -14,12 +14,9 @@ cr.define('downloads', function() { ...@@ -14,12 +14,9 @@ cr.define('downloads', function() {
chrome.send('discardDangerous', [id]); chrome.send('discardDangerous', [id]);
} }
/** @param {string} url URL of a file to download. */ /** @param {string} id ID of the download to retry. */
download(url) { retryDownload(id) {
const a = document.createElement('a'); chrome.send('retryDownload', [id]);
a.href = url;
a.setAttribute('download', '');
a.click();
} }
/** @param {string} id ID of the download that the user started dragging. */ /** @param {string} id ID of the download that the user started dragging. */
......
...@@ -325,7 +325,7 @@ cr.define('downloads', function() { ...@@ -325,7 +325,7 @@ cr.define('downloads', function() {
/** @private */ /** @private */
onRetryTap_: function() { onRetryTap_: function() {
this.browserProxy_.download(this.data.url); this.browserProxy_.retryDownload(this.data.id);
}, },
/** @private */ /** @private */
......
...@@ -37,6 +37,9 @@ ...@@ -37,6 +37,9 @@
#include "components/safe_browsing/common/safe_browsing_prefs.h" #include "components/safe_browsing/common/safe_browsing_prefs.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_manager.h" #include "content/public/browser/download_manager.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/url_data_source.h" #include "content/public/browser/url_data_source.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui.h"
...@@ -61,6 +64,7 @@ enum DownloadsDOMEvent { ...@@ -61,6 +64,7 @@ enum DownloadsDOMEvent {
DOWNLOADS_DOM_EVENT_CLEAR_ALL = 9, DOWNLOADS_DOM_EVENT_CLEAR_ALL = 9,
DOWNLOADS_DOM_EVENT_OPEN_FOLDER = 10, DOWNLOADS_DOM_EVENT_OPEN_FOLDER = 10,
DOWNLOADS_DOM_EVENT_RESUME = 11, DOWNLOADS_DOM_EVENT_RESUME = 11,
DOWNLOADS_DOM_EVENT_RETRY_DOWNLOAD = 12,
DOWNLOADS_DOM_EVENT_MAX DOWNLOADS_DOM_EVENT_MAX
}; };
...@@ -104,6 +108,10 @@ void MdDownloadsDOMHandler::RegisterMessages() { ...@@ -104,6 +108,10 @@ void MdDownloadsDOMHandler::RegisterMessages() {
"saveDangerousRequiringGesture", "saveDangerousRequiringGesture",
base::BindRepeating(&MdDownloadsDOMHandler::HandleSaveDangerous, base::BindRepeating(&MdDownloadsDOMHandler::HandleSaveDangerous,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
web_ui()->RegisterMessageCallback(
"retryDownload",
base::BindRepeating(&MdDownloadsDOMHandler::HandleRetryDownload,
weak_ptr_factory_.GetWeakPtr()));
web_ui()->RegisterMessageCallback( web_ui()->RegisterMessageCallback(
"discardDangerous", "discardDangerous",
base::BindRepeating(&MdDownloadsDOMHandler::HandleDiscardDangerous, base::BindRepeating(&MdDownloadsDOMHandler::HandleDiscardDangerous,
...@@ -201,6 +209,11 @@ void MdDownloadsDOMHandler::HandleSaveDangerous(const base::ListValue* args) { ...@@ -201,6 +209,11 @@ void MdDownloadsDOMHandler::HandleSaveDangerous(const base::ListValue* args) {
ShowDangerPrompt(file); ShowDangerPrompt(file);
} }
void MdDownloadsDOMHandler::HandleRetryDownload(const base::ListValue* args) {
CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_RETRY_DOWNLOAD);
RetryDownload(args);
}
void MdDownloadsDOMHandler::HandleDiscardDangerous( void MdDownloadsDOMHandler::HandleDiscardDangerous(
const base::ListValue* args) { const base::ListValue* args) {
CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_DISCARD_DANGEROUS); CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_DISCARD_DANGEROUS);
...@@ -438,3 +451,49 @@ void MdDownloadsDOMHandler::RemoveDownloadInArgs(const base::ListValue* args) { ...@@ -438,3 +451,49 @@ void MdDownloadsDOMHandler::RemoveDownloadInArgs(const base::ListValue* args) {
downloads.push_back(file); downloads.push_back(file);
RemoveDownloads(downloads); RemoveDownloads(downloads);
} }
void MdDownloadsDOMHandler::RetryDownload(const base::ListValue* args) {
download::DownloadItem* file = GetDownloadByValue(args);
if (!file)
return;
content::WebContents* web_contents = GetWebUIWebContents();
content::RenderFrameHost* render_frame_host = web_contents->GetMainFrame();
const GURL url = file->GetURL();
content::StoragePartition* storage_partition =
content::BrowserContext::GetStoragePartition(
web_contents->GetBrowserContext(),
render_frame_host->GetSiteInstance());
net::NetworkTrafficAnnotationTag traffic_annotation =
net::DefineNetworkTrafficAnnotation("md_downloads_dom_handler", R"(
semantics {
sender: "The downloads page."
description: "Retrying a download."
trigger:
"The user selects the 'Retry' button for a cancelled download on "
"the downloads page."
data: "None."
destination: WEBSITE
}
policy {
cookies_allowed: YES
cookies_store: "user"
setting:
"This feature cannot be disabled by settings, but it's only "
"triggered by user request."
policy_exception_justification: "Not implemented."
})");
auto dl_params = std::make_unique<download::DownloadUrlParameters>(
url, render_frame_host->GetProcess()->GetID(),
render_frame_host->GetRenderViewHost()->GetRoutingID(),
render_frame_host->GetRoutingID(),
storage_partition->GetURLRequestContext(), traffic_annotation);
dl_params->set_content_initiated(true);
dl_params->set_initiator(url::Origin::Create(GURL("chrome://downloads")));
dl_params->set_download_source(download::DownloadSource::FROM_RENDERER);
content::BrowserContext::GetDownloadManager(web_contents->GetBrowserContext())
->DownloadUrl(std::move(dl_params));
}
...@@ -60,6 +60,10 @@ class MdDownloadsDOMHandler : public content::WebContentsObserver, ...@@ -60,6 +60,10 @@ class MdDownloadsDOMHandler : public content::WebContentsObserver,
// wishes to save a dangerous file. // wishes to save a dangerous file.
void HandleSaveDangerous(const base::ListValue* args); void HandleSaveDangerous(const base::ListValue* args);
// Callback for the "retryDownload" message - specifies that the user wishes
// to download an item again.
void HandleRetryDownload(const base::ListValue* args);
// Callback for the "discardDangerous" message - specifies that the user // Callback for the "discardDangerous" message - specifies that the user
// wishes to discard (remove) a dangerous file. // wishes to discard (remove) a dangerous file.
void HandleDiscardDangerous(const base::ListValue* args); void HandleDiscardDangerous(const base::ListValue* args);
...@@ -141,6 +145,9 @@ class MdDownloadsDOMHandler : public content::WebContentsObserver, ...@@ -141,6 +145,9 @@ class MdDownloadsDOMHandler : public content::WebContentsObserver,
// Removes the download specified by an ID from JavaScript in |args|. // Removes the download specified by an ID from JavaScript in |args|.
void RemoveDownloadInArgs(const base::ListValue* args); void RemoveDownloadInArgs(const base::ListValue* args);
// Retry the download specified by an ID from JavaScript in |args|.
void RetryDownload(const base::ListValue* args);
// Checks whether a download's file was removed from its original location. // Checks whether a download's file was removed from its original location.
void CheckForRemovedFiles(); void CheckForRemovedFiles();
......
...@@ -102,7 +102,9 @@ bool IsWebUIAllowedToMakeNetworkRequests(const url::Origin& origin) { ...@@ -102,7 +102,9 @@ bool IsWebUIAllowedToMakeNetworkRequests(const url::Origin& origin) {
// https://crbug.com/831812 // https://crbug.com/831812
origin.host() == "sync-confirmation" || origin.host() == "sync-confirmation" ||
// https://crbug.com/831813 // https://crbug.com/831813
origin.host() == "inspect"; origin.host() == "inspect" ||
// https://crbug.com/859345
origin.host() == "downloads";
} }
PermissionsData::PageAccess CanExtensionAccessURLInternal( PermissionsData::PageAccess CanExtensionAccessURLInternal(
......
...@@ -10828,6 +10828,7 @@ Called by update_net_error_codes.py.--> ...@@ -10828,6 +10828,7 @@ Called by update_net_error_codes.py.-->
<int value="9" label="ClearAll"/> <int value="9" label="ClearAll"/>
<int value="10" label="OpenFolder"/> <int value="10" label="OpenFolder"/>
<int value="11" label="Resume"/> <int value="11" label="Resume"/>
<int value="12" label="RetryDownload"/>
</enum> </enum>
<enum name="DownloadedFileAction"> <enum name="DownloadedFileAction">
...@@ -136,6 +136,7 @@ Refer to README.md for content description and update process. ...@@ -136,6 +136,7 @@ Refer to README.md for content description and update process.
<item id="invalidation_service" hash_code="72354423" type="0" content_hash_code="78425687" os_list="linux,windows" file_path="components/invalidation/impl/gcm_network_channel.cc"/> <item id="invalidation_service" hash_code="72354423" type="0" content_hash_code="78425687" os_list="linux,windows" file_path="components/invalidation/impl/gcm_network_channel.cc"/>
<item id="lib_address_input" hash_code="50816767" type="0" content_hash_code="57977576" os_list="linux,windows" file_path="third_party/libaddressinput/chromium/chrome_metadata_source.cc"/> <item id="lib_address_input" hash_code="50816767" type="0" content_hash_code="57977576" os_list="linux,windows" file_path="third_party/libaddressinput/chromium/chrome_metadata_source.cc"/>
<item id="logo_tracker" hash_code="36859107" type="0" content_hash_code="67588075" os_list="linux,windows" file_path="components/search_provider_logos/logo_tracker.cc"/> <item id="logo_tracker" hash_code="36859107" type="0" content_hash_code="67588075" os_list="linux,windows" file_path="components/search_provider_logos/logo_tracker.cc"/>
<item id="md_downloads_dom_handler" hash_code="65603364" type="0" content_hash_code="134779147" os_list="linux,windows" file_path="chrome/browser/ui/webui/md_downloads/md_downloads_dom_handler.cc"/>
<item id="metrics_report_ukm" hash_code="727478" type="0" content_hash_code="40919254" os_list="linux,windows" file_path="components/metrics/net/net_metrics_log_uploader.cc"/> <item id="metrics_report_ukm" hash_code="727478" type="0" content_hash_code="40919254" os_list="linux,windows" file_path="components/metrics/net/net_metrics_log_uploader.cc"/>
<item id="metrics_report_uma" hash_code="727528" type="0" content_hash_code="10176197" os_list="linux,windows" file_path="components/metrics/net/net_metrics_log_uploader.cc"/> <item id="metrics_report_uma" hash_code="727528" type="0" content_hash_code="10176197" os_list="linux,windows" file_path="components/metrics/net/net_metrics_log_uploader.cc"/>
<item id="mirroring_get_setup_info" hash_code="78447809" type="0" content_hash_code="112561099" os_list="linux,windows" file_path="components/mirroring/service/session_monitor.cc"/> <item id="mirroring_get_setup_info" hash_code="78447809" type="0" content_hash_code="112561099" os_list="linux,windows" file_path="components/mirroring/service/session_monitor.cc"/>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment