Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Unified Diff: net/base/net_util.cc

Issue 83002: download filename fix (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/net_util.h ('k') | net/base/net_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/net_util.cc
===================================================================
--- net/base/net_util.cc (revision 15065)
+++ net/base/net_util.cc (working copy)
@@ -247,17 +247,22 @@
}
bool DecodeWord(const std::string& encoded_word,
+ const std::string& referrer_charset,
bool *is_rfc2047,
std::string* output) {
- // TODO(jungshik) : Revisit this later. Do we want to pass through non-ASCII
- // strings which can be mozibake? WinHTTP converts a raw 8bit string
- // UTF-16 assuming it's in the OS default encoding.
if (!IsStringASCII(encoded_word)) {
- // Try falling back to the NativeMB encoding if the raw input is not UTF-8.
+ // Try UTF-8, referrer_charset and the native OS default charset in turn.
if (IsStringUTF8(encoded_word)) {
*output = encoded_word;
} else {
- *output = WideToUTF8(base::SysNativeMBToWide(encoded_word));
+ std::wstring wide_output;
+ if (!referrer_charset.empty() &&
+ CodepageToWide(encoded_word, referrer_charset.c_str(),
+ OnStringUtilConversionError::FAIL, &wide_output)) {
+ *output = WideToUTF8(wide_output);
+ } else {
+ *output = WideToUTF8(base::SysNativeMBToWide(encoded_word));
+ }
}
*is_rfc2047 = false;
return true;
@@ -357,7 +362,9 @@
return false;
}
-bool DecodeParamValue(const std::string& input, std::string* output) {
+bool DecodeParamValue(const std::string& input,
+ const std::string& referrer_charset,
+ std::string* output) {
std::string tmp;
// Tokenize with whitespace characters.
StringTokenizer t(input, " \t\n\r");
@@ -378,7 +385,8 @@
// in a single encoded-word. Firefox/Thunderbird do not support
// it, either.
std::string decoded;
- if (!DecodeWord(t.token(), &is_previous_token_rfc2047, &decoded))
+ if (!DecodeWord(t.token(), referrer_charset, &is_previous_token_rfc2047,
+ &decoded))
return false;
tmp.append(decoded);
}
@@ -683,7 +691,8 @@
return GetSpecificHeaderT(headers, name);
}
-std::wstring GetFileNameFromCD(const std::string& header) {
+std::wstring GetFileNameFromCD(const std::string& header,
+ const std::string& referrer_charset) {
std::string param_value = GetHeaderParamValue(header, "filename");
if (param_value.empty()) {
// Some servers use 'name' parameter.
@@ -692,7 +701,7 @@
if (param_value.empty())
return std::wstring();
std::string decoded;
- if (DecodeParamValue(param_value, &decoded))
+ if (DecodeParamValue(param_value, referrer_charset, &decoded))
return UTF8ToWide(decoded);
return std::wstring();
}
@@ -863,8 +872,10 @@
std::wstring GetSuggestedFilename(const GURL& url,
const std::string& content_disposition,
+ const std::string& referrer_charset,
const std::wstring& default_name) {
- std::wstring filename = GetFileNameFromCD(content_disposition);
+ std::wstring filename = GetFileNameFromCD(content_disposition,
+ referrer_charset);
if (!filename.empty()) {
// Remove any path information the server may have sent, take the name
// only.
@@ -901,13 +912,6 @@
return filename;
}
-std::wstring GetSuggestedFilename(const GURL& url,
- const std::wstring& content_disposition,
- const std::wstring& default_name) {
- return GetSuggestedFilename(
- url, WideToUTF8(content_disposition), default_name);
-}
-
bool IsPortAllowedByDefault(int port) {
int array_size = arraysize(kRestrictedPorts);
for (int i = 0; i < array_size; i++) {
« no previous file with comments | « net/base/net_util.h ('k') | net/base/net_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698