OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ |
6 #define CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ | 6 #define CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/task.h" |
10 #include "chrome/browser/download/download_manager_delegate.h" | 12 #include "chrome/browser/download/download_manager_delegate.h" |
11 | 13 |
| 14 class DownloadItem; |
| 15 class DownloadManager; |
| 16 struct DownloadStateInfo; |
| 17 |
12 // Browser's download manager: manages all downloads and destination view. | 18 // Browser's download manager: manages all downloads and destination view. |
13 class ChromeDownloadManagerDelegate : public DownloadManagerDelegate { | 19 class ChromeDownloadManagerDelegate : public DownloadManagerDelegate { |
14 public: | 20 public: |
15 ChromeDownloadManagerDelegate(); | 21 ChromeDownloadManagerDelegate(); |
16 | 22 |
| 23 virtual bool ShouldStartDownload(int32 download_id) OVERRIDE; |
| 24 virtual void ChooseDownloadPath(TabContents* tab_contents, |
| 25 const FilePath& suggested_path, |
| 26 void* data) OVERRIDE; |
| 27 virtual TabContents* GetAlternativeTabContentsToNotifyForDownload() OVERRIDE; |
| 28 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path) OVERRIDE; |
17 virtual void GetSaveDir(TabContents* tab_contents, | 29 virtual void GetSaveDir(TabContents* tab_contents, |
18 FilePath* website_save_dir, | 30 FilePath* website_save_dir, |
19 FilePath* download_save_dir) OVERRIDE; | 31 FilePath* download_save_dir) OVERRIDE; |
20 virtual void ChooseSavePath(const base::WeakPtr<SavePackage>& save_package, | 32 virtual void ChooseSavePath(const base::WeakPtr<SavePackage>& save_package, |
21 const FilePath& suggested_path, | 33 const FilePath& suggested_path, |
22 bool can_save_as_complete) OVERRIDE; | 34 bool can_save_as_complete) OVERRIDE; |
23 virtual void ChooseDownloadPath(DownloadManager* download_manager, | |
24 TabContents* tab_contents, | |
25 const FilePath& suggested_path, | |
26 void* data) OVERRIDE; | |
27 virtual TabContents* GetAlternativeTabContentsToNotifyForDownload( | |
28 DownloadManager* download_manager) OVERRIDE; | |
29 | 35 |
30 void set_download_manager(DownloadManager* dm) { download_manager_ = dm; } | 36 void set_download_manager(DownloadManager* dm) { download_manager_ = dm; } |
31 | 37 |
32 private: | 38 private: |
33 DownloadManager* download_manager_; | 39 // Callback function after url is checked with safebrowsing service. |
| 40 void CheckDownloadUrlDone(int32 download_id, bool is_dangerous_url); |
| 41 |
| 42 // Callback function after we check whether the referrer URL has been visited |
| 43 // before today. |
| 44 void CheckVisitedReferrerBeforeDone(int32 download_id, |
| 45 bool visited_referrer_before); |
| 46 |
| 47 // Called on the download thread to check whether the suggested file path |
| 48 // exists. We don't check if the file exists on the UI thread to avoid UI |
| 49 // stalls from interacting with the file system. |
| 50 void CheckIfSuggestedPathExists(int32 download_id, |
| 51 DownloadStateInfo state, |
| 52 const FilePath& default_path); |
| 53 |
| 54 // Called on the UI thread once it's determined whether the suggested file |
| 55 // path exists. |
| 56 void OnPathExistenceAvailable(int32 download_id, |
| 57 const DownloadStateInfo& new_state); |
| 58 |
| 59 // Returns true if this download should show the "dangerous file" warning. |
| 60 // Various factors are considered, such as the type of the file, whether a |
| 61 // user action initiated the download, and whether the user has explicitly |
| 62 // marked the file type as "auto open". |
| 63 bool IsDangerousFile(const DownloadItem& download, |
| 64 const DownloadStateInfo& state, |
| 65 bool visited_referrer_before); |
| 66 |
| 67 ScopedRunnableMethodFactory<ChromeDownloadManagerDelegate> method_factory_; |
| 68 |
| 69 scoped_refptr<DownloadManager> download_manager_; |
34 | 70 |
35 DISALLOW_COPY_AND_ASSIGN(ChromeDownloadManagerDelegate); | 71 DISALLOW_COPY_AND_ASSIGN(ChromeDownloadManagerDelegate); |
36 }; | 72 }; |
37 | 73 |
38 #endif // CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ | 74 #endif // CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ |
OLD | NEW |