feat: allow headers to be sent with session.downloadURL() (#38871)

* feat: allow headers to be sent with session.downloadURL

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* Update shell/browser/api/electron_api_session.cc

Co-authored-by: Charles Kerr <charles@charleskerr.com>

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot]
2023-06-22 14:40:11 -04:00
committed by GitHub
parent 16aac6da13
commit 76f4291130
4 changed files with 120 additions and 4 deletions

View File

@@ -804,10 +804,24 @@ v8::Local<v8::Promise> Session::GetBlobData(v8::Isolate* isolate,
return holder->ReadAll(isolate);
}
void Session::DownloadURL(const GURL& url) {
auto* download_manager = browser_context()->GetDownloadManager();
void Session::DownloadURL(const GURL& url, gin::Arguments* args) {
std::map<std::string, std::string> headers;
gin_helper::Dictionary options;
if (args->GetNext(&options)) {
if (options.Has("headers") && !options.Get("headers", &headers)) {
args->ThrowTypeError("Invalid value for headers - must be an object");
return;
}
}
auto download_params = std::make_unique<download::DownloadUrlParameters>(
url, MISSING_TRAFFIC_ANNOTATION);
for (const auto& [name, value] : headers) {
download_params->add_request_header(name, value);
}
auto* download_manager = browser_context()->GetDownloadManager();
download_manager->DownloadUrl(std::move(download_params));
}

View File

@@ -131,7 +131,7 @@ class Session : public gin::Wrappable<Session>,
bool IsPersistent();
v8::Local<v8::Promise> GetBlobData(v8::Isolate* isolate,
const std::string& uuid);
void DownloadURL(const GURL& url);
void DownloadURL(const GURL& url, gin::Arguments* args);
void CreateInterruptedDownload(const gin_helper::Dictionary& options);
void SetPreloads(const std::vector<base::FilePath>& preloads);
std::vector<base::FilePath> GetPreloads() const;