OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_PUBLIC_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_ |
6 #define CONTENT_PUBLIC_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_ | 6 #define CONTENT_PUBLIC_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/time.h" | 13 #include "base/time.h" |
14 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
15 #include "content/public/browser/download_danger_type.h" | |
16 #include "content/public/browser/download_item.h" | |
15 #include "content/public/browser/save_page_type.h" | 17 #include "content/public/browser/save_page_type.h" |
16 | 18 |
17 namespace content { | 19 namespace content { |
18 | 20 |
19 class DownloadId; | 21 class DownloadId; |
20 class DownloadItem; | |
21 class WebContents; | 22 class WebContents; |
22 | 23 |
23 // Called by SavePackage when it creates a DownloadItem. | 24 // Called by SavePackage when it creates a DownloadItem. |
24 typedef base::Callback<void(DownloadItem*)> | 25 typedef base::Callback<void(DownloadItem*)> |
25 SavePackageDownloadCreatedCallback; | 26 SavePackageDownloadCreatedCallback; |
26 | 27 |
27 // Will be called asynchronously with the results of the ChooseSavePath | 28 // Will be called asynchronously with the results of the ChooseSavePath |
28 // operation. If the delegate wants notification of the download item created | 29 // operation. If the delegate wants notification of the download item created |
29 // in response to this operation, the SavePackageDownloadCreatedCallback will be | 30 // in response to this operation, the SavePackageDownloadCreatedCallback will be |
30 // non-null. | 31 // non-null. |
31 typedef base::Callback<void(const FilePath&, | 32 typedef base::Callback<void(const FilePath&, |
32 content::SavePageType, | 33 content::SavePageType, |
33 const SavePackageDownloadCreatedCallback&)> | 34 const SavePackageDownloadCreatedCallback&)> |
34 SavePackagePathPickedCallback; | 35 SavePackagePathPickedCallback; |
35 | 36 |
37 typedef base::Callback<void( | |
38 const FilePath& target_path, | |
39 content::DownloadItem::TargetDisposition disposition, | |
40 content::DownloadDangerType danger_type, | |
41 const FilePath& intermediate_path)> DownloadTargetCallback; | |
42 | |
36 // Browser's download manager: manages all downloads and destination view. | 43 // Browser's download manager: manages all downloads and destination view. |
37 class CONTENT_EXPORT DownloadManagerDelegate { | 44 class CONTENT_EXPORT DownloadManagerDelegate { |
38 public: | 45 public: |
39 // Lets the delegate know that the download manager is shutting down. | 46 // Lets the delegate know that the download manager is shutting down. |
40 virtual void Shutdown() {} | 47 virtual void Shutdown() {} |
41 | 48 |
42 // Returns a new DownloadId. | 49 // Returns a new DownloadId. |
43 virtual DownloadId GetNextId(); | 50 virtual DownloadId GetNextId(); |
44 | 51 |
45 // Notifies the delegate that a download is starting. The delegate can return | 52 // Called to notify the delegate that a new download |item| requires a |
46 // false to delay the start of the download, in which case it should call | 53 // download target to be determined. The delegate should return |true| if it |
47 // DownloadManager::RestartDownload when it's ready. | 54 // will determine the target information and will invoke |callback|. The |
48 virtual bool ShouldStartDownload(int32 download_id); | 55 // callback may be invoked directly (synchronously). If this function returns |
49 | 56 // |false|, the download manager will continue the download using a default, |
50 // Asks the user for the path for a download. The delegate calls | 57 // possibly empty, target path. |
Randy Smith (Not in Mondays)
2012/07/12 17:01:22
I'd like to say something about the state changes
asanka
2012/07/18 21:50:56
I made a note that the state of |item| shouldn't b
| |
51 // DownloadManager::FileSelected or DownloadManager::FileSelectionCanceled to | 58 virtual bool DetermineDownloadTarget(DownloadItem* item, |
52 // give the answer. | 59 const DownloadTargetCallback& callback); |
53 virtual void ChooseDownloadPath(DownloadItem* item) {} | |
54 | |
55 // Allows the embedder to set an intermediate name for the download until it's | |
56 // complete. The return value is the intermediate path to use. If the embedder | |
57 // doesn't want to set an intermediate path, it should return | |
58 // item.GetTargetFilePath(). If there's already a file at the returned path, | |
59 // it will not be overwritten. Instead the path will be uniquified by adding a | |
60 // suffix to the filename. | |
61 virtual FilePath GetIntermediatePath(const DownloadItem& item); | |
62 | 60 |
63 // Called when the download system wants to alert a WebContents that a | 61 // Called when the download system wants to alert a WebContents that a |
64 // download has started, but the TabConetnts has gone away. This lets an | 62 // download has started, but the TabConetnts has gone away. This lets an |
65 // delegate return an alternative WebContents. The delegate can return NULL. | 63 // delegate return an alternative WebContents. The delegate can return NULL. |
66 virtual WebContents* GetAlternativeWebContentsToNotifyForDownload(); | 64 virtual WebContents* GetAlternativeWebContentsToNotifyForDownload(); |
67 | 65 |
68 // Tests if a file type should be opened automatically. | 66 // Tests if a file type should be opened automatically. |
69 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path); | 67 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path); |
70 | 68 |
71 // Allows the delegate to delay completion of the download. This function | 69 // Allows the delegate to delay completion of the download. This function |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 const SavePackagePathPickedCallback& callback) { | 130 const SavePackagePathPickedCallback& callback) { |
133 } | 131 } |
134 | 132 |
135 protected: | 133 protected: |
136 virtual ~DownloadManagerDelegate(); | 134 virtual ~DownloadManagerDelegate(); |
137 }; | 135 }; |
138 | 136 |
139 } // namespace content | 137 } // namespace content |
140 | 138 |
141 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_ | 139 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_ |
OLD | NEW |