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 11 matching lines...) Expand all Loading... | |
| 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #include "platform/weborigin/KURL.h" | 28 #include "platform/weborigin/KURL.h" |
| 29 | 29 |
| 30 #include "platform/weborigin/KnownPorts.h" | 30 #include "platform/weborigin/KnownPorts.h" |
| 31 #include "url/url_util.h" | 31 #include "url/url_util.h" |
| 32 #include "wtf/MathExtras.h" | |
| 32 #include "wtf/PtrUtil.h" | 33 #include "wtf/PtrUtil.h" |
| 33 #include "wtf/StdLibExtras.h" | 34 #include "wtf/StdLibExtras.h" |
| 34 #include "wtf/text/CString.h" | 35 #include "wtf/text/CString.h" |
| 35 #include "wtf/text/StringHash.h" | 36 #include "wtf/text/StringHash.h" |
| 36 #include "wtf/text/StringUTF8Adaptor.h" | 37 #include "wtf/text/StringUTF8Adaptor.h" |
| 37 #include "wtf/text/TextEncoding.h" | 38 #include "wtf/text/TextEncoding.h" |
| 38 #include <algorithm> | 39 #include <algorithm> |
| 39 #ifndef NDEBUG | 40 #ifndef NDEBUG |
| 40 #include <stdio.h> | 41 #include <stdio.h> |
| 41 #endif | 42 #endif |
| (...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 710 if (url.is8Bit()) | 711 if (url.is8Bit()) |
| 711 return url::FindAndCompareScheme(asURLChar8Subtle(url), url.length(), | 712 return url::FindAndCompareScheme(asURLChar8Subtle(url), url.length(), |
| 712 protocol, 0); | 713 protocol, 0); |
| 713 return url::FindAndCompareScheme(url.characters16(), url.length(), protocol, | 714 return url::FindAndCompareScheme(url.characters16(), url.length(), protocol, |
| 714 0); | 715 0); |
| 715 } | 716 } |
| 716 | 717 |
| 717 void KURL::init(const KURL& base, | 718 void KURL::init(const KURL& base, |
| 718 const String& relative, | 719 const String& relative, |
| 719 const WTF::TextEncoding* queryEncoding) { | 720 const WTF::TextEncoding* queryEncoding) { |
| 720 if (!relative.isNull() && relative.is8Bit()) { | |
| 721 StringUTF8Adaptor relativeUTF8(relative); | |
| 722 init(base, relativeUTF8.data(), relativeUTF8.length(), queryEncoding); | |
| 723 } else | |
| 724 init(base, relative.characters16(), relative.length(), queryEncoding); | |
| 725 initProtocolIsInHTTPFamily(); | |
| 726 initInnerURL(); | |
| 727 DCHECK_EQ(protocol(), protocol().lower()); | |
| 728 } | |
| 729 | |
| 730 template <typename CHAR> | |
| 731 void KURL::init(const KURL& base, | |
| 732 const CHAR* relative, | |
| 733 int relativeLength, | |
| 734 const WTF::TextEncoding* queryEncoding) { | |
| 735 // As a performance optimization, we do not use the charset converter | 721 // As a performance optimization, we do not use the charset converter |
| 736 // if encoding is UTF-8 or other Unicode encodings. Note that this is | 722 // if encoding is UTF-8 or other Unicode encodings. Note that this is |
| 737 // per HTML5 2.5.3 (resolving URL). The URL canonicalizer will be more | 723 // per HTML5 2.5.3 (resolving URL). The URL canonicalizer will be more |
| 738 // efficient with no charset converter object because it can do UTF-8 | 724 // efficient with no charset converter object because it can do UTF-8 |
| 739 // internally with no extra copies. | 725 // internally with no extra copies. |
| 740 | 726 |
| 727 StringUTF8Adaptor baseUTF8(base.getString()); | |
| 728 | |
| 741 // We feel free to make the charset converter object every time since it's | 729 // We feel free to make the charset converter object every time since it's |
| 742 // just a wrapper around a reference. | 730 // just a wrapper around a reference. |
| 743 KURLCharsetConverter charsetConverterObject(queryEncoding); | 731 KURLCharsetConverter charsetConverterObject(queryEncoding); |
| 744 KURLCharsetConverter* charsetConverter = | 732 KURLCharsetConverter* charsetConverter = |
| 745 (!queryEncoding || isUnicodeEncoding(queryEncoding)) | 733 (!queryEncoding || isUnicodeEncoding(queryEncoding)) |
| 746 ? 0 | 734 ? 0 |
| 747 : &charsetConverterObject; | 735 : &charsetConverterObject; |
| 748 | 736 |
| 749 StringUTF8Adaptor baseUTF8(base.getString()); | 737 // Clamp to int max to avoid overflow. |
| 738 url::RawCanonOutputT<char> output; | |
| 739 if (!relative.isNull() && relative.is8Bit()) { | |
| 740 StringUTF8Adaptor relativeUTF8(relative); | |
| 741 m_isValid = url::ResolveRelative(baseUTF8.data(), baseUTF8.length(), | |
| 742 base.m_parsed, relativeUTF8.data(), | |
| 743 clampTo<int>(relativeUTF8.length()), | |
| 744 charsetConverter, &output, &m_parsed); | |
| 745 } else { | |
| 746 m_isValid = url::ResolveRelative(baseUTF8.data(), baseUTF8.length(), | |
| 747 base.m_parsed, relative.characters16(), | |
| 748 clampTo<int>(relative.length()), | |
| 749 charsetConverter, &output, &m_parsed); | |
| 750 } | |
| 750 | 751 |
| 751 url::RawCanonOutputT<char> output; | 752 // AtomicString::fromUTF8 will re-hash the raw output and check the |
| 752 m_isValid = url::ResolveRelative(baseUTF8.data(), baseUTF8.length(), | 753 // AtomicStringTable (addWithTranslator) for the string. This can be very |
| 753 base.m_parsed, relative, relativeLength, | 754 // expensive for large URLs. However, since many URLs are generated from |
| 754 charsetConverter, &output, &m_parsed); | 755 // existing AtomicStrings (which already have their hashes computed), this |
| 756 // fast path is used if the input string is already canonicalized. | |
| 757 // | |
| 758 // Because this optimization does not apply to non-AtomicStrings, explicitly | |
| 759 // check that the input is Atomic before moving forward with it. If we mark | |
| 760 // non-Atomic input as Atomic here, we will render the (const) input string | |
| 761 // thread unsafe. | |
| 762 if (!relative.isNull() && relative.impl()->isAtomic() && | |
| 763 StringView(output.data(), static_cast<unsigned>(output.length())) == | |
| 764 relative) { | |
| 765 m_string = relative; | |
|
esprehn
2016/11/05 02:33:14
btw why does this compile?
explicit AtomicString(
Charlie Harrison
2016/11/05 03:20:16
m_string is just a String on KURL, not an explicit
| |
| 766 } else { | |
| 767 m_string = AtomicString::fromUTF8(output.data(), output.length()); | |
| 768 } | |
| 755 | 769 |
| 756 // See FIXME in KURLPrivate in the header. If canonicalization has not | 770 initProtocolIsInHTTPFamily(); |
| 757 // changed the string, we can avoid an extra allocation by using assignment. | 771 initInnerURL(); |
| 758 m_string = AtomicString::fromUTF8(output.data(), output.length()); | 772 DCHECK_EQ(protocol(), protocol().lower()); |
| 759 } | 773 } |
| 760 | 774 |
| 761 void KURL::initInnerURL() { | 775 void KURL::initInnerURL() { |
| 762 if (!m_isValid) { | 776 if (!m_isValid) { |
| 763 m_innerURL.reset(); | 777 m_innerURL.reset(); |
| 764 return; | 778 return; |
| 765 } | 779 } |
| 766 if (url::Parsed* innerParsed = m_parsed.inner_parsed()) | 780 if (url::Parsed* innerParsed = m_parsed.inner_parsed()) |
| 767 m_innerURL = wrapUnique(new KURL( | 781 m_innerURL = wrapUnique(new KURL( |
| 768 ParsedURLString, | 782 ParsedURLString, |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 869 m_parsed = newParsed; | 883 m_parsed = newParsed; |
| 870 m_string = AtomicString::fromUTF8(output.data(), output.length()); | 884 m_string = AtomicString::fromUTF8(output.data(), output.length()); |
| 871 } | 885 } |
| 872 | 886 |
| 873 bool KURL::isSafeToSendToAnotherThread() const { | 887 bool KURL::isSafeToSendToAnotherThread() const { |
| 874 return m_string.isSafeToSendToAnotherThread() && | 888 return m_string.isSafeToSendToAnotherThread() && |
| 875 (!m_innerURL || m_innerURL->isSafeToSendToAnotherThread()); | 889 (!m_innerURL || m_innerURL->isSafeToSendToAnotherThread()); |
| 876 } | 890 } |
| 877 | 891 |
| 878 } // namespace blink | 892 } // namespace blink |
| OLD | NEW |