| 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 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/time.h" | 12 #include "base/time.h" |
| 13 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
| 14 #include "content/public/browser/download_danger_type.h" |
| 15 #include "content/public/browser/download_item.h" |
| 14 #include "content/public/browser/save_page_type.h" | 16 #include "content/public/browser/save_page_type.h" |
| 15 | 17 |
| 16 namespace content { | 18 namespace content { |
| 17 | 19 |
| 18 class DownloadId; | 20 class DownloadId; |
| 19 class DownloadItem; | |
| 20 class WebContents; | 21 class WebContents; |
| 21 | 22 |
| 22 // Called by SavePackage when it creates a DownloadItem. | 23 // Called by SavePackage when it creates a DownloadItem. |
| 23 typedef base::Callback<void(DownloadItem*)> | 24 typedef base::Callback<void(DownloadItem*)> |
| 24 SavePackageDownloadCreatedCallback; | 25 SavePackageDownloadCreatedCallback; |
| 25 | 26 |
| 26 // Will be called asynchronously with the results of the ChooseSavePath | 27 // Will be called asynchronously with the results of the ChooseSavePath |
| 27 // operation. If the delegate wants notification of the download item created | 28 // operation. If the delegate wants notification of the download item created |
| 28 // in response to this operation, the SavePackageDownloadCreatedCallback will be | 29 // in response to this operation, the SavePackageDownloadCreatedCallback will be |
| 29 // non-null. | 30 // non-null. |
| 30 typedef base::Callback<void(const FilePath&, | 31 typedef base::Callback<void(const FilePath&, |
| 31 content::SavePageType, | 32 content::SavePageType, |
| 32 const SavePackageDownloadCreatedCallback&)> | 33 const SavePackageDownloadCreatedCallback&)> |
| 33 SavePackagePathPickedCallback; | 34 SavePackagePathPickedCallback; |
| 34 | 35 |
| 36 // Called with the results of DetermineDownloadTarget(). If the delegate decides |
| 37 // to cancel the download, then |target_path| should be set to an empty path. If |
| 38 // |target_path| is non-empty, then |intermediate_path| is required to be |
| 39 // non-empty and specify the path to the intermediate file (which could be the |
| 40 // same as |target_path|). Both |target_path| and |intermediate_path| are |
| 41 // expected to in the same directory. |
| 42 typedef base::Callback<void( |
| 43 const FilePath& target_path, |
| 44 content::DownloadItem::TargetDisposition disposition, |
| 45 content::DownloadDangerType danger_type, |
| 46 const FilePath& intermediate_path)> DownloadTargetCallback; |
| 47 |
| 35 // Browser's download manager: manages all downloads and destination view. | 48 // Browser's download manager: manages all downloads and destination view. |
| 36 class CONTENT_EXPORT DownloadManagerDelegate { | 49 class CONTENT_EXPORT DownloadManagerDelegate { |
| 37 public: | 50 public: |
| 38 // Lets the delegate know that the download manager is shutting down. | 51 // Lets the delegate know that the download manager is shutting down. |
| 39 virtual void Shutdown() {} | 52 virtual void Shutdown() {} |
| 40 | 53 |
| 41 // Returns a new DownloadId. | 54 // Returns a new DownloadId. |
| 42 virtual DownloadId GetNextId(); | 55 virtual DownloadId GetNextId(); |
| 43 | 56 |
| 44 // Notifies the delegate that a download is starting. The delegate can return | 57 // Called to notify the delegate that a new download |item| requires a |
| 45 // false to delay the start of the download, in which case it should call | 58 // download target to be determined. The delegate should return |true| if it |
| 46 // DownloadManager::RestartDownload when it's ready. | 59 // will determine the target information and will invoke |callback|. The |
| 47 virtual bool ShouldStartDownload(int32 download_id); | 60 // callback may be invoked directly (synchronously). If this function returns |
| 48 | 61 // |false|, the download manager will continue the download using a default |
| 49 // Asks the user for the path for a download. The delegate calls | 62 // target path. |
| 50 // DownloadManager::FileSelected or DownloadManager::FileSelectionCanceled to | 63 // |
| 51 // give the answer. | 64 // The state of the |item| shouldn't be modified during the process of |
| 52 virtual void ChooseDownloadPath(DownloadItem* item) {} | 65 // filename determination save for external data (GetExternalData() / |
| 53 | 66 // SetExternalData()). |
| 54 // Allows the embedder to set an intermediate name for the download until it's | 67 // |
| 55 // complete. The return value is the intermediate path to use. If the embedder | 68 // If the download should be canceled, |callback| should be invoked with an |
| 56 // doesn't want to set an intermediate path, it should return | 69 // empty |target_path| argument. |
| 57 // item.GetTargetFilePath(). If there's already a file at the returned path, | 70 virtual bool DetermineDownloadTarget(DownloadItem* item, |
| 58 // it will not be overwritten. Instead the path will be uniquified by adding a | 71 const DownloadTargetCallback& callback); |
| 59 // suffix to the filename. | |
| 60 virtual FilePath GetIntermediatePath(const DownloadItem& item); | |
| 61 | 72 |
| 62 // Called when the download system wants to alert a WebContents that a | 73 // Called when the download system wants to alert a WebContents that a |
| 63 // download has started, but the TabConetnts has gone away. This lets an | 74 // download has started, but the TabConetnts has gone away. This lets an |
| 64 // delegate return an alternative WebContents. The delegate can return NULL. | 75 // delegate return an alternative WebContents. The delegate can return NULL. |
| 65 virtual WebContents* GetAlternativeWebContentsToNotifyForDownload(); | 76 virtual WebContents* GetAlternativeWebContentsToNotifyForDownload(); |
| 66 | 77 |
| 67 // Tests if a file type should be opened automatically. | 78 // Tests if a file type should be opened automatically. |
| 68 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path); | 79 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path); |
| 69 | 80 |
| 70 // Allows the delegate to delay completion of the download. This function | 81 // Allows the delegate to delay completion of the download. This function |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 const SavePackagePathPickedCallback& callback) { | 142 const SavePackagePathPickedCallback& callback) { |
| 132 } | 143 } |
| 133 | 144 |
| 134 protected: | 145 protected: |
| 135 virtual ~DownloadManagerDelegate(); | 146 virtual ~DownloadManagerDelegate(); |
| 136 }; | 147 }; |
| 137 | 148 |
| 138 } // namespace content | 149 } // namespace content |
| 139 | 150 |
| 140 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_ | 151 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_ |
| OLD | NEW |