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

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: non-cros works Created 8 years, 8 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 #if defined(ENABLE_SAFE_BROWSING)
197 // static
198 void ChromeDownloadManagerDelegate::DisableSafeBrowsing(DownloadItem* item) {
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;
206 state->verdict = DownloadProtectionService::SAFE;
207 }
208 #endif
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 } 385 }
369 386
370 void ChromeDownloadManagerDelegate::ChooseSavePath( 387 void ChromeDownloadManagerDelegate::ChooseSavePath(
371 WebContents* web_contents, 388 WebContents* web_contents,
372 const FilePath& suggested_path, 389 const FilePath& suggested_path,
373 const FilePath::StringType& default_extension, 390 const FilePath::StringType& default_extension,
374 bool can_save_as_complete, 391 bool can_save_as_complete,
375 content::SaveFilePathPickedCallback callback) { 392 content::SaveFilePathPickedCallback callback) {
376 // Deletes itself. 393 // Deletes itself.
377 #if defined(OS_CHROMEOS) 394 #if defined(OS_CHROMEOS)
378 // Note that we're ignoring the callback here. 395 new SavePackageFilePickerChromeOS(web_contents, suggested_path, callback);
379 // SavePackageFilePickerChromeOS completes the save operation itself.
380 // TODO(achuith): Fix this.
381 new SavePackageFilePickerChromeOS(web_contents, suggested_path);
382 #else 396 #else
383 new SavePackageFilePicker(web_contents, suggested_path, default_extension, 397 new SavePackageFilePicker(web_contents, suggested_path, default_extension,
384 can_save_as_complete, download_prefs_.get(), callback); 398 can_save_as_complete, download_prefs_.get(), callback);
385 #endif 399 #endif
386 } 400 }
387 401
388 #if defined(ENABLE_SAFE_BROWSING) 402 #if defined(ENABLE_SAFE_BROWSING)
389 DownloadProtectionService* 403 DownloadProtectionService*
390 ChromeDownloadManagerDelegate::GetDownloadProtectionService() { 404 ChromeDownloadManagerDelegate::GetDownloadProtectionService() {
391 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); 405 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service();
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 int32 download_id, int64 db_handle) { 711 int32 download_id, int64 db_handle) {
698 // It's not immediately obvious, but HistoryBackend::CreateDownload() can 712 // It's not immediately obvious, but HistoryBackend::CreateDownload() can
699 // call this function with an invalid |db_handle|. For instance, this can 713 // call this function with an invalid |db_handle|. For instance, this can
700 // happen when the history database is offline. We cannot have multiple 714 // happen when the history database is offline. We cannot have multiple
701 // DownloadItems with the same invalid db_handle, so we need to assign a 715 // DownloadItems with the same invalid db_handle, so we need to assign a
702 // unique |db_handle| here. 716 // unique |db_handle| here.
703 if (db_handle == DownloadItem::kUninitializedHandle) 717 if (db_handle == DownloadItem::kUninitializedHandle)
704 db_handle = download_history_->GetNextFakeDbHandle(); 718 db_handle = download_history_->GetNextFakeDbHandle();
705 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); 719 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle);
706 } 720 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698