| OLD | NEW |
| 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 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <unicode/ucnv.h> | 6 #include <unicode/ucnv.h> |
| 7 #include <unicode/uidna.h> | 7 #include <unicode/uidna.h> |
| 8 #include <unicode/ulocdata.h> | 8 #include <unicode/ulocdata.h> |
| 9 #include <unicode/uniset.h> | 9 #include <unicode/uniset.h> |
| 10 #include <unicode/uscript.h> | 10 #include <unicode/uscript.h> |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 out->resize(host_begin_in_output + comp_len); | 649 out->resize(host_begin_in_output + comp_len); |
| 650 for (int i = 0; i < comp_len; i++) | 650 for (int i = 0; i < comp_len; i++) |
| 651 (*out)[host_begin_in_output + i] = comp[i]; | 651 (*out)[host_begin_in_output + i] = comp[i]; |
| 652 } | 652 } |
| 653 | 653 |
| 654 } // namespace | 654 } // namespace |
| 655 | 655 |
| 656 namespace net { | 656 namespace net { |
| 657 | 657 |
| 658 // Appends the substring |in_component| inside of the URL |spec| to |output|, | 658 // Appends the substring |in_component| inside of the URL |spec| to |output|, |
| 659 // and the resulting range will be filled into |out_component|. Calls the | 659 // and the resulting range will be filled into |out_component|. |unescape_rules| |
| 660 // unescaper for the substring if |unescape| is true. | 660 // defines how to clean the URL for human readability. |
| 661 static void AppendFormattedComponent(const std::string& spec, | 661 static void AppendFormattedComponent(const std::string& spec, |
| 662 const url_parse::Component& in_component, | 662 const url_parse::Component& in_component, |
| 663 bool unescape, | 663 UnescapeRule::Type unescape_rules, |
| 664 std::wstring* output, | 664 std::wstring* output, |
| 665 url_parse::Component* out_component); | 665 url_parse::Component* out_component); |
| 666 | 666 |
| 667 GURL FilePathToFileURL(const FilePath& path) { | 667 GURL FilePathToFileURL(const FilePath& path) { |
| 668 // Produce a URL like "file:///C:/foo" for a regular file, or | 668 // Produce a URL like "file:///C:/foo" for a regular file, or |
| 669 // "file://///server/path" for UNC. The URL canonicalizer will fix up the | 669 // "file://///server/path" for UNC. The URL canonicalizer will fix up the |
| 670 // latter case to be the canonical UNC form: "file://server/path" | 670 // latter case to be the canonical UNC form: "file://server/path" |
| 671 FilePath::StringType url_string(kFileURLPrefix); | 671 FilePath::StringType url_string(kFileURLPrefix); |
| 672 url_string.append(path.value()); | 672 url_string.append(path.value()); |
| 673 | 673 |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1077 static_cast<int>(output->length()) - new_parsed->host.begin; | 1077 static_cast<int>(output->length()) - new_parsed->host.begin; |
| 1078 } | 1078 } |
| 1079 } else if (new_parsed) { | 1079 } else if (new_parsed) { |
| 1080 new_parsed->host.reset(); | 1080 new_parsed->host.reset(); |
| 1081 } | 1081 } |
| 1082 } | 1082 } |
| 1083 | 1083 |
| 1084 /* static */ | 1084 /* static */ |
| 1085 void AppendFormattedComponent(const std::string& spec, | 1085 void AppendFormattedComponent(const std::string& spec, |
| 1086 const url_parse::Component& in_component, | 1086 const url_parse::Component& in_component, |
| 1087 bool unescape, | 1087 UnescapeRule::Type unescape_rules, |
| 1088 std::wstring* output, | 1088 std::wstring* output, |
| 1089 url_parse::Component* out_component) { | 1089 url_parse::Component* out_component) { |
| 1090 if (in_component.is_nonempty()) { | 1090 if (in_component.is_nonempty()) { |
| 1091 out_component->begin = static_cast<int>(output->length()); | 1091 out_component->begin = static_cast<int>(output->length()); |
| 1092 if (unescape) { | 1092 if (unescape_rules == UnescapeRule::NONE) { |
| 1093 output->append(UTF8ToWide(spec.substr( |
| 1094 in_component.begin, in_component.len))); |
| 1095 } else { |
| 1093 output->append(UnescapeAndDecodeUTF8URLComponent( | 1096 output->append(UnescapeAndDecodeUTF8URLComponent( |
| 1094 spec.substr(in_component.begin, in_component.len), | 1097 spec.substr(in_component.begin, in_component.len), |
| 1095 UnescapeRule::NORMAL)); | 1098 unescape_rules)); |
| 1096 } else { | |
| 1097 output->append(UTF8ToWide(spec.substr( | |
| 1098 in_component.begin, in_component.len))); | |
| 1099 } | 1099 } |
| 1100 out_component->len = | 1100 out_component->len = |
| 1101 static_cast<int>(output->length()) - out_component->begin; | 1101 static_cast<int>(output->length()) - out_component->begin; |
| 1102 } else { | 1102 } else { |
| 1103 out_component->reset(); | 1103 out_component->reset(); |
| 1104 } | 1104 } |
| 1105 } | 1105 } |
| 1106 | 1106 |
| 1107 std::wstring FormatUrl( | 1107 std::wstring FormatUrl(const GURL& url, |
| 1108 const GURL& url, const std::wstring& languages, bool omit_username_password, | 1108 const std::wstring& languages, |
| 1109 bool unescape, url_parse::Parsed* new_parsed, size_t* prefix_end) { | 1109 bool omit_username_password, |
| 1110 UnescapeRule::Type unescape_rules, |
| 1111 url_parse::Parsed* new_parsed, |
| 1112 size_t* prefix_end) { |
| 1110 url_parse::Parsed parsed_temp; | 1113 url_parse::Parsed parsed_temp; |
| 1111 if (!new_parsed) | 1114 if (!new_parsed) |
| 1112 new_parsed = &parsed_temp; | 1115 new_parsed = &parsed_temp; |
| 1113 | 1116 |
| 1114 std::wstring url_string; | 1117 std::wstring url_string; |
| 1115 | 1118 |
| 1116 // Check for empty URLs or 0 available text width. | 1119 // Check for empty URLs or 0 available text width. |
| 1117 if (url.is_empty()) { | 1120 if (url.is_empty()) { |
| 1118 if (prefix_end) | 1121 if (prefix_end) |
| 1119 *prefix_end = 0; | 1122 *prefix_end = 0; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1133 new_parsed->scheme = parsed.scheme; | 1136 new_parsed->scheme = parsed.scheme; |
| 1134 | 1137 |
| 1135 if (omit_username_password) { | 1138 if (omit_username_password) { |
| 1136 // Remove the username and password fields. We don't want to display those | 1139 // Remove the username and password fields. We don't want to display those |
| 1137 // to the user since they can be used for attacks, | 1140 // to the user since they can be used for attacks, |
| 1138 // e.g. "http://google.com:search@evil.ru/" | 1141 // e.g. "http://google.com:search@evil.ru/" |
| 1139 new_parsed->username.reset(); | 1142 new_parsed->username.reset(); |
| 1140 new_parsed->password.reset(); | 1143 new_parsed->password.reset(); |
| 1141 } else { | 1144 } else { |
| 1142 AppendFormattedComponent( | 1145 AppendFormattedComponent( |
| 1143 spec, parsed.username, unescape, &url_string, &new_parsed->username); | 1146 spec, parsed.username, unescape_rules, |
| 1147 &url_string, &new_parsed->username); |
| 1144 if (parsed.password.is_valid()) { | 1148 if (parsed.password.is_valid()) { |
| 1145 url_string.push_back(':'); | 1149 url_string.push_back(':'); |
| 1146 } | 1150 } |
| 1147 AppendFormattedComponent( | 1151 AppendFormattedComponent( |
| 1148 spec, parsed.password, unescape, &url_string, &new_parsed->password); | 1152 spec, parsed.password, unescape_rules, |
| 1153 &url_string, &new_parsed->password); |
| 1149 if (parsed.username.is_valid() || parsed.password.is_valid()) { | 1154 if (parsed.username.is_valid() || parsed.password.is_valid()) { |
| 1150 url_string.push_back('@'); | 1155 url_string.push_back('@'); |
| 1151 } | 1156 } |
| 1152 } | 1157 } |
| 1153 if (prefix_end) | 1158 if (prefix_end) |
| 1154 *prefix_end = static_cast<size_t>(url_string.length()); | 1159 *prefix_end = static_cast<size_t>(url_string.length()); |
| 1155 | 1160 |
| 1156 AppendFormattedHost(url, languages, &url_string, new_parsed); | 1161 AppendFormattedHost(url, languages, &url_string, new_parsed); |
| 1157 | 1162 |
| 1158 // Port. | 1163 // Port. |
| 1159 if (parsed.port.is_nonempty()) { | 1164 if (parsed.port.is_nonempty()) { |
| 1160 url_string.push_back(':'); | 1165 url_string.push_back(':'); |
| 1161 int begin = url_string.length(); | 1166 int begin = url_string.length(); |
| 1162 for (int i = parsed.port.begin; i < parsed.port.end(); ++i) | 1167 for (int i = parsed.port.begin; i < parsed.port.end(); ++i) |
| 1163 url_string.push_back(spec[i]); | 1168 url_string.push_back(spec[i]); |
| 1164 new_parsed->port.begin = begin; | 1169 new_parsed->port.begin = begin; |
| 1165 new_parsed->port.len = url_string.length() - begin; | 1170 new_parsed->port.len = url_string.length() - begin; |
| 1166 } else { | 1171 } else { |
| 1167 new_parsed->port.reset(); | 1172 new_parsed->port.reset(); |
| 1168 } | 1173 } |
| 1169 | 1174 |
| 1170 // Path and query both get the same general unescape & convert treatment. | 1175 // Path and query both get the same general unescape & convert treatment. |
| 1171 AppendFormattedComponent( | 1176 AppendFormattedComponent( |
| 1172 spec, parsed.path, unescape, &url_string, &new_parsed->path); | 1177 spec, parsed.path, unescape_rules, &url_string, |
| 1178 &new_parsed->path); |
| 1173 if (parsed.query.is_valid()) | 1179 if (parsed.query.is_valid()) |
| 1174 url_string.push_back('?'); | 1180 url_string.push_back('?'); |
| 1175 AppendFormattedComponent( | 1181 AppendFormattedComponent( |
| 1176 spec, parsed.query, unescape, &url_string, &new_parsed->query); | 1182 spec, parsed.query, unescape_rules, &url_string, |
| 1183 &new_parsed->query); |
| 1177 | 1184 |
| 1178 // Reference is stored in valid, unescaped UTF-8, so we can just convert. | 1185 // Reference is stored in valid, unescaped UTF-8, so we can just convert. |
| 1179 if (parsed.ref.is_valid()) { | 1186 if (parsed.ref.is_valid()) { |
| 1180 url_string.push_back('#'); | 1187 url_string.push_back('#'); |
| 1181 int begin = url_string.length(); | 1188 int begin = url_string.length(); |
| 1182 if (parsed.ref.len > 0) | 1189 if (parsed.ref.len > 0) |
| 1183 url_string.append(UTF8ToWide(std::string(&spec[parsed.ref.begin], | 1190 url_string.append(UTF8ToWide(std::string(&spec[parsed.ref.begin], |
| 1184 parsed.ref.len))); | 1191 parsed.ref.len))); |
| 1185 new_parsed->ref.begin = begin; | 1192 new_parsed->ref.begin = begin; |
| 1186 new_parsed->ref.len = url_string.length() - begin; | 1193 new_parsed->ref.len = url_string.length() - begin; |
| 1187 } | 1194 } |
| 1188 | 1195 |
| 1189 return url_string; | 1196 return url_string; |
| 1190 } | 1197 } |
| 1191 | 1198 |
| 1192 } // namespace net | 1199 } // namespace net |
| OLD | NEW |