diff options
Diffstat (limited to 'chrome/browser/download/save_package.cc')
-rw-r--r-- | chrome/browser/download/save_package.cc | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc index a67d890..f8b85af 100644 --- a/chrome/browser/download/save_package.cc +++ b/chrome/browser/download/save_package.cc @@ -40,23 +40,31 @@ using base::Time; +namespace { + // Default name which will be used when we can not get proper name from // resource URL. -static const wchar_t kDefaultSaveName[] = L"saved_resource"; +const wchar_t kDefaultSaveName[] = L"saved_resource"; // Maximum number of file ordinal number. I think it's big enough for resolving // name-conflict files which has same base file name. -static const int32 kMaxFileOrdinalNumber = 9999; +const int32 kMaxFileOrdinalNumber = 9999; // Maximum length for file path. Since Windows have MAX_PATH limitation for // file path, we need to make sure length of file path of every saved file // is less than MAX_PATH -static const uint32 kMaxFilePathLength = MAX_PATH - 1; +const uint32 kMaxFilePathLength = MAX_PATH - 1; // Maximum length for file ordinal number part. Since we only support the // maximum 9999 for ordinal number, which means maximum file ordinal number part // should be "(9998)", so the value is 6. -static const uint32 kMaxFileOrdinalNumberPartLength = 6; +const uint32 kMaxFileOrdinalNumberPartLength = 6; + +// If false, we don't prompt the user as to where to save the file. This +// exists only for testing. +bool g_should_prompt_for_filename = true; + +} // namespace SavePackage::SavePackage(WebContents* web_content, SavePackageType save_type, @@ -885,6 +893,10 @@ void SavePackage::OnReceivedSavableResourceLinksForCurrentPage( } } +void SavePackage::SetShouldPromptUser(bool should_prompt) { + g_should_prompt_for_filename = should_prompt; +} + std::wstring SavePackage::GetSuggestNameForSaveAs(PrefService* prefs, const std::wstring& name) { // Check whether the preference has the preferred directory for saving file. @@ -934,17 +946,25 @@ bool SavePackage::GetSaveInfo(const std::wstring& suggest_name, filter[filter.size() - 1] = L'\0'; filter[filter.size() - 2] = L'\0'; - if (!win_util::SaveFileAsWithFilter(container_hwnd, - suggest_name, - filter, - L"htm", - &index, - ¶m->saved_main_file_path)) - return false; + if (g_should_prompt_for_filename) { + if (!win_util::SaveFileAsWithFilter(container_hwnd, + suggest_name, + filter, + L"htm", + &index, + ¶m->saved_main_file_path)) + return false; + } else { + param->saved_main_file_path = suggest_name; + } } else { - if (!win_util::SaveFileAs(container_hwnd, suggest_name, - ¶m->saved_main_file_path)) - return false; + if (g_should_prompt_for_filename) { + if (!win_util::SaveFileAs(container_hwnd, suggest_name, + ¶m->saved_main_file_path)) + return false; + } else { + param->saved_main_file_path = suggest_name; + } // Set save-as type to only-HTML if the contents of current tab can not be // saved as complete-HTML. index = 1; @@ -952,7 +972,7 @@ bool SavePackage::GetSaveInfo(const std::wstring& suggest_name, DCHECK(download_manager); // Ensure the filename is safe. - FilePath path; + FilePath path(param->saved_main_file_path); download_manager->GenerateSafeFilename(param->current_tab_mime_type, &path); param->saved_main_file_path = path.ToWStringHack(); |