Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2007, 2008, 2011, 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2007, 2008, 2011, 2012 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2012 Research In Motion Limited. All rights reserved. | 3 * Copyright (C) 2012 Research In Motion Limited. All rights reserved. |
| 4 * Copyright (C) 2008, 2009, 2011 Google Inc. All rights reserved. | 4 * Copyright (C) 2008, 2009, 2011 Google Inc. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. 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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 init(base, relative, &encoding.encodingForFormSubmission()); | 233 init(base, relative, &encoding.encodingForFormSubmission()); |
| 234 } | 234 } |
| 235 | 235 |
| 236 KURL::KURL(const AtomicString& canonicalString, | 236 KURL::KURL(const AtomicString& canonicalString, |
| 237 const url::Parsed& parsed, | 237 const url::Parsed& parsed, |
| 238 bool isValid) | 238 bool isValid) |
| 239 : m_isValid(isValid), | 239 : m_isValid(isValid), |
| 240 m_protocolIsInHTTPFamily(false), | 240 m_protocolIsInHTTPFamily(false), |
| 241 m_parsed(parsed), | 241 m_parsed(parsed), |
| 242 m_string(canonicalString) { | 242 m_string(canonicalString) { |
| 243 initProtocolIsInHTTPFamily(); | 243 initProtocolMetadata(); |
| 244 initInnerURL(); | 244 initInnerURL(); |
| 245 } | 245 } |
| 246 | 246 |
| 247 KURL::KURL(WTF::HashTableDeletedValueType) | 247 KURL::KURL(WTF::HashTableDeletedValueType) |
| 248 : m_isValid(false), | 248 : m_isValid(false), |
| 249 m_protocolIsInHTTPFamily(false), | 249 m_protocolIsInHTTPFamily(false), |
| 250 m_string(WTF::HashTableDeletedValue) {} | 250 m_string(WTF::HashTableDeletedValue) {} |
| 251 | 251 |
| 252 KURL::KURL(const KURL& other) | 252 KURL::KURL(const KURL& other) |
| 253 : m_isValid(other.m_isValid), | 253 : m_isValid(other.m_isValid), |
| 254 m_protocolIsInHTTPFamily(other.m_protocolIsInHTTPFamily), | 254 m_protocolIsInHTTPFamily(other.m_protocolIsInHTTPFamily), |
| 255 m_protocol(other.m_protocol), | |
| 255 m_parsed(other.m_parsed), | 256 m_parsed(other.m_parsed), |
| 256 m_string(other.m_string) { | 257 m_string(other.m_string) { |
| 257 if (other.m_innerURL.get()) | 258 if (other.m_innerURL.get()) |
| 258 m_innerURL = wrapUnique(new KURL(other.m_innerURL->copy())); | 259 m_innerURL = wrapUnique(new KURL(other.m_innerURL->copy())); |
| 259 } | 260 } |
| 260 | 261 |
| 261 KURL::~KURL() {} | 262 KURL::~KURL() {} |
| 262 | 263 |
| 263 KURL& KURL::operator=(const KURL& other) { | 264 KURL& KURL::operator=(const KURL& other) { |
| 264 m_isValid = other.m_isValid; | 265 m_isValid = other.m_isValid; |
| 265 m_protocolIsInHTTPFamily = other.m_protocolIsInHTTPFamily; | 266 m_protocolIsInHTTPFamily = other.m_protocolIsInHTTPFamily; |
| 267 m_protocol = other.m_protocol; | |
| 266 m_parsed = other.m_parsed; | 268 m_parsed = other.m_parsed; |
| 267 m_string = other.m_string; | 269 m_string = other.m_string; |
| 268 if (other.m_innerURL) | 270 if (other.m_innerURL) |
| 269 m_innerURL = wrapUnique(new KURL(other.m_innerURL->copy())); | 271 m_innerURL = wrapUnique(new KURL(other.m_innerURL->copy())); |
| 270 else | 272 else |
| 271 m_innerURL.reset(); | 273 m_innerURL.reset(); |
| 272 return *this; | 274 return *this; |
| 273 } | 275 } |
| 274 | 276 |
| 275 KURL KURL::copy() const { | 277 KURL KURL::copy() const { |
| 276 KURL result; | 278 KURL result; |
| 277 result.m_isValid = m_isValid; | 279 result.m_isValid = m_isValid; |
| 278 result.m_protocolIsInHTTPFamily = m_protocolIsInHTTPFamily; | 280 result.m_protocolIsInHTTPFamily = m_protocolIsInHTTPFamily; |
| 281 result.m_protocol = m_protocol.isolatedCopy(); | |
| 279 result.m_parsed = m_parsed; | 282 result.m_parsed = m_parsed; |
| 280 result.m_string = m_string.isolatedCopy(); | 283 result.m_string = m_string.isolatedCopy(); |
| 281 if (m_innerURL) | 284 if (m_innerURL) |
| 282 result.m_innerURL = wrapUnique(new KURL(m_innerURL->copy())); | 285 result.m_innerURL = wrapUnique(new KURL(m_innerURL->copy())); |
| 283 return result; | 286 return result; |
| 284 } | 287 } |
| 285 | 288 |
| 286 bool KURL::isNull() const { | 289 bool KURL::isNull() const { |
| 287 return m_string.isNull(); | 290 return m_string.isNull(); |
| 288 } | 291 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 url::ExtractFileName(m_string.characters16(), path, &file); | 331 url::ExtractFileName(m_string.characters16(), path, &file); |
| 329 | 332 |
| 330 // Bug: https://bugs.webkit.org/show_bug.cgi?id=21015 this function returns | 333 // Bug: https://bugs.webkit.org/show_bug.cgi?id=21015 this function returns |
| 331 // a null string when the path is empty, which we duplicate here. | 334 // a null string when the path is empty, which we duplicate here. |
| 332 if (!file.is_nonempty()) | 335 if (!file.is_nonempty()) |
| 333 return String(); | 336 return String(); |
| 334 return componentString(file); | 337 return componentString(file); |
| 335 } | 338 } |
| 336 | 339 |
| 337 String KURL::protocol() const { | 340 String KURL::protocol() const { |
| 338 return componentString(m_parsed.scheme); | 341 return m_protocol; |
| 339 } | 342 } |
| 340 | 343 |
| 341 String KURL::host() const { | 344 String KURL::host() const { |
| 342 return componentString(m_parsed.host); | 345 return componentString(m_parsed.host); |
| 343 } | 346 } |
| 344 | 347 |
| 345 // Returns 0 when there is no port. | 348 // Returns 0 when there is no port. |
| 346 // | 349 // |
| 347 // We treat URL's with out-of-range port numbers as invalid URLs, and they will | 350 // We treat URL's with out-of-range port numbers as invalid URLs, and they will |
| 348 // be rejected by the canonicalizer. KURL.cpp will allow them in parsing, but | 351 // be rejected by the canonicalizer. KURL.cpp will allow them in parsing, but |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 if (!url::CanonicalizeScheme(newProtocolUTF8.data(), | 428 if (!url::CanonicalizeScheme(newProtocolUTF8.data(), |
| 426 url::Component(0, newProtocolUTF8.length()), | 429 url::Component(0, newProtocolUTF8.length()), |
| 427 &canonProtocol, &protocolComponent) || | 430 &canonProtocol, &protocolComponent) || |
| 428 !protocolComponent.is_nonempty()) | 431 !protocolComponent.is_nonempty()) |
| 429 return false; | 432 return false; |
| 430 | 433 |
| 431 url::Replacements<char> replacements; | 434 url::Replacements<char> replacements; |
| 432 replacements.SetScheme(charactersOrEmpty(newProtocolUTF8), | 435 replacements.SetScheme(charactersOrEmpty(newProtocolUTF8), |
| 433 url::Component(0, newProtocolUTF8.length())); | 436 url::Component(0, newProtocolUTF8.length())); |
| 434 replaceComponents(replacements); | 437 replaceComponents(replacements); |
| 438 initProtocolMetadata(); | |
| 435 | 439 |
| 436 // isValid could be false but we still return true here. This is because | 440 // isValid could be false but we still return true here. This is because |
| 437 // WebCore or JS scripts can build up a URL by setting individual | 441 // WebCore or JS scripts can build up a URL by setting individual |
| 438 // components, and a JS exception is based on the return value of this | 442 // components, and a JS exception is based on the return value of this |
| 439 // function. We want to throw the exception and stop the script only when | 443 // function. We want to throw the exception and stop the script only when |
| 440 // its trying to set a bad protocol, and not when it maybe just hasn't | 444 // its trying to set a bad protocol, and not when it maybe just hasn't |
| 441 // finished building up its final scheme. | 445 // finished building up its final scheme. |
| 442 return true; | 446 return true; |
| 443 } | 447 } |
| 444 | 448 |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 715 } | 719 } |
| 716 | 720 |
| 717 void KURL::init(const KURL& base, | 721 void KURL::init(const KURL& base, |
| 718 const String& relative, | 722 const String& relative, |
| 719 const WTF::TextEncoding* queryEncoding) { | 723 const WTF::TextEncoding* queryEncoding) { |
| 720 if (!relative.isNull() && relative.is8Bit()) { | 724 if (!relative.isNull() && relative.is8Bit()) { |
| 721 StringUTF8Adaptor relativeUTF8(relative); | 725 StringUTF8Adaptor relativeUTF8(relative); |
| 722 init(base, relativeUTF8.data(), relativeUTF8.length(), queryEncoding); | 726 init(base, relativeUTF8.data(), relativeUTF8.length(), queryEncoding); |
| 723 } else | 727 } else |
| 724 init(base, relative.characters16(), relative.length(), queryEncoding); | 728 init(base, relative.characters16(), relative.length(), queryEncoding); |
| 725 initProtocolIsInHTTPFamily(); | 729 initProtocolMetadata(); |
| 726 initInnerURL(); | 730 initInnerURL(); |
| 727 DCHECK_EQ(protocol(), protocol().lower()); | 731 DCHECK_EQ(protocol(), protocol().lower()); |
| 728 } | 732 } |
| 729 | 733 |
| 730 template <typename CHAR> | 734 template <typename CHAR> |
| 731 void KURL::init(const KURL& base, | 735 void KURL::init(const KURL& base, |
| 732 const CHAR* relative, | 736 const CHAR* relative, |
| 733 int relativeLength, | 737 int relativeLength, |
| 734 const WTF::TextEncoding* queryEncoding) { | 738 const WTF::TextEncoding* queryEncoding) { |
| 735 // As a performance optimization, we do not use the charset converter | 739 // As a performance optimization, we do not use the charset converter |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 765 } | 769 } |
| 766 if (url::Parsed* innerParsed = m_parsed.inner_parsed()) | 770 if (url::Parsed* innerParsed = m_parsed.inner_parsed()) |
| 767 m_innerURL = wrapUnique(new KURL( | 771 m_innerURL = wrapUnique(new KURL( |
| 768 ParsedURLString, | 772 ParsedURLString, |
| 769 m_string.substring(innerParsed->scheme.begin, | 773 m_string.substring(innerParsed->scheme.begin, |
| 770 innerParsed->Length() - innerParsed->scheme.begin))); | 774 innerParsed->Length() - innerParsed->scheme.begin))); |
| 771 else | 775 else |
| 772 m_innerURL.reset(); | 776 m_innerURL.reset(); |
| 773 } | 777 } |
| 774 | 778 |
| 775 template <typename CHAR> | 779 void KURL::initProtocolMetadata() { |
| 776 bool internalProtocolIs(const url::Component& scheme, | |
| 777 const CHAR* spec, | |
| 778 const char* protocol) { | |
| 779 const CHAR* begin = spec + scheme.begin; | |
| 780 const CHAR* end = begin + scheme.len; | |
| 781 | |
| 782 while (begin != end && *protocol) { | |
| 783 ASSERT(toASCIILower(*protocol) == *protocol); | |
| 784 if (toASCIILower(*begin++) != *protocol++) | |
| 785 return false; | |
| 786 } | |
| 787 | |
| 788 // Both strings are equal (ignoring case) if and only if all of the characters | |
| 789 // were equal, and the end of both has been reached. | |
| 790 return begin == end && !*protocol; | |
| 791 } | |
| 792 | |
| 793 template <typename CHAR> | |
| 794 bool checkIfProtocolIsInHTTPFamily(const url::Component& scheme, | |
| 795 const CHAR* spec) { | |
| 796 if (scheme.len == 4) | |
| 797 return internalProtocolIs(scheme, spec, "http"); | |
| 798 if (scheme.len == 5) | |
| 799 return internalProtocolIs(scheme, spec, "https"); | |
| 800 if (scheme.len == 7) | |
| 801 return internalProtocolIs(scheme, spec, "http-so"); | |
| 802 if (scheme.len == 8) | |
| 803 return internalProtocolIs(scheme, spec, "https-so"); | |
| 804 return false; | |
| 805 } | |
| 806 | |
| 807 void KURL::initProtocolIsInHTTPFamily() { | |
| 808 if (!m_isValid) { | 780 if (!m_isValid) { |
| 809 m_protocolIsInHTTPFamily = false; | 781 m_protocolIsInHTTPFamily = false; |
| 810 return; | 782 return; |
| 811 } | 783 } |
| 812 | 784 |
| 813 ASSERT(!m_string.isNull()); | 785 ASSERT(!m_string.isNull()); |
| 814 m_protocolIsInHTTPFamily = | 786 m_protocol = componentString(m_parsed.scheme); |
| 815 m_string.is8Bit() ? checkIfProtocolIsInHTTPFamily(m_parsed.scheme, | 787 if (!m_protocol.isEmpty()) |
| 816 m_string.characters8()) | 788 m_protocol = (m_protocol); |
|
esprehn
2016/11/04 23:48:32
what does this do? assigning m_protocol to itself
Charlie Harrison
2016/11/04 23:58:35
Oops. That should be m_protocol = AtomicString(m_p
| |
| 817 : checkIfProtocolIsInHTTPFamily( | 789 |
| 818 m_parsed.scheme, m_string.characters16()); | 790 // TODO(csharrison): Add "http" and "https" to the AtomicString table at init |
| 791 // time so that the normal case here is just a pointer comparison. | |
| 792 m_protocolIsInHTTPFamily = m_protocol == "http" || m_protocol == "https" || | |
| 793 m_protocol == "http-so" || | |
| 794 m_protocol == "https-so"; | |
| 819 } | 795 } |
| 820 | 796 |
| 821 bool KURL::protocolIs(const char* protocol) const { | 797 bool KURL::protocolIs(const char* protocol) const { |
| 822 assertProtocolIsGood(protocol); | 798 assertProtocolIsGood(protocol); |
| 823 | 799 |
| 824 // JavaScript URLs are "valid" and should be executed even if KURL decides | 800 // JavaScript URLs are "valid" and should be executed even if KURL decides |
| 825 // they are invalid. The free function protocolIsJavaScript() should be used | 801 // they are invalid. The free function protocolIsJavaScript() should be used |
| 826 // instead. | 802 // instead. |
| 827 // FIXME: Chromium code needs to be fixed for this assert to be enabled. | 803 // FIXME: Chromium code needs to be fixed for this assert to be enabled. |
| 828 // ASSERT(strcmp(protocol, "javascript")); | 804 // ASSERT(strcmp(protocol, "javascript")); |
| 829 | 805 |
| 830 if (m_string.isNull() || m_parsed.scheme.len <= 0) | 806 if (m_string.isNull() || m_protocol.isNull() || m_parsed.scheme.len <= 0) |
| 831 return *protocol == '\0'; | 807 return *protocol == '\0'; |
| 832 | 808 return m_protocol == protocol; |
| 833 return m_string.is8Bit() | |
| 834 ? internalProtocolIs(m_parsed.scheme, m_string.characters8(), | |
| 835 protocol) | |
| 836 : internalProtocolIs(m_parsed.scheme, m_string.characters16(), | |
| 837 protocol); | |
| 838 } | 809 } |
| 839 | 810 |
| 840 String KURL::stringForInvalidComponent() const { | 811 String KURL::stringForInvalidComponent() const { |
| 841 if (m_string.isNull()) | 812 if (m_string.isNull()) |
| 842 return String(); | 813 return String(); |
| 843 return emptyString(); | 814 return emptyString(); |
| 844 } | 815 } |
| 845 | 816 |
| 846 String KURL::componentString(const url::Component& component) const { | 817 String KURL::componentString(const url::Component& component) const { |
| 847 if (!m_isValid || component.len <= 0) | 818 if (!m_isValid || component.len <= 0) |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 869 m_parsed = newParsed; | 840 m_parsed = newParsed; |
| 870 m_string = AtomicString::fromUTF8(output.data(), output.length()); | 841 m_string = AtomicString::fromUTF8(output.data(), output.length()); |
| 871 } | 842 } |
| 872 | 843 |
| 873 bool KURL::isSafeToSendToAnotherThread() const { | 844 bool KURL::isSafeToSendToAnotherThread() const { |
| 874 return m_string.isSafeToSendToAnotherThread() && | 845 return m_string.isSafeToSendToAnotherThread() && |
| 875 (!m_innerURL || m_innerURL->isSafeToSendToAnotherThread()); | 846 (!m_innerURL || m_innerURL->isSafeToSendToAnotherThread()); |
| 876 } | 847 } |
| 877 | 848 |
| 878 } // namespace blink | 849 } // namespace blink |
| OLD | NEW |