summaryrefslogtreecommitdiffstats
path: root/chrome/browser/download/save_package.cc
diff options
context:
space:
mode:
authortc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-07 21:43:20 +0000
committertc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-07 21:43:20 +0000
commit5bcdb31304d676b38ce605180b7d8816e9a8b745 (patch)
tree8e12e0a79c722b6199fb067c2b020c40ec0ddfbf /chrome/browser/download/save_package.cc
parentc2374c94270d846055463aa1e61f239957f82f09 (diff)
downloadchromium_src-5bcdb31304d676b38ce605180b7d8816e9a8b745.zip
chromium_src-5bcdb31304d676b38ce605180b7d8816e9a8b745.tar.gz
chromium_src-5bcdb31304d676b38ce605180b7d8816e9a8b745.tar.bz2
Add a UI test to make sure we sanitize the filename
of files saved using the "Save page as..." menu item. This involves adding a new automation provider method for disabling the dialog prompting for a filename. Review URL: http://codereview.chromium.org/16555 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7683 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download/save_package.cc')
-rw-r--r--chrome/browser/download/save_package.cc50
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,
- &param->saved_main_file_path))
- return false;
+ if (g_should_prompt_for_filename) {
+ if (!win_util::SaveFileAsWithFilter(container_hwnd,
+ suggest_name,
+ filter,
+ L"htm",
+ &index,
+ &param->saved_main_file_path))
+ return false;
+ } else {
+ param->saved_main_file_path = suggest_name;
+ }
} else {
- if (!win_util::SaveFileAs(container_hwnd, suggest_name,
- &param->saved_main_file_path))
- return false;
+ if (g_should_prompt_for_filename) {
+ if (!win_util::SaveFileAs(container_hwnd, suggest_name,
+ &param->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();