blob: 46c13bf80bfe029daca62bed2894192bc57b8ee8 [file] [log] [blame]
Googler11871152020-10-01 14:59:09 -04001// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CEF_LIBCEF_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_
6#define CEF_LIBCEF_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_
7#pragma once
8
9#include <set>
10
Googler39a97572023-12-13 22:53:26 +000011#include "libcef/browser/browser_host_base.h"
Googler11871152020-10-01 14:59:09 -040012
Googler11871152020-10-01 14:59:09 -040013#include "base/memory/weak_ptr.h"
14#include "components/download/public/common/download_item.h"
15#include "content/public/browser/download_manager.h"
16#include "content/public/browser/download_manager_delegate.h"
17
Googler39a97572023-12-13 22:53:26 +000018class AlloyBrowserHostImpl;
19
Googler11871152020-10-01 14:59:09 -040020class CefDownloadManagerDelegate : public download::DownloadItem::Observer,
21 public content::DownloadManager::Observer,
22 public content::DownloadManagerDelegate,
Googler39a97572023-12-13 22:53:26 +000023 public CefBrowserHostBase::Observer {
Googler11871152020-10-01 14:59:09 -040024 public:
25 explicit CefDownloadManagerDelegate(content::DownloadManager* manager);
Googler39a97572023-12-13 22:53:26 +000026
27 CefDownloadManagerDelegate(const CefDownloadManagerDelegate&) = delete;
28 CefDownloadManagerDelegate& operator=(const CefDownloadManagerDelegate&) =
29 delete;
30
Googler11871152020-10-01 14:59:09 -040031 ~CefDownloadManagerDelegate() override;
32
33 private:
34 // DownloadItem::Observer methods.
35 void OnDownloadUpdated(download::DownloadItem* item) override;
36 void OnDownloadDestroyed(download::DownloadItem* item) override;
37
38 // DownloadManager::Observer methods.
39 void OnDownloadCreated(content::DownloadManager* manager,
40 download::DownloadItem* item) override;
41 void ManagerGoingDown(content::DownloadManager* manager) override;
42
43 // DownloadManagerDelegate methods.
44 bool DetermineDownloadTarget(
45 download::DownloadItem* item,
46 content::DownloadTargetCallback* callback) override;
47 void GetNextId(content::DownloadIdCallback callback) override;
48 std::string ApplicationClientIdForFileScanning() override;
49
Googler39a97572023-12-13 22:53:26 +000050 // CefBrowserHostBase::Observer methods.
51 void OnBrowserDestroyed(CefBrowserHostBase* browser) override;
Googler11871152020-10-01 14:59:09 -040052
Googler39a97572023-12-13 22:53:26 +000053 AlloyBrowserHostImpl* GetOrAssociateBrowser(download::DownloadItem* item);
54 AlloyBrowserHostImpl* GetBrowser(download::DownloadItem* item);
Googler11871152020-10-01 14:59:09 -040055
56 content::DownloadManager* manager_;
57 base::WeakPtrFactory<content::DownloadManager> manager_ptr_factory_;
58
Googler39a97572023-12-13 22:53:26 +000059 // Map of DownloadItem to originating AlloyBrowserHostImpl. Maintaining this
Googler11871152020-10-01 14:59:09 -040060 // map is necessary because DownloadItem::GetWebContents() may return NULL if
61 // the browser navigates while the download is in progress.
Googler39a97572023-12-13 22:53:26 +000062 using ItemBrowserMap =
63 std::map<download::DownloadItem*, AlloyBrowserHostImpl*>;
Googler11871152020-10-01 14:59:09 -040064 ItemBrowserMap item_browser_map_;
Googler11871152020-10-01 14:59:09 -040065};
66
67#endif // CEF_LIBCEF_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_