diff options
Diffstat (limited to 'Source/WebCore/page/UserContentURLPattern.cpp')
-rw-r--r-- | Source/WebCore/page/UserContentURLPattern.cpp | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/Source/WebCore/page/UserContentURLPattern.cpp b/Source/WebCore/page/UserContentURLPattern.cpp index fdaed1e50..d431ee74d 100644 --- a/Source/WebCore/page/UserContentURLPattern.cpp +++ b/Source/WebCore/page/UserContentURLPattern.cpp @@ -10,10 +10,10 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR @@ -27,6 +27,7 @@ #include "UserContentURLPattern.h" #include "URL.h" +#include <wtf/NeverDestroyed.h> #include <wtf/StdLibExtras.h> namespace WebCore { @@ -37,9 +38,8 @@ bool UserContentURLPattern::matchesPatterns(const URL& url, const Vector<String> // If there is no whitelist at all, then all URLs are assumed to be in the whitelist. bool matchesWhitelist = whitelist.isEmpty(); if (!matchesWhitelist) { - size_t whitelistSize = whitelist.size(); - for (size_t i = 0; i < whitelistSize; ++i) { - UserContentURLPattern contentPattern(whitelist[i]); + for (auto& entry : whitelist) { + UserContentURLPattern contentPattern(entry); if (contentPattern.matches(url)) { matchesWhitelist = true; break; @@ -49,9 +49,8 @@ bool UserContentURLPattern::matchesPatterns(const URL& url, const Vector<String> bool matchesBlacklist = false; if (!blacklist.isEmpty()) { - size_t blacklistSize = blacklist.size(); - for (size_t i = 0; i < blacklistSize; ++i) { - UserContentURLPattern contentPattern(blacklist[i]); + for (auto& entry : blacklist) { + UserContentURLPattern contentPattern(entry); if (contentPattern.matches(url)) { matchesBlacklist = true; break; @@ -64,7 +63,7 @@ bool UserContentURLPattern::matchesPatterns(const URL& url, const Vector<String> bool UserContentURLPattern::parse(const String& pattern) { - DEFINE_STATIC_LOCAL(const String, schemeSeparator, (ASCIILiteral("://"))); + static NeverDestroyed<const String> schemeSeparator(ASCIILiteral("://")); size_t schemeEndPos = pattern.find(schemeSeparator); if (schemeEndPos == notFound) @@ -72,16 +71,16 @@ bool UserContentURLPattern::parse(const String& pattern) m_scheme = pattern.left(schemeEndPos); - unsigned hostStartPos = schemeEndPos + schemeSeparator.length(); + unsigned hostStartPos = schemeEndPos + schemeSeparator.get().length(); if (hostStartPos >= pattern.length()) return false; int pathStartPos = 0; - if (equalIgnoringCase(m_scheme, "file")) + if (equalLettersIgnoringASCIICase(m_scheme, "file")) pathStartPos = hostStartPos; else { - size_t hostEndPos = pattern.find("/", hostStartPos); + size_t hostEndPos = pattern.find('/', hostStartPos); if (hostEndPos == notFound) return false; @@ -90,7 +89,7 @@ bool UserContentURLPattern::parse(const String& pattern) if (m_host == "*") { // The pattern can be just '*', which means match all domains. - m_host = ""; + m_host = emptyString(); m_matchSubdomains = true; } else if (m_host.startsWith("*.")) { // The first component can be '*', which means to match all subdomains. @@ -99,7 +98,7 @@ bool UserContentURLPattern::parse(const String& pattern) } // No other '*' can occur in the host. - if (m_host.find("*") != notFound) + if (m_host.find('*') != notFound) return false; pathStartPos = hostEndPos; @@ -115,10 +114,10 @@ bool UserContentURLPattern::matches(const URL& test) const if (m_invalid) return false; - if (!equalIgnoringCase(test.protocol(), m_scheme)) + if (!equalIgnoringASCIICase(test.protocol(), m_scheme)) return false; - if (!equalIgnoringCase(m_scheme, "file") && !matchesHost(test)) + if (!equalLettersIgnoringASCIICase(m_scheme, "file") && !matchesHost(test)) return false; return matchesPath(test); @@ -127,7 +126,7 @@ bool UserContentURLPattern::matches(const URL& test) const bool UserContentURLPattern::matchesHost(const URL& test) const { const String& host = test.host(); - if (equalIgnoringCase(host, m_host)) + if (equalIgnoringASCIICase(host, m_host)) return true; if (!m_matchSubdomains) |