blob: 80344be1b64f1eaf3b352a962ea9ff3f0ad6dff0 [file] [log] [blame]
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include "base/callback_forward.h"
#include "base/optional.h"
#include "url/origin.h"
class GURL;
namespace weblayer {
class Download;
using AllowDownloadCallback = base::OnceCallback<void(bool /*allow*/)>;
// An interface that allows clients to handle download requests originating in
// the browser. The object is safe to hold on to until DownloadCompleted or
// DownloadFailed are called.
class DownloadDelegate {
// Gives the embedder the opportunity to asynchronously allow or disallow the
// given download. The download is paused until the callback is run. It's safe
// to run |callback| synchronously.
virtual void AllowDownload(const GURL& url,
const std::string& request_method,
base::Optional<url::Origin> request_initiator,
AllowDownloadCallback callback) = 0;
// A download of |url| has been requested with the specified details. If
// it returns true the download will be considered intercepted and WebLayer
// won't proceed with it. Note that there are many corner cases where the
// embedder downloading it won't work (e.g. POSTs, one-time URLs, requests
// that depend on cookies or auth state). This is called after AllowDownload.
virtual bool InterceptDownload(const GURL& url,
const std::string& user_agent,
const std::string& content_disposition,
const std::string& mime_type,
int64_t content_length) = 0;
// A download has started. There will be 0..n calls to
// DownloadProgressChanged, then either a call to DownloadCompleted or
// DownloadFailed.
virtual void DownloadStarted(Download* download) {}
// The progress percentage of a download has changed.
virtual void DownloadProgressChanged(Download* download) {}
// A download has completed successfully.
virtual void DownloadCompleted(Download* download) {}
// A download has failed because the user cancelled it or because of a server
// or network error.
virtual void DownloadFailed(Download* download) {}
virtual ~DownloadDelegate() {}
} // namespace weblayer