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 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 710 if (url.is8Bit()) | 710 if (url.is8Bit()) |
| 711 return url::FindAndCompareScheme(asURLChar8Subtle(url), url.length(), | 711 return url::FindAndCompareScheme(asURLChar8Subtle(url), url.length(), |
| 712 protocol, 0); | 712 protocol, 0); |
| 713 return url::FindAndCompareScheme(url.characters16(), url.length(), protocol, | 713 return url::FindAndCompareScheme(url.characters16(), url.length(), protocol, |
| 714 0); | 714 0); |
| 715 } | 715 } |
| 716 | 716 |
| 717 void KURL::init(const KURL& base, | 717 void KURL::init(const KURL& base, |
| 718 const String& relative, | 718 const String& relative, |
| 719 const WTF::TextEncoding* queryEncoding) { | 719 const WTF::TextEncoding* queryEncoding) { |
| 720 url::RawCanonOutputT<char> canonical; | |
| 720 if (!relative.isNull() && relative.is8Bit()) { | 721 if (!relative.isNull() && relative.is8Bit()) { |
| 721 StringUTF8Adaptor relativeUTF8(relative); | 722 StringUTF8Adaptor relativeUTF8(relative); |
| 722 init(base, relativeUTF8.data(), relativeUTF8.length(), queryEncoding); | 723 int relativeLength = static_cast<int>(relativeUTF8.length()); |
|
esprehn
2016/10/25 22:23:50
This is scary, our strings can be unsigned in leng
Charlie Harrison
2016/10/27 02:12:36
Done.
| |
| 723 } else | 724 init(base, relativeUTF8.data(), relativeLength, queryEncoding, &canonical); |
| 724 init(base, relative.characters16(), relative.length(), queryEncoding); | 725 |
| 726 // If the relative input is exactly equal to the canonical output, do not | |
| 727 // re-allocate the string. Note that this dangerously makes the input String | |
| 728 // an AtomicString, which is not safe for Strings that are meant to be | |
| 729 // passed between threads. | |
| 730 if (!relative.isEmpty() && relative.containsOnlyASCII() && | |
|
esprehn
2016/10/25 22:23:50
Why does containsOnlyASCII() matter here? I don't
Charlie Harrison
2016/10/27 02:12:36
You're right. removed.
| |
| 731 relativeLength == canonical.length() && | |
| 732 !memcmp(canonical.data(), relativeUTF8.data(), canonical.length())) { | |
| 733 m_string = AtomicString(relative); | |
| 734 } | |
| 735 } else { | |
| 736 init(base, relative.characters16(), relative.length(), queryEncoding, | |
| 737 &canonical); | |
| 738 } | |
| 739 | |
| 740 if (!m_string) | |
| 741 m_string = AtomicString::fromUTF8(canonical.data(), canonical.length()); | |
| 742 | |
| 725 initProtocolIsInHTTPFamily(); | 743 initProtocolIsInHTTPFamily(); |
| 726 initInnerURL(); | 744 initInnerURL(); |
| 727 } | 745 } |
| 728 | 746 |
| 729 template <typename CHAR> | 747 template <typename CHAR> |
| 730 void KURL::init(const KURL& base, | 748 void KURL::init(const KURL& base, |
| 731 const CHAR* relative, | 749 const CHAR* relative, |
| 732 int relativeLength, | 750 int relativeLength, |
| 733 const WTF::TextEncoding* queryEncoding) { | 751 const WTF::TextEncoding* queryEncoding, |
| 752 url::RawCanonOutputT<char>* output) { | |
| 734 // As a performance optimization, we do not use the charset converter | 753 // As a performance optimization, we do not use the charset converter |
| 735 // if encoding is UTF-8 or other Unicode encodings. Note that this is | 754 // if encoding is UTF-8 or other Unicode encodings. Note that this is |
| 736 // per HTML5 2.5.3 (resolving URL). The URL canonicalizer will be more | 755 // per HTML5 2.5.3 (resolving URL). The URL canonicalizer will be more |
| 737 // efficient with no charset converter object because it can do UTF-8 | 756 // efficient with no charset converter object because it can do UTF-8 |
| 738 // internally with no extra copies. | 757 // internally with no extra copies. |
| 739 | 758 |
| 740 // We feel free to make the charset converter object every time since it's | 759 // We feel free to make the charset converter object every time since it's |
| 741 // just a wrapper around a reference. | 760 // just a wrapper around a reference. |
| 742 KURLCharsetConverter charsetConverterObject(queryEncoding); | 761 KURLCharsetConverter charsetConverterObject(queryEncoding); |
| 743 KURLCharsetConverter* charsetConverter = | 762 KURLCharsetConverter* charsetConverter = |
| 744 (!queryEncoding || isUnicodeEncoding(queryEncoding)) | 763 (!queryEncoding || isUnicodeEncoding(queryEncoding)) |
| 745 ? 0 | 764 ? 0 |
| 746 : &charsetConverterObject; | 765 : &charsetConverterObject; |
| 747 | 766 |
| 748 StringUTF8Adaptor baseUTF8(base.getString()); | 767 StringUTF8Adaptor baseUTF8(base.getString()); |
| 749 | 768 |
| 750 url::RawCanonOutputT<char> output; | |
| 751 m_isValid = url::ResolveRelative(baseUTF8.data(), baseUTF8.length(), | 769 m_isValid = url::ResolveRelative(baseUTF8.data(), baseUTF8.length(), |
| 752 base.m_parsed, relative, relativeLength, | 770 base.m_parsed, relative, relativeLength, |
| 753 charsetConverter, &output, &m_parsed); | 771 charsetConverter, output, &m_parsed); |
| 754 | |
| 755 // See FIXME in KURLPrivate in the header. If canonicalization has not | |
| 756 // changed the string, we can avoid an extra allocation by using assignment. | |
| 757 m_string = AtomicString::fromUTF8(output.data(), output.length()); | |
| 758 } | 772 } |
| 759 | 773 |
| 760 void KURL::initInnerURL() { | 774 void KURL::initInnerURL() { |
| 761 if (!m_isValid) { | 775 if (!m_isValid) { |
| 762 m_innerURL.reset(); | 776 m_innerURL.reset(); |
| 763 return; | 777 return; |
| 764 } | 778 } |
| 765 if (url::Parsed* innerParsed = m_parsed.inner_parsed()) | 779 if (url::Parsed* innerParsed = m_parsed.inner_parsed()) |
| 766 m_innerURL = wrapUnique(new KURL( | 780 m_innerURL = wrapUnique(new KURL( |
| 767 ParsedURLString, | 781 ParsedURLString, |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 868 m_parsed = newParsed; | 882 m_parsed = newParsed; |
| 869 m_string = AtomicString::fromUTF8(output.data(), output.length()); | 883 m_string = AtomicString::fromUTF8(output.data(), output.length()); |
| 870 } | 884 } |
| 871 | 885 |
| 872 bool KURL::isSafeToSendToAnotherThread() const { | 886 bool KURL::isSafeToSendToAnotherThread() const { |
| 873 return m_string.isSafeToSendToAnotherThread() && | 887 return m_string.isSafeToSendToAnotherThread() && |
| 874 (!m_innerURL || m_innerURL->isSafeToSendToAnotherThread()); | 888 (!m_innerURL || m_innerURL->isSafeToSendToAnotherThread()); |
| 875 } | 889 } |
| 876 | 890 |
| 877 } // namespace blink | 891 } // namespace blink |
| OLD | NEW |