diff options
author | paulg@google.com <paulg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-23 19:42:33 +0000 |
---|---|---|
committer | paulg@google.com <paulg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-23 19:42:33 +0000 |
commit | 65333c20ddb320cc0b5f5fd377d2a870f0e442fc (patch) | |
tree | 9ed584c46cd19bc97266d893d8d9426e389093b4 /chrome | |
parent | 1fead07102dd798a44fd501f56002dff9ccae8e3 (diff) | |
download | chromium_src-65333c20ddb320cc0b5f5fd377d2a870f0e442fc.zip chromium_src-65333c20ddb320cc0b5f5fd377d2a870f0e442fc.tar.gz chromium_src-65333c20ddb320cc0b5f5fd377d2a870f0e442fc.tar.bz2 |
Fix a bug when saving web pages that have a period in their title.
The save dialog code attempts to generate a file extension based on
the suggested name provided to it, which in the case of saving a web
page is the title. If that title contains a '.' character, it treats
anything that follows as the file extension and appends it to the name
the user selects.
For example, saving a page with the title "Google Inc. - A search engine"
and the user choosing the save name as "Google" will result in the saved
file being named "Google. - A search engine.htm" when it should be
"Google.htm".
In the case of saving a web page, we can ignore trying to figure out
the file extension since we already know it will be ".htm".
BUG=6105 (http://crbug.com/6105)
Review URL: http://codereview.chromium.org/18699
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8569 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/download/save_package.cc | 4 | ||||
-rw-r--r-- | chrome/browser/views/shell_dialogs.cc | 2 | ||||
-rw-r--r-- | chrome/common/win_util.cc | 11 | ||||
-rw-r--r-- | chrome/common/win_util.h | 7 |
4 files changed, 19 insertions, 5 deletions
diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc index ac3844e..1127017 100644 --- a/chrome/browser/download/save_package.cc +++ b/chrome/browser/download/save_package.cc @@ -947,10 +947,14 @@ bool SavePackage::GetSaveInfo(const std::wstring& suggest_name, filter[filter.size() - 2] = L'\0'; if (g_should_prompt_for_filename) { + // Since we take the suggested name from the web page's title, we want to + // ignore the file extension generated by SaveFileAsWithFilter, since it + // will always be ".htm". if (!win_util::SaveFileAsWithFilter(container_hwnd, suggest_name, filter, L"htm", + true, &index, ¶m->saved_main_file_path)) return false; diff --git a/chrome/browser/views/shell_dialogs.cc b/chrome/browser/views/shell_dialogs.cc index ab85d0a..be3da01 100644 --- a/chrome/browser/views/shell_dialogs.cc +++ b/chrome/browser/views/shell_dialogs.cc @@ -304,7 +304,7 @@ void SelectFileDialogImpl::ExecuteSelectFile( } else if (type == SELECT_SAVEAS_FILE) { unsigned index = 0; success = win_util::SaveFileAsWithFilter(run_state.owner, default_path, - filter, default_extension, &index, &path); + filter, default_extension, false, &index, &path); DisableOwner(run_state.owner); } else if (type == SELECT_OPEN_FILE) { success = RunOpenFileDialog(title, filter, run_state.owner, &path); diff --git a/chrome/common/win_util.cc b/chrome/common/win_util.cc index 1c552a2..8442bb0 100644 --- a/chrome/common/win_util.cc +++ b/chrome/common/win_util.cc @@ -387,6 +387,7 @@ bool SaveFileAs(HWND owner, suggested_name, filter, L"", + false, &index, final_name); } @@ -395,6 +396,7 @@ bool SaveFileAsWithFilter(HWND owner, const std::wstring& suggested_name, const std::wstring& filter, const std::wstring& def_ext, + bool ignore_suggested_ext, unsigned* index, std::wstring* final_name) { DCHECK(final_name); @@ -472,9 +474,12 @@ bool SaveFileAsWithFilter(HWND owner, filter_selected = filters[(2 * (save_as.nFilterIndex - 1)) + 1]; // Get the extension that was suggested to the user (when the Save As dialog - // was opened). - std::wstring suggested_ext = - file_util::GetFileExtensionFromPath(suggested_name); + // was opened). For saving web pages, we skip this step since there may be + // 'extension characters' in the title of the web page. + std::wstring suggested_ext; + if (!ignore_suggested_ext) + suggested_ext = file_util::GetFileExtensionFromPath(suggested_name); + // If we can't get the extension from the suggested_name, we use the default // extension passed in. This is to cover cases like when saving a web page, // where we get passed in a name without an extension and a default extension diff --git a/chrome/common/win_util.h b/chrome/common/win_util.h index 5de3329..c93b098 100644 --- a/chrome/common/win_util.h +++ b/chrome/common/win_util.h @@ -174,11 +174,16 @@ bool SaveFileAs(HWND owner, // |final_name| returns the file name which contains the drive designator, // path, file name, and extension of the user selected file name. |def_ext| is // the default extension to give to the file if the user did not enter an -// extension. +// extension. If |ignore_suggested_ext| is true, any file extension contained in +// |suggested_name| will not be used to generate the file name. This is useful +// in the case of saving web pages, where we know the extension type already and +// where |suggested_name| may contain a '.' character as a valid part of the +// name, thus confusing our extension detection code. bool SaveFileAsWithFilter(HWND owner, const std::wstring& suggested_name, const std::wstring& filter, const std::wstring& def_ext, + bool ignore_suggested_ext, unsigned* index, std::wstring* final_name); |