<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[195650] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/195650">195650</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-01-26 19:05:49 -0800 (Tue, 26 Jan 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Source/WebKit2:
Implement wildcard matching for plug-in policy host.
https://bugs.webkit.org/show_bug.cgi?id=153090

Patch by I-Ting Liu &lt;iting_liu@apple.com&gt; on 2016-01-26
Reviewed by Darin Adler.

WebPlatformStrategies decides the plug-in load policy for a host by looking
for a matched hostname in the list of plug-in policies sent by Safari. This
patch adds support for wildcard matching -- if there's a policy with hostname
&quot;*.example.com,&quot; the policy for &quot;foo.example.com&quot; would be replaced with that
of &quot;*.example.com&quot; if there's no policy for this hostname. If there is more
than one wildcard hostname, the host with the longest wildcard hostname will
be used.

This patch adds a helper function in StringUtilites that matches a string to
another string, which may contain wildcard ('*') characters.

* Platform/mac/StringUtilities.h:
- Add WebKit::stringMatchesWildcardString.
- Remove #if ENABLE(TELEPHONE_NUMBER_DETECTION) &amp;&amp; PLATFORM(MAC) flag so that
the compiler allows exposing StringUtilities.h.
- Add #if __OBJC__ to allow the file to be included in WebPltformStrategies.cpp

* Platform/mac/StringUtilities.mm:
(WebKit::stringMatchesWildcardString):
Return true if the entire first given String matches the second. The second string
may contain wildcard characters.
(WebKit::wildcardRegexPatternString):
Return the regex expression from a wildcard string by replacing the wildcard
character ('*') with (&quot;.*&quot;) and escaping regular expression metacharacters.
(WebKit::formattedPhoneNumberString):
To expose StringUtilities.h for tests, we removed #if ENABLE(TELEPHONE_NUMBER_DETECTION)
&amp;&amp; PLATFORM(MAC) flag in the header. Add a function that returns nil for
#if !(ENABLE(TELEPHONE_NUMBER_DETECTION) &amp;&amp; PLATFORM(MAC)) to fix the removal
of the flag in the header file.

* WebKit2.xcodeproj/project.pbxproj:
Change the file attribute of StringUtilities.h from Project to Private for
testing in TestWebKitAPI.

* WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
(WebKit::WebPlatformStrategies::longestMatchedWildcardHostForHost):
Return the wildcard hostname whose matched substring with the host is the longest.
(WebKit::WebPlatformStrategies::replaceHostWithMatchedWildcardHost):
Replace the look-up host with a matched wildcard host if there is a match and that
the matched wildcard host's plug-in identifier is the same as that of the host.
(WebKit::WebPlatformStrategies::pluginLoadClientPolicyForHost):
Try to replace the look-up host with the wildcard host if there's no policy for
the host. Restructure the function to reduce hashmap lookup.

* WebProcess/WebCoreSupport/WebPlatformStrategies.h:
Declare the methods.

Source/WTF:
Implement wildcard matching for plug-in policy host.
https://bugs.webkit.org/show_bug.cgi?id=153090

Patch by I-Ting Liu &lt;iting_liu@apple.com&gt; on 2016-01-26
Reviewed by Darin Adler.

* wtf/text/AtomicString.h:
(WTF::AtomicString::AtomicString):
Add __bridge to allow compilation.

Tools:
Add a test for WebKit::stringMatchesWildcardString.
https://bugs.webkit.org/show_bug.cgi?id=153090

Patch by I-Ting Liu &lt;iting_liu@apple.com&gt; on 2016-01-26
Reviewed by Darin Adler.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
Add the file to the project.

* TestWebKitAPI/Tests/WebKit2/mac/StringUtilities.mm: Added.
(TestWebKitAPI::TEST):
Test that a string matches another string that may contain wildcard characters.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtftextAtomicStringh">trunk/Source/WTF/wtf/text/AtomicString.h</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2PlatformmacStringUtilitiesh">trunk/Source/WebKit2/Platform/mac/StringUtilities.h</a></li>
<li><a href="#trunkSourceWebKit2PlatformmacStringUtilitiesmm">trunk/Source/WebKit2/Platform/mac/StringUtilities.mm</a></li>
<li><a href="#trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj">trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebCoreSupportWebPlatformStrategiescpp">trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebCoreSupportWebPlatformStrategiesh">trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.h</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj">trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2macStringUtilitiesmm">trunk/Tools/TestWebKitAPI/Tests/WebKit2/mac/StringUtilities.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (195649 => 195650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2016-01-27 02:41:55 UTC (rev 195649)
+++ trunk/Source/WTF/ChangeLog        2016-01-27 03:05:49 UTC (rev 195650)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2016-01-26  I-Ting Liu  &lt;iting_liu@apple.com&gt;
+
+        Implement wildcard matching for plug-in policy host.
+        https://bugs.webkit.org/show_bug.cgi?id=153090
+
+        Reviewed by Darin Adler.
+
+        * wtf/text/AtomicString.h:
+        (WTF::AtomicString::AtomicString):
+        Add __bridge to allow compilation.
+
</ins><span class="cx"> 2016-01-26  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Generalize ResourceUsageData gathering to be used outside of ResourceUsageOverlay
</span></span></pre></div>
<a id="trunkSourceWTFwtftextAtomicStringh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/text/AtomicString.h (195649 => 195650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/text/AtomicString.h        2016-01-27 02:41:55 UTC (rev 195649)
+++ trunk/Source/WTF/wtf/text/AtomicString.h        2016-01-27 03:05:49 UTC (rev 195650)
</span><span class="lines">@@ -297,7 +297,7 @@
</span><span class="cx"> 
</span><span class="cx"> #ifdef __OBJC__
</span><span class="cx"> inline AtomicString::AtomicString(NSString* s)
</span><del>-    : m_string(AtomicStringImpl::add((CFStringRef)s))
</del><ins>+    : m_string(AtomicStringImpl::add((__bridge CFStringRef)s))
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (195649 => 195650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-01-27 02:41:55 UTC (rev 195649)
+++ trunk/Source/WebKit2/ChangeLog        2016-01-27 03:05:49 UTC (rev 195650)
</span><span class="lines">@@ -1,3 +1,57 @@
</span><ins>+2016-01-26  I-Ting Liu  &lt;iting_liu@apple.com&gt;
+
+        Implement wildcard matching for plug-in policy host.
+        https://bugs.webkit.org/show_bug.cgi?id=153090
+
+        Reviewed by Darin Adler.
+
+        WebPlatformStrategies decides the plug-in load policy for a host by looking
+        for a matched hostname in the list of plug-in policies sent by Safari. This
+        patch adds support for wildcard matching -- if there's a policy with hostname
+        &quot;*.example.com,&quot; the policy for &quot;foo.example.com&quot; would be replaced with that
+        of &quot;*.example.com&quot; if there's no policy for this hostname. If there is more
+        than one wildcard hostname, the host with the longest wildcard hostname will
+        be used.
+
+        This patch adds a helper function in StringUtilites that matches a string to
+        another string, which may contain wildcard ('*') characters.
+
+        * Platform/mac/StringUtilities.h:
+        - Add WebKit::stringMatchesWildcardString.
+        - Remove #if ENABLE(TELEPHONE_NUMBER_DETECTION) &amp;&amp; PLATFORM(MAC) flag so that
+        the compiler allows exposing StringUtilities.h.
+        - Add #if __OBJC__ to allow the file to be included in WebPltformStrategies.cpp
+
+        * Platform/mac/StringUtilities.mm:
+        (WebKit::stringMatchesWildcardString):
+        Return true if the entire first given String matches the second. The second string 
+        may contain wildcard characters.
+        (WebKit::wildcardRegexPatternString):
+        Return the regex expression from a wildcard string by replacing the wildcard
+        character ('*') with (&quot;.*&quot;) and escaping regular expression metacharacters.
+        (WebKit::formattedPhoneNumberString):
+        To expose StringUtilities.h for tests, we removed #if ENABLE(TELEPHONE_NUMBER_DETECTION)
+        &amp;&amp; PLATFORM(MAC) flag in the header. Add a function that returns nil for
+        #if !(ENABLE(TELEPHONE_NUMBER_DETECTION) &amp;&amp; PLATFORM(MAC)) to fix the removal
+        of the flag in the header file.
+
+        * WebKit2.xcodeproj/project.pbxproj:
+        Change the file attribute of StringUtilities.h from Project to Private for
+        testing in TestWebKitAPI.
+
+        * WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
+        (WebKit::WebPlatformStrategies::longestMatchedWildcardHostForHost):
+        Return the wildcard hostname whose matched substring with the host is the longest.
+        (WebKit::WebPlatformStrategies::replaceHostWithMatchedWildcardHost):
+        Replace the look-up host with a matched wildcard host if there is a match and that
+        the matched wildcard host's plug-in identifier is the same as that of the host.
+        (WebKit::WebPlatformStrategies::pluginLoadClientPolicyForHost):
+        Try to replace the look-up host with the wildcard host if there's no policy for
+        the host. Restructure the function to reduce hashmap lookup.
+
+        * WebProcess/WebCoreSupport/WebPlatformStrategies.h:
+        Declare the methods.
+
</ins><span class="cx"> 2016-01-26  Anders Carlsson  &lt;andersca@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Remove -d flag from make invocation.
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformmacStringUtilitiesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Platform/mac/StringUtilities.h (195649 => 195650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/mac/StringUtilities.h        2016-01-27 02:41:55 UTC (rev 195649)
+++ trunk/Source/WebKit2/Platform/mac/StringUtilities.h        2016-01-27 03:05:49 UTC (rev 195650)
</span><span class="lines">@@ -26,18 +26,22 @@
</span><span class="cx"> #ifndef StringUtilities_h
</span><span class="cx"> #define StringUtilities_h
</span><span class="cx"> 
</span><ins>+#import &lt;WebKit/WKDeclarationSpecifiers.h&gt;
</ins><span class="cx"> #import &lt;wtf/Forward.h&gt;
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><ins>+#ifdef __OBJC__
+
</ins><span class="cx"> // NOTE: This does not use String::operator NSString*() since that function
</span><span class="cx"> // expects to be called on the thread running WebCore.
</span><span class="cx"> NSString *nsStringFromWebCoreString(const String&amp;);
</span><del>-
-#if ENABLE(TELEPHONE_NUMBER_DETECTION) &amp;&amp; PLATFORM(MAC)
</del><span class="cx"> NSString *formattedPhoneNumberString(NSString *originalPhoneNumber);
</span><del>-#endif
</del><span class="cx"> 
</span><ins>+#endif // defined(__OBJC__)
+
+WK_EXPORT bool stringMatchesWildcardString(const String&amp; stringToBeMatched, const String&amp; wildcardString);
+
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #endif // StringUtilities_h
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformmacStringUtilitiesmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Platform/mac/StringUtilities.mm (195649 => 195650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/mac/StringUtilities.mm        2016-01-27 02:41:55 UTC (rev 195649)
+++ trunk/Source/WebKit2/Platform/mac/StringUtilities.mm        2016-01-27 03:05:49 UTC (rev 195650)
</span><span class="lines">@@ -30,7 +30,8 @@
</span><span class="cx"> #import &quot;WKStringCF.h&quot;
</span><span class="cx"> #import &lt;WebCore/SoftLinking.h&gt;
</span><span class="cx"> #import &lt;wtf/ObjcRuntimeExtras.h&gt;
</span><del>-#import &lt;wtf/text/WTFString.h&gt;
</del><ins>+#import &lt;wtf/text/StringBuilder.h&gt;
+#import &lt;yarr/RegularExpression.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><span class="lines">@@ -39,6 +40,34 @@
</span><span class="cx">     return string.isEmpty() ? @&quot;&quot; : CFBridgingRelease(WKStringCopyCFString(0, toAPI(string.impl())));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static String wildcardRegexPatternString(const String&amp; string)
+{
+    String metaCharacters = &quot;.|+?()[]{}^$&quot;;
+    UChar escapeCharacter = '\\';
+    UChar wildcardCharacter = '*';
+
+    StringBuilder stringBuilder;
+
+    stringBuilder.append('^');
+    for (unsigned i = 0; i &lt; string.length(); i++) {
+        auto character = string[i];
+        if (metaCharacters.contains(character) || character == escapeCharacter)
+            stringBuilder.append(escapeCharacter);
+        else if (character == wildcardCharacter)
+            stringBuilder.append('.');
+
+        stringBuilder.append(character);
+    }
+    stringBuilder.append('$');
+
+    return stringBuilder.toString();
+}
+
+bool stringMatchesWildcardString(const String&amp; string, const String&amp; wildcardString)
+{
+    return JSC::Yarr::RegularExpression(wildcardRegexPatternString(wildcardString), TextCaseInsensitive).match(string) != -1;
+}
+
</ins><span class="cx"> #if ENABLE(TELEPHONE_NUMBER_DETECTION) &amp;&amp; PLATFORM(MAC)
</span><span class="cx"> 
</span><span class="cx"> SOFT_LINK_PRIVATE_FRAMEWORK(PhoneNumbers);
</span><span class="lines">@@ -72,6 +101,13 @@
</span><span class="cx">     return [(NSString *)phoneNumberString autorelease];
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#else
+
+NSString *formattedPhoneNumberString(NSString *)
+{
+    return nil;
+}
+
</ins><span class="cx"> #endif // ENABLE(TELEPHONE_NUMBER_DETECTION) &amp;&amp; PLATFORM(MAC)
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (195649 => 195650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2016-01-27 02:41:55 UTC (rev 195649)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2016-01-27 03:05:49 UTC (rev 195650)
</span><span class="lines">@@ -579,7 +579,7 @@
</span><span class="cx">                 293EBEAB1627D9C9005F89F1 /* WKDOMText.h in Headers */ = {isa = PBXBuildFile; fileRef = 293EBEA91627D9C9005F89F1 /* WKDOMText.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 293EBEAC1627D9C9005F89F1 /* WKDOMText.mm in Sources */ = {isa = PBXBuildFile; fileRef = 293EBEAA1627D9C9005F89F1 /* WKDOMText.mm */; };
</span><span class="cx">                 29501724162A4504004A9D71 /* WKWebProcessPlugInBrowserContextControllerPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 29501723162A4504004A9D71 /* WKWebProcessPlugInBrowserContextControllerPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><del>-                296BD85D15019BC30071F424 /* StringUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 296BD85B15019BC30071F424 /* StringUtilities.h */; };
</del><ins>+                296BD85D15019BC30071F424 /* StringUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 296BD85B15019BC30071F424 /* StringUtilities.h */; settings = {ATTRIBUTES = (Private, ); }; };
</ins><span class="cx">                 296BD85E15019BC30071F424 /* StringUtilities.mm in Sources */ = {isa = PBXBuildFile; fileRef = 296BD85C15019BC30071F424 /* StringUtilities.mm */; };
</span><span class="cx">                 2984F57C164B915F004BC0C6 /* CustomProtocolManagerProxyMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2984F57A164B915F004BC0C6 /* CustomProtocolManagerProxyMessageReceiver.cpp */; };
</span><span class="cx">                 2984F57D164B915F004BC0C6 /* CustomProtocolManagerProxyMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 2984F57B164B915F004BC0C6 /* CustomProtocolManagerProxyMessages.h */; };
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebCoreSupportWebPlatformStrategiescpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp (195649 => 195650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp        2016-01-27 02:41:55 UTC (rev 195649)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp        2016-01-27 03:05:49 UTC (rev 195650)
</span><span class="lines">@@ -67,6 +67,10 @@
</span><span class="cx"> #include &lt;WebCore/URL.h&gt;
</span><span class="cx"> #include &lt;wtf/Atomics.h&gt;
</span><span class="cx"> 
</span><ins>+#if PLATFORM(MAC)
+#include &quot;StringUtilities.h&quot;
+#endif
+
</ins><span class="cx"> using namespace WebCore;
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="lines">@@ -239,29 +243,85 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(NETSCAPE_PLUGIN_API)
</span><span class="cx"> #if PLATFORM(MAC)
</span><ins>+
+String WebPlatformStrategies::longestMatchedWildcardHostForHost(const String&amp; host) const
+{
+    String longestMatchedHost;
+
+    for (auto&amp; key : m_hostsToPluginIdentifierData.keys()) {
+        if (key.contains('*') &amp;&amp; key != &quot;*&quot; &amp;&amp; stringMatchesWildcardString(host, key)) {
+            if (key.length() &gt; longestMatchedHost.length())
+                longestMatchedHost = key;
+            else if (key.length() == longestMatchedHost.length() &amp;&amp; codePointCompareLessThan(key, longestMatchedHost))
+                longestMatchedHost = key;
+        }
+    }
+
+    return longestMatchedHost;
+}
+
+bool WebPlatformStrategies::replaceHostWithMatchedWildcardHost(String&amp; host, const String&amp; identifier) const
+{
+    String matchedWildcardHost = longestMatchedWildcardHostForHost(host);
+
+    if (matchedWildcardHost.isNull())
+        return false;
+
+    auto plugInIdentifierData = m_hostsToPluginIdentifierData.find(matchedWildcardHost);
+    if (plugInIdentifierData == m_hostsToPluginIdentifierData.end() || !plugInIdentifierData-&gt;value.contains(identifier))
+        return false;
+
+    host = matchedWildcardHost;
+    return true;
+}
+
</ins><span class="cx"> bool WebPlatformStrategies::pluginLoadClientPolicyForHost(const String&amp; host, const PluginInfo&amp; info, PluginLoadClientPolicy&amp; policy) const
</span><span class="cx"> {
</span><span class="cx">     String hostToLookUp = host;
</span><del>-    if (!m_hostsToPluginIdentifierData.contains(hostToLookUp))
-        hostToLookUp = &quot;*&quot;;
-    if (!m_hostsToPluginIdentifierData.contains(hostToLookUp))
</del><ins>+    String identifier = info.bundleIdentifier;
+
+    auto policiesByIdentifierIterator = m_hostsToPluginIdentifierData.find(hostToLookUp);
+
+    if (!identifier.isNull() &amp;&amp; policiesByIdentifierIterator == m_hostsToPluginIdentifierData.end()) {
+        if (!replaceHostWithMatchedWildcardHost(hostToLookUp, identifier))
+            hostToLookUp = &quot;*&quot;;
+        policiesByIdentifierIterator = m_hostsToPluginIdentifierData.find(hostToLookUp);
+        if (hostToLookUp != &quot;*&quot; &amp;&amp; policiesByIdentifierIterator == m_hostsToPluginIdentifierData.end()) {
+            hostToLookUp = &quot;*&quot;;
+            policiesByIdentifierIterator = m_hostsToPluginIdentifierData.find(hostToLookUp);
+        }
+    }
+    if (policiesByIdentifierIterator == m_hostsToPluginIdentifierData.end())
</ins><span class="cx">         return false;
</span><span class="cx"> 
</span><del>-    PluginPolicyMapsByIdentifier policiesByIdentifier = m_hostsToPluginIdentifierData.get(hostToLookUp);
-    String identifier = info.bundleIdentifier;
-    if (!identifier || !policiesByIdentifier.contains(identifier))
</del><ins>+    auto&amp; policiesByIdentifier = policiesByIdentifierIterator-&gt;value;
+
+    if (!identifier)
</ins><span class="cx">         identifier = &quot;*&quot;;
</span><del>-    if (!policiesByIdentifier.contains(identifier))
</del><ins>+
+    auto identifierPolicyIterator = policiesByIdentifier.find(identifier);
+    if (identifier != &quot;*&quot; &amp;&amp; identifierPolicyIterator == policiesByIdentifier.end()) {
+        identifier = &quot;*&quot;;
+        identifierPolicyIterator = policiesByIdentifier.find(identifier);
+    }
+    if (identifierPolicyIterator == policiesByIdentifier.end())
</ins><span class="cx">         return false;
</span><span class="cx"> 
</span><del>-    PluginLoadClientPoliciesByBundleVersion versionsToPolicies = policiesByIdentifier.get(identifier);
</del><ins>+    auto&amp; versionsToPolicies = identifierPolicyIterator-&gt;value;
+
</ins><span class="cx">     String version = info.versionString;
</span><del>-    if (!version || !versionsToPolicies.contains(version))
</del><ins>+    if (!version)
</ins><span class="cx">         version = &quot;*&quot;;
</span><del>-    if (!versionsToPolicies.contains(version))
</del><ins>+    auto policyIterator = versionsToPolicies.find(version);
+    if (version != &quot;*&quot; &amp;&amp; policyIterator == versionsToPolicies.end()) {
+        version = &quot;*&quot;;
+        policyIterator = versionsToPolicies.find(version);
+    }
+
+    if (policyIterator == versionsToPolicies.end())
</ins><span class="cx">         return false;
</span><span class="cx"> 
</span><del>-    policy = versionsToPolicies.get(version);
</del><ins>+    policy = policyIterator-&gt;value;
</ins><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> #endif // PLATFORM(MAC)
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebCoreSupportWebPlatformStrategiesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.h (195649 => 195650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.h        2016-01-27 02:41:55 UTC (rev 195649)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.h        2016-01-27 03:05:49 UTC (rev 195650)
</span><span class="lines">@@ -112,6 +112,8 @@
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx">     HashMap&lt;String, PluginPolicyMapsByIdentifier&gt; m_hostsToPluginIdentifierData;
</span><span class="cx">     bool pluginLoadClientPolicyForHost(const String&amp;, const WebCore::PluginInfo&amp;, WebCore::PluginLoadClientPolicy&amp;) const;
</span><ins>+    String longestMatchedWildcardHostForHost(const String&amp; host) const;
+    bool replaceHostWithMatchedWildcardHost(String&amp; host, const String&amp; identifier) const;
</ins><span class="cx"> #endif // PLATFORM(MAC)
</span><span class="cx"> #endif // ENABLE(NETSCAPE_PLUGIN_API)
</span><span class="cx"> };
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (195649 => 195650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2016-01-27 02:41:55 UTC (rev 195649)
+++ trunk/Tools/ChangeLog        2016-01-27 03:05:49 UTC (rev 195650)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2016-01-26  I-Ting Liu  &lt;iting_liu@apple.com&gt;
+
+        Add a test for WebKit::stringMatchesWildcardString.
+        https://bugs.webkit.org/show_bug.cgi?id=153090
+
+        Reviewed by Darin Adler.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        Add the file to the project.
+
+        * TestWebKitAPI/Tests/WebKit2/mac/StringUtilities.mm: Added.
+        (TestWebKitAPI::TEST):
+        Test that a string matches another string that may contain wildcard characters.
+
</ins><span class="cx"> 2016-01-26  Konstantin Tokarev  &lt;annulen@yandex.ru&gt;
</span><span class="cx"> 
</span><span class="cx">         [webkitdirs] Removed check for bison, gperf, and flex.
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (195649 => 195650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2016-01-27 02:41:55 UTC (rev 195649)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2016-01-27 03:05:49 UTC (rev 195650)
</span><span class="lines">@@ -260,6 +260,7 @@
</span><span class="cx">                 7CCE7F4F1A411BA400447C4C /* RetainPtrHashing.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C0991C50143C7D68007998F2 /* RetainPtrHashing.cpp */; };
</span><span class="cx">                 7CEFA9661AC0B9E200B910FD /* _WKUserContentExtensionStore.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7CEFA9641AC0B9E200B910FD /* _WKUserContentExtensionStore.mm */; };
</span><span class="cx">                 7CFBCAE51743238F00B2BFCF /* WillLoad_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CFBCAE31743238E00B2BFCF /* WillLoad_Bundle.cpp */; };
</span><ins>+                83CF1C301C4F1B8B00688447 /* StringUtilities.mm in Sources */ = {isa = PBXBuildFile; fileRef = 83CF1C2C1C4F19AE00688447 /* StringUtilities.mm */; };
</ins><span class="cx">                 930AD402150698D00067970F /* lots-of-text.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 930AD401150698B30067970F /* lots-of-text.html */; };
</span><span class="cx">                 9361002914DC95A70061379D /* lots-of-iframes.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9361002814DC957B0061379D /* lots-of-iframes.html */; };
</span><span class="cx">                 93AF4ECE1506F064007FD57E /* NewFirstVisuallyNonEmptyLayoutForImages_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93AF4ECD1506F064007FD57E /* NewFirstVisuallyNonEmptyLayoutForImages_Bundle.cpp */; };
</span><span class="lines">@@ -628,6 +629,7 @@
</span><span class="cx">                 7CFBCADD1743234F00B2BFCF /* WillLoad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WillLoad.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 7CFBCAE31743238E00B2BFCF /* WillLoad_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WillLoad_Bundle.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 81B50192140F232300D9EB58 /* StringBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringBuilder.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                83CF1C2C1C4F19AE00688447 /* StringUtilities.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = StringUtilities.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 86BD19971A2DB05B006DCF0A /* RefCounter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RefCounter.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 8A2C750D16CED9550024F352 /* ResizeWindowAfterCrash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResizeWindowAfterCrash.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 8A3AF93A16C9ED2700D248C1 /* ReloadPageAfterCrash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ReloadPageAfterCrash.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -1449,6 +1451,7 @@
</span><span class="cx">                                 C0C5D3BC14598B6F00A802A6 /* GetBackingScaleFactor.mm */,
</span><span class="cx">                                 C0C5D3BD14598B6F00A802A6 /* GetBackingScaleFactor_Bundle.mm */,
</span><span class="cx">                                 1AEF994817A09F5300998EF0 /* GetPIDAfterAbortedProcessLaunch.cpp */,
</span><ins>+                                83CF1C2C1C4F19AE00688447 /* StringUtilities.mm */,
</ins><span class="cx">                         );
</span><span class="cx">                         path = mac;
</span><span class="cx">                         sourceTree = &quot;&lt;group&gt;&quot;;
</span><span class="lines">@@ -1740,6 +1743,7 @@
</span><span class="cx">                                 7CCE7F411A411B8E00447C4C /* RefPtr.cpp in Sources */,
</span><span class="cx">                                 7CCE7F0D1A411AE600447C4C /* ReloadPageAfterCrash.cpp in Sources */,
</span><span class="cx">                                 7CCE7EC91A411A7E00447C4C /* RenderedImageFromDOMNode.mm in Sources */,
</span><ins>+                                83CF1C301C4F1B8B00688447 /* StringUtilities.mm in Sources */,
</ins><span class="cx">                                 7CCE7ECA1A411A7E00447C4C /* RenderedImageFromDOMRange.mm in Sources */,
</span><span class="cx">                                 51CD1C6C1B38CE4300142CA5 /* ModalAlerts.mm in Sources */,
</span><span class="cx">                                 0FFC45A61B73EBEB0085BD62 /* Lock.cpp in Sources */,
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2macStringUtilitiesmm"></a>
<div class="addfile"><h4>Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2/mac/StringUtilities.mm (0 => 195650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/mac/StringUtilities.mm                                (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/mac/StringUtilities.mm        2016-01-27 03:05:49 UTC (rev 195650)
</span><span class="lines">@@ -0,0 +1,102 @@
</span><ins>+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    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 INC. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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 PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import &quot;config.h&quot;
+
+#import &lt;WebKit/StringUtilities.h&gt;
+#import &lt;wtf/text/WTFString.h&gt;
+
+namespace TestWebKitAPI {
+
+TEST(WebKit2, WildcardStringMatching)
+{
+    String wildcardString = &quot;a*b&quot;;
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString(&quot;aaaabb&quot;, &quot;a*b&quot;));
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString(&quot;ab&quot;, wildcardString));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString(&quot;ba&quot;, wildcardString));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString(&quot;&quot;, wildcardString));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString(&quot;a&quot;, wildcardString));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString(&quot;b&quot;, wildcardString));
+
+    wildcardString = &quot;aabb&quot;;
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString(&quot;aabb&quot;, wildcardString));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString(&quot;a*b&quot;, wildcardString));
+
+    wildcardString = &quot;*apple*&quot;;
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString(&quot;freshapple&quot;, wildcardString));
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString(&quot;applefresh&quot;, wildcardString));
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString(&quot;freshapplefresh&quot;, wildcardString));
+
+    wildcardString = &quot;a*b*c&quot;;
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString(&quot;aabbcc&quot;, wildcardString));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString(&quot;bca&quot;, wildcardString));
+
+    wildcardString = &quot;*.example*.com/*&quot;;
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString(&quot;food.examplehello.com/&quot;, wildcardString));
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString(&quot;food.example.com/bar.html&quot;, wildcardString));
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString(&quot;foo.bar.example.com/hello?query#fragment.html&quot;, wildcardString));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString(&quot;food.example.com&quot;, wildcardString));
+
+    wildcardString = &quot;a*b.b*c&quot;;
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString(&quot;aabb.bbcc&quot;, wildcardString));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString(&quot;aabbcbbcc&quot;, wildcardString));
+
+    wildcardString = &quot;a+b&quot;;
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString(&quot;a+b&quot;, wildcardString));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString(&quot;ab&quot;, wildcardString));
+
+    wildcardString = &quot;(a*)b aa&quot;;
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString(&quot;(aaa)b aa&quot;, wildcardString));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString(&quot;aab aa&quot;, wildcardString));
+
+    wildcardString = &quot;a|c&quot;;
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString(&quot;a|c&quot;, wildcardString));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString(&quot;abc&quot;, wildcardString));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString(&quot;a&quot;, wildcardString));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString(&quot;c&quot;, wildcardString));
+
+    wildcardString = &quot;(a+|b)*&quot;;
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString(&quot;(a+|b)acca&quot;, &quot;(a+|b)*&quot;));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString(&quot;ab&quot;, &quot;(a+|b)*&quot;));
+
+    wildcardString = &quot;a[-]?c&quot;;
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString(&quot;a[-]?c&quot;, wildcardString));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString(&quot;ac&quot;, wildcardString));
+
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString(&quot;hello&quot;, &quot;^hello$&quot;));
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString(&quot; &quot;, &quot; &quot;));
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString(&quot;^$&quot;, &quot;^$&quot;));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString(&quot;a&quot;, &quot;a{1}&quot;));
+
+    // stringMatchesWildcardString should only match the entire string.
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString(&quot;aabbaabb&quot;, &quot;aabb&quot;));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString(&quot;aabb\naabb&quot;, &quot;aabb&quot;));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString(&quot;bab&quot;, &quot;a*&quot;));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString(&quot;bab&quot;, &quot;*a&quot;));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString(&quot;bab&quot;, &quot;a*b&quot;));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString(&quot;abcd&quot;, &quot;b*c&quot;));
+}
+
+}
</ins></span></pre>
</div>
</div>

</body>
</html>