Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1197)

Unified Diff: third_party/WebKit/Source/platform/weborigin/KURL.cpp

Issue 2647633006: Make KURL::protocolIs take StringView (+ DCHECK cleanups) (Closed)
Patch Set: comment only changes Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/weborigin/KURL.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 c81f2d3a3eff09c385138a0a2d350b98e191248b..efa526fb3cda5c0bf4decd5817f56bfda3176c4b 100644
--- a/third_party/WebKit/Source/platform/weborigin/KURL.cpp
+++ b/third_party/WebKit/Source/platform/weborigin/KURL.cpp
@@ -47,21 +47,20 @@ namespace blink {
static const int maximumValidPortNumber = 0xFFFE;
static const int invalidPortNumber = 0xFFFF;
-static void assertProtocolIsGood(const char* protocol) {
#if DCHECK_IS_ON()
- DCHECK_NE(protocol, "");
- const char* p = protocol;
- while (*p) {
- ASSERT(*p > ' ' && *p < 0x7F && !(*p >= 'A' && *p <= 'Z'));
- ++p;
+static void assertProtocolIsGood(const StringView protocol) {
+ DCHECK(protocol != "");
+ for (size_t i = 0; i < protocol.length(); ++i) {
+ LChar c = protocol.characters8()[i];
+ DCHECK(c > ' ' && c < 0x7F && !(c >= 'A' && c <= 'Z'));
esprehn 2017/01/20 17:50:04 This could probably be simpler I think? You want i
}
-#endif
}
+#endif
// Note: You must ensure that |spec| is a valid canonicalized URL before calling
// this function.
static const char* asURLChar8Subtle(const String& spec) {
- ASSERT(spec.is8Bit());
+ DCHECK(spec.is8Bit());
// characters8 really return characters in Latin-1, but because we
// canonicalize URL strings, we know that everything before the fragment
// identifier will actually be ASCII, which means this cast is safe as long as
@@ -318,7 +317,7 @@ bool KURL::hasPath() const {
String KURL::lastPathComponent() const {
if (!m_isValid)
return stringViewForInvalidComponent().toString();
- ASSERT(!m_string.isNull());
+ DCHECK(!m_string.isNull());
// When the output ends in a slash, WebCore has different expectations than
// the GoogleURL library. For "/foo/bar/" the library will return the empty
@@ -358,11 +357,11 @@ String KURL::host() const {
unsigned short KURL::port() const {
if (!m_isValid || m_parsed.port.len <= 0)
return 0;
- ASSERT(!m_string.isNull());
+ DCHECK(!m_string.isNull());
int port = m_string.is8Bit()
? url::ParsePort(asURLChar8Subtle(m_string), m_parsed.port)
: url::ParsePort(m_string.characters16(), m_parsed.port);
- ASSERT(port != url::PORT_UNSPECIFIED); // Checked port.len <= 0 before.
+ DCHECK_NE(port, url::PORT_UNSPECIFIED); // Checked port.len <= 0 before.
if (port == url::PORT_INVALID ||
port > maximumValidPortNumber) // Mimic KURL::port()
@@ -526,7 +525,7 @@ void KURL::setPort(unsigned short port) {
}
String portString = String::number(port);
- ASSERT(portString.is8Bit());
+ DCHECK(portString.is8Bit());
url::Replacements<char> replacements;
replacements.SetPort(reinterpret_cast<const char*>(portString.characters8()),
@@ -714,7 +713,9 @@ unsigned KURL::pathAfterLastSlash() const {
}
bool protocolIs(const String& url, const char* protocol) {
+#if DCHECK_IS_ON()
assertProtocolIsGood(protocol);
+#endif
if (url.isNull())
return false;
if (url.is8Bit())
@@ -816,8 +817,10 @@ void KURL::initProtocolMetadata() {
DCHECK_EQ(m_protocol, m_protocol.lower());
}
-bool KURL::protocolIs(const char* protocol) const {
+bool KURL::protocolIs(const StringView protocol) const {
+#if DCHECK_IS_ON()
assertProtocolIsGood(protocol);
+#endif
// JavaScript URLs are "valid" and should be executed even if KURL decides
// they are invalid. The free function protocolIsJavaScript() should be used
« no previous file with comments | « third_party/WebKit/Source/platform/weborigin/KURL.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698