#include "content/browser/download/save_file_manager.h"
#include <string_view>
#include <utility>
#include "base/containers/contains.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/string_util.h"
#include "build/build_config.h"
#include "components/download/public/common/download_task_runner.h"
#include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/data_url_loader_factory.h"
#include "content/browser/download/save_file.h"
#include "content/browser/download/save_package.h"
#include "content/browser/file_system/file_system_url_loader_factory.h"
#include "content/browser/loader/file_url_loader_factory.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/storage_partition_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/shared_cors_origin_access_list.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_ui_url_loader_factory.h"
#include "content/public/common/content_client.h"
#include "content/public/common/url_constants.h"
#include "net/base/isolation_info.h"
#include "net/base/load_flags.h"
#include "net/cookies/site_for_cookies.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/cpp/simple_url_loader_stream_consumer.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "storage/browser/file_system/native_file_util.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace content {
namespace {
static SaveFileManager* g_save_file_manager = …;
}
class SaveFileManager::SimpleURLLoaderHelper
: public network::SimpleURLLoaderStreamConsumer { … };
SaveFileManager::SaveFileManager() { … }
SaveFileManager::~SaveFileManager() { … }
SaveFileManager* SaveFileManager::Get() { … }
void SaveFileManager::Shutdown() { … }
void SaveFileManager::OnShutdown() { … }
SaveFile* SaveFileManager::LookupSaveFile(SaveItemId save_item_id) { … }
SavePackage* SaveFileManager::LookupPackage(SaveItemId save_item_id) { … }
void SaveFileManager::SaveURL(
SaveItemId save_item_id,
const GURL& url,
const Referrer& referrer,
const net::IsolationInfo& isolation_info,
network::mojom::RequestMode request_mode,
bool is_outermost_main_frame,
int render_process_host_id,
int render_view_routing_id,
int render_frame_routing_id,
SaveFileCreateInfo::SaveFileSource save_source,
const base::FilePath& file_full_path,
BrowserContext* context,
StoragePartition* storage_partition,
SavePackage* save_package,
const std::string& client_guid,
mojo::PendingRemote<quarantine::mojom::Quarantine> remote_quarantine) { … }
void SaveFileManager::RemoveSaveFile(SaveItemId save_item_id,
SavePackage* save_package) { … }
SavePackage* SaveFileManager::GetSavePackageFromRenderIds(
int render_process_id,
int render_frame_routing_id) { … }
void SaveFileManager::SendCancelRequest(SaveItemId save_item_id) { … }
void SaveFileManager::OnURLLoaderComplete(
SaveItemId save_item_id,
SavePackageId save_package_id,
const GURL& url,
const GURL& referrer_url,
const std::string& client_guid,
mojo::PendingRemote<quarantine::mojom::Quarantine> remote_quarantine,
bool is_success) { … }
void SaveFileManager::OnQuarantineComplete(
SaveItemId save_item_id,
SavePackageId save_package_id,
download::DownloadInterruptReason result) { … }
void SaveFileManager::StartSave(std::unique_ptr<SaveFileCreateInfo> info) { … }
void SaveFileManager::UpdateSaveProgress(SaveItemId save_item_id,
const std::string& data) { … }
void SaveFileManager::SaveFinished(SaveItemId save_item_id,
SavePackageId save_package_id,
bool is_success) { … }
void SaveFileManager::OnStartSave(const SaveFileCreateInfo& info) { … }
void SaveFileManager::OnUpdateSaveProgress(SaveItemId save_item_id,
int64_t bytes_so_far,
bool write_success) { … }
void SaveFileManager::OnSaveFinished(SaveItemId save_item_id,
int64_t bytes_so_far,
bool is_success) { … }
void SaveFileManager::CancelSave(SaveItemId save_item_id) { … }
void SaveFileManager::ClearURLLoader(SaveItemId save_item_id) { … }
void SaveFileManager::RenameAllFiles(const FinalNamesMap& final_names,
const base::FilePath& resource_dir,
int render_process_id,
int render_frame_routing_id,
SavePackageId save_package_id) { … }
void SaveFileManager::OnFinishSavePageJob(int render_process_id,
int render_frame_routing_id,
SavePackageId save_package_id) { … }
void SaveFileManager::RemoveSavedFileFromFileMap(
const std::vector<SaveItemId>& save_item_ids) { … }
void SaveFileManager::GetSaveFilePaths(
const std::vector<std::pair<SaveItemId, base::FilePath>>&
ids_and_final_paths,
base::OnceCallback<void(base::flat_map<base::FilePath, base::FilePath>)>
callback) { … }
}