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

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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 CheckDownloadUrlDone(download_id, DownloadProtectionService::SAFE); 147 CheckDownloadUrlDone(download_id, DownloadProtectionService::SAFE);
148 return false; 148 return false;
149 } 149 }
150 150
151 void ChromeDownloadManagerDelegate::ChooseDownloadPath( 151 void ChromeDownloadManagerDelegate::ChooseDownloadPath(
152 WebContents* web_contents, 152 WebContents* web_contents,
153 const FilePath& suggested_path, 153 const FilePath& suggested_path,
154 int32 download_id) { 154 int32 download_id) {
155 // Deletes itself. 155 // Deletes itself.
156 #if defined(OS_CHROMEOS) 156 #if defined(OS_CHROMEOS)
157 new DownloadFilePickerChromeOS( 157 new DownloadFilePickerChromeOS
158 #else 158 #else
159 new DownloadFilePicker( 159 new DownloadFilePicker
160 #endif 160 #endif
161 download_manager_, web_contents, suggested_path, download_id); 161 (download_manager_, web_contents, suggested_path, download_id);
162 } 162 }
163 163
164 FilePath ChromeDownloadManagerDelegate::GetIntermediatePath( 164 FilePath ChromeDownloadManagerDelegate::GetIntermediatePath(
165 const FilePath& suggested_path) { 165 const FilePath& suggested_path) {
166 return download_util::GetCrDownloadPath(suggested_path); 166 return download_util::GetCrDownloadPath(suggested_path);
167 } 167 }
168 168
169 WebContents* ChromeDownloadManagerDelegate:: 169 WebContents* ChromeDownloadManagerDelegate::
170 GetAlternativeWebContentsToNotifyForDownload() { 170 GetAlternativeWebContentsToNotifyForDownload() {
171 #if defined(OS_ANDROID) 171 #if defined(OS_ANDROID)
(...skipping 14 matching lines...) Expand all
186 FilePath::StringType extension = path.Extension(); 186 FilePath::StringType extension = path.Extension();
187 if (extension.empty()) 187 if (extension.empty())
188 return false; 188 return false;
189 if (Extension::IsExtension(path)) 189 if (Extension::IsExtension(path))
190 return false; 190 return false;
191 DCHECK(extension[0] == FilePath::kExtensionSeparator); 191 DCHECK(extension[0] == FilePath::kExtensionSeparator);
192 extension.erase(0, 1); 192 extension.erase(0, 1);
193 return download_prefs_->IsAutoOpenEnabledForExtension(extension); 193 return download_prefs_->IsAutoOpenEnabledForExtension(extension);
194 } 194 }
195 195
196 // static
197 void ChromeDownloadManagerDelegate::DisableSafeBrowsing(DownloadItem* item) {
198 #if defined(ENABLE_SAFE_BROWSING)
199 SafeBrowsingState* state = static_cast<SafeBrowsingState*>(
200 item->GetExternalData(&safe_browsing_id));
201 if (state == NULL) {
202 state = new SafeBrowsingState();
203 item->SetExternalData(&safe_browsing_id, state);
204 }
205 state->pending = false;
asanka 2012/05/02 19:26:10 Shouldn't this only be done if state == NULL? Ide
benjhayden 2012/05/03 16:56:48 Done.
206 state->verdict = DownloadProtectionService::SAFE;
207 #endif
208 }
209
196 bool ChromeDownloadManagerDelegate::ShouldCompleteDownload(DownloadItem* item) { 210 bool ChromeDownloadManagerDelegate::ShouldCompleteDownload(DownloadItem* item) {
197 #if defined(ENABLE_SAFE_BROWSING) 211 #if defined(ENABLE_SAFE_BROWSING)
198 // See if there is already a pending SafeBrowsing check for that download. 212 // See if there is already a pending SafeBrowsing check for that download.
199 SafeBrowsingState* state = static_cast<SafeBrowsingState*>( 213 SafeBrowsingState* state = static_cast<SafeBrowsingState*>(
200 item->GetExternalData(&safe_browsing_id)); 214 item->GetExternalData(&safe_browsing_id));
201 if (state) 215 // Don't complete the download until we have an answer.
202 // Don't complete the download until we have an answer. 216 if (state && state->pending)
203 return !state->pending; 217 return false;
204 218
205 // Begin the safe browsing download protection check. 219 if (state == NULL) {
206 DownloadProtectionService* service = GetDownloadProtectionService(); 220 // Begin the safe browsing download protection check.
207 if (service) { 221 DownloadProtectionService* service = GetDownloadProtectionService();
208 VLOG(2) << __FUNCTION__ << "() Start SB download check for download = " 222 if (service) {
209 << item->DebugString(false); 223 VLOG(2) << __FUNCTION__ << "() Start SB download check for download = "
210 state = new SafeBrowsingState(); 224 << item->DebugString(false);
211 state->pending = true; 225 state = new SafeBrowsingState();
212 state->verdict = DownloadProtectionService::SAFE; 226 state->pending = true;
213 item->SetExternalData(&safe_browsing_id, state); 227 state->verdict = DownloadProtectionService::SAFE;
214 service->CheckClientDownload( 228 item->SetExternalData(&safe_browsing_id, state);
215 DownloadProtectionService::DownloadInfo::FromDownloadItem(*item), 229 service->CheckClientDownload(
216 base::Bind( 230 DownloadProtectionService::DownloadInfo::FromDownloadItem(*item),
217 &ChromeDownloadManagerDelegate::CheckClientDownloadDone, 231 base::Bind(
218 this, 232 &ChromeDownloadManagerDelegate::CheckClientDownloadDone,
219 item->GetId())); 233 this,
220 return false; 234 item->GetId()));
235 return false;
236 }
221 } 237 }
222 #endif 238 #endif
239
223 #if defined(OS_CHROMEOS) 240 #if defined(OS_CHROMEOS)
224 // If there's a GData upload associated with this download, we wait until that 241 // If there's a GData upload associated with this download, we wait until that
225 // is complete before allowing the download item to complete. 242 // is complete before allowing the download item to complete.
226 if (!gdata::GDataDownloadObserver::IsReadyToComplete(item)) 243 if (!gdata::GDataDownloadObserver::IsReadyToComplete(item))
227 return false; 244 return false;
228 #endif 245 #endif
229 return true; 246 return true;
230 } 247 }
231 248
232 bool ChromeDownloadManagerDelegate::ShouldOpenDownload(DownloadItem* item) { 249 bool ChromeDownloadManagerDelegate::ShouldOpenDownload(DownloadItem* item) {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 DCHECK(!website_save_dir->empty()); 385 DCHECK(!website_save_dir->empty());
369 386
370 *download_save_dir = prefs->GetFilePath(prefs::kDownloadDefaultDirectory); 387 *download_save_dir = prefs->GetFilePath(prefs::kDownloadDefaultDirectory);
371 } 388 }
372 389
373 void ChromeDownloadManagerDelegate::ChooseSavePath( 390 void ChromeDownloadManagerDelegate::ChooseSavePath(
374 WebContents* web_contents, 391 WebContents* web_contents,
375 const FilePath& suggested_path, 392 const FilePath& suggested_path,
376 const FilePath::StringType& default_extension, 393 const FilePath::StringType& default_extension,
377 bool can_save_as_complete, 394 bool can_save_as_complete,
378 content::SaveFilePathPickedCallback callback) { 395 const content::SavePackagePathPickedCallback& callback) {
379 // Deletes itself. 396 // Deletes itself.
380 #if defined(OS_CHROMEOS) 397 #if defined(OS_CHROMEOS)
381 // Note that we're ignoring the callback here. 398 new SavePackageFilePickerChromeOS(web_contents, suggested_path, callback);
382 // SavePackageFilePickerChromeOS completes the save operation itself.
383 // TODO(achuith): Fix this.
384 new SavePackageFilePickerChromeOS(web_contents, suggested_path);
385 #else 399 #else
386 new SavePackageFilePicker(web_contents, suggested_path, default_extension, 400 new SavePackageFilePicker(web_contents, suggested_path, default_extension,
387 can_save_as_complete, download_prefs_.get(), callback); 401 can_save_as_complete, download_prefs_.get(), callback);
388 #endif 402 #endif
389 } 403 }
390 404
391 #if defined(ENABLE_SAFE_BROWSING) 405 #if defined(ENABLE_SAFE_BROWSING)
392 DownloadProtectionService* 406 DownloadProtectionService*
393 ChromeDownloadManagerDelegate::GetDownloadProtectionService() { 407 ChromeDownloadManagerDelegate::GetDownloadProtectionService() {
394 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); 408 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service();
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 int32 download_id, int64 db_handle) { 714 int32 download_id, int64 db_handle) {
701 // It's not immediately obvious, but HistoryBackend::CreateDownload() can 715 // It's not immediately obvious, but HistoryBackend::CreateDownload() can
702 // call this function with an invalid |db_handle|. For instance, this can 716 // call this function with an invalid |db_handle|. For instance, this can
703 // happen when the history database is offline. We cannot have multiple 717 // happen when the history database is offline. We cannot have multiple
704 // DownloadItems with the same invalid db_handle, so we need to assign a 718 // DownloadItems with the same invalid db_handle, so we need to assign a
705 // unique |db_handle| here. 719 // unique |db_handle| here.
706 if (db_handle == DownloadItem::kUninitializedHandle) 720 if (db_handle == DownloadItem::kUninitializedHandle)
707 db_handle = download_history_->GetNextFakeDbHandle(); 721 db_handle = download_history_->GetNextFakeDbHandle();
708 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); 722 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle);
709 } 723 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698