Index: third_party/WebKit/Source/platform/weborigin/KURL.cpp |
diff --git a/third_party/WebKit/Source/platform/weborigin/KURL.cpp b/third_party/WebKit/Source/platform/weborigin/KURL.cpp |
index 48edd0ef58e8855386d8a68fd54b5f9909915ab7..d6b59269cc37aba2d11450f8b004a54df21236e6 100644 |
--- a/third_party/WebKit/Source/platform/weborigin/KURL.cpp |
+++ b/third_party/WebKit/Source/platform/weborigin/KURL.cpp |
@@ -34,6 +34,7 @@ |
#include "wtf/StdLibExtras.h" |
#include "wtf/text/CString.h" |
#include "wtf/text/StringHash.h" |
+#include "wtf/text/StringStatics.h" |
#include "wtf/text/StringUTF8Adaptor.h" |
#include "wtf/text/TextEncoding.h" |
#include <algorithm> |
@@ -48,6 +49,7 @@ static const int invalidPortNumber = 0xFFFF; |
static void assertProtocolIsGood(const char* protocol) { |
#if ENABLE(ASSERT) |
+ DCHECK_NE(protocol, ""); |
const char* p = protocol; |
while (*p) { |
ASSERT(*p > ' ' && *p < 0x7F && !(*p >= 'A' && *p <= 'Z')); |
@@ -241,7 +243,7 @@ KURL::KURL(const AtomicString& canonicalString, |
m_protocolIsInHTTPFamily(false), |
m_parsed(parsed), |
m_string(canonicalString) { |
- initProtocolIsInHTTPFamily(); |
+ initProtocolMetadata(); |
initInnerURL(); |
} |
@@ -253,6 +255,7 @@ KURL::KURL(WTF::HashTableDeletedValueType) |
KURL::KURL(const KURL& other) |
: m_isValid(other.m_isValid), |
m_protocolIsInHTTPFamily(other.m_protocolIsInHTTPFamily), |
+ m_protocol(other.m_protocol), |
m_parsed(other.m_parsed), |
m_string(other.m_string) { |
if (other.m_innerURL.get()) |
@@ -264,6 +267,7 @@ KURL::~KURL() {} |
KURL& KURL::operator=(const KURL& other) { |
m_isValid = other.m_isValid; |
m_protocolIsInHTTPFamily = other.m_protocolIsInHTTPFamily; |
+ m_protocol = other.m_protocol; |
m_parsed = other.m_parsed; |
m_string = other.m_string; |
if (other.m_innerURL) |
@@ -277,6 +281,7 @@ KURL KURL::copy() const { |
KURL result; |
result.m_isValid = m_isValid; |
result.m_protocolIsInHTTPFamily = m_protocolIsInHTTPFamily; |
+ result.m_protocol = m_protocol.isolatedCopy(); |
result.m_parsed = m_parsed; |
result.m_string = m_string.isolatedCopy(); |
if (m_innerURL) |
@@ -336,7 +341,7 @@ String KURL::lastPathComponent() const { |
} |
String KURL::protocol() const { |
- return componentString(m_parsed.scheme); |
+ return m_protocol; |
} |
String KURL::host() const { |
@@ -365,6 +370,9 @@ unsigned short KURL::port() const { |
return static_cast<unsigned short>(port); |
} |
+// TODO(csharrison): Migrate pass() and user() to return a StringView. Most |
+// consumers just need to know if the string is empty. |
+ |
String KURL::pass() const { |
// Bug: https://bugs.webkit.org/show_bug.cgi?id=21015 this function returns |
// a null string when the password is empty, which we duplicate here. |
@@ -433,6 +441,7 @@ bool KURL::setProtocol(const String& protocol) { |
replacements.SetScheme(charactersOrEmpty(newProtocolUTF8), |
url::Component(0, newProtocolUTF8.length())); |
replaceComponents(replacements); |
+ initProtocolMetadata(); |
// isValid could be false but we still return true here. This is because |
// WebCore or JS scripts can build up a URL by setting individual |
@@ -767,7 +776,7 @@ void KURL::init(const KURL& base, |
m_string = AtomicString::fromUTF8(output.data(), output.length()); |
} |
- initProtocolIsInHTTPFamily(); |
+ initProtocolMetadata(); |
initInnerURL(); |
DCHECK_EQ(protocol(), protocol().lower()); |
} |
@@ -786,50 +795,24 @@ void KURL::initInnerURL() { |
m_innerURL.reset(); |
} |
-template <typename CHAR> |
-bool internalProtocolIs(const url::Component& scheme, |
- const CHAR* spec, |
- const char* protocol) { |
- const CHAR* begin = spec + scheme.begin; |
- const CHAR* end = begin + scheme.len; |
- |
- while (begin != end && *protocol) { |
- ASSERT(toASCIILower(*protocol) == *protocol); |
- if (toASCIILower(*begin++) != *protocol++) |
- return false; |
- } |
- |
- // Both strings are equal (ignoring case) if and only if all of the characters |
- // were equal, and the end of both has been reached. |
- return begin == end && !*protocol; |
-} |
- |
-template <typename CHAR> |
-bool checkIfProtocolIsInHTTPFamily(const url::Component& scheme, |
- const CHAR* spec) { |
- if (scheme.len == 4) |
- return internalProtocolIs(scheme, spec, "http"); |
- if (scheme.len == 5) |
- return internalProtocolIs(scheme, spec, "https"); |
- if (scheme.len == 7) |
- return internalProtocolIs(scheme, spec, "http-so"); |
esprehn
2016/12/12 22:18:46
This was all case insensitive before.
Charlie Harrison
2016/12/12 22:26:06
We should always have a canonical, lowercase schem
Charlie Harrison
2016/12/13 16:03:22
Actually, we have a DCHECK_EQ(protocol(), protocol
|
- if (scheme.len == 8) |
- return internalProtocolIs(scheme, spec, "https-so"); |
- return false; |
-} |
- |
-void KURL::initProtocolIsInHTTPFamily() { |
+void KURL::initProtocolMetadata() { |
if (!m_isValid) { |
m_protocolIsInHTTPFamily = false; |
return; |
} |
ASSERT(!m_string.isNull()); |
- m_protocolIsInHTTPFamily = |
- m_string.is8Bit() ? checkIfProtocolIsInHTTPFamily(m_parsed.scheme, |
- m_string.characters8()) |
- : checkIfProtocolIsInHTTPFamily( |
- m_parsed.scheme, m_string.characters16()); |
+ StringView protocol = componentStringView(m_parsed.scheme); |
+ m_protocolIsInHTTPFamily = true; |
+ if (protocol == WTF::httpsAtom) { |
+ m_protocol = WTF::httpsAtom; |
+ } else if (protocol == WTF::httpAtom) { |
+ m_protocol = WTF::httpAtom; |
+ } else { |
+ m_protocol = AtomicString(protocol.toString()); |
+ m_protocolIsInHTTPFamily = |
+ m_protocol == "http-so" || m_protocol == "https-so"; |
esprehn
2016/12/12 22:18:46
What strange protocols are these?
Charlie Harrison
2016/12/12 22:26:06
suborigin protocols:
https://w3c.github.io/webapps
|
+ } |
} |
bool KURL::protocolIs(const char* protocol) const { |
@@ -840,15 +823,7 @@ bool KURL::protocolIs(const char* protocol) const { |
// instead. |
// FIXME: Chromium code needs to be fixed for this assert to be enabled. |
// ASSERT(strcmp(protocol, "javascript")); |
- |
- if (m_string.isNull() || m_parsed.scheme.len <= 0) |
- return *protocol == '\0'; |
- |
- return m_string.is8Bit() |
- ? internalProtocolIs(m_parsed.scheme, m_string.characters8(), |
- protocol) |
- : internalProtocolIs(m_parsed.scheme, m_string.characters16(), |
- protocol); |
+ return m_protocol == protocol; |
esprehn
2016/12/12 22:18:46
internalProtocolIs was case insensitive, are you s
Charlie Harrison
2016/12/12 22:26:06
assertProtocolIsGood checks that the input protoco
|
} |
String KURL::stringForInvalidComponent() const { |
@@ -857,7 +832,7 @@ String KURL::stringForInvalidComponent() const { |
return emptyString(); |
} |
-String KURL::componentString(const url::Component& component) const { |
+StringView KURL::componentStringView(const url::Component& component) const { |
if (!m_isValid || component.len <= 0) |
return stringForInvalidComponent(); |
// begin and len are in terms of bytes which do not match |
@@ -868,7 +843,14 @@ String KURL::componentString(const url::Component& component) const { |
// byte) will be longer than what's needed by 'mid'. However, mid |
// truncates len to avoid go past the end of a string so that we can |
// get away without doing anything here. |
- return getString().substring(component.begin, component.len); |
+ |
+ int maxLength = getString().length() - component.begin; |
+ return StringView(getString(), component.begin, |
+ component.len > maxLength ? maxLength : component.len); |
+} |
+ |
+String KURL::componentString(const url::Component& component) const { |
+ return componentStringView(component).toString(); |
} |
template <typename CHAR> |