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

Unified Diff: third_party/WebKit/Source/core/frame/csp/CSPSource.cpp

Issue 2456493002: Splitting *Matches functions in CSPSource (Closed)
Patch Set: Removing equalIgnoringCase Created 4 years, 2 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
Index: third_party/WebKit/Source/core/frame/csp/CSPSource.cpp
diff --git a/third_party/WebKit/Source/core/frame/csp/CSPSource.cpp b/third_party/WebKit/Source/core/frame/csp/CSPSource.cpp
index 8f15383227bf8708b37b23f6073c0cd5387bf1cc..fbfec32a97f006d9b542abfa5bc50351734c60ac 100644
--- a/third_party/WebKit/Source/core/frame/csp/CSPSource.cpp
+++ b/third_party/WebKit/Source/core/frame/csp/CSPSource.cpp
@@ -42,17 +42,23 @@ bool CSPSource::matches(const KURL& url,
bool CSPSource::schemeMatches(const KURL& url) const {
if (m_scheme.isEmpty())
return m_policy->protocolMatchesSelf(url);
- if (equalIgnoringCase(m_scheme, "http"))
- return equalIgnoringCase(url.protocol(), "http") ||
- equalIgnoringCase(url.protocol(), "https");
- if (equalIgnoringCase(m_scheme, "ws"))
- return equalIgnoringCase(url.protocol(), "ws") ||
- equalIgnoringCase(url.protocol(), "wss");
- return equalIgnoringCase(url.protocol(), m_scheme);
+ return schemeMatches(url.protocol());
+}
+
+bool CSPSource::schemeMatches(const String& protocol) const {
+ DCHECK_EQ(m_scheme, m_scheme.lower());
+ if (m_scheme == "http")
+ return protocol == "http" || protocol == "https";
+ if (m_scheme == "ws")
+ protocol == "ws" || protocol == "wss";
+ return protocol == m_scheme;
}
bool CSPSource::hostMatches(const KURL& url) const {
- const String& host = url.host();
+ return hostMatches(url.host());
+}
+
+bool CSPSource::hostMatches(const String& host) const {
Document* document = m_policy->document();
bool match;
@@ -75,10 +81,14 @@ bool CSPSource::hostMatches(const KURL& url) const {
}
bool CSPSource::pathMatches(const KURL& url) const {
+ return pathMatches(url.path());
+}
+
+bool CSPSource::pathMatches(const String& urlPath) const {
if (m_path.isEmpty())
return true;
- String path = decodeURLEscapeSequences(url.path());
+ String path = decodeURLEscapeSequences(urlPath);
if (m_path.endsWith("/"))
return path.startsWith(m_path);
@@ -87,24 +97,25 @@ bool CSPSource::pathMatches(const KURL& url) const {
}
bool CSPSource::portMatches(const KURL& url) const {
+ return portMatches(url.port(), url.protocol());
+}
+
+bool CSPSource::portMatches(int port, const String& protocol) const {
if (m_portWildcard == HasWildcard)
return true;
- int port = url.port();
-
if (port == m_port)
return true;
if (m_port == 80 &&
- (port == 443 ||
- (port == 0 && defaultPortForProtocol(url.protocol()) == 443)))
+ (port == 443 || (port == 0 && defaultPortForProtocol(protocol) == 443)))
return true;
if (!port)
- return isDefaultPortForProtocol(m_port, url.protocol());
+ return isDefaultPortForProtocol(m_port, protocol);
if (!m_port)
- return isDefaultPortForProtocol(port, url.protocol());
+ return isDefaultPortForProtocol(port, protocol);
return false;
}

Powered by Google App Engine
This is Rietveld 408576698