<!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>[198613] trunk/Source/WebCore</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/198613">198613</a></dd>
<dt>Author</dt> <dd>dbates@webkit.org</dd>
<dt>Date</dt> <dd>2016-03-23 19:41:28 -0700 (Wed, 23 Mar 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>CSP: Simplify logic for checking policies
https://bugs.webkit.org/show_bug.cgi?id=155817
&lt;rdar://problem/25326546&gt;

Reviewed by Zalan Bujtas.

Consolidate the various static template functions into a single function called ContentSecurityPolicy::allPoliciesAllow()
that tests whether a resource request when evaluated with respect to a directive (given as a ContentSecurityPolicyDirectiveList
pointer-to-member function) violates any of the CSPs that were delivered with the document.

No functionality changed. So, no new tests.

* page/csp/ContentSecurityPolicy.cpp:
(WebCore::ContentSecurityPolicy::allPoliciesAllowHashFromContent): Formerly name isAllowedByAllWithHash. Made it
a member function so that we query for the document encoding instead of taking it as an argument. Modified
it to take a predicate function to pass it to allPoliciesAllow().
(WebCore::ContentSecurityPolicy::allowJavaScriptURLs): Modified to use ContentSecurityPolicy::allPoliciesAllow().
(WebCore::ContentSecurityPolicy::allowInlineEventHandlers): Ditto.
(WebCore::ContentSecurityPolicy::allowScriptWithNonce): Ditto.
(WebCore::ContentSecurityPolicy::allowStyleWithNonce): Ditto.
(WebCore::ContentSecurityPolicy::allowInlineScript): Modified to use ContentSecurityPolicy::allPoliciesAllow() and
ContentSecurityPolicy::allPoliciesAllowHashFromContent().
(WebCore::ContentSecurityPolicy::allowInlineStyle): Ditto.
(WebCore::ContentSecurityPolicy::allowEval): Modified to use ContentSecurityPolicy::allPoliciesAllow().
(WebCore::ContentSecurityPolicy::allowFrameAncestors): Ditto.
(WebCore::ContentSecurityPolicy::allowPluginType): Ditto.
(WebCore::ContentSecurityPolicy::allowScriptFromSource): Ditto.
(WebCore::ContentSecurityPolicy::allowObjectFromSource): Ditto.
(WebCore::ContentSecurityPolicy::allowChildFrameFromSource): Ditto.
(WebCore::ContentSecurityPolicy::allowChildContextFromSource): Ditto.
(WebCore::ContentSecurityPolicy::allowImageFromSource): Ditto.
(WebCore::ContentSecurityPolicy::allowStyleFromSource): Ditto.
(WebCore::ContentSecurityPolicy::allowFontFromSource): Ditto.
(WebCore::ContentSecurityPolicy::allowMediaFromSource): Ditto.
(WebCore::ContentSecurityPolicy::allowConnectToSource): Ditto.
(WebCore::ContentSecurityPolicy::allowFormAction): Ditto.
(WebCore::ContentSecurityPolicy::allowBaseURI): Ditto.
(WebCore::isAllowedByAllWithFrame): Deleted.
(WebCore::isAllowedByAll): Deleted.
(WebCore::isAllowedByAllWithState): Deleted.
(WebCore::isAllowedByAllWithContext): Deleted.
(WebCore::isAllowedByAllWithNonce): Deleted.
(WebCore::isAllowedByAllWithHash): Deleted.
(WebCore::isAllowedByAllWithHashFromContent): Deleted.
(WebCore::isAllowedByAllWithURL): Deleted.
(WebCore::ContentSecurityPolicy::documentEncoding): Deleted. Incorporated its functionality into ContentSecurityPolicy::allPoliciesAllowHashFromContent().
(WebCore::ContentSecurityPolicy::isActive): Deleted. This function has been unused since the removal of the CSP script
interface in &lt;http://trac.webkit.org/changeset/197142&gt;.
* page/csp/ContentSecurityPolicy.h:
(WebCore::ContentSecurityPolicy::allPoliciesAllow): Added. Returns whether the predicate function evaluates to true
for all CSP policies.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorepagecspContentSecurityPolicycpp">trunk/Source/WebCore/page/csp/ContentSecurityPolicy.cpp</a></li>
<li><a href="#trunkSourceWebCorepagecspContentSecurityPolicyh">trunk/Source/WebCore/page/csp/ContentSecurityPolicy.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (198612 => 198613)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-03-24 02:40:36 UTC (rev 198612)
+++ trunk/Source/WebCore/ChangeLog        2016-03-24 02:41:28 UTC (rev 198613)
</span><span class="lines">@@ -1,3 +1,57 @@
</span><ins>+2016-03-23  Daniel Bates  &lt;dabates@apple.com&gt;
+
+        CSP: Simplify logic for checking policies
+        https://bugs.webkit.org/show_bug.cgi?id=155817
+        &lt;rdar://problem/25326546&gt;
+
+        Reviewed by Zalan Bujtas.
+
+        Consolidate the various static template functions into a single function called ContentSecurityPolicy::allPoliciesAllow()
+        that tests whether a resource request when evaluated with respect to a directive (given as a ContentSecurityPolicyDirectiveList
+        pointer-to-member function) violates any of the CSPs that were delivered with the document.
+
+        No functionality changed. So, no new tests.
+
+        * page/csp/ContentSecurityPolicy.cpp:
+        (WebCore::ContentSecurityPolicy::allPoliciesAllowHashFromContent): Formerly name isAllowedByAllWithHash. Made it
+        a member function so that we query for the document encoding instead of taking it as an argument. Modified
+        it to take a predicate function to pass it to allPoliciesAllow().
+        (WebCore::ContentSecurityPolicy::allowJavaScriptURLs): Modified to use ContentSecurityPolicy::allPoliciesAllow().
+        (WebCore::ContentSecurityPolicy::allowInlineEventHandlers): Ditto.
+        (WebCore::ContentSecurityPolicy::allowScriptWithNonce): Ditto.
+        (WebCore::ContentSecurityPolicy::allowStyleWithNonce): Ditto.
+        (WebCore::ContentSecurityPolicy::allowInlineScript): Modified to use ContentSecurityPolicy::allPoliciesAllow() and
+        ContentSecurityPolicy::allPoliciesAllowHashFromContent().
+        (WebCore::ContentSecurityPolicy::allowInlineStyle): Ditto.
+        (WebCore::ContentSecurityPolicy::allowEval): Modified to use ContentSecurityPolicy::allPoliciesAllow().
+        (WebCore::ContentSecurityPolicy::allowFrameAncestors): Ditto.
+        (WebCore::ContentSecurityPolicy::allowPluginType): Ditto.
+        (WebCore::ContentSecurityPolicy::allowScriptFromSource): Ditto.
+        (WebCore::ContentSecurityPolicy::allowObjectFromSource): Ditto.
+        (WebCore::ContentSecurityPolicy::allowChildFrameFromSource): Ditto.
+        (WebCore::ContentSecurityPolicy::allowChildContextFromSource): Ditto.
+        (WebCore::ContentSecurityPolicy::allowImageFromSource): Ditto.
+        (WebCore::ContentSecurityPolicy::allowStyleFromSource): Ditto.
+        (WebCore::ContentSecurityPolicy::allowFontFromSource): Ditto.
+        (WebCore::ContentSecurityPolicy::allowMediaFromSource): Ditto.
+        (WebCore::ContentSecurityPolicy::allowConnectToSource): Ditto.
+        (WebCore::ContentSecurityPolicy::allowFormAction): Ditto.
+        (WebCore::ContentSecurityPolicy::allowBaseURI): Ditto.
+        (WebCore::isAllowedByAllWithFrame): Deleted.
+        (WebCore::isAllowedByAll): Deleted.
+        (WebCore::isAllowedByAllWithState): Deleted.
+        (WebCore::isAllowedByAllWithContext): Deleted.
+        (WebCore::isAllowedByAllWithNonce): Deleted.
+        (WebCore::isAllowedByAllWithHash): Deleted.
+        (WebCore::isAllowedByAllWithHashFromContent): Deleted.
+        (WebCore::isAllowedByAllWithURL): Deleted.
+        (WebCore::ContentSecurityPolicy::documentEncoding): Deleted. Incorporated its functionality into ContentSecurityPolicy::allPoliciesAllowHashFromContent().
+        (WebCore::ContentSecurityPolicy::isActive): Deleted. This function has been unused since the removal of the CSP script
+        interface in &lt;http://trac.webkit.org/changeset/197142&gt;.
+        * page/csp/ContentSecurityPolicy.h:
+        (WebCore::ContentSecurityPolicy::allPoliciesAllow): Added. Returns whether the predicate function evaluates to true
+        for all CSP policies.
+
</ins><span class="cx"> 2016-03-23  Jer Noble  &lt;jer.noble@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Media elements allowed to play without a user gesture, but requiring fullscreen playback, should not be allowed to autoplay.
</span></span></pre></div>
<a id="trunkSourceWebCorepagecspContentSecurityPolicycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/csp/ContentSecurityPolicy.cpp (198612 => 198613)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/csp/ContentSecurityPolicy.cpp        2016-03-24 02:40:36 UTC (rev 198612)
+++ trunk/Source/WebCore/page/csp/ContentSecurityPolicy.cpp        2016-03-24 02:41:28 UTC (rev 198613)
</span><span class="lines">@@ -174,56 +174,6 @@
</span><span class="cx">     return equalIgnoringASCIICase(url.protocol(), m_selfSourceProtocol);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-template&lt;bool (ContentSecurityPolicyDirectiveList::*allowed)(const Frame&amp;, const URL&amp;, ContentSecurityPolicyDirectiveList::ReportingStatus) const&gt;
-static bool isAllowedByAllWithFrame(const CSPDirectiveListVector&amp; policies, const Frame&amp; frame, const URL&amp; url, ContentSecurityPolicyDirectiveList::ReportingStatus reportingStatus)
-{
-    for (auto&amp; policy : policies) {
-        if (!(policy.get()-&gt;*allowed)(frame, url, reportingStatus))
-            return false;
-    }
-    return true;
-}
-
-template&lt;bool (ContentSecurityPolicyDirectiveList::*allowed)(ContentSecurityPolicyDirectiveList::ReportingStatus) const&gt;
-static bool isAllowedByAll(const CSPDirectiveListVector&amp; policies, ContentSecurityPolicyDirectiveList::ReportingStatus reportingStatus)
-{
-    for (auto&amp; policy : policies) {
-        if (!(policy.get()-&gt;*allowed)(reportingStatus))
-            return false;
-    }
-    return true;
-}
-
-template&lt;bool (ContentSecurityPolicyDirectiveList::*allowed)(JSC::ExecState* state, ContentSecurityPolicyDirectiveList::ReportingStatus) const&gt;
-static bool isAllowedByAllWithState(const CSPDirectiveListVector&amp; policies, JSC::ExecState* state, ContentSecurityPolicyDirectiveList::ReportingStatus reportingStatus)
-{
-    for (auto&amp; policy : policies) {
-        if (!(policy.get()-&gt;*allowed)(state, reportingStatus))
-            return false;
-    }
-    return true;
-}
-
-template&lt;bool (ContentSecurityPolicyDirectiveList::*allowed)(const String&amp;, const WTF::OrdinalNumber&amp;, ContentSecurityPolicyDirectiveList::ReportingStatus) const&gt;
-static bool isAllowedByAllWithContext(const CSPDirectiveListVector&amp; policies, const String&amp; contextURL, const WTF::OrdinalNumber&amp; contextLine, ContentSecurityPolicyDirectiveList::ReportingStatus reportingStatus)
-{
-    for (auto&amp; policy : policies) {
-        if (!(policy.get()-&gt;*allowed)(contextURL, contextLine, reportingStatus))
-            return false;
-    }
-    return true;
-}
-
-template&lt;bool (ContentSecurityPolicyDirectiveList::*allowed)(const String&amp; nonce) const&gt;
-static bool isAllowedByAllWithNonce(const CSPDirectiveListVector&amp; policies, const String&amp; nonce)
-{
-    for (auto&amp; policy : policies) {
-        if (!(policy.get()-&gt;*allowed)(nonce))
-            return false;
-    }
-    return true;
-}
-
</del><span class="cx"> static CryptoDigest::Algorithm toCryptoDigestAlgorithm(ContentSecurityPolicyHashAlgorithm algorithm)
</span><span class="cx"> {
</span><span class="cx">     switch (algorithm) {
</span><span class="lines">@@ -238,66 +188,42 @@
</span><span class="cx">     return CryptoDigest::Algorithm::SHA_512;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-template&lt;bool (ContentSecurityPolicyDirectiveList::*allowed)(const ContentSecurityPolicyHash&amp;) const&gt;
-static bool isAllowedByAllWithHash(const CSPDirectiveListVector&amp; policies, const ContentSecurityPolicyHash&amp; hash)
</del><ins>+template&lt;typename Predicate&gt;
+bool ContentSecurityPolicy::allPoliciesAllowHashFromContent(Predicate&amp;&amp; predicate, const String&amp; content, OptionSet&lt;ContentSecurityPolicyHashAlgorithm&gt; algorithms) const
</ins><span class="cx"> {
</span><del>-    for (auto&amp; policy : policies) {
-        if (!(policy.get()-&gt;*allowed)(hash))
-            return false;
-    }
-    return true;
-}
</del><ins>+    // FIXME: We should compute the document encoding once and cache it instead of computing it on each invocation.
+    TextEncoding documentEncoding;
+    if (is&lt;Document&gt;(m_scriptExecutionContext))
+        documentEncoding = downcast&lt;Document&gt;(*m_scriptExecutionContext).textEncoding();
+    const TextEncoding&amp; encodingToUse = documentEncoding.isValid() ? documentEncoding : UTF8Encoding();
</ins><span class="cx"> 
</span><del>-template&lt;bool (ContentSecurityPolicyDirectiveList::*allowed)(const ContentSecurityPolicyHash&amp;) const&gt;
-static bool isAllowedByAllWithHashFromContent(const CSPDirectiveListVector&amp; policies, const String&amp; content, const TextEncoding&amp; encoding, OptionSet&lt;ContentSecurityPolicyHashAlgorithm&gt; algorithms)
-{
</del><span class="cx">     // FIXME: Compute the digest with respect to the raw bytes received from the page.
</span><span class="cx">     // See &lt;https://bugs.webkit.org/show_bug.cgi?id=155184&gt;.
</span><del>-    CString contentCString = encoding.encode(content, EntitiesForUnencodables);
</del><ins>+    CString contentCString = encodingToUse.encode(content, EntitiesForUnencodables);
</ins><span class="cx">     for (auto algorithm : algorithms) {
</span><span class="cx">         auto cryptoDigest = CryptoDigest::create(toCryptoDigestAlgorithm(algorithm));
</span><span class="cx">         cryptoDigest-&gt;addBytes(contentCString.data(), contentCString.length());
</span><span class="cx">         Vector&lt;uint8_t&gt; digest = cryptoDigest-&gt;computeHash();
</span><del>-        if (isAllowedByAllWithHash&lt;allowed&gt;(policies, { algorithm, digest }))
</del><ins>+        if (allPoliciesAllow(std::forward&lt;Predicate&gt;(predicate), std::make_pair(algorithm, digest)))
</ins><span class="cx">             return true;
</span><span class="cx">     }
</span><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-template&lt;bool (ContentSecurityPolicyDirectiveList::*allowFromURL)(const URL&amp;, ContentSecurityPolicyDirectiveList::ReportingStatus) const&gt;
-static bool isAllowedByAllWithURL(const CSPDirectiveListVector&amp; policies, const URL&amp; url, ContentSecurityPolicyDirectiveList::ReportingStatus reportingStatus)
</del><ins>+bool ContentSecurityPolicy::allowJavaScriptURLs(const String&amp; contextURL, const WTF::OrdinalNumber&amp; contextLine, bool overrideContentSecurityPolicy) const
</ins><span class="cx"> {
</span><del>-    if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol()))
</del><ins>+    if (overrideContentSecurityPolicy)
</ins><span class="cx">         return true;
</span><del>-
-    for (auto&amp; policy : policies) {
-        if (!(policy.get()-&gt;*allowFromURL)(url, reportingStatus))
-            return false;
-    }
-    return true;
</del><ins>+    return allPoliciesAllow(&amp;ContentSecurityPolicyDirectiveList::allowJavaScriptURLs, contextURL, contextLine, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool ContentSecurityPolicy::allowJavaScriptURLs(const String&amp; contextURL, const WTF::OrdinalNumber&amp; contextLine, bool overrideContentSecurityPolicy) const
-{
-    return overrideContentSecurityPolicy || isAllowedByAllWithContext&lt;&amp;ContentSecurityPolicyDirectiveList::allowJavaScriptURLs&gt;(m_policies, contextURL, contextLine, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
-}
-
</del><span class="cx"> bool ContentSecurityPolicy::allowInlineEventHandlers(const String&amp; contextURL, const WTF::OrdinalNumber&amp; contextLine, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><del>-    return overrideContentSecurityPolicy || isAllowedByAllWithContext&lt;&amp;ContentSecurityPolicyDirectiveList::allowInlineEventHandlers&gt;(m_policies, contextURL, contextLine, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+    if (overrideContentSecurityPolicy)
+        return true;
+    return allPoliciesAllow(&amp;ContentSecurityPolicyDirectiveList::allowInlineEventHandlers, contextURL, contextLine, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-// FIXME: We should compute the document encoding once and cache it instead of computing it on each invocation.
-const TextEncoding&amp; ContentSecurityPolicy::documentEncoding() const
-{
-    if (!is&lt;Document&gt;(m_scriptExecutionContext))
-        return UTF8Encoding();
-    Document&amp; document = downcast&lt;Document&gt;(*m_scriptExecutionContext);
-    if (TextResourceDecoder* decoder = document.decoder())
-        return decoder-&gt;encoding();
-    return UTF8Encoding();
-}
-
</del><span class="cx"> bool ContentSecurityPolicy::allowScriptWithNonce(const String&amp; nonce, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><span class="cx">     if (overrideContentSecurityPolicy)
</span><span class="lines">@@ -305,7 +231,7 @@
</span><span class="cx">     String strippedNonce = stripLeadingAndTrailingHTMLSpaces(nonce);
</span><span class="cx">     if (strippedNonce.isEmpty())
</span><span class="cx">         return false;
</span><del>-    if (isAllowedByAllWithNonce&lt;&amp;ContentSecurityPolicyDirectiveList::allowScriptWithNonce&gt;(m_policies, strippedNonce))
</del><ins>+    if (allPoliciesAllow(&amp;ContentSecurityPolicyDirectiveList::allowScriptWithNonce, strippedNonce))
</ins><span class="cx">         return true;
</span><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="lines">@@ -317,7 +243,7 @@
</span><span class="cx">     String strippedNonce = stripLeadingAndTrailingHTMLSpaces(nonce);
</span><span class="cx">     if (strippedNonce.isEmpty())
</span><span class="cx">         return false;
</span><del>-    if (isAllowedByAllWithNonce&lt;&amp;ContentSecurityPolicyDirectiveList::allowStyleWithNonce&gt;(m_policies, strippedNonce))
</del><ins>+    if (allPoliciesAllow(&amp;ContentSecurityPolicyDirectiveList::allowStyleWithNonce, strippedNonce))
</ins><span class="cx">         return true;
</span><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="lines">@@ -327,9 +253,9 @@
</span><span class="cx">     if (overrideContentSecurityPolicy)
</span><span class="cx">         return true;
</span><span class="cx">     if (!m_hashAlgorithmsForInlineScripts.isEmpty() &amp;&amp; !scriptContent.isEmpty()
</span><del>-        &amp;&amp; isAllowedByAllWithHashFromContent&lt;&amp;ContentSecurityPolicyDirectiveList::allowInlineScriptWithHash&gt;(m_policies, scriptContent, documentEncoding(), m_hashAlgorithmsForInlineScripts))
</del><ins>+        &amp;&amp; allPoliciesAllowHashFromContent(&amp;ContentSecurityPolicyDirectiveList::allowInlineScriptWithHash, scriptContent, m_hashAlgorithmsForInlineScripts))
</ins><span class="cx">         return true;
</span><del>-    return isAllowedByAllWithContext&lt;&amp;ContentSecurityPolicyDirectiveList::allowInlineScript&gt;(m_policies, contextURL, contextLine, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+    return allPoliciesAllow(&amp;ContentSecurityPolicyDirectiveList::allowInlineScript, contextURL, contextLine, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool ContentSecurityPolicy::allowInlineStyle(const String&amp; contextURL, const WTF::OrdinalNumber&amp; contextLine, const String&amp; styleContent, bool overrideContentSecurityPolicy) const
</span><span class="lines">@@ -339,14 +265,16 @@
</span><span class="cx">     if (m_overrideInlineStyleAllowed)
</span><span class="cx">         return true;
</span><span class="cx">     if (!m_hashAlgorithmsForInlineStylesheets.isEmpty() &amp;&amp; !styleContent.isEmpty()
</span><del>-        &amp;&amp; isAllowedByAllWithHashFromContent&lt;&amp;ContentSecurityPolicyDirectiveList::allowInlineStyleWithHash&gt;(m_policies, styleContent, documentEncoding(), m_hashAlgorithmsForInlineStylesheets))
</del><ins>+        &amp;&amp; allPoliciesAllowHashFromContent(&amp;ContentSecurityPolicyDirectiveList::allowInlineStyleWithHash, styleContent, m_hashAlgorithmsForInlineStylesheets))
</ins><span class="cx">         return true;
</span><del>-    return isAllowedByAllWithContext&lt;&amp;ContentSecurityPolicyDirectiveList::allowInlineStyle&gt;(m_policies, contextURL, contextLine, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+    return allPoliciesAllow(&amp;ContentSecurityPolicyDirectiveList::allowInlineStyle, contextURL, contextLine, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool ContentSecurityPolicy::allowEval(JSC::ExecState* state, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><del>-    return overrideContentSecurityPolicy || isAllowedByAllWithState&lt;&amp;ContentSecurityPolicyDirectiveList::allowEval&gt;(m_policies, state, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+    if (overrideContentSecurityPolicy)
+        return true;
+    return allPoliciesAllow(&amp;ContentSecurityPolicyDirectiveList::allowEval, state, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool ContentSecurityPolicy::allowFrameAncestors(const Frame&amp; frame, const URL&amp; url, bool overrideContentSecurityPolicy) const
</span><span class="lines">@@ -356,80 +284,115 @@
</span><span class="cx">     Frame&amp; topFrame = frame.tree().top();
</span><span class="cx">     if (&amp;frame == &amp;topFrame)
</span><span class="cx">         return true;
</span><del>-    return isAllowedByAllWithFrame&lt;&amp;ContentSecurityPolicyDirectiveList::allowFrameAncestors&gt;(m_policies, frame, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+    return allPoliciesAllow(&amp;ContentSecurityPolicyDirectiveList::allowFrameAncestors, frame, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool ContentSecurityPolicy::allowPluginType(const String&amp; type, const String&amp; typeAttribute, const URL&amp; url, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><span class="cx">     if (overrideContentSecurityPolicy)
</span><span class="cx">         return true;
</span><del>-    for (auto&amp; policy : m_policies) {
-        if (!policy-&gt;allowPluginType(type, typeAttribute, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport))
-            return false;
-    }
-    return true;
</del><ins>+    return allPoliciesAllow(&amp;ContentSecurityPolicyDirectiveList::allowPluginType, type, typeAttribute, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool ContentSecurityPolicy::allowScriptFromSource(const URL&amp; url, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><del>-    return overrideContentSecurityPolicy || isAllowedByAllWithURL&lt;&amp;ContentSecurityPolicyDirectiveList::allowScriptFromSource&gt;(m_policies, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+    if (overrideContentSecurityPolicy)
+        return true;
+    if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol()))
+        return true;
+    return allPoliciesAllow(&amp;ContentSecurityPolicyDirectiveList::allowScriptFromSource, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool ContentSecurityPolicy::allowObjectFromSource(const URL&amp; url, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><del>-    return overrideContentSecurityPolicy || isAllowedByAllWithURL&lt;&amp;ContentSecurityPolicyDirectiveList::allowObjectFromSource&gt;(m_policies, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+    if (overrideContentSecurityPolicy)
+        return true;
+    if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol()))
+        return true;
+    return allPoliciesAllow(&amp;ContentSecurityPolicyDirectiveList::allowObjectFromSource, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool ContentSecurityPolicy::allowChildFrameFromSource(const URL&amp; url, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><del>-    return overrideContentSecurityPolicy || isAllowedByAllWithURL&lt;&amp;ContentSecurityPolicyDirectiveList::allowChildFrameFromSource&gt;(m_policies, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+    if (overrideContentSecurityPolicy)
+        return true;
+    if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol()))
+        return true;
+    return allPoliciesAllow(&amp;ContentSecurityPolicyDirectiveList::allowChildFrameFromSource, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool ContentSecurityPolicy::allowChildContextFromSource(const URL&amp; url, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><del>-    return overrideContentSecurityPolicy || isAllowedByAllWithURL&lt;&amp;ContentSecurityPolicyDirectiveList::allowChildContextFromSource&gt;(m_policies, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+    if (overrideContentSecurityPolicy)
+        return true;
+    if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol()))
+        return true;
+    return allPoliciesAllow(&amp;ContentSecurityPolicyDirectiveList::allowChildContextFromSource, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool ContentSecurityPolicy::allowImageFromSource(const URL&amp; url, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><del>-    return overrideContentSecurityPolicy || isAllowedByAllWithURL&lt;&amp;ContentSecurityPolicyDirectiveList::allowImageFromSource&gt;(m_policies, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+    if (overrideContentSecurityPolicy)
+        return true;
+    if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol()))
+        return true;
+    return allPoliciesAllow(&amp;ContentSecurityPolicyDirectiveList::allowImageFromSource, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool ContentSecurityPolicy::allowStyleFromSource(const URL&amp; url, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><del>-    return overrideContentSecurityPolicy || isAllowedByAllWithURL&lt;&amp;ContentSecurityPolicyDirectiveList::allowStyleFromSource&gt;(m_policies, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+    if (overrideContentSecurityPolicy)
+        return true;
+    if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol()))
+        return true;
+    return allPoliciesAllow(&amp;ContentSecurityPolicyDirectiveList::allowStyleFromSource, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool ContentSecurityPolicy::allowFontFromSource(const URL&amp; url, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><del>-    return overrideContentSecurityPolicy || isAllowedByAllWithURL&lt;&amp;ContentSecurityPolicyDirectiveList::allowFontFromSource&gt;(m_policies, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+    if (overrideContentSecurityPolicy)
+        return true;
+    if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol()))
+        return true;
+    return allPoliciesAllow(&amp;ContentSecurityPolicyDirectiveList::allowFontFromSource, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool ContentSecurityPolicy::allowMediaFromSource(const URL&amp; url, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><del>-    return overrideContentSecurityPolicy || isAllowedByAllWithURL&lt;&amp;ContentSecurityPolicyDirectiveList::allowMediaFromSource&gt;(m_policies, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+    if (overrideContentSecurityPolicy)
+        return true;
+    if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol()))
+        return true;
+    return allPoliciesAllow(&amp;ContentSecurityPolicyDirectiveList::allowMediaFromSource, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool ContentSecurityPolicy::allowConnectToSource(const URL&amp; url, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><del>-    return overrideContentSecurityPolicy || isAllowedByAllWithURL&lt;&amp;ContentSecurityPolicyDirectiveList::allowConnectToSource&gt;(m_policies, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+    if (overrideContentSecurityPolicy)
+        return true;
+    if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol()))
+        return true;
+    return allPoliciesAllow(&amp;ContentSecurityPolicyDirectiveList::allowConnectToSource, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool ContentSecurityPolicy::allowFormAction(const URL&amp; url, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><del>-    return overrideContentSecurityPolicy || isAllowedByAllWithURL&lt;&amp;ContentSecurityPolicyDirectiveList::allowFormAction&gt;(m_policies, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+    if (overrideContentSecurityPolicy)
+        return true;
+    if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol()))
+        return true;
+    return allPoliciesAllow(&amp;ContentSecurityPolicyDirectiveList::allowFormAction, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool ContentSecurityPolicy::allowBaseURI(const URL&amp; url, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><del>-    return overrideContentSecurityPolicy || isAllowedByAllWithURL&lt;&amp;ContentSecurityPolicyDirectiveList::allowBaseURI&gt;(m_policies, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+    if (overrideContentSecurityPolicy)
+        return true;
+    if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol()))
+        return true;
+    return allPoliciesAllow(&amp;ContentSecurityPolicyDirectiveList::allowBaseURI, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool ContentSecurityPolicy::isActive() const
-{
-    return !m_policies.isEmpty();
-}
-
</del><span class="cx"> ContentSecurityPolicy::ReflectedXSSDisposition ContentSecurityPolicy::reflectedXSSDisposition() const
</span><span class="cx"> {
</span><span class="cx">     ReflectedXSSDisposition disposition = ReflectedXSSUnset;
</span></span></pre></div>
<a id="trunkSourceWebCorepagecspContentSecurityPolicyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/csp/ContentSecurityPolicy.h (198612 => 198613)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/csp/ContentSecurityPolicy.h        2016-03-24 02:40:36 UTC (rev 198612)
+++ trunk/Source/WebCore/page/csp/ContentSecurityPolicy.h        2016-03-24 02:41:28 UTC (rev 198613)
</span><span class="lines">@@ -107,8 +107,6 @@
</span><span class="cx"> 
</span><span class="cx">     void setOverrideAllowInlineStyle(bool);
</span><span class="cx"> 
</span><del>-    bool isActive() const;
-
</del><span class="cx">     void gatherReportURIs(DOMStringList&amp;) const;
</span><span class="cx"> 
</span><span class="cx">     bool experimentalFeaturesEnabled() const;
</span><span class="lines">@@ -157,7 +155,8 @@
</span><span class="cx"> 
</span><span class="cx">     void didReceiveHeader(const String&amp;, ContentSecurityPolicyHeaderType, ContentSecurityPolicy::PolicyFrom);
</span><span class="cx"> 
</span><del>-    const TextEncoding&amp; documentEncoding() const;
</del><ins>+    template&lt;typename Predicate, typename... Args&gt; bool allPoliciesAllow(Predicate&amp;&amp;, Args&amp;&amp;...) const WARN_UNUSED_RETURN;
+    template&lt;typename Predicate&gt; bool allPoliciesAllowHashFromContent(Predicate&amp;&amp;, const String&amp; content, OptionSet&lt;ContentSecurityPolicyHashAlgorithm&gt;) const WARN_UNUSED_RETURN;
</ins><span class="cx"> 
</span><span class="cx">     // We can never have both a script execution context and a frame.
</span><span class="cx">     ScriptExecutionContext* m_scriptExecutionContext { nullptr };
</span><span class="lines">@@ -173,6 +172,16 @@
</span><span class="cx">     OptionSet&lt;ContentSecurityPolicyHashAlgorithm&gt; m_hashAlgorithmsForInlineStylesheets;
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+template&lt;typename Predicate, typename... Args&gt;
+inline bool ContentSecurityPolicy::allPoliciesAllow(Predicate&amp;&amp; predicate, Args&amp;&amp;... args) const
+{
+    for (auto&amp; policy : m_policies) {
+        if (!(policy.get()-&gt;*predicate)(std::forward&lt;Args&gt;(args)...))
+            return false;
+    }
+    return true;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+}
+
</ins><span class="cx"> #endif
</span></span></pre>
</div>
</div>

</body>
</html>