| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 static void assertProtocolIsGood(const char* protocol) { | 48 static void assertProtocolIsGood(const char* protocol) { |
| 49 #if ENABLE(ASSERT) | 49 #if ENABLE(ASSERT) |
| 50 const char* p = protocol; | 50 const char* p = protocol; |
| 51 while (*p) { | 51 while (*p) { |
| 52 ASSERT(*p > ' ' && *p < 0x7F && !(*p >= 'A' && *p <= 'Z')); | 52 ASSERT(*p > ' ' && *p < 0x7F && !(*p >= 'A' && *p <= 'Z')); |
| 53 ++p; | 53 ++p; |
| 54 } | 54 } |
| 55 #endif | 55 #endif |
| 56 } | 56 } |
| 57 | 57 |
| 58 // Note: You must ensure that |spec| is a valid canonicalized URL before calling
this function. | 58 // Note: You must ensure that |spec| is a valid canonicalized URL before calling |
| 59 // this function. |
| 59 static const char* asURLChar8Subtle(const String& spec) { | 60 static const char* asURLChar8Subtle(const String& spec) { |
| 60 ASSERT(spec.is8Bit()); | 61 ASSERT(spec.is8Bit()); |
| 61 // characters8 really return characters in Latin-1, but because we canonicaliz
e | 62 // characters8 really return characters in Latin-1, but because we |
| 62 // URL strings, we know that everything before the fragment identifier will | 63 // canonicalize URL strings, we know that everything before the fragment |
| 63 // actually be ASCII, which means this cast is safe as long as you don't look | 64 // identifier will actually be ASCII, which means this cast is safe as long as |
| 64 // at the fragment component. | 65 // you don't look at the fragment component. |
| 65 return reinterpret_cast<const char*>(spec.characters8()); | 66 return reinterpret_cast<const char*>(spec.characters8()); |
| 66 } | 67 } |
| 67 | 68 |
| 68 // Returns the characters for the given string, or a pointer to a static empty | 69 // Returns the characters for the given string, or a pointer to a static empty |
| 69 // string if the input string is null. This will always ensure we have a non- | 70 // string if the input string is null. This will always ensure we have a non- |
| 70 // null character pointer since ReplaceComponents has special meaning for null. | 71 // null character pointer since ReplaceComponents has special meaning for null. |
| 71 static const char* charactersOrEmpty(const StringUTF8Adaptor& string) { | 72 static const char* charactersOrEmpty(const StringUTF8Adaptor& string) { |
| 72 static const char zero = 0; | 73 static const char zero = 0; |
| 73 return string.data() ? string.data() : &zero; | 74 return string.data() ? string.data() : &zero; |
| 74 } | 75 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 85 static bool isUnicodeEncoding(const WTF::TextEncoding* encoding) { | 86 static bool isUnicodeEncoding(const WTF::TextEncoding* encoding) { |
| 86 return encoding->encodingForFormSubmission() == UTF8Encoding(); | 87 return encoding->encodingForFormSubmission() == UTF8Encoding(); |
| 87 } | 88 } |
| 88 | 89 |
| 89 namespace { | 90 namespace { |
| 90 | 91 |
| 91 class KURLCharsetConverter final : public url::CharsetConverter { | 92 class KURLCharsetConverter final : public url::CharsetConverter { |
| 92 DISALLOW_NEW(); | 93 DISALLOW_NEW(); |
| 93 | 94 |
| 94 public: | 95 public: |
| 95 // The encoding parameter may be 0, but in this case the object must not be ca
lled. | 96 // The encoding parameter may be 0, but in this case the object must not be |
| 97 // called. |
| 96 explicit KURLCharsetConverter(const WTF::TextEncoding* encoding) | 98 explicit KURLCharsetConverter(const WTF::TextEncoding* encoding) |
| 97 : m_encoding(encoding) {} | 99 : m_encoding(encoding) {} |
| 98 | 100 |
| 99 void ConvertFromUTF16(const base::char16* input, | 101 void ConvertFromUTF16(const base::char16* input, |
| 100 int inputLength, | 102 int inputLength, |
| 101 url::CanonOutput* output) override { | 103 url::CanonOutput* output) override { |
| 102 CString encoded = m_encoding->encode( | 104 CString encoded = m_encoding->encode( |
| 103 String(input, inputLength), WTF::URLEncodedEntitiesForUnencodables); | 105 String(input, inputLength), WTF::URLEncodedEntitiesForUnencodables); |
| 104 output->Append(encoded.data(), static_cast<int>(encoded.length())); | 106 output->Append(encoded.data(), static_cast<int>(encoded.length())); |
| 105 } | 107 } |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 } | 339 } |
| 338 | 340 |
| 339 String KURL::host() const { | 341 String KURL::host() const { |
| 340 return componentString(m_parsed.host); | 342 return componentString(m_parsed.host); |
| 341 } | 343 } |
| 342 | 344 |
| 343 // Returns 0 when there is no port. | 345 // Returns 0 when there is no port. |
| 344 // | 346 // |
| 345 // We treat URL's with out-of-range port numbers as invalid URLs, and they will | 347 // We treat URL's with out-of-range port numbers as invalid URLs, and they will |
| 346 // be rejected by the canonicalizer. KURL.cpp will allow them in parsing, but | 348 // be rejected by the canonicalizer. KURL.cpp will allow them in parsing, but |
| 347 // return invalidPortNumber from this port() function, so we mirror that behavio
r here. | 349 // return invalidPortNumber from this port() function, so we mirror that |
| 350 // behavior here. |
| 348 unsigned short KURL::port() const { | 351 unsigned short KURL::port() const { |
| 349 if (!m_isValid || m_parsed.port.len <= 0) | 352 if (!m_isValid || m_parsed.port.len <= 0) |
| 350 return 0; | 353 return 0; |
| 351 ASSERT(!m_string.isNull()); | 354 ASSERT(!m_string.isNull()); |
| 352 int port = m_string.is8Bit() | 355 int port = m_string.is8Bit() |
| 353 ? url::ParsePort(asURLChar8Subtle(m_string), m_parsed.port) | 356 ? url::ParsePort(asURLChar8Subtle(m_string), m_parsed.port) |
| 354 : url::ParsePort(m_string.characters16(), m_parsed.port); | 357 : url::ParsePort(m_string.characters16(), m_parsed.port); |
| 355 ASSERT(port != url::PORT_UNSPECIFIED); // Checked port.len <= 0 before. | 358 ASSERT(port != url::PORT_UNSPECIFIED); // Checked port.len <= 0 before. |
| 356 | 359 |
| 357 if (port == url::PORT_INVALID || | 360 if (port == url::PORT_INVALID || |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 774 const char* protocol) { | 777 const char* protocol) { |
| 775 const CHAR* begin = spec + scheme.begin; | 778 const CHAR* begin = spec + scheme.begin; |
| 776 const CHAR* end = begin + scheme.len; | 779 const CHAR* end = begin + scheme.len; |
| 777 | 780 |
| 778 while (begin != end && *protocol) { | 781 while (begin != end && *protocol) { |
| 779 ASSERT(toASCIILower(*protocol) == *protocol); | 782 ASSERT(toASCIILower(*protocol) == *protocol); |
| 780 if (toASCIILower(*begin++) != *protocol++) | 783 if (toASCIILower(*begin++) != *protocol++) |
| 781 return false; | 784 return false; |
| 782 } | 785 } |
| 783 | 786 |
| 784 // Both strings are equal (ignoring case) if and only if all of the characters
were equal, | 787 // Both strings are equal (ignoring case) if and only if all of the characters |
| 785 // and the end of both has been reached. | 788 // were equal, and the end of both has been reached. |
| 786 return begin == end && !*protocol; | 789 return begin == end && !*protocol; |
| 787 } | 790 } |
| 788 | 791 |
| 789 template <typename CHAR> | 792 template <typename CHAR> |
| 790 bool checkIfProtocolIsInHTTPFamily(const url::Component& scheme, | 793 bool checkIfProtocolIsInHTTPFamily(const url::Component& scheme, |
| 791 const CHAR* spec) { | 794 const CHAR* spec) { |
| 792 if (scheme.len == 4) | 795 if (scheme.len == 4) |
| 793 return internalProtocolIs(scheme, spec, "http"); | 796 return internalProtocolIs(scheme, spec, "http"); |
| 794 if (scheme.len == 5) | 797 if (scheme.len == 5) |
| 795 return internalProtocolIs(scheme, spec, "https"); | 798 return internalProtocolIs(scheme, spec, "https"); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 810 m_protocolIsInHTTPFamily = | 813 m_protocolIsInHTTPFamily = |
| 811 m_string.is8Bit() ? checkIfProtocolIsInHTTPFamily(m_parsed.scheme, | 814 m_string.is8Bit() ? checkIfProtocolIsInHTTPFamily(m_parsed.scheme, |
| 812 m_string.characters8()) | 815 m_string.characters8()) |
| 813 : checkIfProtocolIsInHTTPFamily( | 816 : checkIfProtocolIsInHTTPFamily( |
| 814 m_parsed.scheme, m_string.characters16()); | 817 m_parsed.scheme, m_string.characters16()); |
| 815 } | 818 } |
| 816 | 819 |
| 817 bool KURL::protocolIs(const char* protocol) const { | 820 bool KURL::protocolIs(const char* protocol) const { |
| 818 assertProtocolIsGood(protocol); | 821 assertProtocolIsGood(protocol); |
| 819 | 822 |
| 820 // JavaScript URLs are "valid" and should be executed even if KURL decides the
y are invalid. | 823 // JavaScript URLs are "valid" and should be executed even if KURL decides |
| 821 // The free function protocolIsJavaScript() should be used instead. | 824 // they are invalid. The free function protocolIsJavaScript() should be used |
| 822 // FIXME: Chromium code needs to be fixed for this assert to be enabled. ASSER
T(strcmp(protocol, "javascript")); | 825 // instead. |
| 826 // FIXME: Chromium code needs to be fixed for this assert to be enabled. |
| 827 // ASSERT(strcmp(protocol, "javascript")); |
| 823 | 828 |
| 824 if (m_string.isNull() || m_parsed.scheme.len <= 0) | 829 if (m_string.isNull() || m_parsed.scheme.len <= 0) |
| 825 return *protocol == '\0'; | 830 return *protocol == '\0'; |
| 826 | 831 |
| 827 return m_string.is8Bit() | 832 return m_string.is8Bit() |
| 828 ? internalProtocolIs(m_parsed.scheme, m_string.characters8(), | 833 ? internalProtocolIs(m_parsed.scheme, m_string.characters8(), |
| 829 protocol) | 834 protocol) |
| 830 : internalProtocolIs(m_parsed.scheme, m_string.characters16(), | 835 : internalProtocolIs(m_parsed.scheme, m_string.characters16(), |
| 831 protocol); | 836 protocol); |
| 832 } | 837 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 863 m_parsed = newParsed; | 868 m_parsed = newParsed; |
| 864 m_string = AtomicString::fromUTF8(output.data(), output.length()); | 869 m_string = AtomicString::fromUTF8(output.data(), output.length()); |
| 865 } | 870 } |
| 866 | 871 |
| 867 bool KURL::isSafeToSendToAnotherThread() const { | 872 bool KURL::isSafeToSendToAnotherThread() const { |
| 868 return m_string.isSafeToSendToAnotherThread() && | 873 return m_string.isSafeToSendToAnotherThread() && |
| 869 (!m_innerURL || m_innerURL->isSafeToSendToAnotherThread()); | 874 (!m_innerURL || m_innerURL->isSafeToSendToAnotherThread()); |
| 870 } | 875 } |
| 871 | 876 |
| 872 } // namespace blink | 877 } // namespace blink |
| OLD | NEW |