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>
|
|
|
|
|
2016-02-12 23:31:22 +01:00
|
|
|
#include "libcef/browser/browser_host_impl.h"
|
|
|
|
|
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"
|
|
|
|
|
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,
|
|
|
|
public CefBrowserHostImpl::Observer {
|
2012-04-03 03:34:16 +02:00
|
|
|
public:
|
2012-11-30 20:08:20 +01:00
|
|
|
explicit CefDownloadManagerDelegate(content::DownloadManager* manager);
|
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,
|
2014-11-12 20:25:15 +01:00
|
|
|
const content::DownloadTargetCallback& callback) override;
|
|
|
|
void GetNextId(const content::DownloadIdCallback& callback) override;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2016-02-12 23:31:22 +01:00
|
|
|
// CefBrowserHostImpl::Observer methods.
|
|
|
|
void OnBrowserDestroyed(CefBrowserHostImpl* browser) override;
|
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
CefBrowserHostImpl* 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
|
|
|
|
|
|
|
// Map of DownloadItem to originating CefBrowserHostImpl. Maintaining this
|
|
|
|
// map is necessary because DownloadItem::GetWebContents() may return NULL if
|
|
|
|
// the browser navigates while the download is in progress.
|
2018-03-20 21:15:08 +01:00
|
|
|
typedef std::map<download::DownloadItem*, CefBrowserHostImpl*> ItemBrowserMap;
|
2016-02-12 23:31:22 +01:00
|
|
|
ItemBrowserMap item_browser_map_;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CefDownloadManagerDelegate);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_
|