2012-06-08 18:01:01 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
2012-04-03 03:34:16 +02:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef CEF_LIBCEF_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_
|
|
|
|
#pragma once
|
|
|
|
|
2012-11-30 20:08:20 +01:00
|
|
|
#include <set>
|
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
#include "libcef/browser/browser_host_base.h"
|
2016-02-12 23:31:22 +01:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "base/compiler_specific.h"
|
2012-11-30 20:08:20 +01:00
|
|
|
#include "base/memory/weak_ptr.h"
|
2018-03-20 21:15:08 +01:00
|
|
|
#include "components/download/public/common/download_item.h"
|
2012-11-30 20:08:20 +01:00
|
|
|
#include "content/public/browser/download_manager.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "content/public/browser/download_manager_delegate.h"
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
class AlloyBrowserHostImpl;
|
2020-09-18 00:24:08 +02:00
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
class CefDownloadManagerDelegate : public download::DownloadItem::Observer,
|
2017-05-17 11:29:28 +02:00
|
|
|
public content::DownloadManager::Observer,
|
|
|
|
public content::DownloadManagerDelegate,
|
2020-09-18 00:24:08 +02:00
|
|
|
public CefBrowserHostBase::Observer {
|
2012-04-03 03:34:16 +02:00
|
|
|
public:
|
2012-11-30 20:08:20 +01:00
|
|
|
explicit CefDownloadManagerDelegate(content::DownloadManager* manager);
|
2021-12-06 21:40:25 +01:00
|
|
|
|
|
|
|
CefDownloadManagerDelegate(const CefDownloadManagerDelegate&) = delete;
|
|
|
|
CefDownloadManagerDelegate& operator=(const CefDownloadManagerDelegate&) =
|
|
|
|
delete;
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
~CefDownloadManagerDelegate() override;
|
2012-11-30 20:08:20 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
// DownloadItem::Observer methods.
|
2018-03-20 21:15:08 +01:00
|
|
|
void OnDownloadUpdated(download::DownloadItem* item) override;
|
|
|
|
void OnDownloadDestroyed(download::DownloadItem* item) override;
|
2012-11-30 20:08:20 +01:00
|
|
|
|
|
|
|
// DownloadManager::Observer methods.
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnDownloadCreated(content::DownloadManager* manager,
|
2018-03-20 21:15:08 +01:00
|
|
|
download::DownloadItem* item) override;
|
2014-11-12 20:25:15 +01:00
|
|
|
void ManagerGoingDown(content::DownloadManager* manager) override;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// DownloadManagerDelegate methods.
|
2014-11-12 20:25:15 +01:00
|
|
|
bool DetermineDownloadTarget(
|
2018-03-20 21:15:08 +01:00
|
|
|
download::DownloadItem* item,
|
2020-03-04 01:29:39 +01:00
|
|
|
content::DownloadTargetCallback* callback) override;
|
|
|
|
void GetNextId(content::DownloadIdCallback callback) override;
|
2019-09-04 17:13:32 +02:00
|
|
|
std::string ApplicationClientIdForFileScanning() override;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
// CefBrowserHostBase::Observer methods.
|
|
|
|
void OnBrowserDestroyed(CefBrowserHostBase* browser) override;
|
2016-02-12 23:31:22 +01:00
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
AlloyBrowserHostImpl* GetOrAssociateBrowser(download::DownloadItem* item);
|
|
|
|
AlloyBrowserHostImpl* GetBrowser(download::DownloadItem* item);
|
2016-02-12 23:31:22 +01:00
|
|
|
|
2012-11-30 20:08:20 +01:00
|
|
|
content::DownloadManager* manager_;
|
|
|
|
base::WeakPtrFactory<content::DownloadManager> manager_ptr_factory_;
|
2016-02-12 23:31:22 +01:00
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
// Map of DownloadItem to originating AlloyBrowserHostImpl. Maintaining this
|
2016-02-12 23:31:22 +01:00
|
|
|
// map is necessary because DownloadItem::GetWebContents() may return NULL if
|
|
|
|
// the browser navigates while the download is in progress.
|
2021-12-06 21:40:25 +01:00
|
|
|
using ItemBrowserMap =
|
|
|
|
std::map<download::DownloadItem*, AlloyBrowserHostImpl*>;
|
2016-02-12 23:31:22 +01:00
|
|
|
ItemBrowserMap item_browser_map_;
|
2012-04-03 03:34:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_
|