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

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

Issue 7065015: For downloads requiring a user gesture, also require... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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) 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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 bool is_dangerous_url) { 273 bool is_dangerous_url) {
274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
275 275
276 DownloadItem* download = GetActiveDownloadItem(download_id); 276 DownloadItem* download = GetActiveDownloadItem(download_id);
277 if (!download) 277 if (!download)
278 return; 278 return;
279 279
280 if (is_dangerous_url) 280 if (is_dangerous_url)
281 download->MarkUrlDangerous(); 281 download->MarkUrlDangerous();
282 282
283 DownloadStateInfo state = download->state_info(); 283 download_history_->CheckVisitedReferrerBefore(download_id,
284 download->referrer_url(),
285 NewCallback(this, &DownloadManager::CheckVisitedReferrerBeforeDone));
286 }
287
288 void DownloadManager::CheckVisitedReferrerBeforeDone(
289 int32 download_id,
290 bool visited_referrer_before) {
291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
292
293 DownloadItem* download = GetActiveDownloadItem(download_id);
294 if (!download)
295 return;
284 296
285 // Check whether this download is for an extension install or not. 297 // Check whether this download is for an extension install or not.
286 // Allow extensions to be explicitly saved. 298 // Allow extensions to be explicitly saved.
299 DownloadStateInfo state = download->state_info();
287 if (!state.prompt_user_for_save_location) { 300 if (!state.prompt_user_for_save_location) {
288 if (UserScript::IsURLUserScript(download->GetURL(), 301 if (UserScript::IsURLUserScript(download->GetURL(),
289 download->mime_type()) || 302 download->mime_type()) ||
290 (download->mime_type() == Extension::kMimeType)) { 303 (download->mime_type() == Extension::kMimeType)) {
291 state.is_extension_install = true; 304 state.is_extension_install = true;
292 } 305 }
293 } 306 }
294 307
295 if (state.force_file_name.empty()) { 308 if (state.force_file_name.empty()) {
296 FilePath generated_name; 309 FilePath generated_name;
(...skipping 27 matching lines...) Expand all
324 if (state.prompt_user_for_save_location && !last_download_path_.empty()) { 337 if (state.prompt_user_for_save_location && !last_download_path_.empty()) {
325 state.suggested_path = last_download_path_; 338 state.suggested_path = last_download_path_;
326 } else { 339 } else {
327 state.suggested_path = download_prefs_->download_path(); 340 state.suggested_path = download_prefs_->download_path();
328 } 341 }
329 state.suggested_path = state.suggested_path.Append(generated_name); 342 state.suggested_path = state.suggested_path.Append(generated_name);
330 } else { 343 } else {
331 state.suggested_path = state.force_file_name; 344 state.suggested_path = state.force_file_name;
332 } 345 }
333 346
334 if (!state.prompt_user_for_save_location && state.force_file_name.empty()) 347 if (!state.prompt_user_for_save_location && state.force_file_name.empty()) {
335 state.is_dangerous_file = IsDangerous(*download, state); 348 state.is_dangerous_file =
349 IsDangerous(*download, state, visited_referrer_before);
350 }
336 351
337 // We need to move over to the download thread because we don't want to stat 352 // We need to move over to the download thread because we don't want to stat
338 // the suggested path on the UI thread. 353 // the suggested path on the UI thread.
339 // We can only access preferences on the UI thread, so check the download path 354 // We can only access preferences on the UI thread, so check the download path
340 // now and pass the value to the FILE thread. 355 // now and pass the value to the FILE thread.
341 BrowserThread::PostTask( 356 BrowserThread::PostTask(
342 BrowserThread::FILE, FROM_HERE, 357 BrowserThread::FILE, FROM_HERE,
343 NewRunnableMethod( 358 NewRunnableMethod(
344 this, 359 this,
345 &DownloadManager::CheckIfSuggestedPathExists, 360 &DownloadManager::CheckIfSuggestedPathExists,
346 download_id, 361 download->id(),
347 state, 362 state,
348 download_prefs()->download_path())); 363 download_prefs()->download_path()));
349 } 364 }
350 365
351 void DownloadManager::CheckIfSuggestedPathExists(int32 download_id, 366 void DownloadManager::CheckIfSuggestedPathExists(int32 download_id,
352 DownloadStateInfo state, 367 DownloadStateInfo state,
353 const FilePath& default_path) { 368 const FilePath& default_path) {
354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 369 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
355 370
356 // Make sure the default download directory exists. 371 // Make sure the default download directory exists.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 } 445 }
431 446
432 BrowserThread::PostTask( 447 BrowserThread::PostTask(
433 BrowserThread::UI, FROM_HERE, 448 BrowserThread::UI, FROM_HERE,
434 NewRunnableMethod(this, 449 NewRunnableMethod(this,
435 &DownloadManager::OnPathExistenceAvailable, 450 &DownloadManager::OnPathExistenceAvailable,
436 download_id, 451 download_id,
437 state)); 452 state));
438 } 453 }
439 454
440 void DownloadManager::OnPathExistenceAvailable( 455 void DownloadManager::OnPathExistenceAvailable(int32 download_id,
441 int32 download_id, DownloadStateInfo new_state) { 456 DownloadStateInfo new_state) {
442 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 457 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
443 458
444 DownloadItem* download = GetActiveDownloadItem(download_id); 459 DownloadItem* download = GetActiveDownloadItem(download_id);
445 if (!download) 460 if (!download)
446 return; 461 return;
447 462
448 VLOG(20) << __FUNCTION__ << "()" 463 VLOG(20) << __FUNCTION__ << "()"
449 << " download = " << download->DebugString(true); 464 << " download = " << download->DebugString(true);
450 465
451 download->SetFileCheckResults(new_state); 466 download->SetFileCheckResults(new_state);
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 return; 1045 return;
1031 1046
1032 VLOG(20) << __FUNCTION__ << "()" 1047 VLOG(20) << __FUNCTION__ << "()"
1033 << " download = " << download->DebugString(true); 1048 << " download = " << download->DebugString(true);
1034 1049
1035 DownloadCancelledInternal(download_id, download->process_handle()); 1050 DownloadCancelledInternal(download_id, download->process_handle());
1036 } 1051 }
1037 1052
1038 // TODO(phajdan.jr): This is apparently not being exercised in tests. 1053 // TODO(phajdan.jr): This is apparently not being exercised in tests.
1039 bool DownloadManager::IsDangerous(const DownloadItem& download, 1054 bool DownloadManager::IsDangerous(const DownloadItem& download,
1040 const DownloadStateInfo& state) { 1055 const DownloadStateInfo& state,
1056 bool visited_referrer_before) {
1041 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1057 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1042 1058
1043 bool auto_open = ShouldOpenFileBasedOnExtension(state.suggested_path); 1059 bool auto_open = ShouldOpenFileBasedOnExtension(state.suggested_path);
1044 download_util::DownloadDangerLevel danger_level = 1060 download_util::DownloadDangerLevel danger_level =
1045 download_util::GetFileDangerLevel(state.suggested_path.BaseName()); 1061 download_util::GetFileDangerLevel(state.suggested_path.BaseName());
1046 1062
1047 if (danger_level == download_util::Dangerous) 1063 if (danger_level == download_util::Dangerous)
1048 return !(auto_open && state.has_user_gesture); 1064 return !(auto_open && state.has_user_gesture);
1049 1065
1050 if (danger_level == download_util::AllowOnUserGesture && 1066 if (danger_level == download_util::AllowOnUserGesture &&
1051 !state.has_user_gesture) 1067 (!state.has_user_gesture || !visited_referrer_before))
1052 return true; 1068 return true;
1053 1069
1054 if (state.is_extension_install) { 1070 if (state.is_extension_install) {
1055 // Extensions that are not from the gallery are considered dangerous. 1071 // Extensions that are not from the gallery are considered dangerous.
1056 ExtensionService* service = profile()->GetExtensionService(); 1072 ExtensionService* service = profile()->GetExtensionService();
1057 if (!service || !service->IsDownloadFromGallery(download.GetURL(), 1073 if (!service || !service->IsDownloadFromGallery(download.GetURL(),
1058 download.referrer_url())) 1074 download.referrer_url()))
1059 return true; 1075 return true;
1060 } 1076 }
1061 return false; 1077 return false;
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 observed_download_manager_->RemoveObserver(this); 1277 observed_download_manager_->RemoveObserver(this);
1262 } 1278 }
1263 1279
1264 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { 1280 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() {
1265 observing_download_manager_->NotifyModelChanged(); 1281 observing_download_manager_->NotifyModelChanged();
1266 } 1282 }
1267 1283
1268 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { 1284 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() {
1269 observed_download_manager_ = NULL; 1285 observed_download_manager_ = NULL;
1270 } 1286 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_manager.h ('k') | chrome/browser/download/download_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698