| 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" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/task.h" | 12 #include "base/task.h" |
| 13 #include "base/thread.h" | 13 #include "base/thread.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/download/download_item_model.h" | 15 #include "chrome/browser/download/download_item_model.h" |
| 16 #include "chrome/browser/download/download_manager.h" | 16 #include "chrome/browser/download/download_manager.h" |
| 17 #include "chrome/browser/download/download_shelf.h" | 17 #include "chrome/browser/download/download_shelf.h" |
| 18 #include "chrome/browser/download/save_file.h" | 18 #include "chrome/browser/download/save_file.h" |
| 19 #include "chrome/browser/download/save_file_manager.h" | 19 #include "chrome/browser/download/save_file_manager.h" |
| 20 #include "chrome/browser/profile.h" | 20 #include "chrome/browser/profile.h" |
| 21 #include "chrome/browser/renderer_host/render_process_host.h" | 21 #include "chrome/browser/renderer_host/render_process_host.h" |
| 22 #include "chrome/browser/renderer_host/render_view_host.h" | 22 #include "chrome/browser/renderer_host/render_view_host.h" |
| 23 #include "chrome/browser/renderer_host/render_view_host_delegate.h" | 23 #include "chrome/browser/renderer_host/render_view_host_delegate.h" |
| 24 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 24 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 25 #include "chrome/browser/tab_contents/tab_util.h" | 25 #include "chrome/browser/tab_contents/tab_util.h" |
| 26 #include "chrome/browser/tab_contents/web_contents.h" | 26 #include "chrome/browser/tab_contents/web_contents.h" |
| 27 #include "chrome/common/chrome_paths.h" | 27 #include "chrome/common/chrome_paths.h" |
| 28 #include "chrome/common/l10n_util.h" | 28 #include "chrome/common/l10n_util.h" |
| 29 #include "chrome/common/platform_util.h" |
| 29 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/common/pref_service.h" | 31 #include "chrome/common/pref_service.h" |
| 31 #include "chrome/common/stl_util-inl.h" | 32 #include "chrome/common/stl_util-inl.h" |
| 32 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
| 33 #include "grit/generated_resources.h" | 34 #include "grit/generated_resources.h" |
| 34 #include "net/base/io_buffer.h" | 35 #include "net/base/io_buffer.h" |
| 35 #include "net/base/mime_util.h" | 36 #include "net/base/mime_util.h" |
| 36 #include "net/base/net_util.h" | 37 #include "net/base/net_util.h" |
| 37 #include "net/url_request/url_request_context.h" | 38 #include "net/url_request/url_request_context.h" |
| 38 #include "webkit/glue/dom_serializer_delegate.h" | 39 #include "webkit/glue/dom_serializer_delegate.h" |
| (...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 // FilePaths. | 979 // FilePaths. |
| 979 file_util::ReplaceIllegalCharacters(&file_name, L' '); | 980 file_util::ReplaceIllegalCharacters(&file_name, L' '); |
| 980 TrimWhitespace(file_name, TRIM_ALL, &file_name); | 981 TrimWhitespace(file_name, TRIM_ALL, &file_name); |
| 981 FilePath suggest_name = FilePath::FromWStringHack(save_file_path.GetValue()); | 982 FilePath suggest_name = FilePath::FromWStringHack(save_file_path.GetValue()); |
| 982 suggest_name = suggest_name.Append(FilePath::FromWStringHack(file_name)); | 983 suggest_name = suggest_name.Append(FilePath::FromWStringHack(file_name)); |
| 983 | 984 |
| 984 return suggest_name; | 985 return suggest_name; |
| 985 } | 986 } |
| 986 | 987 |
| 987 void SavePackage::GetSaveInfo() { | 988 void SavePackage::GetSaveInfo() { |
| 988 #if defined(OS_WIN) | |
| 989 // Use "Web Page, Complete" option as default choice of saving page. | 989 // Use "Web Page, Complete" option as default choice of saving page. |
| 990 int filter_index = 2; | 990 int filter_index = 2; |
| 991 std::wstring filter; | 991 std::wstring filter; |
| 992 std::wstring default_extension; | 992 std::wstring default_extension; |
| 993 FilePath title = | 993 FilePath title = |
| 994 FilePath::FromWStringHack(UTF16ToWideHack(web_contents_->GetTitle())); | 994 FilePath::FromWStringHack(UTF16ToWideHack(web_contents_->GetTitle())); |
| 995 FilePath suggested_path = | 995 FilePath suggested_path = |
| 996 GetSuggestNameForSaveAs(web_contents_->profile()->GetPrefs(), title); | 996 GetSuggestNameForSaveAs(web_contents_->profile()->GetPrefs(), title); |
| 997 std::wstring suggested_name = suggested_path.ToWStringHack(); | 997 std::wstring suggested_name = suggested_path.ToWStringHack(); |
| 998 | 998 |
| 999 SavePackageParam* save_params = | 999 SavePackageParam* save_params = |
| 1000 new SavePackageParam(web_contents_->contents_mime_type()); | 1000 new SavePackageParam(web_contents_->contents_mime_type()); |
| 1001 | 1001 |
| 1002 // If the contents can not be saved as complete-HTML, do not show the | 1002 // If the contents can not be saved as complete-HTML, do not show the |
| 1003 // file filters. | 1003 // file filters. |
| 1004 if (CanSaveAsComplete(save_params->current_tab_mime_type)) { | 1004 if (CanSaveAsComplete(save_params->current_tab_mime_type)) { |
| 1005 filter = l10n_util::GetString(IDS_SAVE_PAGE_FILTER); | 1005 filter = l10n_util::GetString(IDS_SAVE_PAGE_FILTER); |
| 1006 filter.resize(filter.size() + 2); | 1006 filter.resize(filter.size() + 2); |
| 1007 filter[filter.size() - 1] = L'\0'; | 1007 filter[filter.size() - 1] = L'\0'; |
| 1008 filter[filter.size() - 2] = L'\0'; | 1008 filter[filter.size() - 2] = L'\0'; |
| 1009 default_extension = L"htm"; | 1009 default_extension = L"htm"; |
| 1010 } else { | 1010 } else { |
| 1011 #if defined(OS_WIN) |
| 1011 filter = win_util::GetFileFilterFromPath(suggested_name); | 1012 filter = win_util::GetFileFilterFromPath(suggested_name); |
| 1013 #else |
| 1014 // TODO(port): implement this. |
| 1015 NOTIMPLEMENTED(); |
| 1016 #endif |
| 1012 filter_index = 1; | 1017 filter_index = 1; |
| 1013 } | 1018 } |
| 1014 | 1019 |
| 1020 |
| 1021 #if defined(OS_LINUX) || defined(OS_WIN) |
| 1015 if (g_should_prompt_for_filename) { | 1022 if (g_should_prompt_for_filename) { |
| 1016 if (!select_file_dialog_.get()) | 1023 if (!select_file_dialog_.get()) |
| 1017 select_file_dialog_ = SelectFileDialog::Create(this); | 1024 select_file_dialog_ = SelectFileDialog::Create(this); |
| 1018 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE, | 1025 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE, |
| 1019 std::wstring(), | 1026 std::wstring(), |
| 1020 suggested_name, | 1027 suggested_name, |
| 1021 filter, | 1028 filter, |
| 1022 filter_index, | 1029 filter_index, |
| 1023 default_extension, | 1030 default_extension, |
| 1024 GetAncestor(web_contents_->GetNativeView(), | 1031 platform_util::GetTopLevel( |
| 1025 GA_ROOT), | 1032 web_contents_->GetNativeView()), |
| 1026 save_params); | 1033 save_params); |
| 1027 } else { | 1034 } else |
| 1035 #endif // defined(OS_LINUX) || defined(OS_WIN) |
| 1036 { |
| 1028 // Just use 'suggested_name' instead of opening the dialog prompt. | 1037 // Just use 'suggested_name' instead of opening the dialog prompt. |
| 1029 ContinueSave(save_params, suggested_name, filter_index); | 1038 ContinueSave(save_params, suggested_name, filter_index); |
| 1030 delete save_params; | 1039 delete save_params; |
| 1031 } | 1040 } |
| 1032 #else | |
| 1033 NOTIMPLEMENTED(); | |
| 1034 #endif // OS_WIN | |
| 1035 } | 1041 } |
| 1036 | 1042 |
| 1037 // Called after the save file dialog box returns. | 1043 // Called after the save file dialog box returns. |
| 1038 void SavePackage::ContinueSave(SavePackageParam* param, | 1044 void SavePackage::ContinueSave(SavePackageParam* param, |
| 1039 const std::wstring& final_name, | 1045 const std::wstring& final_name, |
| 1040 int index) { | 1046 int index) { |
| 1041 // Ensure the filename is safe. | 1047 // Ensure the filename is safe. |
| 1042 param->saved_main_file_path = FilePath::FromWStringHack(final_name); | 1048 param->saved_main_file_path = FilePath::FromWStringHack(final_name); |
| 1043 DownloadManager* dlm = web_contents_->profile()->GetDownloadManager(); | 1049 DownloadManager* dlm = web_contents_->profile()->GetDownloadManager(); |
| 1044 DCHECK(dlm); | 1050 DCHECK(dlm); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1132 int index, void* params) { | 1138 int index, void* params) { |
| 1133 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); | 1139 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); |
| 1134 ContinueSave(save_params, path, index); | 1140 ContinueSave(save_params, path, index); |
| 1135 delete save_params; | 1141 delete save_params; |
| 1136 } | 1142 } |
| 1137 | 1143 |
| 1138 void SavePackage::FileSelectionCanceled(void* params) { | 1144 void SavePackage::FileSelectionCanceled(void* params) { |
| 1139 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); | 1145 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); |
| 1140 delete save_params; | 1146 delete save_params; |
| 1141 } | 1147 } |
| OLD | NEW |