| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google, Inc. All rights reserved. | 2 * Copyright (C) 2011 Google, Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 // Ensure that 'self' processes correctly. | 157 // Ensure that 'self' processes correctly. |
| 158 m_selfSource = adoptPtr(new CSPSource(this, securityOrigin()->protocol(), se
curityOrigin()->host(), securityOrigin()->port(), String(), CSPSource::NoWildcar
d, CSPSource::NoWildcard)); | 158 m_selfSource = adoptPtr(new CSPSource(this, securityOrigin()->protocol(), se
curityOrigin()->host(), securityOrigin()->port(), String(), CSPSource::NoWildcar
d, CSPSource::NoWildcard)); |
| 159 | 159 |
| 160 // If we're in a Document, set the referrer policy and sandbox flags, then d
ump all the | 160 // If we're in a Document, set the referrer policy and sandbox flags, then d
ump all the |
| 161 // parsing error messages, then poke at histograms. | 161 // parsing error messages, then poke at histograms. |
| 162 if (Document* document = this->document()) { | 162 if (Document* document = this->document()) { |
| 163 document->enforceSandboxFlags(m_sandboxMask); | 163 document->enforceSandboxFlags(m_sandboxMask); |
| 164 if (didSetReferrerPolicy()) | 164 if (didSetReferrerPolicy()) |
| 165 document->setReferrerPolicy(m_referrerPolicy); | 165 document->setReferrerPolicy(m_referrerPolicy); |
| 166 | 166 |
| 167 for (ConsoleMessageVector::const_iterator iter = m_consoleMessages.begin
(); iter != m_consoleMessages.end(); ++iter) | 167 for (const auto& consoleMessage : m_consoleMessages) |
| 168 m_executionContext->addConsoleMessage(*iter); | 168 m_executionContext->addConsoleMessage(consoleMessage); |
| 169 m_consoleMessages.clear(); | 169 m_consoleMessages.clear(); |
| 170 | 170 |
| 171 for (CSPDirectiveListVector::const_iterator iter = m_policies.begin(); i
ter != m_policies.end(); ++iter) | 171 for (const auto& cspDirective : m_policies) |
| 172 UseCounter::count(*document, getUseCounterType((*iter)->headerType()
)); | 172 UseCounter::count(*document, getUseCounterType(cspDirective->headerT
ype())); |
| 173 } | 173 } |
| 174 | 174 |
| 175 // We disable 'eval()' even in the case of report-only policies, and rely on
the check in the | 175 // We disable 'eval()' even in the case of report-only policies, and rely on
the check in the |
| 176 // V8Initializer::codeGenerationCheckCallbackInMainThread callback to determ
ine whether the | 176 // V8Initializer::codeGenerationCheckCallbackInMainThread callback to determ
ine whether the |
| 177 // call should execute or not. | 177 // call should execute or not. |
| 178 if (!m_disableEvalErrorMessage.isNull()) | 178 if (!m_disableEvalErrorMessage.isNull()) |
| 179 m_executionContext->disableEval(m_disableEvalErrorMessage); | 179 m_executionContext->disableEval(m_disableEvalErrorMessage); |
| 180 } | 180 } |
| 181 | 181 |
| 182 ContentSecurityPolicy::~ContentSecurityPolicy() | 182 ContentSecurityPolicy::~ContentSecurityPolicy() |
| 183 { | 183 { |
| 184 } | 184 } |
| 185 | 185 |
| 186 Document* ContentSecurityPolicy::document() const | 186 Document* ContentSecurityPolicy::document() const |
| 187 { | 187 { |
| 188 return m_executionContext->isDocument() ? toDocument(m_executionContext) : 0
; | 188 return m_executionContext->isDocument() ? toDocument(m_executionContext) : 0
; |
| 189 } | 189 } |
| 190 | 190 |
| 191 void ContentSecurityPolicy::copyStateFrom(const ContentSecurityPolicy* other) | 191 void ContentSecurityPolicy::copyStateFrom(const ContentSecurityPolicy* other) |
| 192 { | 192 { |
| 193 ASSERT(m_policies.isEmpty()); | 193 ASSERT(m_policies.isEmpty()); |
| 194 for (CSPDirectiveListVector::const_iterator iter = other->m_policies.begin()
; iter != other->m_policies.end(); ++iter) | 194 for (const auto& cspDirective : other->m_policies) |
| 195 addPolicyFromHeaderValue((*iter)->header(), (*iter)->headerType(), (*ite
r)->headerSource()); | 195 addPolicyFromHeaderValue(cspDirective->header(), cspDirective->headerTyp
e(), cspDirective->headerSource()); |
| 196 } | 196 } |
| 197 | 197 |
| 198 void ContentSecurityPolicy::didReceiveHeaders(const ContentSecurityPolicyRespons
eHeaders& headers) | 198 void ContentSecurityPolicy::didReceiveHeaders(const ContentSecurityPolicyRespons
eHeaders& headers) |
| 199 { | 199 { |
| 200 if (!headers.contentSecurityPolicy().isEmpty()) | 200 if (!headers.contentSecurityPolicy().isEmpty()) |
| 201 addPolicyFromHeaderValue(headers.contentSecurityPolicy(), ContentSecurit
yPolicyHeaderTypeEnforce, ContentSecurityPolicyHeaderSourceHTTP); | 201 addPolicyFromHeaderValue(headers.contentSecurityPolicy(), ContentSecurit
yPolicyHeaderTypeEnforce, ContentSecurityPolicyHeaderSourceHTTP); |
| 202 if (!headers.contentSecurityPolicyReportOnly().isEmpty()) | 202 if (!headers.contentSecurityPolicyReportOnly().isEmpty()) |
| 203 addPolicyFromHeaderValue(headers.contentSecurityPolicyReportOnly(), Cont
entSecurityPolicyHeaderTypeReport, ContentSecurityPolicyHeaderSourceHTTP); | 203 addPolicyFromHeaderValue(headers.contentSecurityPolicyReportOnly(), Cont
entSecurityPolicyHeaderTypeReport, ContentSecurityPolicyHeaderSourceHTTP); |
| 204 } | 204 } |
| 205 | 205 |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 // Collisions have no security impact, so we can save space by storing only
the string's hash rather than the whole report. | 873 // Collisions have no security impact, so we can save space by storing only
the string's hash rather than the whole report. |
| 874 return !m_violationReportsSent.contains(report.impl()->hash()); | 874 return !m_violationReportsSent.contains(report.impl()->hash()); |
| 875 } | 875 } |
| 876 | 876 |
| 877 void ContentSecurityPolicy::didSendViolationReport(const String& report) | 877 void ContentSecurityPolicy::didSendViolationReport(const String& report) |
| 878 { | 878 { |
| 879 m_violationReportsSent.add(report.impl()->hash()); | 879 m_violationReportsSent.add(report.impl()->hash()); |
| 880 } | 880 } |
| 881 | 881 |
| 882 } // namespace blink | 882 } // namespace blink |
| OLD | NEW |