| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/save_package.h" | 5 #include "chrome/browser/download/save_package.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 988 file_util::ReplaceIllegalCharacters(&file_name, L' '); | 988 file_util::ReplaceIllegalCharacters(&file_name, L' '); |
| 989 TrimWhitespace(file_name, TRIM_ALL, &file_name); | 989 TrimWhitespace(file_name, TRIM_ALL, &file_name); |
| 990 FilePath suggest_name = FilePath::FromWStringHack(save_file_path.GetValue()); | 990 FilePath suggest_name = FilePath::FromWStringHack(save_file_path.GetValue()); |
| 991 suggest_name = suggest_name.Append(FilePath::FromWStringHack(file_name)); | 991 suggest_name = suggest_name.Append(FilePath::FromWStringHack(file_name)); |
| 992 | 992 |
| 993 return suggest_name; | 993 return suggest_name; |
| 994 } | 994 } |
| 995 | 995 |
| 996 void SavePackage::GetSaveInfo() { | 996 void SavePackage::GetSaveInfo() { |
| 997 // Use "Web Page, Complete" option as default choice of saving page. | 997 // Use "Web Page, Complete" option as default choice of saving page. |
| 998 int filter_index = 2; | 998 int file_type_index = 2; |
| 999 std::wstring filter; | 999 SelectFileDialog::FileTypeInfo file_type_info; |
| 1000 FilePath::StringType default_extension; | 1000 FilePath::StringType default_extension; |
| 1001 FilePath title = | 1001 FilePath title = |
| 1002 FilePath::FromWStringHack(UTF16ToWideHack(web_contents_->GetTitle())); | 1002 FilePath::FromWStringHack(UTF16ToWideHack(web_contents_->GetTitle())); |
| 1003 FilePath suggested_path = | 1003 FilePath suggested_path = |
| 1004 GetSuggestNameForSaveAs(web_contents_->profile()->GetPrefs(), title); | 1004 GetSuggestNameForSaveAs(web_contents_->profile()->GetPrefs(), title); |
| 1005 | 1005 |
| 1006 SavePackageParam* save_params = | 1006 SavePackageParam* save_params = |
| 1007 new SavePackageParam(web_contents_->contents_mime_type()); | 1007 new SavePackageParam(web_contents_->contents_mime_type()); |
| 1008 | 1008 |
| 1009 // If the contents can not be saved as complete-HTML, do not show the | 1009 // If the contents can not be saved as complete-HTML, do not show the |
| 1010 // file filters. | 1010 // file filters. |
| 1011 if (CanSaveAsComplete(save_params->current_tab_mime_type)) { | 1011 if (CanSaveAsComplete(save_params->current_tab_mime_type)) { |
| 1012 filter = l10n_util::GetString(IDS_SAVE_PAGE_FILTER); | 1012 file_type_info.extensions.resize(2); |
| 1013 filter.resize(filter.size() + 2); | 1013 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("htm")); |
| 1014 filter[filter.size() - 1] = L'\0'; | 1014 file_type_info.extension_description_overrides.push_back( |
| 1015 filter[filter.size() - 2] = L'\0'; | 1015 WideToUTF16(l10n_util::GetString(IDS_SAVE_PAGE_DESC_HTML_ONLY))); |
| 1016 file_type_info.extensions[1].push_back(FILE_PATH_LITERAL("htm")); |
| 1017 file_type_info.extension_description_overrides.push_back( |
| 1018 WideToUTF16(l10n_util::GetString(IDS_SAVE_PAGE_DESC_COMPLETE))); |
| 1019 file_type_info.include_all_files = false; |
| 1016 default_extension = FILE_PATH_LITERAL("htm"); | 1020 default_extension = FILE_PATH_LITERAL("htm"); |
| 1017 } else { | 1021 } else { |
| 1018 #if defined(OS_WIN) | 1022 file_type_info.extensions.resize(1); |
| 1019 filter = win_util::GetFileFilterFromPath(suggested_path.ToWStringHack()); | 1023 file_type_info.extensions[0].push_back(suggested_path.Extension()); |
| 1020 #else | 1024 file_type_info.include_all_files = true; |
| 1021 // TODO(port): implement this. | 1025 file_type_index = 1; |
| 1022 NOTIMPLEMENTED(); | |
| 1023 #endif | |
| 1024 filter_index = 1; | |
| 1025 } | 1026 } |
| 1026 | 1027 |
| 1027 | |
| 1028 #if defined(OS_LINUX) || defined(OS_WIN) | 1028 #if defined(OS_LINUX) || defined(OS_WIN) |
| 1029 if (g_should_prompt_for_filename) { | 1029 if (g_should_prompt_for_filename) { |
| 1030 if (!select_file_dialog_.get()) | 1030 if (!select_file_dialog_.get()) |
| 1031 select_file_dialog_ = SelectFileDialog::Create(this); | 1031 select_file_dialog_ = SelectFileDialog::Create(this); |
| 1032 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE, | 1032 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE, |
| 1033 string16(), | 1033 string16(), |
| 1034 suggested_path, | 1034 suggested_path, |
| 1035 filter, | 1035 &file_type_info, |
| 1036 filter_index, | 1036 file_type_index, |
| 1037 default_extension, | 1037 default_extension, |
| 1038 platform_util::GetTopLevel( | 1038 platform_util::GetTopLevel( |
| 1039 web_contents_->GetNativeView()), | 1039 web_contents_->GetNativeView()), |
| 1040 save_params); | 1040 save_params); |
| 1041 } else | 1041 } else |
| 1042 #endif // defined(OS_LINUX) || defined(OS_WIN) | 1042 #endif // defined(OS_LINUX) || defined(OS_WIN) |
| 1043 { | 1043 { |
| 1044 // Just use 'suggested_path' instead of opening the dialog prompt. | 1044 // Just use 'suggested_path' instead of opening the dialog prompt. |
| 1045 ContinueSave(save_params, suggested_path, filter_index); | 1045 ContinueSave(save_params, suggested_path, file_type_index); |
| 1046 delete save_params; | 1046 delete save_params; |
| 1047 } | 1047 } |
| 1048 } | 1048 } |
| 1049 | 1049 |
| 1050 // Called after the save file dialog box returns. | 1050 // Called after the save file dialog box returns. |
| 1051 void SavePackage::ContinueSave(SavePackageParam* param, | 1051 void SavePackage::ContinueSave(SavePackageParam* param, |
| 1052 const FilePath& final_name, | 1052 const FilePath& final_name, |
| 1053 int index) { | 1053 int index) { |
| 1054 // Ensure the filename is safe. | 1054 // Ensure the filename is safe. |
| 1055 param->saved_main_file_path = final_name; | 1055 param->saved_main_file_path = final_name; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1145 int index, void* params) { | 1145 int index, void* params) { |
| 1146 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); | 1146 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); |
| 1147 ContinueSave(save_params, path, index); | 1147 ContinueSave(save_params, path, index); |
| 1148 delete save_params; | 1148 delete save_params; |
| 1149 } | 1149 } |
| 1150 | 1150 |
| 1151 void SavePackage::FileSelectionCanceled(void* params) { | 1151 void SavePackage::FileSelectionCanceled(void* params) { |
| 1152 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); | 1152 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); |
| 1153 delete save_params; | 1153 delete save_params; |
| 1154 } | 1154 } |
| OLD | NEW |