| 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 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 // return false only for invalid or nonstandard URLs. | 292 // return false only for invalid or nonstandard URLs. |
| 293 return m_parsed.path.len >= 0; | 293 return m_parsed.path.len >= 0; |
| 294 } | 294 } |
| 295 | 295 |
| 296 // We handle "parameters" separated by a semicolon, while KURL.cpp does not, | 296 // We handle "parameters" separated by a semicolon, while KURL.cpp does not, |
| 297 // which can lead to different results in some cases. | 297 // which can lead to different results in some cases. |
| 298 String KURL::lastPathComponent() const | 298 String KURL::lastPathComponent() const |
| 299 { | 299 { |
| 300 if (!m_isValid) | 300 if (!m_isValid) |
| 301 return stringForInvalidComponent(); | 301 return stringForInvalidComponent(); |
| 302 ASSERT(!m_string.isNull()); |
| 302 | 303 |
| 303 // When the output ends in a slash, WebCore has different expectations than | 304 // When the output ends in a slash, WebCore has different expectations than |
| 304 // the GoogleURL library. For "/foo/bar/" the library will return the empty | 305 // the GoogleURL library. For "/foo/bar/" the library will return the empty |
| 305 // string, but WebCore wants "bar". | 306 // string, but WebCore wants "bar". |
| 306 url_parse::Component path = m_parsed.path; | 307 url_parse::Component path = m_parsed.path; |
| 307 if (path.len > 0 && m_string[path.end() - 1] == '/') | 308 if (path.len > 0 && m_string[path.end() - 1] == '/') |
| 308 path.len--; | 309 path.len--; |
| 309 | 310 |
| 310 url_parse::Component file; | 311 url_parse::Component file; |
| 311 if (!m_string.isNull() && m_string.is8Bit()) | 312 if (m_string.is8Bit()) |
| 312 url_parse::ExtractFileName(asURLChar8Subtle(m_string), path, &file); | 313 url_parse::ExtractFileName(asURLChar8Subtle(m_string), path, &file); |
| 313 else | 314 else |
| 314 url_parse::ExtractFileName(m_string.characters16(), path, &file); | 315 url_parse::ExtractFileName(m_string.characters16(), path, &file); |
| 315 | 316 |
| 316 // Bug: https://bugs.webkit.org/show_bug.cgi?id=21015 this function returns | 317 // Bug: https://bugs.webkit.org/show_bug.cgi?id=21015 this function returns |
| 317 // a null string when the path is empty, which we duplicate here. | 318 // a null string when the path is empty, which we duplicate here. |
| 318 if (!file.is_nonempty()) | 319 if (!file.is_nonempty()) |
| 319 return String(); | 320 return String(); |
| 320 return componentString(file); | 321 return componentString(file); |
| 321 } | 322 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 332 | 333 |
| 333 // Returns 0 when there is no port. | 334 // Returns 0 when there is no port. |
| 334 // | 335 // |
| 335 // We treat URL's with out-of-range port numbers as invalid URLs, and they will | 336 // We treat URL's with out-of-range port numbers as invalid URLs, and they will |
| 336 // be rejected by the canonicalizer. KURL.cpp will allow them in parsing, but | 337 // be rejected by the canonicalizer. KURL.cpp will allow them in parsing, but |
| 337 // return invalidPortNumber from this port() function, so we mirror that behavio
r here. | 338 // return invalidPortNumber from this port() function, so we mirror that behavio
r here. |
| 338 unsigned short KURL::port() const | 339 unsigned short KURL::port() const |
| 339 { | 340 { |
| 340 if (!m_isValid || m_parsed.port.len <= 0) | 341 if (!m_isValid || m_parsed.port.len <= 0) |
| 341 return 0; | 342 return 0; |
| 342 int port = 0; | 343 ASSERT(!m_string.isNull()); |
| 343 if (!m_string.isNull() && m_string.is8Bit()) | 344 int port = m_string.is8Bit() ? |
| 344 port = url_parse::ParsePort(asURLChar8Subtle(m_string), m_parsed.port); | 345 url_parse::ParsePort(asURLChar8Subtle(m_string), m_parsed.port) : |
| 345 else | 346 url_parse::ParsePort(m_string.characters16(), m_parsed.port); |
| 346 port = url_parse::ParsePort(m_string.characters16(), m_parsed.port); | |
| 347 ASSERT(port != url_parse::PORT_UNSPECIFIED); // Checked port.len <= 0 before
. | 347 ASSERT(port != url_parse::PORT_UNSPECIFIED); // Checked port.len <= 0 before
. |
| 348 | 348 |
| 349 if (port == url_parse::PORT_INVALID || port > maximumValidPortNumber) // Mim
ic KURL::port() | 349 if (port == url_parse::PORT_INVALID || port > maximumValidPortNumber) // Mim
ic KURL::port() |
| 350 port = invalidPortNumber; | 350 port = invalidPortNumber; |
| 351 | 351 |
| 352 return static_cast<unsigned short>(port); | 352 return static_cast<unsigned short>(port); |
| 353 } | 353 } |
| 354 | 354 |
| 355 String KURL::pass() const | 355 String KURL::pass() const |
| 356 { | 356 { |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 | 617 |
| 618 url_util::EncodeURIComponent(utf8.data(), inputLength, &buffer); | 618 url_util::EncodeURIComponent(utf8.data(), inputLength, &buffer); |
| 619 String escaped(buffer.data(), buffer.length()); | 619 String escaped(buffer.data(), buffer.length()); |
| 620 // Unescape '/'; it's safe and much prettier. | 620 // Unescape '/'; it's safe and much prettier. |
| 621 escaped.replace("%2F", "/"); | 621 escaped.replace("%2F", "/"); |
| 622 return escaped; | 622 return escaped; |
| 623 } | 623 } |
| 624 | 624 |
| 625 bool KURL::isHierarchical() const | 625 bool KURL::isHierarchical() const |
| 626 { | 626 { |
| 627 if (!m_parsed.scheme.is_nonempty()) | 627 if (m_string.isNull() || !m_parsed.scheme.is_nonempty()) |
| 628 return false; | 628 return false; |
| 629 if (!m_string.isNull() && m_string.is8Bit()) | 629 return m_string.is8Bit() ? |
| 630 return url_util::IsStandard(asURLChar8Subtle(m_string), m_parsed.scheme)
; | 630 url_util::IsStandard(asURLChar8Subtle(m_string), m_parsed.scheme) : |
| 631 return url_util::IsStandard(m_string.characters16(), m_parsed.scheme); | 631 url_util::IsStandard(m_string.characters16(), m_parsed.scheme); |
| 632 } | 632 } |
| 633 | 633 |
| 634 #ifndef NDEBUG | 634 #ifndef NDEBUG |
| 635 void KURL::print() const | 635 void KURL::print() const |
| 636 { | 636 { |
| 637 printf("%s\n", m_string.utf8().data()); | 637 printf("%s\n", m_string.utf8().data()); |
| 638 } | 638 } |
| 639 #endif | 639 #endif |
| 640 | 640 |
| 641 bool equalIgnoringFragmentIdentifier(const KURL& a, const KURL& b) | 641 bool equalIgnoringFragmentIdentifier(const KURL& a, const KURL& b) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 return m_parsed.CountCharactersBefore(url_parse::Parsed::PATH, false); | 679 return m_parsed.CountCharactersBefore(url_parse::Parsed::PATH, false); |
| 680 } | 680 } |
| 681 | 681 |
| 682 unsigned KURL::pathEnd() const | 682 unsigned KURL::pathEnd() const |
| 683 { | 683 { |
| 684 return m_parsed.CountCharactersBefore(url_parse::Parsed::QUERY, true); | 684 return m_parsed.CountCharactersBefore(url_parse::Parsed::QUERY, true); |
| 685 } | 685 } |
| 686 | 686 |
| 687 unsigned KURL::pathAfterLastSlash() const | 687 unsigned KURL::pathAfterLastSlash() const |
| 688 { | 688 { |
| 689 if (m_string.isNull()) |
| 690 return 0; |
| 689 if (!m_isValid || !m_parsed.path.is_valid()) | 691 if (!m_isValid || !m_parsed.path.is_valid()) |
| 690 return m_parsed.CountCharactersBefore(url_parse::Parsed::PATH, false); | 692 return m_parsed.CountCharactersBefore(url_parse::Parsed::PATH, false); |
| 691 | |
| 692 url_parse::Component filename; | 693 url_parse::Component filename; |
| 693 if (!m_string.isNull() && m_string.is8Bit()) | 694 if (m_string.is8Bit()) |
| 694 url_parse::ExtractFileName(asURLChar8Subtle(m_string), m_parsed.path, &f
ilename); | 695 url_parse::ExtractFileName(asURLChar8Subtle(m_string), m_parsed.path, &f
ilename); |
| 695 else | 696 else |
| 696 url_parse::ExtractFileName(m_string.characters16(), m_parsed.path, &file
name); | 697 url_parse::ExtractFileName(m_string.characters16(), m_parsed.path, &file
name); |
| 697 return filename.begin; | 698 return filename.begin; |
| 698 } | 699 } |
| 699 | 700 |
| 700 bool protocolIs(const String& url, const char* protocol) | 701 bool protocolIs(const String& url, const char* protocol) |
| 701 { | 702 { |
| 702 assertProtocolIsGood(protocol); | 703 assertProtocolIsGood(protocol); |
| 703 if (url.isNull()) | 704 if (url.isNull()) |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 return false; | 782 return false; |
| 782 } | 783 } |
| 783 | 784 |
| 784 void KURL::initProtocolIsInHTTPFamily() | 785 void KURL::initProtocolIsInHTTPFamily() |
| 785 { | 786 { |
| 786 if (!m_isValid) { | 787 if (!m_isValid) { |
| 787 m_protocolIsInHTTPFamily = false; | 788 m_protocolIsInHTTPFamily = false; |
| 788 return; | 789 return; |
| 789 } | 790 } |
| 790 | 791 |
| 791 if (!m_string.isNull() && m_string.is8Bit()) | 792 ASSERT(!m_string.isNull()); |
| 792 m_protocolIsInHTTPFamily = checkIfProtocolIsInHTTPFamily(m_parsed.scheme
, m_string.characters8()); | 793 m_protocolIsInHTTPFamily = m_string.is8Bit() ? |
| 793 else | 794 checkIfProtocolIsInHTTPFamily(m_parsed.scheme, m_string.characters8()) : |
| 794 m_protocolIsInHTTPFamily = checkIfProtocolIsInHTTPFamily(m_parsed.scheme
, m_string.characters16()); | 795 checkIfProtocolIsInHTTPFamily(m_parsed.scheme, m_string.characters16()); |
| 795 } | 796 } |
| 796 | 797 |
| 797 bool KURL::protocolIs(const char* protocol) const | 798 bool KURL::protocolIs(const char* protocol) const |
| 798 { | 799 { |
| 799 assertProtocolIsGood(protocol); | 800 assertProtocolIsGood(protocol); |
| 800 | 801 |
| 801 // JavaScript URLs are "valid" and should be executed even if KURL decides t
hey are invalid. | 802 // JavaScript URLs are "valid" and should be executed even if KURL decides t
hey are invalid. |
| 802 // The free function protocolIsJavaScript() should be used instead. | 803 // The free function protocolIsJavaScript() should be used instead. |
| 803 // FIXME: Chromium code needs to be fixed for this assert to be enabled. ASS
ERT(strcmp(protocol, "javascript")); | 804 // FIXME: Chromium code needs to be fixed for this assert to be enabled. ASS
ERT(strcmp(protocol, "javascript")); |
| 804 | 805 |
| 805 if (m_parsed.scheme.len <= 0) | 806 if (m_string.isNull() || m_parsed.scheme.len <= 0) |
| 806 return !protocol; | 807 return *protocol == '\0'; |
| 807 if (!m_string.isNull() && m_string.is8Bit()) | 808 |
| 808 return internalProtocolIs(m_parsed.scheme, m_string.characters8(), proto
col); | 809 return m_string.is8Bit() ? |
| 809 return internalProtocolIs(m_parsed.scheme, m_string.characters16(), protocol
); | 810 internalProtocolIs(m_parsed.scheme, m_string.characters8(), protocol) : |
| 811 internalProtocolIs(m_parsed.scheme, m_string.characters16(), protocol); |
| 810 } | 812 } |
| 811 | 813 |
| 812 String KURL::stringForInvalidComponent() const | 814 String KURL::stringForInvalidComponent() const |
| 813 { | 815 { |
| 814 if (m_string.isNull()) | 816 if (m_string.isNull()) |
| 815 return String(); | 817 return String(); |
| 816 return emptyString(); | 818 return emptyString(); |
| 817 } | 819 } |
| 818 | 820 |
| 819 String KURL::componentString(const url_parse::Component& component) const | 821 String KURL::componentString(const url_parse::Component& component) const |
| (...skipping 24 matching lines...) Expand all Loading... |
| 844 m_string = AtomicString::fromUTF8(output.data(), output.length()); | 846 m_string = AtomicString::fromUTF8(output.data(), output.length()); |
| 845 } | 847 } |
| 846 | 848 |
| 847 bool KURL::isSafeToSendToAnotherThread() const | 849 bool KURL::isSafeToSendToAnotherThread() const |
| 848 { | 850 { |
| 849 return m_string.isSafeToSendToAnotherThread() | 851 return m_string.isSafeToSendToAnotherThread() |
| 850 && (!m_innerURL || m_innerURL->isSafeToSendToAnotherThread()); | 852 && (!m_innerURL || m_innerURL->isSafeToSendToAnotherThread()); |
| 851 } | 853 } |
| 852 | 854 |
| 853 } // namespace WebCore | 855 } // namespace WebCore |
| OLD | NEW |