Googler | 1187115 | 2020-10-01 14:59:09 -0400 | [diff] [blame] | 1 | // 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 | |
Googler | 39a9757 | 2023-12-13 22:53:26 +0000 | [diff] [blame^] | 11 | #include "libcef/browser/browser_host_base.h" |
Googler | 1187115 | 2020-10-01 14:59:09 -0400 | [diff] [blame] | 12 | |
Googler | 1187115 | 2020-10-01 14:59:09 -0400 | [diff] [blame] | 13 | #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 | |
Googler | 39a9757 | 2023-12-13 22:53:26 +0000 | [diff] [blame^] | 18 | class AlloyBrowserHostImpl; |
| 19 | |
Googler | 1187115 | 2020-10-01 14:59:09 -0400 | [diff] [blame] | 20 | class CefDownloadManagerDelegate : public download::DownloadItem::Observer, |
| 21 | public content::DownloadManager::Observer, |
| 22 | public content::DownloadManagerDelegate, |
Googler | 39a9757 | 2023-12-13 22:53:26 +0000 | [diff] [blame^] | 23 | public CefBrowserHostBase::Observer { |
Googler | 1187115 | 2020-10-01 14:59:09 -0400 | [diff] [blame] | 24 | public: |
| 25 | explicit CefDownloadManagerDelegate(content::DownloadManager* manager); |
Googler | 39a9757 | 2023-12-13 22:53:26 +0000 | [diff] [blame^] | 26 | |
| 27 | CefDownloadManagerDelegate(const CefDownloadManagerDelegate&) = delete; |
| 28 | CefDownloadManagerDelegate& operator=(const CefDownloadManagerDelegate&) = |
| 29 | delete; |
| 30 | |
Googler | 1187115 | 2020-10-01 14:59:09 -0400 | [diff] [blame] | 31 | ~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 | |
Googler | 39a9757 | 2023-12-13 22:53:26 +0000 | [diff] [blame^] | 50 | // CefBrowserHostBase::Observer methods. |
| 51 | void OnBrowserDestroyed(CefBrowserHostBase* browser) override; |
Googler | 1187115 | 2020-10-01 14:59:09 -0400 | [diff] [blame] | 52 | |
Googler | 39a9757 | 2023-12-13 22:53:26 +0000 | [diff] [blame^] | 53 | AlloyBrowserHostImpl* GetOrAssociateBrowser(download::DownloadItem* item); |
| 54 | AlloyBrowserHostImpl* GetBrowser(download::DownloadItem* item); |
Googler | 1187115 | 2020-10-01 14:59:09 -0400 | [diff] [blame] | 55 | |
| 56 | content::DownloadManager* manager_; |
| 57 | base::WeakPtrFactory<content::DownloadManager> manager_ptr_factory_; |
| 58 | |
Googler | 39a9757 | 2023-12-13 22:53:26 +0000 | [diff] [blame^] | 59 | // Map of DownloadItem to originating AlloyBrowserHostImpl. Maintaining this |
Googler | 1187115 | 2020-10-01 14:59:09 -0400 | [diff] [blame] | 60 | // map is necessary because DownloadItem::GetWebContents() may return NULL if |
| 61 | // the browser navigates while the download is in progress. |
Googler | 39a9757 | 2023-12-13 22:53:26 +0000 | [diff] [blame^] | 62 | using ItemBrowserMap = |
| 63 | std::map<download::DownloadItem*, AlloyBrowserHostImpl*>; |
Googler | 1187115 | 2020-10-01 14:59:09 -0400 | [diff] [blame] | 64 | ItemBrowserMap item_browser_map_; |
Googler | 1187115 | 2020-10-01 14:59:09 -0400 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | #endif // CEF_LIBCEF_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_ |