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 #include "chrome/browser/download/download_manager.h" | 5 #include "chrome/browser/download/download_manager.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
262 return; | 262 return; |
263 | 263 |
264 // Create a client to verify download URL with safebrowsing. | 264 // Create a client to verify download URL with safebrowsing. |
265 // It deletes itself after the callback. | 265 // It deletes itself after the callback. |
266 scoped_refptr<DownloadSBClient> sb_client = new DownloadSBClient( | 266 scoped_refptr<DownloadSBClient> sb_client = new DownloadSBClient( |
267 download_id, download->url_chain(), download->referrer_url()); | 267 download_id, download->url_chain(), download->referrer_url()); |
268 sb_client->CheckDownloadUrl( | 268 sb_client->CheckDownloadUrl( |
269 NewCallback(this, &DownloadManager::CheckDownloadUrlDone)); | 269 NewCallback(this, &DownloadManager::CheckDownloadUrlDone)); |
270 } | 270 } |
271 | 271 |
272 void DownloadManager::CheckVisitedBeforeDone(int32 download_id, | |
273 bool visited_before) { | |
274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
275 | |
276 DownloadItem* download = GetActiveDownloadItem(download_id); | |
277 if (download) { | |
278 download->SetVisitedBefore(visited_before); | |
279 HistoryAndSBChecksMaybeDone(download); | |
280 } | |
281 } | |
282 | |
272 void DownloadManager::CheckDownloadUrlDone(int32 download_id, | 283 void DownloadManager::CheckDownloadUrlDone(int32 download_id, |
273 bool is_dangerous_url) { | 284 bool is_dangerous_url) { |
274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
275 | 286 |
276 DownloadItem* download = GetActiveDownloadItem(download_id); | 287 DownloadItem* download = GetActiveDownloadItem(download_id); |
277 if (!download) | 288 if (download) { |
Randy Smith (Not in Mondays)
2011/05/24 18:28:25
It's a personal style preference (which probably m
| |
289 download->SetUrlDangerous(is_dangerous_url); | |
290 HistoryAndSBChecksMaybeDone(download); | |
291 } | |
292 } | |
293 | |
294 void DownloadManager::HistoryAndSBChecksMaybeDone(DownloadItem* download) { | |
Randy Smith (Not in Mondays)
2011/05/24 18:28:25
One of the biggest things we've done in the past c
| |
295 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
296 DCHECK(download); | |
297 | |
298 // Only proceed once both the history and safe browsing checks have completed. | |
299 DownloadStateInfo state = download->state_info(); | |
300 if ((state.visited_referrer_before == DownloadStateInfo::UNKNOWN) || | |
301 (state.is_dangerous_url == DownloadStateInfo::UNKNOWN)) | |
278 return; | 302 return; |
279 | 303 |
280 if (is_dangerous_url) | |
281 download->MarkUrlDangerous(); | |
282 | |
283 DownloadStateInfo state = download->state_info(); | |
284 | |
285 // Check whether this download is for an extension install or not. | 304 // Check whether this download is for an extension install or not. |
286 // Allow extensions to be explicitly saved. | 305 // Allow extensions to be explicitly saved. |
287 if (!state.prompt_user_for_save_location) { | 306 if (!state.prompt_user_for_save_location) { |
288 if (UserScript::IsURLUserScript(download->GetURL(), | 307 if (UserScript::IsURLUserScript(download->GetURL(), |
289 download->mime_type()) || | 308 download->mime_type()) || |
290 (download->mime_type() == Extension::kMimeType)) { | 309 (download->mime_type() == Extension::kMimeType)) { |
291 state.is_extension_install = true; | 310 state.is_extension_install = true; |
292 } | 311 } |
293 } | 312 } |
294 | 313 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
336 | 355 |
337 // We need to move over to the download thread because we don't want to stat | 356 // We need to move over to the download thread because we don't want to stat |
338 // the suggested path on the UI thread. | 357 // the suggested path on the UI thread. |
339 // We can only access preferences on the UI thread, so check the download path | 358 // We can only access preferences on the UI thread, so check the download path |
340 // now and pass the value to the FILE thread. | 359 // now and pass the value to the FILE thread. |
341 BrowserThread::PostTask( | 360 BrowserThread::PostTask( |
342 BrowserThread::FILE, FROM_HERE, | 361 BrowserThread::FILE, FROM_HERE, |
343 NewRunnableMethod( | 362 NewRunnableMethod( |
344 this, | 363 this, |
345 &DownloadManager::CheckIfSuggestedPathExists, | 364 &DownloadManager::CheckIfSuggestedPathExists, |
346 download_id, | 365 download->id(), |
347 state, | 366 state, |
348 download_prefs()->download_path())); | 367 download_prefs()->download_path())); |
349 } | 368 } |
350 | 369 |
351 void DownloadManager::CheckIfSuggestedPathExists(int32 download_id, | 370 void DownloadManager::CheckIfSuggestedPathExists(int32 download_id, |
352 DownloadStateInfo state, | 371 DownloadStateInfo state, |
353 const FilePath& default_path) { | 372 const FilePath& default_path) { |
354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 373 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
355 | 374 |
356 // Make sure the default download directory exists. | 375 // Make sure the default download directory exists. |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 void DownloadManager::CreateDownloadItem(DownloadCreateInfo* info) { | 509 void DownloadManager::CreateDownloadItem(DownloadCreateInfo* info) { |
491 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 510 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
492 | 511 |
493 DownloadItem* download = new DownloadItem(this, *info, | 512 DownloadItem* download = new DownloadItem(this, *info, |
494 profile_->IsOffTheRecord()); | 513 profile_->IsOffTheRecord()); |
495 int32 download_id = info->download_id; | 514 int32 download_id = info->download_id; |
496 DCHECK(!ContainsKey(in_progress_, download_id)); | 515 DCHECK(!ContainsKey(in_progress_, download_id)); |
497 DCHECK(!ContainsKey(active_downloads_, download_id)); | 516 DCHECK(!ContainsKey(active_downloads_, download_id)); |
498 downloads_.insert(download); | 517 downloads_.insert(download); |
499 active_downloads_[download_id] = download; | 518 active_downloads_[download_id] = download; |
519 | |
520 download_history_->CheckVisitedReferrerBefore(download_id, info->referrer_url, | |
521 NewCallback(this, &DownloadManager::CheckVisitedBeforeDone)); | |
500 } | 522 } |
501 | 523 |
502 void DownloadManager::ContinueDownloadWithPath(DownloadItem* download, | 524 void DownloadManager::ContinueDownloadWithPath(DownloadItem* download, |
503 const FilePath& chosen_file) { | 525 const FilePath& chosen_file) { |
504 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 526 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
505 DCHECK(download); | 527 DCHECK(download); |
506 | 528 |
507 int32 download_id = download->id(); | 529 int32 download_id = download->id(); |
508 | 530 |
509 // NOTE(ahendrickson) Eventually |active_downloads_| will replace | 531 // NOTE(ahendrickson) Eventually |active_downloads_| will replace |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1041 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1063 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1042 | 1064 |
1043 bool auto_open = ShouldOpenFileBasedOnExtension(state.suggested_path); | 1065 bool auto_open = ShouldOpenFileBasedOnExtension(state.suggested_path); |
1044 download_util::DownloadDangerLevel danger_level = | 1066 download_util::DownloadDangerLevel danger_level = |
1045 download_util::GetFileDangerLevel(state.suggested_path.BaseName()); | 1067 download_util::GetFileDangerLevel(state.suggested_path.BaseName()); |
1046 | 1068 |
1047 if (danger_level == download_util::Dangerous) | 1069 if (danger_level == download_util::Dangerous) |
1048 return !(auto_open && state.has_user_gesture); | 1070 return !(auto_open && state.has_user_gesture); |
1049 | 1071 |
1050 if (danger_level == download_util::AllowOnUserGesture && | 1072 if (danger_level == download_util::AllowOnUserGesture && |
1051 !state.has_user_gesture) | 1073 (!state.has_user_gesture || |
1074 state.visited_referrer_before != DownloadStateInfo::YES)) | |
1052 return true; | 1075 return true; |
1053 | 1076 |
1054 if (state.is_extension_install) { | 1077 if (state.is_extension_install) { |
1055 // Extensions that are not from the gallery are considered dangerous. | 1078 // Extensions that are not from the gallery are considered dangerous. |
1056 ExtensionService* service = profile()->GetExtensionService(); | 1079 ExtensionService* service = profile()->GetExtensionService(); |
1057 if (!service || !service->IsDownloadFromGallery(download.GetURL(), | 1080 if (!service || !service->IsDownloadFromGallery(download.GetURL(), |
1058 download.referrer_url())) | 1081 download.referrer_url())) |
1059 return true; | 1082 return true; |
1060 } | 1083 } |
1061 return false; | 1084 return false; |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1261 observed_download_manager_->RemoveObserver(this); | 1284 observed_download_manager_->RemoveObserver(this); |
1262 } | 1285 } |
1263 | 1286 |
1264 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { | 1287 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { |
1265 observing_download_manager_->NotifyModelChanged(); | 1288 observing_download_manager_->NotifyModelChanged(); |
1266 } | 1289 } |
1267 | 1290 |
1268 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { | 1291 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { |
1269 observed_download_manager_ = NULL; | 1292 observed_download_manager_ = NULL; |
1270 } | 1293 } |
OLD | NEW |