diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-22 23:06:12 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-22 23:06:12 +0000 |
commit | de29433580baeecc204edc9ca0c2aa47c51aa93a (patch) | |
tree | ec55f655f63f7e09fb373c1e7d784c2e721c6119 /chrome/browser/views | |
parent | 2c1639589b5932b565c9d420cb79b56a4212a706 (diff) | |
download | chromium_src-de29433580baeecc204edc9ca0c2aa47c51aa93a.zip chromium_src-de29433580baeecc204edc9ca0c2aa47c51aa93a.tar.gz chromium_src-de29433580baeecc204edc9ca0c2aa47c51aa93a.tar.bz2 |
Do some cleanup of file path name handling.
This started trying to cleanup DownloadManager::GenerateFilename which asserts
if your system locale isn't UTF-8 (I ran into this when mine got messed up).
The solution is to have GetSuggestedFilename return a FilePath rather than
calling FromWStringHack.
The rest of the patch is a result of trying to write GetSuggestedFilename in a
reasonable way. I changed ReplaceIllegalCharacters to work on a
FilePath::StringType.
Some places in the code calling these functions got cleaner, some got messier.
I think overall the ones that got messier are the ones doing sketchy things
with paths and the ones that got cleaner are the ones doing things more
properly.
The only code here that gets called a nontrivial number of times is the
weburlloader, and I think the new code does about the same number of string
conversions overall (though on certain platforms the number will be higher or
lower).
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/271056
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29832 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r-- | chrome/browser/views/new_profile_dialog.cc | 14 | ||||
-rw-r--r-- | chrome/browser/views/tab_contents/tab_contents_view_win.cc | 10 |
2 files changed, 14 insertions, 10 deletions
diff --git a/chrome/browser/views/new_profile_dialog.cc b/chrome/browser/views/new_profile_dialog.cc index f0cfded..54ac154 100644 --- a/chrome/browser/views/new_profile_dialog.cc +++ b/chrome/browser/views/new_profile_dialog.cc @@ -65,12 +65,14 @@ bool NewProfileDialog::IsDialogButtonEnabled( MessageBoxFlags::DialogButton button) const { if (button == MessageBoxFlags::DIALOGBUTTON_OK) { std::wstring profile_name = message_box_view_->GetInputText(); - // TODO(munjal): Refactor the function ReplaceIllegalCharacters in - // file_util to something that just checks if there are illegal chars - // since that's what we really need. Also, replaceIllegalChars seems to - // be expensive since it builds a list of illegal characters for each call. - // So at the least fix that. - file_util::ReplaceIllegalCharacters(&profile_name, L'_'); + +#if defined(OS_POSIX) + std::string profile_name_narrow = WideToUTF8(profile_name); + file_util::ReplaceIllegalCharactersInPath(&profile_name_narrow, '_'); + profile_name = UTF8ToWide(profile_name_narrow); +#else + file_util::ReplaceIllegalCharactersInPath(&profile_name, '_'); +#endif return !profile_name.empty() && profile_name == message_box_view_->GetInputText(); } diff --git a/chrome/browser/views/tab_contents/tab_contents_view_win.cc b/chrome/browser/views/tab_contents/tab_contents_view_win.cc index 227425f..e1aa377 100644 --- a/chrome/browser/views/tab_contents/tab_contents_view_win.cc +++ b/chrome/browser/views/tab_contents/tab_contents_view_win.cc @@ -138,10 +138,12 @@ void TabContentsViewWin::StartDragging(const WebDropData& drop_data, file_name = file_name.BaseName().RemoveExtension(); if (file_name.value().empty()) { // Retrieve the name from the URL. - std::wstring fn = net::GetSuggestedFilename(drop_data.url, "", "", L""); - if ((fn.size() + drop_data.file_extension.size() + 1) > MAX_PATH) - fn = fn.substr(0, MAX_PATH - drop_data.file_extension.size() - 2); - file_name = FilePath::FromWStringHack(fn); + file_name = net::GetSuggestedFilename(drop_data.url, "", "", ""); + if (file_name.value().size() + drop_data.file_extension.size() + 1 > + MAX_PATH) { + file_name = FilePath(file_name.value().substr( + 0, MAX_PATH - drop_data.file_extension.size() - 2)); + } } file_name = file_name.ReplaceExtension(drop_data.file_extension); data.SetFileContents(file_name.value(), drop_data.file_contents); |