Index: Source/platform/URLPatternMatcher.cpp |
diff --git a/Source/core/page/UserContentURLPattern.cpp b/Source/platform/URLPatternMatcher.cpp |
similarity index 79% |
rename from Source/core/page/UserContentURLPattern.cpp |
rename to Source/platform/URLPatternMatcher.cpp |
index 4f18ab875ace2fab6465886524f194ed4fdd6cbe..c6dbf3c84c63a4622eb9479eccded347c7a33127 100644 |
--- a/Source/core/page/UserContentURLPattern.cpp |
+++ b/Source/platform/URLPatternMatcher.cpp |
@@ -24,45 +24,29 @@ |
*/ |
#include "config.h" |
-#include "core/page/UserContentURLPattern.h" |
+#include "platform/URLPatternMatcher.h" |
#include "weborigin/KURL.h" |
#include "wtf/StdLibExtras.h" |
namespace WebCore { |
-bool UserContentURLPattern::matchesPatterns(const KURL& url, const Vector<String>& whitelist, const Vector<String>& blacklist) |
+bool URLPatternMatcher::matchesPatterns(const KURL& url, const Vector<String>& whitelist) |
{ |
- // In order for a URL to be a match it has to be present in the whitelist and not present in the blacklist. |
// 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]); |
- if (contentPattern.matches(url)) { |
- matchesWhitelist = true; |
- break; |
- } |
- } |
- } |
+ if (whitelist.isEmpty()) |
+ return true; |
- bool matchesBlacklist = false; |
- if (!blacklist.isEmpty()) { |
- size_t blacklistSize = blacklist.size(); |
- for (size_t i = 0; i < blacklistSize; ++i) { |
- UserContentURLPattern contentPattern(blacklist[i]); |
- if (contentPattern.matches(url)) { |
- matchesBlacklist = true; |
- break; |
- } |
- } |
+ for (size_t i = 0; i < whitelist.size(); ++i) { |
+ URLPatternMatcher contentPattern(whitelist[i]); |
+ if (contentPattern.matches(url)) |
+ return true; |
} |
- return matchesWhitelist && !matchesBlacklist; |
+ return false; |
} |
-bool UserContentURLPattern::parse(const String& pattern) |
+bool URLPatternMatcher::parse(const String& pattern) |
{ |
DEFINE_STATIC_LOCAL(const String, schemeSeparator, ("://")); |
@@ -78,9 +62,9 @@ bool UserContentURLPattern::parse(const String& pattern) |
int pathStartPos = 0; |
- if (equalIgnoringCase(m_scheme, "file")) |
+ if (equalIgnoringCase(m_scheme, "file")) { |
pathStartPos = hostStartPos; |
- else { |
+ } else { |
size_t hostEndPos = pattern.find("/", hostStartPos); |
if (hostEndPos == kNotFound) |
return false; |
@@ -110,7 +94,7 @@ bool UserContentURLPattern::parse(const String& pattern) |
return true; |
} |
-bool UserContentURLPattern::matches(const KURL& test) const |
+bool URLPatternMatcher::matches(const KURL& test) const |
{ |
if (m_invalid) |
return false; |
@@ -124,7 +108,7 @@ bool UserContentURLPattern::matches(const KURL& test) const |
return matchesPath(test); |
} |
-bool UserContentURLPattern::matchesHost(const KURL& test) const |
+bool URLPatternMatcher::matchesHost(const KURL& test) const |
{ |
const String& host = test.host(); |
if (equalIgnoringCase(host, m_host)) |
@@ -148,8 +132,7 @@ bool UserContentURLPattern::matchesHost(const KURL& test) const |
return host[host.length() - m_host.length() - 1] == '.'; |
} |
-struct MatchTester |
-{ |
+struct MatchTester { |
const String m_pattern; |
unsigned m_patternIndex; |
@@ -218,14 +201,13 @@ struct MatchTester |
m_testIndex++; |
} |
- // We reached the end of the string. Let's see if the pattern contains only |
- // wildcards. |
+ // We reached the end of the string. Let's see if the pattern contains only wildcards. |
eatWildcard(); |
return patternStringFinished(); |
} |
}; |
-bool UserContentURLPattern::matchesPath(const KURL& test) const |
+bool URLPatternMatcher::matchesPath(const KURL& test) const |
{ |
MatchTester match(m_path, test.path()); |
return match.test(); |