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/ui/download/download_tab_helper.h" | 5 #include "chrome/browser/ui/download/download_tab_helper.h" |
6 | 6 |
7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
8 #include "chrome/browser/download/download_manager.h" | 8 #include "chrome/browser/download/download_manager.h" |
9 #include "chrome/browser/download/download_request_limiter.h" | 9 #include "chrome/browser/download/download_request_limiter.h" |
10 #include "chrome/browser/download/download_util.h" | 10 #include "chrome/browser/download/download_util.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 // another thread. | 47 // another thread. |
48 save_package_ = new SavePackage(tab_contents_wrapper_); | 48 save_package_ = new SavePackage(tab_contents_wrapper_); |
49 save_package_->GetSaveInfo(); | 49 save_package_->GetSaveInfo(); |
50 } | 50 } |
51 | 51 |
52 void DownloadTabHelper::OnSaveURL(const GURL& url) { | 52 void DownloadTabHelper::OnSaveURL(const GURL& url) { |
53 DownloadManager* dlm = tab_contents()->profile()->GetDownloadManager(); | 53 DownloadManager* dlm = tab_contents()->profile()->GetDownloadManager(); |
54 dlm->DownloadUrl(url, tab_contents()->GetURL(), "", tab_contents()); | 54 dlm->DownloadUrl(url, tab_contents()->GetURL(), "", tab_contents()); |
55 } | 55 } |
56 | 56 |
| 57 // Used in automated testing to bypass prompting the user for file names. |
| 58 // Instead, the names and paths are hard coded rather than running them through |
| 59 // file name sanitation and extension / mime checking. |
57 bool DownloadTabHelper::SavePage(const FilePath& main_file, | 60 bool DownloadTabHelper::SavePage(const FilePath& main_file, |
58 const FilePath& dir_path, | 61 const FilePath& dir_path, |
59 SavePackage::SavePackageType save_type) { | 62 SavePackage::SavePackageType save_type) { |
60 // Stop the page from navigating. | 63 // Stop the page from navigating. |
61 tab_contents()->Stop(); | 64 tab_contents()->Stop(); |
62 | 65 |
63 save_package_ = | 66 save_package_ = |
64 new SavePackage(tab_contents_wrapper_, save_type, main_file, dir_path); | 67 new SavePackage(tab_contents_wrapper_, save_type, main_file, dir_path); |
65 // Skips GetSaveInfo() and directly calls Init(). | |
66 // We do not have to explicitly disable the select file dialog | |
67 // since we skip the process that can show the dialog. | |
68 return save_package_->Init(); | 68 return save_package_->Init(); |
69 } | 69 } |
70 | 70 |
71 string16 DownloadTabHelper::SavePageBasedOnDefaultPrefs() { | |
72 tab_contents()->Stop(); | |
73 | |
74 save_package_ = new SavePackage(tab_contents_wrapper_); | |
75 // Disables the select file dialog. | |
76 save_package_->SetShouldPromptUser(false); | |
77 // This GetSaveInfo() calls save_package_->Init() in the background. | |
78 save_package_->GetSaveInfo(); | |
79 return tab_contents()->GetTitle(); | |
80 } | |
81 | |
82 bool DownloadTabHelper::CanDownload(int request_id) { | 71 bool DownloadTabHelper::CanDownload(int request_id) { |
83 if (delegate_) | 72 if (delegate_) |
84 return delegate_->CanDownload(request_id); | 73 return delegate_->CanDownload(request_id); |
85 return true; | 74 return true; |
86 } | 75 } |
87 | 76 |
88 void DownloadTabHelper::OnStartDownload(DownloadItem* download) { | 77 void DownloadTabHelper::OnStartDownload(DownloadItem* download) { |
89 DCHECK(download); | 78 DCHECK(download); |
90 | 79 |
91 BlockedContentTabHelperDelegate* blocked_content_delegate = | 80 BlockedContentTabHelperDelegate* blocked_content_delegate = |
(...skipping 21 matching lines...) Expand all Loading... |
113 | 102 |
114 return handled; | 103 return handled; |
115 } | 104 } |
116 | 105 |
117 void DownloadTabHelper::DidGetUserGesture() { | 106 void DownloadTabHelper::DidGetUserGesture() { |
118 DownloadRequestLimiter* limiter = | 107 DownloadRequestLimiter* limiter = |
119 g_browser_process->download_request_limiter(); | 108 g_browser_process->download_request_limiter(); |
120 if (limiter) | 109 if (limiter) |
121 limiter->OnUserGesture(tab_contents()); | 110 limiter->OnUserGesture(tab_contents()); |
122 } | 111 } |
OLD | NEW |