summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/os_exchange_data_provider_win.cc5
-rw-r--r--chrome/app/generated_resources.grd14
-rw-r--r--chrome/browser/bookmarks/bookmark_utils.cc3
-rw-r--r--chrome/browser/cocoa/web_drag_source.mm3
-rw-r--r--chrome/browser/download/download_manager.cc11
-rw-r--r--chrome/browser/download/save_package.cc6
-rw-r--r--chrome/browser/views/tab_contents/tab_contents_view_win.cc3
-rw-r--r--net/base/net_util.cc59
-rw-r--r--net/base/net_util.h6
-rw-r--r--net/base/net_util_unittest.cc76
-rw-r--r--webkit/glue/weburlloader_impl.cc10
11 files changed, 116 insertions, 80 deletions
diff --git a/app/os_exchange_data_provider_win.cc b/app/os_exchange_data_provider_win.cc
index 81db40e..9efa5ee 100644
--- a/app/os_exchange_data_provider_win.cc
+++ b/app/os_exchange_data_provider_win.cc
@@ -6,6 +6,7 @@
#include "app/clipboard/clipboard_util_win.h"
#include "app/l10n_util.h"
+#include "base/file_path.h"
#include "base/i18n/file_util_icu.h"
#include "base/logging.h"
#include "base/pickle.h"
@@ -703,8 +704,8 @@ static void CreateValidFileNameFromTitle(const GURL& url,
std::wstring* validated) {
if (title.empty()) {
if (url.is_valid()) {
- *validated = net::GetSuggestedFilename(url, std::string(),
- std::string(), "").ToWStringHack();
+ *validated = net::GetSuggestedFilename(
+ url, std::string(), std::string(), FilePath()).ToWStringHack();
} else {
// Nothing else can be done, just use a default.
*validated = l10n_util::GetString(IDS_APP_UNTITLED_SHORTCUT_FILE_NAME);
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index bb4f689..3520ec7 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -2588,7 +2588,7 @@ each locale. -->
<message name="IDS_EXTENSION_PROMPT_WARNING_NEW_FULL_ACCESS" desc="Warning displayed in body of extension dialog when the extension requires access the local machine.">
This extension will have full access to your computer and private data, and will autoupdate without further notice or action by you.
</message>
-
+
<!-- chrome://extensions page -->
<message name="IDS_EXTENSIONS_DEVELOPER_TOOLS_LINK" desc="Text of the link for developer tools.">
Developer tools
@@ -2676,7 +2676,7 @@ each locale. -->
</message>
<message name="IDS_EXTENSION_PACK_DIALOG_SUCCESS_BODY_NEW" desc="Message shown on successful packing of a new extension.">
Created the following files:
-
+
Extension: <ph name="EXTENSION_FILE">$1<ex>c:\users\aa\myextension.crx</ex></ph>
Key File: <ph name="KEY_FILE">$2<ex>c:\users\aa\myextension.pem</ex></ph>
@@ -4075,7 +4075,7 @@ Keep your key file in a safe place. You will need it to create new versions of y
Show Home button
</message>
</if>
-
+
<if expr="os == 'darwin'">
<!-- Mac has a Toolbar group (IDS_OPTIONS_HOMEPAGE_SHOW_BUTTON moved in this group) -->
<message name="IDS_OPTIONS_TOOLBAR_GROUP_NAME" desc="The title of the toolbar group">
@@ -5250,10 +5250,12 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_BOOKMARK_MANAGER_SEARCH_TITLE" desc="Text shown before the search text field.">
Search:
</message>
-
<message name="IDS_DEFAULT_FILENAME" desc="Default name for saved files when we have no idea what they could be.">
unknown
</message>
+ <message name="IDS_DEFAULT_DOWNLOAD_FILENAME" desc="Default name for downloaded files when we have no idea what they could be.">
+ download
+ </message>
<message name="IDS_BROWSER_WINDOW_MAC_TAB_UNTITLED" desc="Tabs and windows on MacOS with no title use this string.">
Untitled
</message>
@@ -5411,7 +5413,7 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_SYNC_SUCCESS" desc="Operation successful">
Success!
</message>
-
+
<!-- Sync app menu item strings -->
<message name="IDS_SYNC_MENU_BOOKMARKS_SYNCED_LABEL" desc="The text for the sync app menu item when bookmark sync has been enabled">
Bookmarks synced...
@@ -5419,7 +5421,7 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_SYNC_MENU_BOOKMARK_SYNC_ERROR_LABEL" desc="The text for the sync app menu item when a bookmark sync error has occured">
Bookmark sync error...
</message>
-
+
<!-- Merge and Sync dialog strings -->
<message name="IDS_SYNC_MERGE_INTRODUCTION" desc="The header at the top of the merge and sync dialog.">
Your bookmarks will be merged.
diff --git a/chrome/browser/bookmarks/bookmark_utils.cc b/chrome/browser/bookmarks/bookmark_utils.cc
index 3af7910..54ea21cb 100644
--- a/chrome/browser/bookmarks/bookmark_utils.cc
+++ b/chrome/browser/bookmarks/bookmark_utils.cc
@@ -9,6 +9,7 @@
#include "app/l10n_util.h"
#include "app/tree_node_iterator.h"
#include "base/basictypes.h"
+#include "base/file_path.h"
#include "base/string_util.h"
#include "base/time.h"
#include "chrome/browser/bookmarks/bookmark_drag_data.h"
@@ -403,7 +404,7 @@ bool CanPasteFromClipboard(const BookmarkNode* node) {
std::string GetNameForURL(const GURL& url) {
if (url.is_valid()) {
return WideToUTF8(net::GetSuggestedFilename(
- url, std::string(), std::string(), "").ToWStringHack());
+ url, std::string(), std::string(), FilePath()).ToWStringHack());
} else {
return l10n_util::GetStringUTF8(IDS_APP_UNTITLED_SHORTCUT_FILE_NAME);
}
diff --git a/chrome/browser/cocoa/web_drag_source.mm b/chrome/browser/cocoa/web_drag_source.mm
index 3790e0c..2fb135a 100644
--- a/chrome/browser/cocoa/web_drag_source.mm
+++ b/chrome/browser/cocoa/web_drag_source.mm
@@ -4,6 +4,7 @@
#import "chrome/browser/cocoa/web_drag_source.h"
+#include "base/file_path.h"
#include "base/file_util.h"
#include "base/nsimage_cache_mac.h"
#include "base/string_util.h"
@@ -52,7 +53,7 @@ FilePath GetFileNameFromDragData(
if (file_name.empty()) {
// Retrieve the name from the URL.
- file_name = net::GetSuggestedFilename(drop_data.url, "", "", "");
+ file_name = net::GetSuggestedFilename(drop_data.url, "", "", FilePath());
}
file_name = file_name.ReplaceExtension([SysUTF16ToNSString(
diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc
index bb0a280..1295f25 100644
--- a/chrome/browser/download/download_manager.cc
+++ b/chrome/browser/download/download_manager.cc
@@ -1187,10 +1187,19 @@ void DownloadManager::GenerateExtension(
void DownloadManager::GenerateFilename(DownloadCreateInfo* info,
FilePath* generated_name) {
+ std::wstring default_name =
+ l10n_util::GetString(IDS_DEFAULT_DOWNLOAD_FILENAME);
+#if defined(OS_WIN)
+ FilePath default_file_path(default_name);
+#elif defined(OS_POSIX)
+ FilePath default_file_path(base::SysWideToNativeMB(default_name));
+#endif
+
*generated_name = net::GetSuggestedFilename(GURL(info->url),
info->content_disposition,
info->referrer_charset,
- "download");
+ default_file_path);
+
DCHECK(!generated_name->empty());
GenerateSafeFilename(info->mime_type, generated_name);
diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc
index 15e4787..e4df35a 100644
--- a/chrome/browser/download/save_package.cc
+++ b/chrome/browser/download/save_package.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/download/save_package.h"
#include "app/l10n_util.h"
+#include "base/file_path.h"
#include "base/file_util.h"
#include "base/i18n/file_util_icu.h"
#include "base/logging.h"
@@ -67,7 +68,8 @@ namespace {
// Default name which will be used when we can not get proper name from
// resource URL.
-const char kDefaultSaveName[] = "saved_resource";
+const FilePath::CharType kDefaultSaveName[] =
+ FILE_PATH_LITERAL("saved_resource");
const FilePath::CharType kDefaultHtmlExtension[] =
#if defined(OS_WIN)
@@ -339,7 +341,7 @@ bool SavePackage::GenerateFilename(const std::string& disposition,
// TODO(jungshik): Figure out the referrer charset when having one
// makes sense and pass it to GetSuggestedFilename.
FilePath file_path = net::GetSuggestedFilename(url, disposition, "",
- kDefaultSaveName);
+ FilePath(kDefaultSaveName));
DCHECK(!file_path.empty());
FilePath::StringType pure_file_name =
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 65937e0..29c967b 100644
--- a/chrome/browser/views/tab_contents/tab_contents_view_win.cc
+++ b/chrome/browser/views/tab_contents/tab_contents_view_win.cc
@@ -9,6 +9,7 @@
#include "app/gfx/canvas_paint.h"
#include "app/os_exchange_data.h"
#include "app/os_exchange_data_provider_win.h"
+#include "base/file_path.h"
#include "base/keyboard_codes.h"
#include "base/time.h"
#include "base/win_util.h"
@@ -138,7 +139,7 @@ void TabContentsViewWin::StartDragging(const WebDropData& drop_data,
file_name = file_name.BaseName().RemoveExtension();
if (file_name.value().empty()) {
// Retrieve the name from the URL.
- file_name = net::GetSuggestedFilename(drop_data.url, "", "", "");
+ file_name = net::GetSuggestedFilename(drop_data.url, "", "", FilePath());
if (file_name.value().size() + drop_data.file_extension.size() + 1 >
MAX_PATH) {
file_name = FilePath(file_name.value().substr(
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index 9715aa0e..85151e9 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -1042,69 +1042,74 @@ std::wstring StripWWW(const std::wstring& text) {
FilePath GetSuggestedFilename(const GURL& url,
const std::string& content_disposition,
const std::string& referrer_charset,
- const char* default_name) {
- // TODO(rolandsteiner): as pointed out by darin in the code review, this is
- // hardly ideal. "download" should be translated, or another solution found.
- // (cf. http://code.google.com/p/chromium/issues/detail?id=25289)
- const char kFinalFallbackName[] = "download";
+ const FilePath& default_name) {
+ // We don't translate this fallback string, "download". If localization is
+ // needed, the caller should provide localized fallback default_name.
+ static const FilePath::CharType kFinalFallbackName[] =
+ FILE_PATH_LITERAL("download");
// about: and data: URLs don't have file names, but esp. data: URLs may
// contain parts that look like ones (i.e., contain a slash).
// Therefore we don't attempt to divine a file name out of them.
if (url.SchemeIs("about") || url.SchemeIs("data")) {
- return FilePath(UTF8ToFilePathString(
- default_name && default_name[0] ? default_name : kFinalFallbackName));
+ return default_name.empty() ? FilePath(kFinalFallbackName) : default_name;
}
- std::string filename = GetFileNameFromCD(content_disposition,
- referrer_charset);
+ const std::string filename_from_cd = GetFileNameFromCD(content_disposition,
+ referrer_charset);
+#if defined(OS_WIN)
+ FilePath::StringType filename = UTF8ToWide(filename_from_cd);
+#elif defined(OS_POSIX)
+ FilePath::StringType filename = filename_from_cd;
+#endif
+
if (!filename.empty()) {
// Remove any path information the server may have sent, take the name
// only.
-#if defined(OS_WIN)
- filename = UTF16ToUTF8(FilePath(UTF8ToUTF16(filename)).BaseName().value());
-#else
filename = FilePath(filename).BaseName().value();
-#endif
// Next, remove "." from the beginning and end of the file name to avoid
// tricks with hidden files, "..", and "."
- TrimString(filename, ".", &filename);
+ TrimString(filename, FILE_PATH_LITERAL("."), &filename);
}
if (filename.empty()) {
if (url.is_valid()) {
- filename = UnescapeURLComponent(
+ const std::string unescaped_url_filename = UnescapeURLComponent(
url.ExtractFileName(),
UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS);
+#if defined(OS_WIN)
+ filename = UTF8ToWide(unescaped_url_filename);
+#elif defined(OS_POSIX)
+ filename = unescaped_url_filename;
+#endif
}
}
// Trim '.' once more.
- TrimString(filename, ".", &filename);
+ TrimString(filename, FILE_PATH_LITERAL("."), &filename);
// If there's no filename or it gets trimed to be empty, use
// the URL hostname or default_name
if (filename.empty()) {
- if (default_name && default_name[0]) {
- filename = default_name;
+ if (!default_name.empty()) {
+ filename = default_name.value();
} else if (url.is_valid()) {
// Some schemes (e.g. file) do not have a hostname. Even though it's
// not likely to reach here, let's hardcode the last fallback name.
// TODO(jungshik) : Decode a 'punycoded' IDN hostname. (bug 1264451)
- filename = url.host().empty() ? std::string(kFinalFallbackName)
- : url.host();
+ filename = url.host().empty() ? kFinalFallbackName :
+#if defined(OS_WIN)
+ UTF8ToWide(url.host());
+#elif defined(OS_POSIX)
+ url.host();
+#endif
} else {
NOTREACHED();
}
}
-#if defined(OS_WIN)
- FilePath::StringType file_path_string = UTF8ToWide(filename);
-#else
- std::string& file_path_string = filename;
-#endif
- file_util::ReplaceIllegalCharactersInPath(&file_path_string, '-');
- return FilePath(file_path_string);
+ file_util::ReplaceIllegalCharactersInPath(&filename, '-');
+ return FilePath(filename);
}
bool IsPortAllowedByDefault(int port) {
diff --git a/net/base/net_util.h b/net/base/net_util.h
index 9ef4933..1f1516f 100644
--- a/net/base/net_util.h
+++ b/net/base/net_util.h
@@ -196,8 +196,8 @@ std::wstring StripWWW(const std::wstring& text);
// Gets the filename from the raw Content-Disposition header (as read from the
// network). Otherwise uses the last path component name or hostname from
-// |url|. If there is no filename or it can't be used, the given default name
-// will be used if specified.
+// |url|. If there is no filename or it can't be used, the given |default_name|,
+// will be used unless it is empty.
// Note: it's possible for the suggested filename to be empty (e.g.,
// file:///). referrer_charset is used as one of charsets
@@ -206,7 +206,7 @@ std::wstring StripWWW(const std::wstring& text);
FilePath GetSuggestedFilename(const GURL& url,
const std::string& content_disposition,
const std::string& referrer_charset,
- const char* default_name);
+ const FilePath& default_name);
// Checks the given port against a list of ports which are restricted by
// default. Returns true if the port is allowed, false if it is restricted.
diff --git a/net/base/net_util_unittest.cc b/net/base/net_util_unittest.cc
index 1445e43..07ec17c 100644
--- a/net/base/net_util_unittest.cc
+++ b/net/base/net_util_unittest.cc
@@ -5,6 +5,7 @@
#include "base/basictypes.h"
#include "base/file_path.h"
#include "base/string_util.h"
+#include "base/sys_string_conversions.h"
#include "base/time.h"
#include "googleurl/src/gurl.h"
#include "net/base/escape.h"
@@ -353,7 +354,7 @@ struct SuggestedFilenameCase {
const char* url;
const char* content_disp_header;
const char* referrer_charset;
- const char* default_filename;
+ const wchar_t* default_filename;
const wchar_t* expected_filename;
};
@@ -856,32 +857,32 @@ TEST(NetUtilTest, GetSuggestedFilename) {
{"http://www.google.com/",
"Content-disposition: attachment; filename=test.html",
"",
- "",
+ L"",
L"test.html"},
{"http://www.google.com/",
"Content-disposition: attachment; filename=\"test.html\"",
"",
- "",
+ L"",
L"test.html"},
{"http://www.google.com/path/test.html",
"Content-disposition: attachment",
"",
- "",
+ L"",
L"test.html"},
{"http://www.google.com/path/test.html",
"Content-disposition: attachment;",
"",
- "",
+ L"",
L"test.html"},
{"http://www.google.com/",
"",
"",
- "",
+ L"",
L"www.google.com"},
{"http://www.google.com/test.html",
"",
"",
- "",
+ L"",
L"test.html"},
// Now that we use googleurl's ExtractFileName, this case falls back
// to the hostname. If this behavior is not desirable, we'd better
@@ -889,117 +890,134 @@ TEST(NetUtilTest, GetSuggestedFilename) {
{"http://www.google.com/path/",
"",
"",
- "",
+ L"",
L"www.google.com"},
{"http://www.google.com/path",
"",
"",
- "",
+ L"",
L"path"},
{"file:///",
"",
"",
- "",
+ L"",
L"download"},
{"non-standard-scheme:",
"",
"",
- "",
+ L"",
L"download"},
{"http://www.google.com/",
"Content-disposition: attachment; filename =\"test.html\"",
"",
- "download",
+ L"download",
L"test.html"},
{"http://www.google.com/",
"",
"",
- "download",
+ L"download",
L"download"},
{"http://www.google.com/",
"Content-disposition: attachment; filename=\"../test.html\"",
"",
- "",
+ L"",
L"test.html"},
{"http://www.google.com/",
"Content-disposition: attachment; filename=\"..\"",
"",
- "download",
+ L"download",
L"download"},
{"http://www.google.com/test.html",
"Content-disposition: attachment; filename=\"..\"",
"",
- "download",
+ L"download",
L"test.html"},
// Below is a small subset of cases taken from GetFileNameFromCD test above.
{"http://www.google.com/",
"Content-Disposition: attachment; filename=\"%EC%98%88%EC%88%A0%20"
"%EC%98%88%EC%88%A0.jpg\"",
"",
- "",
+ L"",
L"\uc608\uc220 \uc608\uc220.jpg"},
{"http://www.google.com/%EC%98%88%EC%88%A0%20%EC%98%88%EC%88%A0.jpg",
"",
"",
- "download",
+ L"download",
L"\uc608\uc220 \uc608\uc220.jpg"},
{"http://www.google.com/",
"Content-disposition: attachment;",
"",
- "\xEB\x8B\xA4\xEC\x9A\xB4\xEB\xA1\x9C\xEB\x93\x9C",
+ L"\uB2E4\uC6B4\uB85C\uB4DC",
L"\uB2E4\uC6B4\uB85C\uB4DC"},
{"http://www.google.com/",
"Content-Disposition: attachment; filename=\"=?EUC-JP?Q?=B7=DD=BD="
"D13=2Epng?=\"",
"",
- "download",
+ L"download",
L"\u82b8\u88533.png"},
{"http://www.example.com/images?id=3",
"Content-Disposition: attachment; filename=caf\xc3\xa9.png",
"iso-8859-1",
- "",
+ L"",
L"caf\u00e9.png"},
{"http://www.example.com/images?id=3",
"Content-Disposition: attachment; filename=caf\xe5.png",
"windows-1253",
- "",
+ L"",
L"caf\u03b5.png"},
{"http://www.example.com/file?id=3",
"Content-Disposition: attachment; name=\xcf\xc2\xd4\xd8.zip",
"GBK",
- "",
+ L"",
L"\u4e0b\u8f7d.zip"},
// Invalid C-D header. Extracts filename from url.
{"http://www.google.com/test.html",
"Content-Disposition: attachment; filename==?iiso88591?Q?caf=EG?=",
"",
- "",
+ L"",
L"test.html"},
// about: and data: URLs
{"about:chrome",
"",
"",
- "",
+ L"",
L"download"},
{"data:,looks/like/a.path",
"",
"",
- "",
+ L"",
L"download"},
{"data:text/plain;base64,VG8gYmUgb3Igbm90IHRvIGJlLg=",
"",
"",
- "",
+ L"",
L"download"},
+ {"data:,looks/like/a.path",
+ "",
+ "",
+ L"default_filename_is_given",
+ L"default_filename_is_given"},
+ {"data:,looks/like/a.path",
+ "",
+ "",
+ L"\u65e5\u672c\u8a9e", // Japanese Kanji.
+ L"\u65e5\u672c\u8a9e"},
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) {
+#if defined(OS_WIN)
+ FilePath default_name(test_cases[i].default_filename);
+#else
+ FilePath default_name(
+ base::SysWideToNativeMB(test_cases[i].default_filename));
+#endif
FilePath filename = net::GetSuggestedFilename(
GURL(test_cases[i].url), test_cases[i].content_disp_header,
- test_cases[i].referrer_charset, test_cases[i].default_filename);
+ test_cases[i].referrer_charset, default_name);
#if defined(OS_WIN)
EXPECT_EQ(std::wstring(test_cases[i].expected_filename), filename.value())
#else
- EXPECT_EQ(WideToUTF8(test_cases[i].expected_filename), filename.value())
+ EXPECT_EQ(base::SysWideToNativeMB(test_cases[i].expected_filename),
+ filename.value())
#endif
<< "Iteration " << i << ": " << test_cases[i].url;
}
diff --git a/webkit/glue/weburlloader_impl.cc b/webkit/glue/weburlloader_impl.cc
index 7f53df5..4fcc1372 100644
--- a/webkit/glue/weburlloader_impl.cc
+++ b/webkit/glue/weburlloader_impl.cc
@@ -6,6 +6,7 @@
#include "webkit/glue/weburlloader_impl.h"
+#include "base/file_path.h"
#include "base/message_loop.h"
#include "base/process_util.h"
#include "base/string_util.h"
@@ -167,13 +168,8 @@ void PopulateURLResponse(
// pass it to GetSuggestedFilename.
std::string value;
if (headers->EnumerateHeader(NULL, "content-disposition", &value)) {
-#if defined(OS_WIN)
- response->setSuggestedFileName(
- net::GetSuggestedFilename(url, value, "", "").value());
-#else
- response->setSuggestedFileName(UTF8ToUTF16(
- net::GetSuggestedFilename(url, value, "", "").value()));
-#endif
+ response->setSuggestedFileName(webkit_glue::FilePathToWebString(
+ net::GetSuggestedFilename(url, value, "", FilePath())));
}
Time time_val;