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

Side by Side Diff: net/http/http_content_disposition.cc

Issue 270183002: Move IsStringUTF8/ASCII to base namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more minor nit Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/ftp/ftp_network_transaction.cc ('k') | net/proxy/proxy_resolver_v8.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/http_content_disposition.h" 5 #include "net/http/http_content_disposition.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/string_tokenizer.h" 9 #include "base/strings/string_tokenizer.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 bool DecodeWord(const std::string& encoded_word, 79 bool DecodeWord(const std::string& encoded_word,
80 const std::string& referrer_charset, 80 const std::string& referrer_charset,
81 bool* is_rfc2047, 81 bool* is_rfc2047,
82 std::string* output, 82 std::string* output,
83 int* parse_result_flags) { 83 int* parse_result_flags) {
84 *is_rfc2047 = false; 84 *is_rfc2047 = false;
85 output->clear(); 85 output->clear();
86 if (encoded_word.empty()) 86 if (encoded_word.empty())
87 return true; 87 return true;
88 88
89 if (!IsStringASCII(encoded_word)) { 89 if (!base::IsStringASCII(encoded_word)) {
90 // Try UTF-8, referrer_charset and the native OS default charset in turn. 90 // Try UTF-8, referrer_charset and the native OS default charset in turn.
91 if (IsStringUTF8(encoded_word)) { 91 if (base::IsStringUTF8(encoded_word)) {
92 *output = encoded_word; 92 *output = encoded_word;
93 } else { 93 } else {
94 base::string16 utf16_output; 94 base::string16 utf16_output;
95 if (!referrer_charset.empty() && 95 if (!referrer_charset.empty() &&
96 net::ConvertToUTF16(encoded_word, referrer_charset.c_str(), 96 net::ConvertToUTF16(encoded_word, referrer_charset.c_str(),
97 &utf16_output)) { 97 &utf16_output)) {
98 *output = base::UTF16ToUTF8(utf16_output); 98 *output = base::UTF16ToUTF8(utf16_output);
99 } else { 99 } else {
100 *output = base::WideToUTF8(base::SysNativeMBToWide(encoded_word)); 100 *output = base::WideToUTF8(base::SysNativeMBToWide(encoded_word));
101 } 101 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 // We're not handling 'especial' characters quoted with '\', but 184 // We're not handling 'especial' characters quoted with '\', but
185 // it should be Ok because we're not an email client but a 185 // it should be Ok because we're not an email client but a
186 // web browser. 186 // web browser.
187 187
188 // What IE6/7 does: %-escaped UTF-8. 188 // What IE6/7 does: %-escaped UTF-8.
189 decoded_word = net::UnescapeURLComponent(encoded_word, 189 decoded_word = net::UnescapeURLComponent(encoded_word,
190 net::UnescapeRule::SPACES); 190 net::UnescapeRule::SPACES);
191 if (decoded_word != encoded_word) 191 if (decoded_word != encoded_word)
192 *parse_result_flags |= 192 *parse_result_flags |=
193 net::HttpContentDisposition::HAS_PERCENT_ENCODED_STRINGS; 193 net::HttpContentDisposition::HAS_PERCENT_ENCODED_STRINGS;
194 if (IsStringUTF8(decoded_word)) { 194 if (base::IsStringUTF8(decoded_word)) {
195 output->swap(decoded_word); 195 output->swap(decoded_word);
196 return true; 196 return true;
197 // We can try either the OS default charset or 'origin charset' here, 197 // We can try either the OS default charset or 'origin charset' here,
198 // As far as I can tell, IE does not support it. However, I've seen 198 // As far as I can tell, IE does not support it. However, I've seen
199 // web servers emit %-escaped string in a legacy encoding (usually 199 // web servers emit %-escaped string in a legacy encoding (usually
200 // origin charset). 200 // origin charset).
201 // TODO(jungshik) : Test IE further and consider adding a fallback here. 201 // TODO(jungshik) : Test IE further and consider adding a fallback here.
202 } 202 }
203 return false; 203 return false;
204 } 204 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 bool DecodeExtValue(const std::string& param_value, std::string* decoded) { 310 bool DecodeExtValue(const std::string& param_value, std::string* decoded) {
311 if (param_value.find('"') != std::string::npos) 311 if (param_value.find('"') != std::string::npos)
312 return false; 312 return false;
313 313
314 std::string charset; 314 std::string charset;
315 std::string value; 315 std::string value;
316 if (!ParseExtValueComponents(param_value, &charset, &value)) 316 if (!ParseExtValueComponents(param_value, &charset, &value))
317 return false; 317 return false;
318 318
319 // RFC 5987 value should be ASCII-only. 319 // RFC 5987 value should be ASCII-only.
320 if (!IsStringASCII(value)) { 320 if (!base::IsStringASCII(value)) {
321 decoded->clear(); 321 decoded->clear();
322 return true; 322 return true;
323 } 323 }
324 324
325 std::string unescaped = net::UnescapeURLComponent( 325 std::string unescaped = net::UnescapeURLComponent(
326 value, net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS); 326 value, net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS);
327 327
328 return net::ConvertToUtf8AndNormalize(unescaped, charset.c_str(), decoded); 328 return net::ConvertToUtf8AndNormalize(unescaped, charset.c_str(), decoded);
329 } 329 }
330 330
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 429
430 if (!ext_filename.empty()) 430 if (!ext_filename.empty())
431 filename_ = ext_filename; 431 filename_ = ext_filename;
432 else if (!filename.empty()) 432 else if (!filename.empty())
433 filename_ = filename; 433 filename_ = filename;
434 else 434 else
435 filename_ = name; 435 filename_ = name;
436 } 436 }
437 437
438 } // namespace net 438 } // namespace net
OLDNEW
« no previous file with comments | « net/ftp/ftp_network_transaction.cc ('k') | net/proxy/proxy_resolver_v8.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698