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

Side by Side Diff: net/base/filename_util.cc

Issue 252733002: Consolidate most of net/'s icu_string_conversions.h dependencies. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Response to comments (x2) 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/base/filename_util.h" 5 #include "net/base/filename_util.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/i18n/file_util_icu.h" 9 #include "base/i18n/file_util_icu.h"
10 #include "base/i18n/icu_string_conversions.h"
11 #include "base/path_service.h" 10 #include "base/path_service.h"
12 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
13 #include "base/strings/sys_string_conversions.h" 12 #include "base/strings/sys_string_conversions.h"
14 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
15 #include "base/threading/thread_restrictions.h" 14 #include "base/threading/thread_restrictions.h"
16 #include "net/base/escape.h" 15 #include "net/base/escape.h"
17 #include "net/base/mime_util.h" 16 #include "net/base/mime_util.h"
17 #include "net/base/net_string_util.h"
18 #include "net/http/http_content_disposition.h" 18 #include "net/http/http_content_disposition.h"
19 #include "url/gurl.h" 19 #include "url/gurl.h"
20 20
21 namespace net { 21 namespace net {
22 22
23 namespace { 23 namespace {
24 24
25 // what we prepend to get a file URL 25 // what we prepend to get a file URL
26 static const base::FilePath::CharType kFileURLPrefix[] = 26 static const base::FilePath::CharType kFileURLPrefix[] =
27 FILE_PATH_LITERAL("file:///"); 27 FILE_PATH_LITERAL("file:///");
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 url.ExtractFileName(), 70 url.ExtractFileName(),
71 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); 71 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS);
72 72
73 // The URL's path should be escaped UTF-8, but may not be. 73 // The URL's path should be escaped UTF-8, but may not be.
74 std::string decoded_filename = unescaped_url_filename; 74 std::string decoded_filename = unescaped_url_filename;
75 if (!IsStringUTF8(decoded_filename)) { 75 if (!IsStringUTF8(decoded_filename)) {
76 // TODO(jshin): this is probably not robust enough. To be sure, we need 76 // TODO(jshin): this is probably not robust enough. To be sure, we need
77 // encoding detection. 77 // encoding detection.
78 base::string16 utf16_output; 78 base::string16 utf16_output;
79 if (!referrer_charset.empty() && 79 if (!referrer_charset.empty() &&
80 base::CodepageToUTF16(unescaped_url_filename, 80 net::ConvertToUTF16(unescaped_url_filename,
81 referrer_charset.c_str(), 81 referrer_charset.c_str(),
82 base::OnStringConversionError::FAIL, 82 &utf16_output)) {
83 &utf16_output)) {
84 decoded_filename = base::UTF16ToUTF8(utf16_output); 83 decoded_filename = base::UTF16ToUTF8(utf16_output);
85 } else { 84 } else {
86 decoded_filename = base::WideToUTF8( 85 decoded_filename = base::WideToUTF8(
87 base::SysNativeMBToWide(unescaped_url_filename)); 86 base::SysNativeMBToWide(unescaped_url_filename));
88 } 87 }
89 } 88 }
90 // If the URL contains a (possibly empty) query, assume it is a generator, and 89 // If the URL contains a (possibly empty) query, assume it is a generator, and
91 // allow the determined extension to be overwritten. 90 // allow the determined extension to be overwritten.
92 *should_overwrite_extension = !decoded_filename.empty() && url.has_query(); 91 *should_overwrite_extension = !decoded_filename.empty() && url.has_query();
93 92
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 // utf8 encoded characters in name. 496 // utf8 encoded characters in name.
498 file_util::NormalizeFileNameEncoding(&generated_name); 497 file_util::NormalizeFileNameEncoding(&generated_name);
499 #endif 498 #endif
500 499
501 DCHECK(!generated_name.empty()); 500 DCHECK(!generated_name.empty());
502 501
503 return generated_name; 502 return generated_name;
504 } 503 }
505 504
506 } // namespace net 505 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698