• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #include "libcef/browser/browser_host_base.h"
12 
13 #include "base/compiler_specific.h"
14 #include "base/memory/weak_ptr.h"
15 #include "components/download/public/common/download_item.h"
16 #include "content/public/browser/download_manager.h"
17 #include "content/public/browser/download_manager_delegate.h"
18 
19 class AlloyBrowserHostImpl;
20 
21 class CefDownloadManagerDelegate : public download::DownloadItem::Observer,
22                                    public content::DownloadManager::Observer,
23                                    public content::DownloadManagerDelegate,
24                                    public CefBrowserHostBase::Observer {
25  public:
26   explicit CefDownloadManagerDelegate(content::DownloadManager* manager);
27 
28   CefDownloadManagerDelegate(const CefDownloadManagerDelegate&) = delete;
29   CefDownloadManagerDelegate& operator=(const CefDownloadManagerDelegate&) =
30       delete;
31 
32   ~CefDownloadManagerDelegate() override;
33 
34  private:
35   // DownloadItem::Observer methods.
36   void OnDownloadUpdated(download::DownloadItem* item) override;
37   void OnDownloadDestroyed(download::DownloadItem* item) override;
38 
39   // DownloadManager::Observer methods.
40   void OnDownloadCreated(content::DownloadManager* manager,
41                          download::DownloadItem* item) override;
42   void ManagerGoingDown(content::DownloadManager* manager) override;
43 
44   // DownloadManagerDelegate methods.
45   bool DetermineDownloadTarget(
46       download::DownloadItem* item,
47       content::DownloadTargetCallback* callback) override;
48   void GetNextId(content::DownloadIdCallback callback) override;
49   std::string ApplicationClientIdForFileScanning() override;
50 
51   // CefBrowserHostBase::Observer methods.
52   void OnBrowserDestroyed(CefBrowserHostBase* browser) override;
53 
54   AlloyBrowserHostImpl* GetOrAssociateBrowser(download::DownloadItem* item);
55   AlloyBrowserHostImpl* GetBrowser(download::DownloadItem* item);
56 
57   content::DownloadManager* manager_;
58   base::WeakPtrFactory<content::DownloadManager> manager_ptr_factory_;
59 
60   // Map of DownloadItem to originating AlloyBrowserHostImpl. Maintaining this
61   // map is necessary because DownloadItem::GetWebContents() may return NULL if
62   // the browser navigates while the download is in progress.
63   using ItemBrowserMap =
64       std::map<download::DownloadItem*, AlloyBrowserHostImpl*>;
65   ItemBrowserMap item_browser_map_;
66 };
67 
68 #endif  // CEF_LIBCEF_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_
69