// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/download/public/common/download_url_parameters.h"

#include "services/network/public/cpp/shared_url_loader_factory.h"

#include "base/types/pass_key.h"

namespace download {

DownloadUrlParameters::DownloadUrlParameters(
    const GURL& url,
    const net::NetworkTrafficAnnotationTag& traffic_annotation)
    : DownloadUrlParameters(url, std::nullopt, -1, -1, traffic_annotation) {}

DownloadUrlParameters::DownloadUrlParameters(
    base::PassKey<content::RenderFrameHostImpl>,
    const GURL& url,
    std::optional<url::Origin> initiator,
    int render_process_host_id,
    int render_frame_host_routing_id,
    const net::NetworkTrafficAnnotationTag& traffic_annotation)
    : DownloadUrlParameters(url,
                            initiator,
                            render_process_host_id,
                            render_frame_host_routing_id,
                            traffic_annotation) {}

DownloadUrlParameters::DownloadUrlParameters(
    const GURL& url,
    std::optional<url::Origin> initiator,
    int render_process_host_id,
    int render_frame_host_routing_id,
    const net::NetworkTrafficAnnotationTag& traffic_annotation)
    : content_initiated_(false),
      use_if_range_(true),
      method_("GET"),
      credentials_mode_(::network::mojom::CredentialsMode::kInclude),
      post_id_(-1),
      prefer_cache_(false),
      referrer_policy_(
          net::ReferrerPolicy::CLEAR_ON_TRANSITION_FROM_SECURE_TO_INSECURE),
      initiator_(std::move(initiator)),
      render_process_host_id_(render_process_host_id),
      render_frame_host_routing_id_(render_frame_host_routing_id),
      url_(url),
      do_not_prompt_for_login_(false),
      cross_origin_redirects_(network::mojom::RedirectMode::kFollow),
      fetch_error_body_(false),
      transient_(false),
      traffic_annotation_(traffic_annotation),
      download_source_(DownloadSource::UNKNOWN),
      require_safety_checks_(true),
      has_user_gesture_(false),
      update_first_party_url_on_redirect_(true),
      skip_service_worker_interception_(false) {}

DownloadUrlParameters::~DownloadUrlParameters() = default;

void DownloadUrlParameters::set_url_loader_factory(
    std::unique_ptr<network::PendingSharedURLLoaderFactory>
        url_loader_factory) {
  url_loader_factory_ = std::move(url_loader_factory);
}

std::unique_ptr<network::PendingSharedURLLoaderFactory>
DownloadUrlParameters::take_url_loader_factory() {
  return std::move(url_loader_factory_);
}

}  // namespace download
