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

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

Issue 297003: Implement URLRequestDataJob (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 2 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 | « no previous file | net/base/net_util_unittest.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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/net_util.h" 5 #include "net/base/net_util.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <unicode/ucnv.h> 9 #include <unicode/ucnv.h>
10 #include <unicode/uidna.h> 10 #include <unicode/uidna.h>
(...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 std::wstring StripWWW(const std::wstring& text) { 1029 std::wstring StripWWW(const std::wstring& text) {
1030 const std::wstring www(L"www."); 1030 const std::wstring www(L"www.");
1031 return (text.compare(0, www.length(), www) == 0) ? 1031 return (text.compare(0, www.length(), www) == 0) ?
1032 text.substr(www.length()) : text; 1032 text.substr(www.length()) : text;
1033 } 1033 }
1034 1034
1035 std::wstring GetSuggestedFilename(const GURL& url, 1035 std::wstring GetSuggestedFilename(const GURL& url,
1036 const std::string& content_disposition, 1036 const std::string& content_disposition,
1037 const std::string& referrer_charset, 1037 const std::string& referrer_charset,
1038 const std::wstring& default_name) { 1038 const std::wstring& default_name) {
1039 // TODO(rolandsteiner): as pointed out by darin in the code review, this is
1040 // hardly ideal. "download" should be translated, or another solution found.
1041 // (cf. http://code.google.com/p/chromium/issues/detail?id=25289)
1042 const wchar_t kFinalFallbackName[] = L"download";
1043
1044 // about: and data: URLs don't have file names, but esp. data: URLs may
1045 // contain parts that look like ones (i.e., contain a slash).
1046 // Therefore we don't attempt to divine a file name out of them.
1047 if (url.SchemeIs("about") || url.SchemeIs("data"))
1048 return default_name.empty() ? std::wstring(kFinalFallbackName)
1049 : default_name;
1050
1039 std::wstring filename = GetFileNameFromCD(content_disposition, 1051 std::wstring filename = GetFileNameFromCD(content_disposition,
1040 referrer_charset); 1052 referrer_charset);
1041 if (!filename.empty()) { 1053 if (!filename.empty()) {
1042 // Remove any path information the server may have sent, take the name 1054 // Remove any path information the server may have sent, take the name
1043 // only. 1055 // only.
1044 filename = file_util::GetFilenameFromPath(filename); 1056 filename = file_util::GetFilenameFromPath(filename);
1045 // Next, remove "." from the beginning and end of the file name to avoid 1057 // Next, remove "." from the beginning and end of the file name to avoid
1046 // tricks with hidden files, "..", and "." 1058 // tricks with hidden files, "..", and "."
1047 TrimString(filename, L".", &filename); 1059 TrimString(filename, L".", &filename);
1048 } 1060 }
1049 if (filename.empty()) { 1061 if (filename.empty()) {
1050 if (url.is_valid()) { 1062 if (url.is_valid()) {
1051 filename = UnescapeAndDecodeUTF8URLComponent( 1063 filename = UnescapeAndDecodeUTF8URLComponent(
1052 url.ExtractFileName(), 1064 url.ExtractFileName(),
1053 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); 1065 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS);
1054 } 1066 }
1055 } 1067 }
1056 1068
1057 // Trim '.' once more. 1069 // Trim '.' once more.
1058 TrimString(filename, L".", &filename); 1070 TrimString(filename, L".", &filename);
1059 // If there's no filename or it gets trimed to be empty, use 1071 // If there's no filename or it gets trimed to be empty, use
1060 // the URL hostname or default_name 1072 // the URL hostname or default_name
1061 if (filename.empty()) { 1073 if (filename.empty()) {
1062 if (!default_name.empty()) { 1074 if (!default_name.empty()) {
1063 filename = default_name; 1075 filename = default_name;
1064 } else if (url.is_valid()) { 1076 } else if (url.is_valid()) {
1065 // Some schemes (e.g. file) do not have a hostname. Even though it's 1077 // Some schemes (e.g. file) do not have a hostname. Even though it's
1066 // not likely to reach here, let's hardcode the last fallback name. 1078 // not likely to reach here, let's hardcode the last fallback name.
1067 // TODO(jungshik) : Decode a 'punycoded' IDN hostname. (bug 1264451) 1079 // TODO(jungshik) : Decode a 'punycoded' IDN hostname. (bug 1264451)
1068 filename = url.host().empty() ? L"download" : UTF8ToWide(url.host()); 1080 filename = url.host().empty() ? std::wstring(kFinalFallbackName)
1081 : UTF8ToWide(url.host());
1069 } else { 1082 } else {
1070 NOTREACHED(); 1083 NOTREACHED();
1071 } 1084 }
1072 } 1085 }
1073 1086
1074 file_util::ReplaceIllegalCharacters(&filename, '-'); 1087 file_util::ReplaceIllegalCharacters(&filename, '-');
1075 return filename; 1088 return filename;
1076 } 1089 }
1077 1090
1078 bool IsPortAllowedByDefault(int port) { 1091 bool IsPortAllowedByDefault(int port) {
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1414 if (length > 0) 1427 if (length > 0)
1415 ports.insert(StringToInt(WideToASCII( 1428 ports.insert(StringToInt(WideToASCII(
1416 allowed_ports.substr(last, length)))); 1429 allowed_ports.substr(last, length))));
1417 last = i + 1; 1430 last = i + 1;
1418 } 1431 }
1419 } 1432 }
1420 explicitly_allowed_ports = ports; 1433 explicitly_allowed_ports = ports;
1421 } 1434 }
1422 1435
1423 } // namespace net 1436 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/base/net_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698