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 "content/browser/download/save_package.h" | 5 #include "content/browser/download/save_package.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 } | 256 } |
257 | 257 |
258 bool SavePackage::Init() { | 258 bool SavePackage::Init() { |
259 // Set proper running state. | 259 // Set proper running state. |
260 if (wait_state_ != INITIALIZE) | 260 if (wait_state_ != INITIALIZE) |
261 return false; | 261 return false; |
262 | 262 |
263 wait_state_ = START_PROCESS; | 263 wait_state_ = START_PROCESS; |
264 | 264 |
265 // Initialize the request context and resource dispatcher. | 265 // Initialize the request context and resource dispatcher. |
266 Profile* profile = tab_contents()->profile(); | 266 Profile* profile = static_cast<Profile*>(tab_contents()->browser_context()); |
267 if (!profile) { | 267 if (!profile) { |
268 NOTREACHED(); | 268 NOTREACHED(); |
269 return false; | 269 return false; |
270 } | 270 } |
271 | 271 |
272 // Create the fake DownloadItem and display the view. | 272 // Create the fake DownloadItem and display the view. |
273 DownloadManager* download_manager = | 273 DownloadManager* download_manager = profile->GetDownloadManager(); |
274 tab_contents()->profile()->GetDownloadManager(); | |
275 download_ = new DownloadItem(download_manager, | 274 download_ = new DownloadItem(download_manager, |
276 saved_main_file_path_, | 275 saved_main_file_path_, |
277 page_url_, | 276 page_url_, |
278 profile->IsOffTheRecord()); | 277 profile->IsOffTheRecord()); |
279 | 278 |
280 // Transfer the ownership to the download manager. We need the DownloadItem | 279 // Transfer the ownership to the download manager. We need the DownloadItem |
281 // to be alive as long as the Profile is alive. | 280 // to be alive as long as the Profile is alive. |
282 download_manager->SavePageAsDownloadStarted(download_); | 281 download_manager->SavePageAsDownloadStarted(download_); |
283 | 282 |
284 tab_contents()->OnStartDownload(download_); | 283 tab_contents()->OnStartDownload(download_); |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 save_item->url().spec()); | 812 save_item->url().spec()); |
814 DCHECK(it == in_progress_items_.end()); | 813 DCHECK(it == in_progress_items_.end()); |
815 in_progress_items_[save_item->url().spec()] = save_item; | 814 in_progress_items_[save_item->url().spec()] = save_item; |
816 save_item->Start(); | 815 save_item->Start(); |
817 file_manager_->SaveURL(save_item->url(), | 816 file_manager_->SaveURL(save_item->url(), |
818 save_item->referrer(), | 817 save_item->referrer(), |
819 tab_contents()->GetRenderProcessHost()->id(), | 818 tab_contents()->GetRenderProcessHost()->id(), |
820 routing_id(), | 819 routing_id(), |
821 save_item->save_source(), | 820 save_item->save_source(), |
822 save_item->full_path(), | 821 save_item->full_path(), |
823 tab_contents()->profile()->GetResourceContext(), | 822 tab_contents()->browser_context()-> |
| 823 GetResourceContext(), |
824 this); | 824 this); |
825 } while (process_all_remaining_items && waiting_item_queue_.size()); | 825 } while (process_all_remaining_items && waiting_item_queue_.size()); |
826 } | 826 } |
827 | 827 |
828 | 828 |
829 // Open download page in windows explorer on file thread, to avoid blocking the | 829 // Open download page in windows explorer on file thread, to avoid blocking the |
830 // user interface. | 830 // user interface. |
831 void SavePackage::ShowDownloadInShell() { | 831 void SavePackage::ShowDownloadInShell() { |
832 DCHECK(file_manager_); | 832 DCHECK(file_manager_); |
833 DCHECK(finished_ && !canceled() && !saved_main_file_path_.empty()); | 833 DCHECK(finished_ && !canceled() && !saved_main_file_path_.empty()); |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1200 FilePath save_file_path = prefs->GetFilePath( | 1200 FilePath save_file_path = prefs->GetFilePath( |
1201 prefs::kSaveFileDefaultDirectory); | 1201 prefs::kSaveFileDefaultDirectory); |
1202 DCHECK(!save_file_path.empty()); | 1202 DCHECK(!save_file_path.empty()); |
1203 | 1203 |
1204 return save_file_path; | 1204 return save_file_path; |
1205 } | 1205 } |
1206 | 1206 |
1207 void SavePackage::GetSaveInfo() { | 1207 void SavePackage::GetSaveInfo() { |
1208 // Can't use tab_contents_ in the file thread, so get the data that we need | 1208 // Can't use tab_contents_ in the file thread, so get the data that we need |
1209 // before calling to it. | 1209 // before calling to it. |
1210 PrefService* prefs = tab_contents()->profile()->GetPrefs(); | 1210 Profile* profile = static_cast<Profile*>(tab_contents()->browser_context()); |
| 1211 PrefService* prefs = profile->GetPrefs(); |
1211 FilePath website_save_dir = GetSaveDirPreference(prefs); | 1212 FilePath website_save_dir = GetSaveDirPreference(prefs); |
1212 FilePath download_save_dir = prefs->GetFilePath( | 1213 FilePath download_save_dir = prefs->GetFilePath( |
1213 prefs::kDownloadDefaultDirectory); | 1214 prefs::kDownloadDefaultDirectory); |
1214 std::string mime_type = tab_contents()->contents_mime_type(); | 1215 std::string mime_type = tab_contents()->contents_mime_type(); |
1215 | 1216 |
1216 BrowserThread::PostTask( | 1217 BrowserThread::PostTask( |
1217 BrowserThread::FILE, FROM_HERE, | 1218 BrowserThread::FILE, FROM_HERE, |
1218 NewRunnableMethod(this, &SavePackage::CreateDirectoryOnFileThread, | 1219 NewRunnableMethod(this, &SavePackage::CreateDirectoryOnFileThread, |
1219 website_save_dir, download_save_dir, mime_type)); | 1220 website_save_dir, download_save_dir, mime_type)); |
1220 } | 1221 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1276 // Called after the save file dialog box returns. | 1277 // Called after the save file dialog box returns. |
1277 void SavePackage::OnPathPicked(const FilePath& final_name, | 1278 void SavePackage::OnPathPicked(const FilePath& final_name, |
1278 SavePackageType type) { | 1279 SavePackageType type) { |
1279 // Ensure the filename is safe. | 1280 // Ensure the filename is safe. |
1280 saved_main_file_path_ = final_name; | 1281 saved_main_file_path_ = final_name; |
1281 download_util::GenerateSafeFileName(tab_contents()->contents_mime_type(), | 1282 download_util::GenerateSafeFileName(tab_contents()->contents_mime_type(), |
1282 &saved_main_file_path_); | 1283 &saved_main_file_path_); |
1283 | 1284 |
1284 saved_main_directory_path_ = saved_main_file_path_.DirName(); | 1285 saved_main_directory_path_ = saved_main_file_path_.DirName(); |
1285 | 1286 |
1286 PrefService* prefs = tab_contents()->profile()->GetPrefs(); | 1287 Profile* profile = static_cast<Profile*>(tab_contents()->browser_context()); |
| 1288 PrefService* prefs = profile->GetPrefs(); |
1287 StringPrefMember save_file_path; | 1289 StringPrefMember save_file_path; |
1288 save_file_path.Init(prefs::kSaveFileDefaultDirectory, prefs, NULL); | 1290 save_file_path.Init(prefs::kSaveFileDefaultDirectory, prefs, NULL); |
1289 #if defined(OS_POSIX) | 1291 #if defined(OS_POSIX) |
1290 std::string path_string = saved_main_directory_path_.value(); | 1292 std::string path_string = saved_main_directory_path_.value(); |
1291 #elif defined(OS_WIN) | 1293 #elif defined(OS_WIN) |
1292 std::string path_string = WideToUTF8(saved_main_directory_path_.value()); | 1294 std::string path_string = WideToUTF8(saved_main_directory_path_.value()); |
1293 #endif | 1295 #endif |
1294 // If user change the default saving directory, we will remember it just | 1296 // If user change the default saving directory, we will remember it just |
1295 // like IE and FireFox. | 1297 // like IE and FireFox. |
1296 if (!tab_contents()->profile()->IsOffTheRecord() && | 1298 if (!tab_contents()->browser_context()->IsOffTheRecord() && |
1297 save_file_path.GetValue() != path_string) { | 1299 save_file_path.GetValue() != path_string) { |
1298 save_file_path.SetValue(path_string); | 1300 save_file_path.SetValue(path_string); |
1299 } | 1301 } |
1300 | 1302 |
1301 save_type_ = type; | 1303 save_type_ = type; |
1302 | 1304 |
1303 prefs->SetInteger(prefs::kSaveFileType, save_type_); | 1305 prefs->SetInteger(prefs::kSaveFileType, save_type_); |
1304 | 1306 |
1305 if (save_type_ == SavePackage::SAVE_AS_COMPLETE_HTML) { | 1307 if (save_type_ == SavePackage::SAVE_AS_COMPLETE_HTML) { |
1306 // Make new directory for saving complete file. | 1308 // Make new directory for saving complete file. |
(...skipping 19 matching lines...) Expand all Loading... |
1326 bool SavePackage::IsSavableContents(const std::string& contents_mime_type) { | 1328 bool SavePackage::IsSavableContents(const std::string& contents_mime_type) { |
1327 // WebKit creates Document object when MIME type is application/xhtml+xml, | 1329 // WebKit creates Document object when MIME type is application/xhtml+xml, |
1328 // so we also support this MIME type. | 1330 // so we also support this MIME type. |
1329 return contents_mime_type == "text/html" || | 1331 return contents_mime_type == "text/html" || |
1330 contents_mime_type == "text/xml" || | 1332 contents_mime_type == "text/xml" || |
1331 contents_mime_type == "application/xhtml+xml" || | 1333 contents_mime_type == "application/xhtml+xml" || |
1332 contents_mime_type == "text/plain" || | 1334 contents_mime_type == "text/plain" || |
1333 contents_mime_type == "text/css" || | 1335 contents_mime_type == "text/css" || |
1334 net::IsSupportedJavascriptMimeType(contents_mime_type.c_str()); | 1336 net::IsSupportedJavascriptMimeType(contents_mime_type.c_str()); |
1335 } | 1337 } |
OLD | NEW |