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. | |
60 bool DownloadTabHelper::SavePage(const FilePath& main_file, | 57 bool DownloadTabHelper::SavePage(const FilePath& main_file, |
61 const FilePath& dir_path, | 58 const FilePath& dir_path, |
62 SavePackage::SavePackageType save_type) { | 59 SavePackage::SavePackageType save_type) { |
63 // Stop the page from navigating. | 60 // Stop the page from navigating. |
64 tab_contents()->Stop(); | 61 tab_contents()->Stop(); |
65 | 62 |
66 save_package_ = | 63 save_package_ = |
67 new SavePackage(tab_contents_wrapper_, save_type, main_file, dir_path); | 64 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 |
71 bool DownloadTabHelper::CanDownload(int request_id) { | 82 bool DownloadTabHelper::CanDownload(int request_id) { |
72 if (delegate_) | 83 if (delegate_) |
73 return delegate_->CanDownload(request_id); | 84 return delegate_->CanDownload(request_id); |
74 return true; | 85 return true; |
75 } | 86 } |
76 | 87 |
77 void DownloadTabHelper::OnStartDownload(DownloadItem* download) { | 88 void DownloadTabHelper::OnStartDownload(DownloadItem* download) { |
78 DCHECK(download); | 89 DCHECK(download); |
79 | 90 |
80 BlockedContentTabHelperDelegate* blocked_content_delegate = | 91 BlockedContentTabHelperDelegate* blocked_content_delegate = |
(...skipping 21 matching lines...) Expand all Loading... |
102 | 113 |
103 return handled; | 114 return handled; |
104 } | 115 } |
105 | 116 |
106 void DownloadTabHelper::DidGetUserGesture() { | 117 void DownloadTabHelper::DidGetUserGesture() { |
107 DownloadRequestLimiter* limiter = | 118 DownloadRequestLimiter* limiter = |
108 g_browser_process->download_request_limiter(); | 119 g_browser_process->download_request_limiter(); |
109 if (limiter) | 120 if (limiter) |
110 limiter->OnUserGesture(tab_contents()); | 121 limiter->OnUserGesture(tab_contents()); |
111 } | 122 } |
OLD | NEW |