Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(751)

Side by Side Diff: chrome/browser/download/chrome_download_manager_delegate.cc

Issue 10069014: Save Page As MHTML (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "chrome/browser/download/chrome_download_manager_delegate.h" 5 #include "chrome/browser/download/chrome_download_manager_delegate.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 CheckDownloadUrlDone(download_id, DownloadProtectionService::SAFE); 151 CheckDownloadUrlDone(download_id, DownloadProtectionService::SAFE);
152 return false; 152 return false;
153 } 153 }
154 154
155 void ChromeDownloadManagerDelegate::ChooseDownloadPath( 155 void ChromeDownloadManagerDelegate::ChooseDownloadPath(
156 WebContents* web_contents, 156 WebContents* web_contents,
157 const FilePath& suggested_path, 157 const FilePath& suggested_path,
158 int32 download_id) { 158 int32 download_id) {
159 // Deletes itself. 159 // Deletes itself.
160 #if defined(OS_CHROMEOS) 160 #if defined(OS_CHROMEOS)
161 new DownloadFilePickerChromeOS( 161 new DownloadFilePickerChromeOS
162 #else 162 #else
163 new DownloadFilePicker( 163 new DownloadFilePicker
164 #endif 164 #endif
165 download_manager_, web_contents, suggested_path, download_id); 165 (download_manager_, web_contents, suggested_path, download_id);
166 } 166 }
167 167
168 FilePath ChromeDownloadManagerDelegate::GetIntermediatePath( 168 FilePath ChromeDownloadManagerDelegate::GetIntermediatePath(
169 const FilePath& suggested_path) { 169 const FilePath& suggested_path) {
170 return download_util::GetCrDownloadPath(suggested_path); 170 return download_util::GetCrDownloadPath(suggested_path);
171 } 171 }
172 172
173 WebContents* ChromeDownloadManagerDelegate:: 173 WebContents* ChromeDownloadManagerDelegate::
174 GetAlternativeWebContentsToNotifyForDownload() { 174 GetAlternativeWebContentsToNotifyForDownload() {
175 #if defined(OS_ANDROID) 175 #if defined(OS_ANDROID)
(...skipping 14 matching lines...) Expand all
190 FilePath::StringType extension = path.Extension(); 190 FilePath::StringType extension = path.Extension();
191 if (extension.empty()) 191 if (extension.empty())
192 return false; 192 return false;
193 if (Extension::IsExtension(path)) 193 if (Extension::IsExtension(path))
194 return false; 194 return false;
195 DCHECK(extension[0] == FilePath::kExtensionSeparator); 195 DCHECK(extension[0] == FilePath::kExtensionSeparator);
196 extension.erase(0, 1); 196 extension.erase(0, 1);
197 return download_prefs_->IsAutoOpenEnabledForExtension(extension); 197 return download_prefs_->IsAutoOpenEnabledForExtension(extension);
198 } 198 }
199 199
200 // static
201 void ChromeDownloadManagerDelegate::DisableSafeBrowsing(DownloadItem* item) {
202 #if defined(ENABLE_SAFE_BROWSING)
203 SafeBrowsingState* state = static_cast<SafeBrowsingState*>(
204 item->GetExternalData(&safe_browsing_id));
205 DCHECK(state == NULL);
206 if (state == NULL) {
207 state = new SafeBrowsingState();
208 item->SetExternalData(&safe_browsing_id, state);
209 }
210 state->pending = false;
211 state->verdict = DownloadProtectionService::SAFE;
212 #endif
213 }
214
200 bool ChromeDownloadManagerDelegate::ShouldCompleteDownload(DownloadItem* item) { 215 bool ChromeDownloadManagerDelegate::ShouldCompleteDownload(DownloadItem* item) {
201 #if defined(ENABLE_SAFE_BROWSING) 216 #if defined(ENABLE_SAFE_BROWSING)
202 // See if there is already a pending SafeBrowsing check for that download. 217 // See if there is already a pending SafeBrowsing check for that download.
203 SafeBrowsingState* state = static_cast<SafeBrowsingState*>( 218 SafeBrowsingState* state = static_cast<SafeBrowsingState*>(
204 item->GetExternalData(&safe_browsing_id)); 219 item->GetExternalData(&safe_browsing_id));
205 if (state) 220 // Don't complete the download until we have an answer.
206 // Don't complete the download until we have an answer. 221 if (state && state->pending)
207 return !state->pending; 222 return false;
208 223
209 // Begin the safe browsing download protection check. 224 if (state == NULL) {
210 DownloadProtectionService* service = GetDownloadProtectionService(); 225 // Begin the safe browsing download protection check.
211 if (service) { 226 DownloadProtectionService* service = GetDownloadProtectionService();
212 VLOG(2) << __FUNCTION__ << "() Start SB download check for download = " 227 if (service) {
213 << item->DebugString(false); 228 VLOG(2) << __FUNCTION__ << "() Start SB download check for download = "
214 state = new SafeBrowsingState(); 229 << item->DebugString(false);
215 state->pending = true; 230 state = new SafeBrowsingState();
216 state->verdict = DownloadProtectionService::SAFE; 231 state->pending = true;
217 item->SetExternalData(&safe_browsing_id, state); 232 state->verdict = DownloadProtectionService::SAFE;
218 service->CheckClientDownload( 233 item->SetExternalData(&safe_browsing_id, state);
219 DownloadProtectionService::DownloadInfo::FromDownloadItem(*item), 234 service->CheckClientDownload(
220 base::Bind( 235 DownloadProtectionService::DownloadInfo::FromDownloadItem(*item),
221 &ChromeDownloadManagerDelegate::CheckClientDownloadDone, 236 base::Bind(
222 this, 237 &ChromeDownloadManagerDelegate::CheckClientDownloadDone,
223 item->GetId())); 238 this,
224 return false; 239 item->GetId()));
240 return false;
241 }
225 } 242 }
226 #endif 243 #endif
244
227 #if defined(OS_CHROMEOS) 245 #if defined(OS_CHROMEOS)
228 // If there's a GData upload associated with this download, we wait until that 246 // If there's a GData upload associated with this download, we wait until that
229 // is complete before allowing the download item to complete. 247 // is complete before allowing the download item to complete.
230 if (!gdata::GDataDownloadObserver::IsReadyToComplete(item)) 248 if (!gdata::GDataDownloadObserver::IsReadyToComplete(item))
231 return false; 249 return false;
232 #endif 250 #endif
233 return true; 251 return true;
234 } 252 }
235 253
236 bool ChromeDownloadManagerDelegate::ShouldOpenDownload(DownloadItem* item) { 254 bool ChromeDownloadManagerDelegate::ShouldOpenDownload(DownloadItem* item) {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 DCHECK(!website_save_dir->empty()); 390 DCHECK(!website_save_dir->empty());
373 391
374 *download_save_dir = prefs->GetFilePath(prefs::kDownloadDefaultDirectory); 392 *download_save_dir = prefs->GetFilePath(prefs::kDownloadDefaultDirectory);
375 } 393 }
376 394
377 void ChromeDownloadManagerDelegate::ChooseSavePath( 395 void ChromeDownloadManagerDelegate::ChooseSavePath(
378 WebContents* web_contents, 396 WebContents* web_contents,
379 const FilePath& suggested_path, 397 const FilePath& suggested_path,
380 const FilePath::StringType& default_extension, 398 const FilePath::StringType& default_extension,
381 bool can_save_as_complete, 399 bool can_save_as_complete,
382 content::SaveFilePathPickedCallback callback) { 400 const content::SavePackagePathPickedCallback& callback) {
383 // Deletes itself. 401 // Deletes itself.
384 #if defined(OS_CHROMEOS) 402 #if defined(OS_CHROMEOS)
385 // Note that we're ignoring the callback here. 403 new SavePackageFilePickerChromeOS(web_contents, suggested_path, callback);
386 // SavePackageFilePickerChromeOS completes the save operation itself.
387 // TODO(achuith): Fix this.
388 new SavePackageFilePickerChromeOS(web_contents, suggested_path);
389 #else 404 #else
390 new SavePackageFilePicker(web_contents, suggested_path, default_extension, 405 new SavePackageFilePicker(web_contents, suggested_path, default_extension,
391 can_save_as_complete, download_prefs_.get(), callback); 406 can_save_as_complete, download_prefs_.get(), callback);
392 #endif 407 #endif
393 } 408 }
394 409
395 #if defined(ENABLE_SAFE_BROWSING) 410 #if defined(ENABLE_SAFE_BROWSING)
396 DownloadProtectionService* 411 DownloadProtectionService*
397 ChromeDownloadManagerDelegate::GetDownloadProtectionService() { 412 ChromeDownloadManagerDelegate::GetDownloadProtectionService() {
398 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); 413 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service();
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 int32 download_id, int64 db_handle) { 719 int32 download_id, int64 db_handle) {
705 // It's not immediately obvious, but HistoryBackend::CreateDownload() can 720 // It's not immediately obvious, but HistoryBackend::CreateDownload() can
706 // call this function with an invalid |db_handle|. For instance, this can 721 // call this function with an invalid |db_handle|. For instance, this can
707 // happen when the history database is offline. We cannot have multiple 722 // happen when the history database is offline. We cannot have multiple
708 // DownloadItems with the same invalid db_handle, so we need to assign a 723 // DownloadItems with the same invalid db_handle, so we need to assign a
709 // unique |db_handle| here. 724 // unique |db_handle| here.
710 if (db_handle == DownloadItem::kUninitializedHandle) 725 if (db_handle == DownloadItem::kUninitializedHandle)
711 db_handle = download_history_->GetNextFakeDbHandle(); 726 db_handle = download_history_->GetNextFakeDbHandle();
712 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); 727 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle);
713 } 728 }
OLDNEW
« no previous file with comments | « chrome/browser/download/chrome_download_manager_delegate.h ('k') | chrome/browser/download/save_package_file_picker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698