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 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/hash_tables.h" | 10 #include "base/hash_tables.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 public content::NotificationObserver { | 47 public content::NotificationObserver { |
48 public: | 48 public: |
49 explicit ChromeDownloadManagerDelegate(Profile* profile); | 49 explicit ChromeDownloadManagerDelegate(Profile* profile); |
50 | 50 |
51 void SetDownloadManager(content::DownloadManager* dm); | 51 void SetDownloadManager(content::DownloadManager* dm); |
52 | 52 |
53 // Should be called before the first call to ShouldCompleteDownload() to | 53 // Should be called before the first call to ShouldCompleteDownload() to |
54 // disable SafeBrowsing checks for |item|. | 54 // disable SafeBrowsing checks for |item|. |
55 static void DisableSafeBrowsing(content::DownloadItem* item); | 55 static void DisableSafeBrowsing(content::DownloadItem* item); |
56 | 56 |
| 57 // content::DownloadManagerDelegate |
57 virtual void Shutdown() OVERRIDE; | 58 virtual void Shutdown() OVERRIDE; |
58 virtual content::DownloadId GetNextId() OVERRIDE; | 59 virtual content::DownloadId GetNextId() OVERRIDE; |
59 virtual bool ShouldStartDownload(int32 download_id) OVERRIDE; | 60 virtual bool DetermineDownloadTarget( |
60 virtual void ChooseDownloadPath(content::DownloadItem* item) OVERRIDE; | 61 content::DownloadItem* item, |
61 virtual FilePath GetIntermediatePath( | 62 const content::DownloadTargetCallback& callback) OVERRIDE; |
62 const content::DownloadItem& item) OVERRIDE; | |
63 virtual content::WebContents* | 63 virtual content::WebContents* |
64 GetAlternativeWebContentsToNotifyForDownload() OVERRIDE; | 64 GetAlternativeWebContentsToNotifyForDownload() OVERRIDE; |
65 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path) OVERRIDE; | 65 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path) OVERRIDE; |
66 virtual bool ShouldCompleteDownload( | 66 virtual bool ShouldCompleteDownload( |
67 content::DownloadItem* item, | 67 content::DownloadItem* item, |
68 const base::Closure& complete_callback) OVERRIDE; | 68 const base::Closure& complete_callback) OVERRIDE; |
69 virtual bool ShouldOpenDownload(content::DownloadItem* item) OVERRIDE; | 69 virtual bool ShouldOpenDownload(content::DownloadItem* item) OVERRIDE; |
70 virtual bool GenerateFileHash() OVERRIDE; | 70 virtual bool GenerateFileHash() OVERRIDE; |
71 virtual void AddItemToPersistentStore(content::DownloadItem* item) OVERRIDE; | 71 virtual void AddItemToPersistentStore(content::DownloadItem* item) OVERRIDE; |
72 virtual void UpdateItemInPersistentStore( | 72 virtual void UpdateItemInPersistentStore( |
(...skipping 10 matching lines...) Expand all Loading... |
83 FilePath* website_save_dir, | 83 FilePath* website_save_dir, |
84 FilePath* download_save_dir, | 84 FilePath* download_save_dir, |
85 bool* skip_dir_check) OVERRIDE; | 85 bool* skip_dir_check) OVERRIDE; |
86 virtual void ChooseSavePath( | 86 virtual void ChooseSavePath( |
87 content::WebContents* web_contents, | 87 content::WebContents* web_contents, |
88 const FilePath& suggested_path, | 88 const FilePath& suggested_path, |
89 const FilePath::StringType& default_extension, | 89 const FilePath::StringType& default_extension, |
90 bool can_save_as_complete, | 90 bool can_save_as_complete, |
91 const content::SavePackagePathPickedCallback& callback) OVERRIDE; | 91 const content::SavePackagePathPickedCallback& callback) OVERRIDE; |
92 | 92 |
| 93 // Clears the last directory chosen by the user in response to a file chooser |
| 94 // prompt. Called when clearing history. |
| 95 void ClearLastDownloadPath(); |
| 96 |
93 DownloadPrefs* download_prefs() { return download_prefs_.get(); } | 97 DownloadPrefs* download_prefs() { return download_prefs_.get(); } |
94 DownloadHistory* download_history() { return download_history_.get(); } | 98 DownloadHistory* download_history() { return download_history_.get(); } |
95 | 99 |
96 protected: | 100 protected: |
97 // So that test classes can inherit from this for override purposes. | 101 // So that test classes can inherit from this for override purposes. |
98 virtual ~ChromeDownloadManagerDelegate(); | 102 virtual ~ChromeDownloadManagerDelegate(); |
99 | 103 |
100 // Returns the SafeBrowsing download protection service if it's | 104 // Returns the SafeBrowsing download protection service if it's |
101 // enabled. Returns NULL otherwise. Protected virtual for testing. | 105 // enabled. Returns NULL otherwise. Protected virtual for testing. |
102 virtual safe_browsing::DownloadProtectionService* | 106 virtual safe_browsing::DownloadProtectionService* |
103 GetDownloadProtectionService(); | 107 GetDownloadProtectionService(); |
104 | 108 |
105 // Returns true if this download should show the "dangerous file" warning. | 109 // Returns true if this download should show the "dangerous file" warning. |
106 // Various factors are considered, such as the type of the file, whether a | 110 // Various factors are considered, such as the type of the file, whether a |
107 // user action initiated the download, and whether the user has explicitly | 111 // user action initiated the download, and whether the user has explicitly |
108 // marked the file type as "auto open". Protected virtual for testing. | 112 // marked the file type as "auto open". Protected virtual for testing. |
109 virtual bool IsDangerousFile(const content::DownloadItem& download, | 113 virtual bool IsDangerousFile(const content::DownloadItem& download, |
110 const FilePath& suggested_path, | 114 const FilePath& suggested_path, |
111 bool visited_referrer_before); | 115 bool visited_referrer_before); |
112 | 116 |
113 // Obtains a path reservation by calling | 117 // Obtains a path reservation by calling |
114 // DownloadPathReservationTracker::GetReservedPath(). Protected virtual for | 118 // DownloadPathReservationTracker::GetReservedPath(). Protected virtual for |
115 // testing. | 119 // testing. |
116 virtual void GetReservedPath( | 120 virtual void GetReservedPath( |
117 content::DownloadItem& download, | 121 content::DownloadItem& download, |
118 const FilePath& target_path, | 122 const FilePath& target_path, |
119 const FilePath& default_download_path, | 123 const FilePath& default_download_path, |
120 bool should_uniquify_path, | 124 bool should_uniquify_path, |
121 const DownloadPathReservationTracker::ReservedPathCallback callback); | 125 const DownloadPathReservationTracker::ReservedPathCallback& callback); |
| 126 |
| 127 // Displays the file chooser dialog to prompt the user for the download |
| 128 // location for |item|. |suggested_path| will be used as the initial download |
| 129 // path. Once a location is available |file_selected_callback| will be invoked |
| 130 // with the selected full path. If the user cancels the dialog, then an empty |
| 131 // FilePath will be passed into |file_selected_callback|. Protected virtual |
| 132 // for testing. |
| 133 virtual void ChooseDownloadPath(content::DownloadItem* item, |
| 134 const FilePath& suggested_path, |
| 135 const base::Callback<void(const FilePath&)>& |
| 136 file_selected_callback); |
122 | 137 |
123 // So that test classes that inherit from this for override purposes | 138 // So that test classes that inherit from this for override purposes |
124 // can call back into the DownloadManager. | 139 // can call back into the DownloadManager. |
125 scoped_refptr<content::DownloadManager> download_manager_; | 140 scoped_refptr<content::DownloadManager> download_manager_; |
126 | 141 |
127 private: | 142 private: |
128 friend class base::RefCountedThreadSafe<ChromeDownloadManagerDelegate>; | 143 friend class base::RefCountedThreadSafe<ChromeDownloadManagerDelegate>; |
129 | 144 |
130 // content::NotificationObserver implementation. | 145 // content::NotificationObserver implementation. |
131 virtual void Observe(int type, | 146 virtual void Observe(int type, |
132 const content::NotificationSource& source, | 147 const content::NotificationSource& source, |
133 const content::NotificationDetails& details) OVERRIDE; | 148 const content::NotificationDetails& details) OVERRIDE; |
134 | 149 |
135 // Callback function after url is checked with safebrowsing service. | 150 // Callback function after url is checked with safebrowsing service. |
136 void CheckDownloadUrlDone( | 151 void CheckDownloadUrlDone( |
137 int32 download_id, | 152 int32 download_id, |
| 153 const content::DownloadTargetCallback& callback, |
138 safe_browsing::DownloadProtectionService::DownloadCheckResult result); | 154 safe_browsing::DownloadProtectionService::DownloadCheckResult result); |
139 | 155 |
140 // Callback function after the DownloadProtectionService completes. | 156 // Callback function after the DownloadProtectionService completes. |
141 void CheckClientDownloadDone( | 157 void CheckClientDownloadDone( |
142 int32 download_id, | 158 int32 download_id, |
143 safe_browsing::DownloadProtectionService::DownloadCheckResult result); | 159 safe_browsing::DownloadProtectionService::DownloadCheckResult result); |
144 | 160 |
145 // Callback function after we check whether the referrer URL has been visited | 161 // Callback function after we check whether the referrer URL has been visited |
146 // before today. Determines the danger state of the download based on the file | 162 // before today. Determines the danger state of the download based on the file |
147 // type and |visited_referrer_before|. Generates a target path for the | 163 // type and |visited_referrer_before|. Generates a target path for the |
148 // download. Invokes |DownloadPathReservationTracker::GetReservedPath| to get | 164 // download. Invokes |DownloadPathReservationTracker::GetReservedPath| to get |
149 // a reserved path for the download. The path is then passed into | 165 // a reserved path for the download. The path is then passed into |
150 // OnPathReservationAvailable(). | 166 // OnPathReservationAvailable(). |
151 void CheckVisitedReferrerBeforeDone(int32 download_id, | 167 void CheckVisitedReferrerBeforeDone( |
152 content::DownloadDangerType danger_type, | 168 int32 download_id, |
153 bool visited_referrer_before); | 169 const content::DownloadTargetCallback& callback, |
| 170 content::DownloadDangerType danger_type, |
| 171 bool visited_referrer_before); |
154 | 172 |
155 #if defined (OS_CHROMEOS) | 173 #if defined (OS_CHROMEOS) |
156 // GDataDownloadObserver::SubstituteGDataDownloadPath callback. Calls | 174 // GDataDownloadObserver::SubstituteGDataDownloadPath callback. Calls |
157 // |DownloadPathReservationTracker::GetReservedPath| to get a reserved path | 175 // |DownloadPathReservationTracker::GetReservedPath| to get a reserved path |
158 // for the download. The path is then passed into | 176 // for the download. The path is then passed into |
159 // OnPathReservationAvailable(). | 177 // OnPathReservationAvailable(). |
160 void SubstituteGDataDownloadPathCallback( | 178 void SubstituteGDataDownloadPathCallback( |
161 int32 download_id, | 179 int32 download_id, |
| 180 const content::DownloadTargetCallback& callback, |
162 bool should_prompt, | 181 bool should_prompt, |
163 bool is_forced_path, | 182 bool is_forced_path, |
164 content::DownloadDangerType danger_type, | 183 content::DownloadDangerType danger_type, |
165 const FilePath& unverified_path); | 184 const FilePath& unverified_path); |
166 #endif | 185 #endif |
167 | 186 |
| 187 // Determine the intermediate path to use for |target_path|. |danger_type| |
| 188 // specifies the danger level of the download. |
| 189 FilePath GetIntermediatePath(const FilePath& target_path, |
| 190 content::DownloadDangerType danger_type); |
| 191 |
168 // Called on the UI thread once a reserved path is available. Updates the | 192 // Called on the UI thread once a reserved path is available. Updates the |
169 // download identified by |download_id| with the |target_path|, target | 193 // download identified by |download_id| with the |target_path|, target |
170 // disposition and |danger_type|. | 194 // disposition and |danger_type|. |
171 void OnPathReservationAvailable( | 195 void OnPathReservationAvailable( |
172 int32 download_id, | 196 int32 download_id, |
| 197 const content::DownloadTargetCallback& callback, |
173 bool should_prompt, | 198 bool should_prompt, |
174 content::DownloadDangerType danger_type, | 199 content::DownloadDangerType danger_type, |
175 const FilePath& target_path, | 200 const FilePath& reserved_path, |
176 bool target_path_verified); | 201 bool reserved_path_verified); |
| 202 |
| 203 // Called on the UI thread once the final target path is available. |
| 204 void OnTargetPathDetermined( |
| 205 int32 download_id, |
| 206 const content::DownloadTargetCallback& callback, |
| 207 content::DownloadItem::TargetDisposition disposition, |
| 208 content::DownloadDangerType danger_type, |
| 209 const FilePath& target_path); |
177 | 210 |
178 // Callback from history system. | 211 // Callback from history system. |
179 void OnItemAddedToPersistentStore(int32 download_id, int64 db_handle); | 212 void OnItemAddedToPersistentStore(int32 download_id, int64 db_handle); |
180 | 213 |
181 // Check policy of whether we should open this download with a web intents | 214 // Check policy of whether we should open this download with a web intents |
182 // dispatch. | 215 // dispatch. |
183 bool ShouldOpenWithWebIntents(const content::DownloadItem* item); | 216 bool ShouldOpenWithWebIntents(const content::DownloadItem* item); |
184 | 217 |
185 // Open the given item with a web intent dispatch. | 218 // Open the given item with a web intent dispatch. |
186 void OpenWithWebIntent(const content::DownloadItem* item); | 219 void OpenWithWebIntent(const content::DownloadItem* item); |
(...skipping 18 matching lines...) Expand all Loading... |
205 content::NotificationRegistrar registrar_; | 238 content::NotificationRegistrar registrar_; |
206 | 239 |
207 // The ExtensionDownloadsEventRouter dispatches download creation, change, and | 240 // The ExtensionDownloadsEventRouter dispatches download creation, change, and |
208 // erase events to extensions. Like ChromeDownloadManagerDelegate, it's a | 241 // erase events to extensions. Like ChromeDownloadManagerDelegate, it's a |
209 // chrome-level concept and its lifetime should match DownloadManager. There | 242 // chrome-level concept and its lifetime should match DownloadManager. There |
210 // should be a separate EDER for on-record and off-record managers. | 243 // should be a separate EDER for on-record and off-record managers. |
211 // There does not appear to be a separate ExtensionSystem for on-record and | 244 // There does not appear to be a separate ExtensionSystem for on-record and |
212 // off-record profiles, so ExtensionSystem cannot own the EDER. | 245 // off-record profiles, so ExtensionSystem cannot own the EDER. |
213 scoped_ptr<ExtensionDownloadsEventRouter> extension_event_router_; | 246 scoped_ptr<ExtensionDownloadsEventRouter> extension_event_router_; |
214 | 247 |
| 248 // The directory most recently chosen by the user in response to a Save As |
| 249 // dialog for a regular download. |
| 250 FilePath last_download_path_; |
| 251 |
215 DISALLOW_COPY_AND_ASSIGN(ChromeDownloadManagerDelegate); | 252 DISALLOW_COPY_AND_ASSIGN(ChromeDownloadManagerDelegate); |
216 }; | 253 }; |
217 | 254 |
218 #endif // CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ | 255 #endif // CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ |
OLD | NEW |