This CL makes Chrome on par with Firefox in terms of 'GetSuggestedFilename' for file download via context-menu.
For a download initiated with a click on a link in a web page, a webkit-side change is necessary, which will be done later.
Add a field (referrer_charset) to URLRequestContext and DownloadCreateInfo. It's set to the character encoding of a document where the download request originates from when it's known (download initiated via "save as" in the context menu).
If it's not known (a download initiated by clicking on a download link or typing a url directly to the omnibox), it's initialized to the default character encoding in the user's preference. I guess this is marginally better than leaving it empty (in that case, step 2b below will be skipped and step 2c will be taken) because a user has a better control over how raw 8bit characters in C-D are interpreted (especially on Windows where a reboot is required to change the OS default codepage).
This is later passed to GetSuggestedFilename and used as one of fallback encodings (1. UTF-8, 2. origin_charset, 3. default OS codepage). With this change, we support the following:
1. RFC 2047
2. Raw-8bit-characters : a. UTF-8, b. origin_charset, c. default os codepage.
3. %-escaped UTF-8.
In this CL, for #3, I didn't add a fallback similar to one used for #2. If necessary, it can be added easily. New entries are added to 3 existing tests. What's previously not covered (raw 8bit Content-Disposition header) is now covered in all 3 tests.
BUG=1148
TEST=net unit test: NetUtilTest.GetFileNameFromCD
NetUtilTest.GetSuggestedFilename
unittest : DownloadManagerTest.TestDownloadFilename
Review URL: http://codereview.chromium.org/83002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15113 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/webkit/glue/context_menu_client_impl.cc b/webkit/glue/context_menu_client_impl.cc
index 2947968..8fca4a6 100644
--- a/webkit/glue/context_menu_client_impl.cc
+++ b/webkit/glue/context_menu_client_impl.cc
@@ -177,7 +177,8 @@
GURL page_url;
std::string security_info;
- std::wstring frame_encoding;
+ std::string frame_charset = WideToASCII(
+ webkit_glue::StringToStdWString(selected_frame->loader()->encoding()));
// Send the frame and page URLs in any case.
ContextNode frame_node = ContextNode(ContextNode::NONE);
ContextNode page_node =
@@ -188,8 +189,6 @@
frame_node = GetTypeAndURLFromFrame(selected_frame,
&frame_url,
ContextNode(ContextNode::FRAME));
- frame_encoding = webkit_glue::StringToStdWString(
- selected_frame->loader()->encoding());
}
if (r.isSelected()) {
@@ -253,7 +252,8 @@
selection_text_string,
misspelled_word_string,
edit_flags,
- security_info);
+ security_info,
+ frame_charset);
}
return NULL;
}