| 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/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" |
| 11 #include "base/i18n/file_util_icu.h" | 11 #include "base/i18n/file_util_icu.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/stl_util-inl.h" | 14 #include "base/stl_util-inl.h" |
| 15 #include "base/string_piece.h" | 15 #include "base/string_piece.h" |
| 16 #include "base/string_split.h" | 16 #include "base/string_split.h" |
| 17 #include "base/sys_string_conversions.h" | 17 #include "base/sys_string_conversions.h" |
| 18 #include "base/task.h" | 18 #include "base/task.h" |
| 19 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
| 20 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
| 21 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
| 22 #include "chrome/browser/download/download_item.h" | 22 #include "chrome/browser/download/download_item.h" |
| 23 #include "chrome/browser/download/download_item_model.h" | 23 #include "chrome/browser/download/download_item_model.h" |
| 24 #include "chrome/browser/download/download_manager.h" | 24 #include "chrome/browser/download/download_manager.h" |
| 25 #include "chrome/browser/download/download_prefs.h" | |
| 26 #include "chrome/browser/download/download_util.h" | 25 #include "chrome/browser/download/download_util.h" |
| 27 #include "chrome/browser/download/save_file.h" | |
| 28 #include "chrome/browser/download/save_file_manager.h" | |
| 29 #include "chrome/browser/download/save_item.h" | |
| 30 #include "chrome/browser/net/url_fixer_upper.h" | 26 #include "chrome/browser/net/url_fixer_upper.h" |
| 31 #include "chrome/browser/platform_util.h" | 27 #include "chrome/browser/platform_util.h" |
| 32 #include "chrome/browser/prefs/pref_member.h" | 28 #include "chrome/browser/prefs/pref_member.h" |
| 33 #include "chrome/browser/prefs/pref_service.h" | 29 #include "chrome/browser/prefs/pref_service.h" |
| 34 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
| 35 #include "chrome/browser/tab_contents/tab_util.h" | 31 #include "chrome/browser/tab_contents/tab_util.h" |
| 36 #include "chrome/browser/ui/download/download_tab_helper.h" | 32 #include "chrome/browser/ui/download/download_tab_helper.h" |
| 37 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 33 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 38 #include "chrome/common/chrome_notification_types.h" | 34 #include "chrome/common/chrome_notification_types.h" |
| 39 #include "chrome/common/chrome_paths.h" | 35 #include "chrome/common/chrome_paths.h" |
| 40 #include "chrome/common/pref_names.h" | 36 #include "chrome/common/pref_names.h" |
| 41 #include "chrome/common/render_messages.h" | 37 #include "chrome/common/render_messages.h" |
| 42 #include "chrome/common/url_constants.h" | 38 #include "chrome/common/url_constants.h" |
| 43 #include "content/browser/browser_thread.h" | 39 #include "content/browser/browser_thread.h" |
| 40 #include "content/browser/content_browser_client.h" |
| 41 #include "content/browser/download/save_file.h" |
| 42 #include "content/browser/download/save_file_manager.h" |
| 43 #include "content/browser/download/save_item.h" |
| 44 #include "content/browser/renderer_host/render_process_host.h" | 44 #include "content/browser/renderer_host/render_process_host.h" |
| 45 #include "content/browser/renderer_host/render_view_host.h" | 45 #include "content/browser/renderer_host/render_view_host.h" |
| 46 #include "content/browser/renderer_host/render_view_host_delegate.h" | 46 #include "content/browser/renderer_host/render_view_host_delegate.h" |
| 47 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 47 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
| 48 #include "content/browser/tab_contents/tab_contents.h" | 48 #include "content/browser/tab_contents/tab_contents.h" |
| 49 #include "content/common/notification_service.h" | 49 #include "content/common/notification_service.h" |
| 50 #include "grit/generated_resources.h" | |
| 51 #include "net/base/io_buffer.h" | 50 #include "net/base/io_buffer.h" |
| 52 #include "net/base/mime_util.h" | 51 #include "net/base/mime_util.h" |
| 53 #include "net/base/net_util.h" | 52 #include "net/base/net_util.h" |
| 54 #include "net/url_request/url_request_context.h" | 53 #include "net/url_request/url_request_context.h" |
| 55 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializerClie
nt.h" | 54 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializerClie
nt.h" |
| 56 #include "ui/base/l10n/l10n_util.h" | |
| 57 | 55 |
| 58 using base::Time; | 56 using base::Time; |
| 59 using WebKit::WebPageSerializerClient; | 57 using WebKit::WebPageSerializerClient; |
| 60 | 58 |
| 61 namespace { | 59 namespace { |
| 62 | 60 |
| 63 // A counter for uniquely identifying each save package. | 61 // A counter for uniquely identifying each save package. |
| 64 int g_save_package_id = 0; | 62 int g_save_package_id = 0; |
| 65 | 63 |
| 66 // Default name which will be used when we can not get proper name from | 64 // Default name which will be used when we can not get proper name from |
| 67 // resource URL. | 65 // resource URL. |
| 68 const char kDefaultSaveName[] = "saved_resource"; | 66 const char kDefaultSaveName[] = "saved_resource"; |
| 69 | 67 |
| 70 const FilePath::CharType kDefaultHtmlExtension[] = | |
| 71 #if defined(OS_WIN) | |
| 72 FILE_PATH_LITERAL("htm"); | |
| 73 #else | |
| 74 FILE_PATH_LITERAL("html"); | |
| 75 #endif | |
| 76 | |
| 77 // Maximum number of file ordinal number. I think it's big enough for resolving | 68 // Maximum number of file ordinal number. I think it's big enough for resolving |
| 78 // name-conflict files which has same base file name. | 69 // name-conflict files which has same base file name. |
| 79 const int32 kMaxFileOrdinalNumber = 9999; | 70 const int32 kMaxFileOrdinalNumber = 9999; |
| 80 | 71 |
| 81 // Maximum length for file path. Since Windows have MAX_PATH limitation for | 72 // Maximum length for file path. Since Windows have MAX_PATH limitation for |
| 82 // file path, we need to make sure length of file path of every saved file | 73 // file path, we need to make sure length of file path of every saved file |
| 83 // is less than MAX_PATH | 74 // is less than MAX_PATH |
| 84 #if defined(OS_WIN) | 75 #if defined(OS_WIN) |
| 85 const uint32 kMaxFilePathLength = MAX_PATH - 1; | 76 const uint32 kMaxFilePathLength = MAX_PATH - 1; |
| 86 #elif defined(OS_POSIX) | 77 #elif defined(OS_POSIX) |
| 87 const uint32 kMaxFilePathLength = PATH_MAX - 1; | 78 const uint32 kMaxFilePathLength = PATH_MAX - 1; |
| 88 #endif | 79 #endif |
| 89 | 80 |
| 90 // Maximum length for file ordinal number part. Since we only support the | 81 // Maximum length for file ordinal number part. Since we only support the |
| 91 // maximum 9999 for ordinal number, which means maximum file ordinal number part | 82 // maximum 9999 for ordinal number, which means maximum file ordinal number part |
| 92 // should be "(9998)", so the value is 6. | 83 // should be "(9998)", so the value is 6. |
| 93 const uint32 kMaxFileOrdinalNumberPartLength = 6; | 84 const uint32 kMaxFileOrdinalNumberPartLength = 6; |
| 94 | 85 |
| 95 // If false, we don't prompt the user as to where to save the file. This | |
| 96 // exists only for testing. | |
| 97 bool g_should_prompt_for_filename = true; | |
| 98 | |
| 99 // Indexes used for specifying which element in the extensions dropdown | |
| 100 // the user chooses when picking a save type. | |
| 101 const int kSelectFileHtmlOnlyIndex = 1; | |
| 102 const int kSelectFileCompleteIndex = 2; | |
| 103 | |
| 104 // Used for mapping between SavePackageType constants and the indexes above. | |
| 105 const SavePackage::SavePackageType kIndexToSaveType[] = { | |
| 106 SavePackage::SAVE_TYPE_UNKNOWN, | |
| 107 SavePackage::SAVE_AS_ONLY_HTML, | |
| 108 SavePackage::SAVE_AS_COMPLETE_HTML, | |
| 109 }; | |
| 110 | |
| 111 // Used for mapping between the IDS_ string identifiers and the indexes above. | |
| 112 const int kIndexToIDS[] = { | |
| 113 0, IDS_SAVE_PAGE_DESC_HTML_ONLY, IDS_SAVE_PAGE_DESC_COMPLETE, | |
| 114 }; | |
| 115 | |
| 116 int SavePackageTypeToIndex(SavePackage::SavePackageType type) { | |
| 117 for (size_t i = 0; i < arraysize(kIndexToSaveType); ++i) { | |
| 118 if (kIndexToSaveType[i] == type) | |
| 119 return i; | |
| 120 } | |
| 121 NOTREACHED(); | |
| 122 return -1; | |
| 123 } | |
| 124 | |
| 125 // Strip current ordinal number, if any. Should only be used on pure | 86 // Strip current ordinal number, if any. Should only be used on pure |
| 126 // file names, i.e. those stripped of their extensions. | 87 // file names, i.e. those stripped of their extensions. |
| 127 // TODO(estade): improve this to not choke on alternate encodings. | 88 // TODO(estade): improve this to not choke on alternate encodings. |
| 128 FilePath::StringType StripOrdinalNumber( | 89 FilePath::StringType StripOrdinalNumber( |
| 129 const FilePath::StringType& pure_file_name) { | 90 const FilePath::StringType& pure_file_name) { |
| 130 FilePath::StringType::size_type r_paren_index = | 91 FilePath::StringType::size_type r_paren_index = |
| 131 pure_file_name.rfind(FILE_PATH_LITERAL(')')); | 92 pure_file_name.rfind(FILE_PATH_LITERAL(')')); |
| 132 FilePath::StringType::size_type l_paren_index = | 93 FilePath::StringType::size_type l_paren_index = |
| 133 pure_file_name.rfind(FILE_PATH_LITERAL('(')); | 94 pure_file_name.rfind(FILE_PATH_LITERAL('(')); |
| 134 if (l_paren_index >= r_paren_index) | 95 if (l_paren_index >= r_paren_index) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 146 // Check whether we can save page as complete-HTML for the contents which | 107 // Check whether we can save page as complete-HTML for the contents which |
| 147 // have specified a MIME type. Now only contents which have the MIME type | 108 // have specified a MIME type. Now only contents which have the MIME type |
| 148 // "text/html" can be saved as complete-HTML. | 109 // "text/html" can be saved as complete-HTML. |
| 149 bool CanSaveAsComplete(const std::string& contents_mime_type) { | 110 bool CanSaveAsComplete(const std::string& contents_mime_type) { |
| 150 return contents_mime_type == "text/html" || | 111 return contents_mime_type == "text/html" || |
| 151 contents_mime_type == "application/xhtml+xml"; | 112 contents_mime_type == "application/xhtml+xml"; |
| 152 } | 113 } |
| 153 | 114 |
| 154 } // namespace | 115 } // namespace |
| 155 | 116 |
| 117 const FilePath::CharType SavePackage::kDefaultHtmlExtension[] = |
| 118 #if defined(OS_WIN) |
| 119 FILE_PATH_LITERAL("htm"); |
| 120 #else |
| 121 FILE_PATH_LITERAL("html"); |
| 122 #endif |
| 123 |
| 156 SavePackage::SavePackage(TabContentsWrapper* wrapper, | 124 SavePackage::SavePackage(TabContentsWrapper* wrapper, |
| 157 SavePackageType save_type, | 125 SavePackageType save_type, |
| 158 const FilePath& file_full_path, | 126 const FilePath& file_full_path, |
| 159 const FilePath& directory_full_path) | 127 const FilePath& directory_full_path) |
| 160 : TabContentsObserver(wrapper->tab_contents()), | 128 : TabContentsObserver(wrapper->tab_contents()), |
| 161 wrapper_(wrapper), | 129 wrapper_(wrapper), |
| 162 file_manager_(NULL), | 130 file_manager_(NULL), |
| 163 download_(NULL), | 131 download_(NULL), |
| 164 page_url_(GetUrlToBeSaved()), | 132 page_url_(GetUrlToBeSaved()), |
| 165 saved_main_file_path_(file_full_path), | 133 saved_main_file_path_(file_full_path), |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 } | 214 } |
| 247 | 215 |
| 248 STLDeleteValues(&saved_success_items_); | 216 STLDeleteValues(&saved_success_items_); |
| 249 STLDeleteValues(&in_progress_items_); | 217 STLDeleteValues(&in_progress_items_); |
| 250 STLDeleteValues(&saved_failed_items_); | 218 STLDeleteValues(&saved_failed_items_); |
| 251 | 219 |
| 252 // The DownloadItem is owned by DownloadManager. | 220 // The DownloadItem is owned by DownloadManager. |
| 253 download_ = NULL; | 221 download_ = NULL; |
| 254 | 222 |
| 255 file_manager_ = NULL; | 223 file_manager_ = NULL; |
| 256 | |
| 257 // If there's an outstanding save dialog, make sure it doesn't call us back | |
| 258 // now that we're gone. | |
| 259 if (select_file_dialog_.get()) | |
| 260 select_file_dialog_->ListenerDestroyed(); | |
| 261 } | 224 } |
| 262 | 225 |
| 263 // Retrieves the URL to be saved from tab_contents_ variable. | 226 // Retrieves the URL to be saved from tab_contents_ variable. |
| 264 GURL SavePackage::GetUrlToBeSaved() { | 227 GURL SavePackage::GetUrlToBeSaved() { |
| 265 // Instead of using tab_contents_.GetURL here, we use url() | 228 // Instead of using tab_contents_.GetURL here, we use url() |
| 266 // (which is the "real" url of the page) | 229 // (which is the "real" url of the page) |
| 267 // from the NavigationEntry because it reflects its' origin | 230 // from the NavigationEntry because it reflects its' origin |
| 268 // rather than the displayed one (returned by GetURL) which may be | 231 // rather than the displayed one (returned by GetURL) which may be |
| 269 // different (like having "view-source:" on the front). | 232 // different (like having "view-source:" on the front). |
| 270 NavigationEntry* active_entry = | 233 NavigationEntry* active_entry = |
| (...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1116 waiting_item_queue_.push(save_item); | 1079 waiting_item_queue_.push(save_item); |
| 1117 } | 1080 } |
| 1118 wait_state_ = NET_FILES; | 1081 wait_state_ = NET_FILES; |
| 1119 DoSavingProcess(); | 1082 DoSavingProcess(); |
| 1120 } else { | 1083 } else { |
| 1121 // No resource files need to be saved, treat it as user cancel. | 1084 // No resource files need to be saved, treat it as user cancel. |
| 1122 Cancel(true); | 1085 Cancel(true); |
| 1123 } | 1086 } |
| 1124 } | 1087 } |
| 1125 | 1088 |
| 1126 void SavePackage::SetShouldPromptUser(bool should_prompt) { | |
| 1127 g_should_prompt_for_filename = should_prompt; | |
| 1128 } | |
| 1129 | |
| 1130 FilePath SavePackage::GetSuggestedNameForSaveAs( | 1089 FilePath SavePackage::GetSuggestedNameForSaveAs( |
| 1131 bool can_save_as_complete, | 1090 bool can_save_as_complete, |
| 1132 const std::string& contents_mime_type) { | 1091 const std::string& contents_mime_type) { |
| 1133 FilePath name_with_proper_ext = | 1092 FilePath name_with_proper_ext = |
| 1134 FilePath::FromWStringHack(UTF16ToWideHack(title_)); | 1093 FilePath::FromWStringHack(UTF16ToWideHack(title_)); |
| 1135 | 1094 |
| 1136 // If the page's title matches its URL, use the URL. Try to use the last path | 1095 // If the page's title matches its URL, use the URL. Try to use the last path |
| 1137 // component or if there is none, the domain as the file name. | 1096 // component or if there is none, the domain as the file name. |
| 1138 // Normally we want to base the filename on the page title, or if it doesn't | 1097 // Normally we want to base the filename on the page title, or if it doesn't |
| 1139 // exist, on the URL. It's not easy to tell if the page has no title, because | 1098 // exist, on the URL. It's not easy to tell if the page has no title, because |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1307 } | 1266 } |
| 1308 | 1267 |
| 1309 BrowserThread::PostTask( | 1268 BrowserThread::PostTask( |
| 1310 BrowserThread::UI, FROM_HERE, | 1269 BrowserThread::UI, FROM_HERE, |
| 1311 NewRunnableMethod(this, &SavePackage::ContinueGetSaveInfo, save_dir, | 1270 NewRunnableMethod(this, &SavePackage::ContinueGetSaveInfo, save_dir, |
| 1312 can_save_as_complete)); | 1271 can_save_as_complete)); |
| 1313 } | 1272 } |
| 1314 | 1273 |
| 1315 void SavePackage::ContinueGetSaveInfo(const FilePath& suggested_path, | 1274 void SavePackage::ContinueGetSaveInfo(const FilePath& suggested_path, |
| 1316 bool can_save_as_complete) { | 1275 bool can_save_as_complete) { |
| 1317 // The TabContents which owns this SavePackage may have disappeared during | 1276 content::GetContentClient()->browser()->ChooseSavePath( |
| 1318 // the UI->FILE->UI thread hop of | 1277 this, suggested_path, can_save_as_complete); |
| 1319 // GetSaveInfo->CreateDirectoryOnFileThread->ContinueGetSaveInfo. | |
| 1320 if (!tab_contents()) | |
| 1321 return; | |
| 1322 DownloadPrefs* download_prefs = | |
| 1323 tab_contents()->profile()->GetDownloadManager()->download_prefs(); | |
| 1324 int file_type_index = | |
| 1325 SavePackageTypeToIndex( | |
| 1326 static_cast<SavePackageType>(download_prefs->save_file_type())); | |
| 1327 DCHECK_NE(-1, file_type_index); | |
| 1328 | |
| 1329 SelectFileDialog::FileTypeInfo file_type_info; | |
| 1330 FilePath::StringType default_extension; | |
| 1331 | |
| 1332 // If the contents can not be saved as complete-HTML, do not show the | |
| 1333 // file filters. | |
| 1334 if (can_save_as_complete) { | |
| 1335 bool add_extra_extension = false; | |
| 1336 FilePath::StringType extra_extension; | |
| 1337 if (!suggested_path.Extension().empty() && | |
| 1338 suggested_path.Extension().compare(FILE_PATH_LITERAL("htm")) && | |
| 1339 suggested_path.Extension().compare(FILE_PATH_LITERAL("html"))) { | |
| 1340 add_extra_extension = true; | |
| 1341 extra_extension = suggested_path.Extension().substr(1); | |
| 1342 } | |
| 1343 | |
| 1344 file_type_info.extensions.resize(2); | |
| 1345 file_type_info.extensions[kSelectFileHtmlOnlyIndex - 1].push_back( | |
| 1346 FILE_PATH_LITERAL("htm")); | |
| 1347 file_type_info.extensions[kSelectFileHtmlOnlyIndex - 1].push_back( | |
| 1348 FILE_PATH_LITERAL("html")); | |
| 1349 | |
| 1350 if (add_extra_extension) { | |
| 1351 file_type_info.extensions[kSelectFileHtmlOnlyIndex - 1].push_back( | |
| 1352 extra_extension); | |
| 1353 } | |
| 1354 | |
| 1355 file_type_info.extension_description_overrides.push_back( | |
| 1356 l10n_util::GetStringUTF16(kIndexToIDS[kSelectFileCompleteIndex - 1])); | |
| 1357 file_type_info.extensions[kSelectFileCompleteIndex - 1].push_back( | |
| 1358 FILE_PATH_LITERAL("htm")); | |
| 1359 file_type_info.extensions[kSelectFileCompleteIndex - 1].push_back( | |
| 1360 FILE_PATH_LITERAL("html")); | |
| 1361 | |
| 1362 if (add_extra_extension) { | |
| 1363 file_type_info.extensions[kSelectFileCompleteIndex - 1].push_back( | |
| 1364 extra_extension); | |
| 1365 } | |
| 1366 | |
| 1367 file_type_info.extension_description_overrides.push_back( | |
| 1368 l10n_util::GetStringUTF16(kIndexToIDS[kSelectFileCompleteIndex])); | |
| 1369 file_type_info.include_all_files = false; | |
| 1370 default_extension = kDefaultHtmlExtension; | |
| 1371 } else { | |
| 1372 file_type_info.extensions.resize(1); | |
| 1373 file_type_info.extensions[kSelectFileHtmlOnlyIndex - 1].push_back( | |
| 1374 suggested_path.Extension()); | |
| 1375 | |
| 1376 if (!file_type_info.extensions[kSelectFileHtmlOnlyIndex - 1][0].empty()) { | |
| 1377 // Drop the . | |
| 1378 file_type_info.extensions[kSelectFileHtmlOnlyIndex - 1][0].erase(0, 1); | |
| 1379 } | |
| 1380 | |
| 1381 file_type_info.include_all_files = true; | |
| 1382 file_type_index = 1; | |
| 1383 } | |
| 1384 | |
| 1385 if (g_should_prompt_for_filename) { | |
| 1386 if (!select_file_dialog_.get()) | |
| 1387 select_file_dialog_ = SelectFileDialog::Create(this); | |
| 1388 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE, | |
| 1389 string16(), | |
| 1390 suggested_path, | |
| 1391 &file_type_info, | |
| 1392 file_type_index, | |
| 1393 default_extension, | |
| 1394 tab_contents(), | |
| 1395 platform_util::GetTopLevel( | |
| 1396 tab_contents()->GetNativeView()), | |
| 1397 NULL); | |
| 1398 } else { | |
| 1399 // Just use 'suggested_path' instead of opening the dialog prompt. | |
| 1400 ContinueSave(suggested_path, file_type_index); | |
| 1401 } | |
| 1402 } | 1278 } |
| 1403 | 1279 |
| 1404 // Called after the save file dialog box returns. | 1280 // Called after the save file dialog box returns. |
| 1405 void SavePackage::ContinueSave(const FilePath& final_name, | 1281 void SavePackage::OnPathPicked(const FilePath& final_name, |
| 1406 int index) { | 1282 SavePackageType type) { |
| 1407 // Ensure the filename is safe. | 1283 // Ensure the filename is safe. |
| 1408 saved_main_file_path_ = final_name; | 1284 saved_main_file_path_ = final_name; |
| 1409 download_util::GenerateSafeFileName(tab_contents()->contents_mime_type(), | 1285 download_util::GenerateSafeFileName(tab_contents()->contents_mime_type(), |
| 1410 &saved_main_file_path_); | 1286 &saved_main_file_path_); |
| 1411 | 1287 |
| 1412 // The option index is not zero-based. | |
| 1413 DCHECK(index >= kSelectFileHtmlOnlyIndex && | |
| 1414 index <= kSelectFileCompleteIndex); | |
| 1415 | |
| 1416 saved_main_directory_path_ = saved_main_file_path_.DirName(); | 1288 saved_main_directory_path_ = saved_main_file_path_.DirName(); |
| 1417 | 1289 |
| 1418 PrefService* prefs = tab_contents()->profile()->GetPrefs(); | 1290 PrefService* prefs = tab_contents()->profile()->GetPrefs(); |
| 1419 StringPrefMember save_file_path; | 1291 StringPrefMember save_file_path; |
| 1420 save_file_path.Init(prefs::kSaveFileDefaultDirectory, prefs, NULL); | 1292 save_file_path.Init(prefs::kSaveFileDefaultDirectory, prefs, NULL); |
| 1421 #if defined(OS_POSIX) | 1293 #if defined(OS_POSIX) |
| 1422 std::string path_string = saved_main_directory_path_.value(); | 1294 std::string path_string = saved_main_directory_path_.value(); |
| 1423 #elif defined(OS_WIN) | 1295 #elif defined(OS_WIN) |
| 1424 std::string path_string = WideToUTF8(saved_main_directory_path_.value()); | 1296 std::string path_string = WideToUTF8(saved_main_directory_path_.value()); |
| 1425 #endif | 1297 #endif |
| 1426 // If user change the default saving directory, we will remember it just | 1298 // If user change the default saving directory, we will remember it just |
| 1427 // like IE and FireFox. | 1299 // like IE and FireFox. |
| 1428 if (!tab_contents()->profile()->IsOffTheRecord() && | 1300 if (!tab_contents()->profile()->IsOffTheRecord() && |
| 1429 save_file_path.GetValue() != path_string) { | 1301 save_file_path.GetValue() != path_string) { |
| 1430 save_file_path.SetValue(path_string); | 1302 save_file_path.SetValue(path_string); |
| 1431 } | 1303 } |
| 1432 | 1304 |
| 1433 save_type_ = kIndexToSaveType[index]; | 1305 save_type_ = type; |
| 1434 | 1306 |
| 1435 prefs->SetInteger(prefs::kSaveFileType, save_type_); | 1307 prefs->SetInteger(prefs::kSaveFileType, save_type_); |
| 1436 | 1308 |
| 1437 if (save_type_ == SavePackage::SAVE_AS_COMPLETE_HTML) { | 1309 if (save_type_ == SavePackage::SAVE_AS_COMPLETE_HTML) { |
| 1438 // Make new directory for saving complete file. | 1310 // Make new directory for saving complete file. |
| 1439 saved_main_directory_path_ = saved_main_directory_path_.Append( | 1311 saved_main_directory_path_ = saved_main_directory_path_.Append( |
| 1440 saved_main_file_path_.RemoveExtension().BaseName().value() + | 1312 saved_main_file_path_.RemoveExtension().BaseName().value() + |
| 1441 FILE_PATH_LITERAL("_files")); | 1313 FILE_PATH_LITERAL("_files")); |
| 1442 } | 1314 } |
| 1443 | 1315 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1458 bool SavePackage::IsSavableContents(const std::string& contents_mime_type) { | 1330 bool SavePackage::IsSavableContents(const std::string& contents_mime_type) { |
| 1459 // WebKit creates Document object when MIME type is application/xhtml+xml, | 1331 // WebKit creates Document object when MIME type is application/xhtml+xml, |
| 1460 // so we also support this MIME type. | 1332 // so we also support this MIME type. |
| 1461 return contents_mime_type == "text/html" || | 1333 return contents_mime_type == "text/html" || |
| 1462 contents_mime_type == "text/xml" || | 1334 contents_mime_type == "text/xml" || |
| 1463 contents_mime_type == "application/xhtml+xml" || | 1335 contents_mime_type == "application/xhtml+xml" || |
| 1464 contents_mime_type == "text/plain" || | 1336 contents_mime_type == "text/plain" || |
| 1465 contents_mime_type == "text/css" || | 1337 contents_mime_type == "text/css" || |
| 1466 net::IsSupportedJavascriptMimeType(contents_mime_type.c_str()); | 1338 net::IsSupportedJavascriptMimeType(contents_mime_type.c_str()); |
| 1467 } | 1339 } |
| 1468 | |
| 1469 // SelectFileDialog::Listener interface. | |
| 1470 void SavePackage::FileSelected(const FilePath& path, | |
| 1471 int index, void* params) { | |
| 1472 ContinueSave(path, index); | |
| 1473 } | |
| 1474 | |
| 1475 void SavePackage::FileSelectionCanceled(void* params) { | |
| 1476 } | |
| OLD | NEW |