OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "core/frame/csp/CSPDirectiveList.h" | 6 #include "core/frame/csp/CSPDirectiveList.h" |
7 | 7 |
8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
9 #include "core/frame/LocalFrame.h" | 9 #include "core/frame/LocalFrame.h" |
| 10 #include "core/inspector/ConsoleMessage.h" |
10 #include "platform/ParsingUtilities.h" | 11 #include "platform/ParsingUtilities.h" |
11 #include "platform/weborigin/KURL.h" | 12 #include "platform/weborigin/KURL.h" |
12 #include "wtf/text/WTFString.h" | 13 #include "wtf/text/WTFString.h" |
13 | 14 |
14 namespace blink { | 15 namespace blink { |
15 | 16 |
16 CSPDirectiveList::CSPDirectiveList(ContentSecurityPolicy* policy, ContentSecurit
yPolicyHeaderType type, ContentSecurityPolicyHeaderSource source) | 17 CSPDirectiveList::CSPDirectiveList(ContentSecurityPolicy* policy, ContentSecurit
yPolicyHeaderType type, ContentSecurityPolicyHeaderSource source) |
17 : m_policy(policy) | 18 : m_policy(policy) |
18 , m_headerType(type) | 19 , m_headerType(type) |
19 , m_headerSource(source) | 20 , m_headerSource(source) |
(...skipping 18 matching lines...) Expand all Loading... |
38 | 39 |
39 if (directives->isReportOnly() && directives->reportURIs().isEmpty()) | 40 if (directives->isReportOnly() && directives->reportURIs().isEmpty()) |
40 policy->reportMissingReportURI(String(begin, end - begin)); | 41 policy->reportMissingReportURI(String(begin, end - begin)); |
41 | 42 |
42 return directives.release(); | 43 return directives.release(); |
43 } | 44 } |
44 | 45 |
45 void CSPDirectiveList::reportViolation(const String& directiveText, const String
& effectiveDirective, const String& consoleMessage, const KURL& blockedURL) cons
t | 46 void CSPDirectiveList::reportViolation(const String& directiveText, const String
& effectiveDirective, const String& consoleMessage, const KURL& blockedURL) cons
t |
46 { | 47 { |
47 String message = m_reportOnly ? "[Report Only] " + consoleMessage : consoleM
essage; | 48 String message = m_reportOnly ? "[Report Only] " + consoleMessage : consoleM
essage; |
48 m_policy->executionContext()->addConsoleMessage(SecurityMessageSource, Error
MessageLevel, message); | 49 m_policy->executionContext()->addConsoleMessage(ConsoleMessage::create(Secur
ityMessageSource, ErrorMessageLevel, message)); |
49 m_policy->reportViolation(directiveText, effectiveDirective, message, blocke
dURL, m_reportURIs, m_header); | 50 m_policy->reportViolation(directiveText, effectiveDirective, message, blocke
dURL, m_reportURIs, m_header); |
50 } | 51 } |
51 | 52 |
52 void CSPDirectiveList::reportViolationWithLocation(const String& directiveText,
const String& effectiveDirective, const String& consoleMessage, const KURL& bloc
kedURL, const String& contextURL, const WTF::OrdinalNumber& contextLine) const | 53 void CSPDirectiveList::reportViolationWithLocation(const String& directiveText,
const String& effectiveDirective, const String& consoleMessage, const KURL& bloc
kedURL, const String& contextURL, const WTF::OrdinalNumber& contextLine) const |
53 { | 54 { |
54 String message = m_reportOnly ? "[Report Only] " + consoleMessage : consoleM
essage; | 55 String message = m_reportOnly ? "[Report Only] " + consoleMessage : consoleM
essage; |
55 m_policy->executionContext()->addConsoleMessage(SecurityMessageSource, Error
MessageLevel, message, contextURL, contextLine.oneBasedInt()); | 56 m_policy->executionContext()->addConsoleMessage(ConsoleMessage::create(Secur
ityMessageSource, ErrorMessageLevel, message, contextURL, contextLine.oneBasedIn
t())); |
56 m_policy->reportViolation(directiveText, effectiveDirective, message, blocke
dURL, m_reportURIs, m_header); | 57 m_policy->reportViolation(directiveText, effectiveDirective, message, blocke
dURL, m_reportURIs, m_header); |
57 } | 58 } |
58 | 59 |
59 void CSPDirectiveList::reportViolationWithState(const String& directiveText, con
st String& effectiveDirective, const String& consoleMessage, const KURL& blocked
URL, ScriptState* scriptState) const | 60 void CSPDirectiveList::reportViolationWithState(const String& directiveText, con
st String& effectiveDirective, const String& message, const KURL& blockedURL, Sc
riptState* scriptState) const |
60 { | 61 { |
61 String message = m_reportOnly ? "[Report Only] " + consoleMessage : consoleM
essage; | 62 String reportMessage = m_reportOnly ? "[Report Only] " + message : message; |
62 m_policy->executionContext()->addConsoleMessage(SecurityMessageSource, Error
MessageLevel, message, scriptState); | 63 RefPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(SecurityMessa
geSource, ErrorMessageLevel, reportMessage); |
| 64 consoleMessage->setScriptState(scriptState); |
| 65 m_policy->executionContext()->addConsoleMessage(consoleMessage.release()); |
63 m_policy->reportViolation(directiveText, effectiveDirective, message, blocke
dURL, m_reportURIs, m_header); | 66 m_policy->reportViolation(directiveText, effectiveDirective, message, blocke
dURL, m_reportURIs, m_header); |
64 } | 67 } |
65 | 68 |
66 bool CSPDirectiveList::checkEval(SourceListDirective* directive) const | 69 bool CSPDirectiveList::checkEval(SourceListDirective* directive) const |
67 { | 70 { |
68 return !directive || directive->allowEval(); | 71 return !directive || directive->allowEval(); |
69 } | 72 } |
70 | 73 |
71 bool CSPDirectiveList::checkInline(SourceListDirective* directive) const | 74 bool CSPDirectiveList::checkInline(SourceListDirective* directive) const |
72 { | 75 { |
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 parseReferrer(name, value); | 674 parseReferrer(name, value); |
672 else | 675 else |
673 m_policy->reportUnsupportedDirective(name); | 676 m_policy->reportUnsupportedDirective(name); |
674 } else { | 677 } else { |
675 m_policy->reportUnsupportedDirective(name); | 678 m_policy->reportUnsupportedDirective(name); |
676 } | 679 } |
677 } | 680 } |
678 | 681 |
679 | 682 |
680 } // namespace blink | 683 } // namespace blink |
OLD | NEW |