OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2004, 2007, 2008, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2007, 2008, 2009 Apple Inc. All rights reserved. |
3 * Copyright (C) 2008, 2009, 2011 Google Inc. All rights reserved. | 3 * Copyright (C) 2008, 2009, 2011 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 , m_utf8IsASCII(true) | 167 , m_utf8IsASCII(true) |
168 , m_stringIsValid(false) | 168 , m_stringIsValid(false) |
169 { | 169 { |
170 } | 170 } |
171 | 171 |
172 KURLGooglePrivate::KURLGooglePrivate(WTF::HashTableDeletedValueType) | 172 KURLGooglePrivate::KURLGooglePrivate(WTF::HashTableDeletedValueType) |
173 : m_string(WTF::HashTableDeletedValue) | 173 : m_string(WTF::HashTableDeletedValue) |
174 { | 174 { |
175 } | 175 } |
176 | 176 |
177 KURLGooglePrivate::KURLGooglePrivate(const KURLGooglePrivate& o) | |
178 : m_isValid(o.m_isValid) | |
179 , m_protocolIsInHTTPFamily(o.m_protocolIsInHTTPFamily) | |
180 , m_parsed(o.m_parsed) | |
181 , m_utf8(o.m_utf8) | |
182 , m_utf8IsASCII(o.m_utf8IsASCII) | |
183 , m_stringIsValid(o.m_stringIsValid) | |
184 , m_string(o.m_string) | |
185 { | |
186 if (o.m_inner_url.get()) | |
187 m_inner_url = adoptPtr(new KURL(o.m_inner_url->copy())); | |
abarth-chromium
2011/12/20 07:03:15
m_innerURL. Can we avoid calling the KURL parser
ericu
2011/12/20 23:55:34
I'm not sure what you mean. m_inner_url is a KURL
| |
188 } | |
189 | |
190 KURLGooglePrivate& KURLGooglePrivate::operator=(const KURLGooglePrivate& o) | |
191 { | |
192 m_isValid = o.m_isValid; | |
193 m_protocolIsInHTTPFamily = o.m_protocolIsInHTTPFamily; | |
194 m_parsed = o.m_parsed; | |
195 m_utf8 = o.m_utf8; | |
196 m_utf8IsASCII = o.m_utf8IsASCII; | |
197 m_stringIsValid = o.m_stringIsValid; | |
198 m_string = o.m_string; | |
199 if (o.m_inner_url.get()) | |
200 m_inner_url = adoptPtr(new KURL(o.m_inner_url->copy())); | |
201 else | |
202 m_inner_url.clear(); | |
203 return *this; | |
204 } | |
205 | |
177 // Setters for the data. Using the ASCII version when you know the | 206 // Setters for the data. Using the ASCII version when you know the |
178 // data is ASCII will be slightly more efficient. The UTF-8 version | 207 // data is ASCII will be slightly more efficient. The UTF-8 version |
179 // will always be correct if the caller is unsure. | 208 // will always be correct if the caller is unsure. |
180 void KURLGooglePrivate::setUtf8(const CString& str) | 209 void KURLGooglePrivate::setUtf8(const CString& str) |
181 { | 210 { |
182 const char* data = str.data(); | 211 const char* data = str.data(); |
183 unsigned dataLength = str.length(); | 212 unsigned dataLength = str.length(); |
184 | 213 |
185 // The m_utf8IsASCII must always be correct since the DeprecatedString | 214 // The m_utf8IsASCII must always be correct since the DeprecatedString |
186 // getter must create it with the proper constructor. This test can be | 215 // getter must create it with the proper constructor. This test can be |
187 // removed when DeprecatedString is gone, but it still might be a | 216 // removed when DeprecatedString is gone, but it still might be a |
188 // performance win. | 217 // performance win. |
189 m_utf8IsASCII = true; | 218 m_utf8IsASCII = true; |
190 for (unsigned i = 0; i < dataLength; i++) { | 219 for (unsigned i = 0; i < dataLength; i++) { |
191 if (static_cast<unsigned char>(data[i]) >= 0x80) { | 220 if (static_cast<unsigned char>(data[i]) >= 0x80) { |
192 m_utf8IsASCII = false; | 221 m_utf8IsASCII = false; |
193 break; | 222 break; |
194 } | 223 } |
195 } | 224 } |
196 | 225 |
197 m_utf8 = str; | 226 m_utf8 = str; |
198 m_stringIsValid = false; | 227 m_stringIsValid = false; |
199 initProtocolIsInHTTPFamily(); | 228 initProtocolIsInHTTPFamily(); |
229 initInnerURL(); | |
200 } | 230 } |
201 | 231 |
202 void KURLGooglePrivate::setAscii(const CString& str) | 232 void KURLGooglePrivate::setAscii(const CString& str) |
203 { | 233 { |
204 m_utf8 = str; | 234 m_utf8 = str; |
205 m_utf8IsASCII = true; | 235 m_utf8IsASCII = true; |
206 m_stringIsValid = false; | 236 m_stringIsValid = false; |
207 initProtocolIsInHTTPFamily(); | 237 initProtocolIsInHTTPFamily(); |
238 initInnerURL(); | |
208 } | 239 } |
209 | 240 |
210 void KURLGooglePrivate::init(const KURL& base, | 241 void KURLGooglePrivate::init(const KURL& base, |
211 const String& relative, | 242 const String& relative, |
212 const TextEncoding* queryEncoding) | 243 const TextEncoding* queryEncoding) |
213 { | 244 { |
214 init(base, relative.characters(), relative.length(), queryEncoding); | 245 init(base, relative.characters(), relative.length(), queryEncoding); |
215 } | 246 } |
216 | 247 |
217 template <typename CHAR> | 248 template <typename CHAR> |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 if (m_parsed.ref.is_nonempty()) | 282 if (m_parsed.ref.is_nonempty()) |
252 setUtf8(CString(output.data(), output.length())); | 283 setUtf8(CString(output.data(), output.length())); |
253 else | 284 else |
254 setAscii(CString(output.data(), output.length())); | 285 setAscii(CString(output.data(), output.length())); |
255 } else { | 286 } else { |
256 // WebCore expects resolved URLs to be empty rather than null. | 287 // WebCore expects resolved URLs to be empty rather than null. |
257 setUtf8(CString("", 0)); | 288 setUtf8(CString("", 0)); |
258 } | 289 } |
259 } | 290 } |
260 | 291 |
292 void KURLGooglePrivate::initInnerURL() { | |
293 if (!m_isValid) { | |
294 m_inner_url.clear(); | |
295 return; | |
296 } | |
297 url_parse::Parsed* inner_parsed = m_parsed.inner_parsed(); | |
abarth-chromium
2011/12/20 07:03:15
innerParsed
ericu
2011/12/20 23:55:34
Done.
| |
298 if (inner_parsed) | |
299 m_inner_url = adoptPtr(new KURL( | |
300 ParsedURLString, | |
301 String( | |
302 m_utf8.data() + inner_parsed->scheme.begin, | |
303 inner_parsed->Length() - inner_parsed->scheme.begin))); | |
abarth-chromium
2011/12/20 07:03:15
There's no 80 column limit in WebKit. You can go
ericu
2011/12/20 23:55:34
s/excitingly/excruciatingly/, but OK ;'>.
| |
304 else | |
305 m_inner_url.clear(); | |
306 } | |
307 | |
261 void KURLGooglePrivate::initProtocolIsInHTTPFamily() | 308 void KURLGooglePrivate::initProtocolIsInHTTPFamily() |
262 { | 309 { |
263 if (!m_isValid) { | 310 if (!m_isValid) { |
264 m_protocolIsInHTTPFamily = false; | 311 m_protocolIsInHTTPFamily = false; |
265 return; | 312 return; |
266 } | 313 } |
267 | 314 |
268 const char* scheme = m_utf8.data() + m_parsed.scheme.begin; | 315 const char* scheme = m_utf8.data() + m_parsed.scheme.begin; |
269 if (m_parsed.scheme.len == 4) | 316 if (m_parsed.scheme.len == 4) |
270 m_protocolIsInHTTPFamily = lowerCaseEqualsASCII(scheme, scheme + 4, "htt p"); | 317 m_protocolIsInHTTPFamily = lowerCaseEqualsASCII(scheme, scheme + 4, "htt p"); |
271 else if (m_parsed.scheme.len == 5) | 318 else if (m_parsed.scheme.len == 5) |
272 m_protocolIsInHTTPFamily = lowerCaseEqualsASCII(scheme, scheme + 5, "htt ps"); | 319 m_protocolIsInHTTPFamily = lowerCaseEqualsASCII(scheme, scheme + 5, "htt ps"); |
273 else | 320 else |
274 m_protocolIsInHTTPFamily = false; | 321 m_protocolIsInHTTPFamily = false; |
275 } | 322 } |
276 | 323 |
277 void KURLGooglePrivate::copyTo(KURLGooglePrivate* dest) const | 324 void KURLGooglePrivate::copyTo(KURLGooglePrivate* dest) const |
278 { | 325 { |
279 dest->m_isValid = m_isValid; | 326 dest->m_isValid = m_isValid; |
280 dest->m_protocolIsInHTTPFamily = m_protocolIsInHTTPFamily; | 327 dest->m_protocolIsInHTTPFamily = m_protocolIsInHTTPFamily; |
281 dest->m_parsed = m_parsed; | 328 dest->m_parsed = m_parsed; |
282 | 329 |
283 // Don't copy the 16-bit string since that will be regenerated as needed. | 330 // Don't copy the 16-bit string since that will be regenerated as needed. |
284 dest->m_utf8 = CString(m_utf8.data(), m_utf8.length()); | 331 dest->m_utf8 = CString(m_utf8.data(), m_utf8.length()); |
285 dest->m_utf8IsASCII = m_utf8IsASCII; | 332 dest->m_utf8IsASCII = m_utf8IsASCII; |
286 dest->m_stringIsValid = false; | 333 dest->m_stringIsValid = false; |
287 dest->m_string = String(); // Clear the invalid string to avoid cross thread ref counting. | 334 dest->m_string = String(); // Clear the invalid string to avoid cross thread ref counting. |
335 if (m_inner_url) { | |
336 dest->m_inner_url = adoptPtr(new KURL(m_inner_url->copy())); | |
337 } | |
338 else | |
339 dest->m_inner_url.clear(); | |
288 } | 340 } |
289 | 341 |
290 String KURLGooglePrivate::componentString(const url_parse::Component& comp) cons t | 342 String KURLGooglePrivate::componentString(const url_parse::Component& comp) cons t |
291 { | 343 { |
292 if (!m_isValid || comp.len <= 0) { | 344 if (!m_isValid || comp.len <= 0) { |
293 // KURL returns a null string if the URL is itself a null string, and an | 345 // KURL returns a null string if the URL is itself a null string, and an |
294 // empty string for other nonexistent entities. | 346 // empty string for other nonexistent entities. |
295 if (utf8String().isNull()) | 347 if (utf8String().isNull()) |
296 return String(); | 348 return String(); |
297 return String("", 0); | 349 return String("", 0); |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
820 reinterpret_cast<const UChar*>(notEncodedString.characters()), | 872 reinterpret_cast<const UChar*>(notEncodedString.characters()), |
821 notEncodedString.length(), | 873 notEncodedString.length(), |
822 URLEncodedEntitiesForUnencodables); | 874 URLEncodedEntitiesForUnencodables); |
823 const char* input = utf8.data(); | 875 const char* input = utf8.data(); |
824 int inputLength = utf8.length(); | 876 int inputLength = utf8.length(); |
825 url_canon::RawCanonOutputT<char> buffer; | 877 url_canon::RawCanonOutputT<char> buffer; |
826 if (buffer.length() < inputLength * 3) | 878 if (buffer.length() < inputLength * 3) |
827 buffer.Resize(inputLength * 3); | 879 buffer.Resize(inputLength * 3); |
828 | 880 |
829 url_util::EncodeURIComponent(input, inputLength, &buffer); | 881 url_util::EncodeURIComponent(input, inputLength, &buffer); |
830 return String(buffer.data(), buffer.length()); | 882 String escaped(buffer.data(), buffer.length()); |
883 // Unescape '/'; it's safe and much prettier. | |
884 escaped.replace("%2F", "/"); | |
885 return escaped; | |
831 } | 886 } |
832 | 887 |
833 bool KURL::isHierarchical() const | 888 bool KURL::isHierarchical() const |
834 { | 889 { |
835 if (!m_url.m_parsed.scheme.is_nonempty()) | 890 if (!m_url.m_parsed.scheme.is_nonempty()) |
836 return false; | 891 return false; |
837 return url_util::IsStandard( | 892 return url_util::IsStandard( |
838 &m_url.utf8String().data()[m_url.m_parsed.scheme.begin], | 893 &m_url.utf8String().data()[m_url.m_parsed.scheme.begin], |
839 m_url.m_parsed.scheme); | 894 m_url.m_parsed.scheme); |
840 } | 895 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
943 | 998 |
944 if (a.port() != b.port()) | 999 if (a.port() != b.port()) |
945 return false; | 1000 return false; |
946 | 1001 |
947 return true; | 1002 return true; |
948 } | 1003 } |
949 | 1004 |
950 } // namespace WebCore | 1005 } // namespace WebCore |
951 | 1006 |
952 #endif // USE(GOOGLEURL) | 1007 #endif // USE(GOOGLEURL) |
OLD | NEW |