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

Side by Side Diff: net/base/net_util.h

Issue 83002: download filename fix (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 | « chrome/renderer/render_view.cc ('k') | net/base/net_util.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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #ifndef NET_BASE_NET_UTIL_H__ 5 #ifndef NET_BASE_NET_UTIL_H__
6 #define NET_BASE_NET_UTIL_H__ 6 #define NET_BASE_NET_UTIL_H__
7 7
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 9
10 #include <string> 10 #include <string>
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 const std::string& name); 64 const std::string& name);
65 65
66 // Return the value of the HTTP response header field's parameter named 66 // Return the value of the HTTP response header field's parameter named
67 // 'param_name'. Returns the empty string if the parameter is not found or is 67 // 'param_name'. Returns the empty string if the parameter is not found or is
68 // improperly formatted. 68 // improperly formatted.
69 std::wstring GetHeaderParamValue(const std::wstring& field, 69 std::wstring GetHeaderParamValue(const std::wstring& field,
70 const std::wstring& param_name); 70 const std::wstring& param_name);
71 std::string GetHeaderParamValue(const std::string& field, 71 std::string GetHeaderParamValue(const std::string& field,
72 const std::string& param_name); 72 const std::string& param_name);
73 73
74 // Return the filename extracted from Content-Disposition header. Only two 74 // Return the filename extracted from Content-Disposition header. The following
75 // formats are supported: a. %-escaped UTF-8 b. RFC 2047. 75 // formats are tried in order listed below:
76 // 76 //
77 // A non-ASCII param value is just returned as it is (assuming a NativeMB 77 // 1. RFC 2047
78 // encoding). When a param value is ASCII, but is not in one of two forms 78 // 2. Raw-8bit-characters :
79 // supported, it is returned as it is unless it's pretty close to two supported 79 // a. UTF-8, b. referrer_charset, c. default os codepage.
80 // 3. %-escaped UTF-8.
81 //
82 // In step 2, if referrer_charset is empty(i.e. unknown), 2b is skipped.
83 // In step 3, the fallback charsets tried in step 2 are not tried. We
84 // can consider doing that later.
85 //
86 // When a param value is ASCII, but is not in format #1 or format #3 above,
87 // it is returned as it is unless it's pretty close to two supported
80 // formats but not well-formed. In that case, an empty string is returned. 88 // formats but not well-formed. In that case, an empty string is returned.
81 // 89 //
82 // In any case, a caller must check for the empty return value and resort to 90 // In any case, a caller must check for the empty return value and resort to
83 // another means to get a filename (e.g. url). 91 // another means to get a filename (e.g. url).
84 // 92 //
85 // This function does not do any escaping and callers are responsible for 93 // This function does not do any escaping and callers are responsible for
86 // escaping 'unsafe' characters (e.g. (back)slash, colon) as they see fit. 94 // escaping 'unsafe' characters (e.g. (back)slash, colon) as they see fit.
87 // 95 //
88 // TODO(jungshik): revisit this issue. At the moment, the only caller 96 // TODO(jungshik): revisit this issue. At the moment, the only caller
89 // net_util::GetSuggestedFilename and it calls ReplaceIllegalCharacters. The 97 // net_util::GetSuggestedFilename and it calls ReplaceIllegalCharacters. The
90 // other caller is a unit test. Need to figure out expose this function only to 98 // other caller is a unit test. Need to figure out expose this function only to
91 // net_util_unittest. 99 // net_util_unittest.
92 // 100 //
93 std::wstring GetFileNameFromCD(const std::string& header); 101 std::wstring GetFileNameFromCD(const std::string& header,
102 const std::string& referrer_charset);
94 103
95 // Converts the given host name to unicode characters, APPENDING them to the 104 // Converts the given host name to unicode characters, APPENDING them to the
96 // the given output string. This can be called for any host name, if the 105 // the given output string. This can be called for any host name, if the
97 // input is not IDN or is invalid in some way, we'll just append the ASCII 106 // input is not IDN or is invalid in some way, we'll just append the ASCII
98 // source to the output so it is still usable. 107 // source to the output so it is still usable.
99 // 108 //
100 // The input should be the canonicalized ASCII host name from GURL. This 109 // The input should be the canonicalized ASCII host name from GURL. This
101 // function does NOT accept UTF-8! Its length must also be given (this is 110 // function does NOT accept UTF-8! Its length must also be given (this is
102 // designed to work on the substring of the host out of a URL spec). 111 // designed to work on the substring of the host out of a URL spec).
103 // 112 //
(...skipping 22 matching lines...) Expand all
126 std::string GetDirectoryListingEntry(const std::string& name, bool is_dir, 135 std::string GetDirectoryListingEntry(const std::string& name, bool is_dir,
127 int64 size, const base::Time& modified); 136 int64 size, const base::Time& modified);
128 137
129 // If text starts with "www." it is removed, otherwise text is returned 138 // If text starts with "www." it is removed, otherwise text is returned
130 // unmodified. 139 // unmodified.
131 std::wstring StripWWW(const std::wstring& text); 140 std::wstring StripWWW(const std::wstring& text);
132 141
133 // Gets the filename from the raw Content-Disposition header (as read from the 142 // Gets the filename from the raw Content-Disposition header (as read from the
134 // network). Otherwise uses the last path component name or hostname from 143 // network). Otherwise uses the last path component name or hostname from
135 // |url|. Note: it's possible for the suggested filename to be empty (e.g., 144 // |url|. Note: it's possible for the suggested filename to be empty (e.g.,
136 // file:/// or view-cache:). 145 // file:/// or view-cache:). referrer_charset is used as one of charsets
146 // to interpret a raw 8bit string in C-D header (after interpreting
147 // as UTF-8 fails). See the comment for GetFilenameFromCD for more details.
137 std::wstring GetSuggestedFilename(const GURL& url, 148 std::wstring GetSuggestedFilename(const GURL& url,
138 const std::string& content_disposition, 149 const std::string& content_disposition,
139 const std::wstring& default_name); 150 const std::string& referrer_charset,
140
141 // DEPRECATED: Please use the above version of this method.
142 std::wstring GetSuggestedFilename(const GURL& url,
143 const std::wstring& content_disposition,
144 const std::wstring& default_name); 151 const std::wstring& default_name);
145 152
146 // Checks the given port against a list of ports which are restricted by 153 // Checks the given port against a list of ports which are restricted by
147 // default. Returns true if the port is allowed, false if it is restricted. 154 // default. Returns true if the port is allowed, false if it is restricted.
148 bool IsPortAllowedByDefault(int port); 155 bool IsPortAllowedByDefault(int port);
149 156
150 // Checks the given port against a list of ports which are restricted by the 157 // Checks the given port against a list of ports which are restricted by the
151 // FTP protocol. Returns true if the port is allowed, false if it is 158 // FTP protocol. Returns true if the port is allowed, false if it is
152 // restricted. 159 // restricted.
153 bool IsPortAllowedByFtp(int port); 160 bool IsPortAllowedByFtp(int port);
154 161
155 // Set socket to non-blocking mode 162 // Set socket to non-blocking mode
156 int SetNonBlocking(int fd); 163 int SetNonBlocking(int fd);
157 164
158 } // namespace net 165 } // namespace net
159 166
160 #endif // NET_BASE_NET_UTIL_H__ 167 #endif // NET_BASE_NET_UTIL_H__
OLDNEW
« no previous file with comments | « chrome/renderer/render_view.cc ('k') | net/base/net_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698