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 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 if (!relative.isNull() && relative.is8Bit()) { | 720 if (!relative.isNull() && relative.is8Bit()) { |
| 721 StringUTF8Adaptor relativeUTF8(relative); | 721 // Avoid using StringUTF8Adaptor because we want the possibly non-ascii data |
| 722 init(base, relativeUTF8.data(), relativeUTF8.length(), queryEncoding); | 722 // exposed to init<CHAR> as a String to avoid re-allocation. |
| 723 } else | 723 String utf8 = relative.containsOnlyASCII() |
| 724 init(base, relative.characters16(), relative.length(), queryEncoding); | 724 ? relative |
|
esprehn
2016/10/25 22:23:50
We go down this path when relative.isNull() which
Charlie Harrison
2016/10/27 02:12:36
The null check is just for the is8Bit check which
| |
| 725 : String::fromUTF8(relative.utf8()); | |
| 726 init(base, reinterpret_cast<const char*>(utf8.characters8()), utf8.length(), | |
| 727 queryEncoding, utf8); | |
| 728 } else { | |
| 729 init(base, relative.characters16(), relative.length(), queryEncoding, | |
| 730 relative); | |
| 731 } | |
| 725 initProtocolIsInHTTPFamily(); | 732 initProtocolIsInHTTPFamily(); |
| 726 initInnerURL(); | 733 initInnerURL(); |
| 727 } | 734 } |
| 728 | 735 |
| 729 template <typename CHAR> | 736 template <typename CHAR> |
| 730 void KURL::init(const KURL& base, | 737 void KURL::init(const KURL& base, |
| 731 const CHAR* relative, | 738 const CHAR* relative, |
| 732 int relativeLength, | 739 int relativeLength, |
| 733 const WTF::TextEncoding* queryEncoding) { | 740 const WTF::TextEncoding* queryEncoding, |
| 741 const String& originalRelative) { | |
| 734 // As a performance optimization, we do not use the charset converter | 742 // 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 | 743 // 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 | 744 // 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 | 745 // efficient with no charset converter object because it can do UTF-8 |
| 738 // internally with no extra copies. | 746 // internally with no extra copies. |
| 739 | 747 |
| 740 // We feel free to make the charset converter object every time since it's | 748 // We feel free to make the charset converter object every time since it's |
| 741 // just a wrapper around a reference. | 749 // just a wrapper around a reference. |
| 742 KURLCharsetConverter charsetConverterObject(queryEncoding); | 750 KURLCharsetConverter charsetConverterObject(queryEncoding); |
| 743 KURLCharsetConverter* charsetConverter = | 751 KURLCharsetConverter* charsetConverter = |
| 744 (!queryEncoding || isUnicodeEncoding(queryEncoding)) | 752 (!queryEncoding || isUnicodeEncoding(queryEncoding)) |
| 745 ? 0 | 753 ? 0 |
| 746 : &charsetConverterObject; | 754 : &charsetConverterObject; |
| 747 | 755 |
| 748 StringUTF8Adaptor baseUTF8(base.getString()); | 756 StringUTF8Adaptor baseUTF8(base.getString()); |
| 749 | 757 |
| 750 url::RawCanonOutputT<char> output; | 758 url::RawCanonOutputT<char> output; |
| 751 m_isValid = url::ResolveRelative(baseUTF8.data(), baseUTF8.length(), | 759 m_isValid = url::ResolveRelative(baseUTF8.data(), baseUTF8.length(), |
| 752 base.m_parsed, relative, relativeLength, | 760 base.m_parsed, relative, relativeLength, |
| 753 charsetConverter, &output, &m_parsed); | 761 charsetConverter, &output, &m_parsed); |
| 754 | 762 |
| 755 // See FIXME in KURLPrivate in the header. If canonicalization has not | 763 // If the canonicalization has not changed the string, avoid re-allocating. |
| 756 // changed the string, we can avoid an extra allocation by using assignment. | 764 // Note: because we are canonicalizing into narrow characters, this check will |
| 757 m_string = AtomicString::fromUTF8(output.data(), output.length()); | 765 // always be false for 16 bit inputs. |
| 766 if (output.length() == relativeLength && | |
| 767 !memcmp(output.data(), relative, relativeLength)) { | |
| 768 m_string = AtomicString(originalRelative); | |
| 769 } else { | |
| 770 m_string = AtomicString::fromUTF8(output.data(), output.length()); | |
| 771 } | |
| 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 |