1/*
2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * Copyright (C) 2016-2018 Apple Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
28#include "Event.h"
29
30namespace WebCore {
31
32class SecurityPolicyViolationEvent final : public Event {
33public:
34 static Ref<SecurityPolicyViolationEvent> create(const AtomString& type, CanBubble canBubble, IsCancelable cancelable, const String& documentURI, const String& referrer, const String& blockedURI, const String& violatedDirective, const String& effectiveDirective, const String& originalPolicy, const String& sourceFile, unsigned short statusCode, int lineNumber, int columnNumber)
35 {
36 return adoptRef(*new SecurityPolicyViolationEvent(type, canBubble, cancelable, documentURI, referrer, blockedURI, violatedDirective, effectiveDirective, originalPolicy, sourceFile, statusCode, lineNumber, columnNumber));
37 }
38
39 static Ref<SecurityPolicyViolationEvent> createForBindings()
40 {
41 return adoptRef(*new SecurityPolicyViolationEvent());
42 }
43
44 struct Init : EventInit {
45 String documentURI;
46 String referrer;
47 String blockedURI;
48 String violatedDirective;
49 String effectiveDirective;
50 String originalPolicy;
51 String sourceFile;
52 unsigned short statusCode { 0 };
53 int lineNumber { 0 };
54 int columnNumber { 0 };
55
56 template<class Encoder> void encode(Encoder&) const;
57 template<class Decoder> static bool decode(Decoder&, Init&);
58 };
59
60 static Ref<SecurityPolicyViolationEvent> create(const AtomString& type, const Init& initializer, IsTrusted isTrusted = IsTrusted::No)
61 {
62 return adoptRef(*new SecurityPolicyViolationEvent(type, initializer, isTrusted));
63 }
64
65 const String& documentURI() const { return m_documentURI; }
66 const String& referrer() const { return m_referrer; }
67 const String& blockedURI() const { return m_blockedURI; }
68 const String& violatedDirective() const { return m_violatedDirective; }
69 const String& effectiveDirective() const { return m_effectiveDirective; }
70 const String& originalPolicy() const { return m_originalPolicy; }
71 const String& sourceFile() const { return m_sourceFile; }
72 unsigned short statusCode() const { return m_statusCode; }
73 int lineNumber() const { return m_lineNumber; }
74 int columnNumber() const { return m_columnNumber; }
75
76 EventInterface eventInterface() const final { return SecurityPolicyViolationEventInterfaceType; }
77
78private:
79 SecurityPolicyViolationEvent()
80 {
81 }
82
83 SecurityPolicyViolationEvent(const AtomString& type, CanBubble canBubble, IsCancelable cancelable, const String& documentURI, const String& referrer, const String& blockedURI, const String& violatedDirective, const String& effectiveDirective, const String& originalPolicy, const String& sourceFile, unsigned short statusCode, int lineNumber, int columnNumber)
84 : Event(type, canBubble, cancelable)
85 , m_documentURI(documentURI)
86 , m_referrer(referrer)
87 , m_blockedURI(blockedURI)
88 , m_violatedDirective(violatedDirective)
89 , m_effectiveDirective(effectiveDirective)
90 , m_originalPolicy(originalPolicy)
91 , m_sourceFile(sourceFile)
92 , m_statusCode(statusCode)
93 , m_lineNumber(lineNumber)
94 , m_columnNumber(columnNumber)
95 {
96 }
97
98 SecurityPolicyViolationEvent(const AtomString& type, const Init& initializer, IsTrusted isTrusted)
99 : Event(type, initializer, isTrusted)
100 , m_documentURI(initializer.documentURI)
101 , m_referrer(initializer.referrer)
102 , m_blockedURI(initializer.blockedURI)
103 , m_violatedDirective(initializer.violatedDirective)
104 , m_effectiveDirective(initializer.effectiveDirective)
105 , m_originalPolicy(initializer.originalPolicy)
106 , m_sourceFile(initializer.sourceFile)
107 , m_statusCode(initializer.statusCode)
108 , m_lineNumber(initializer.lineNumber)
109 , m_columnNumber(initializer.columnNumber)
110 {
111 }
112
113 String m_documentURI;
114 String m_referrer;
115 String m_blockedURI;
116 String m_violatedDirective;
117 String m_effectiveDirective;
118 String m_originalPolicy;
119 String m_sourceFile;
120 unsigned short m_statusCode;
121 int m_lineNumber;
122 int m_columnNumber;
123};
124
125template<class Encoder>
126void SecurityPolicyViolationEvent::Init::encode(Encoder& encoder) const
127{
128 encoder << static_cast<const EventInit&>(*this);
129 encoder << documentURI;
130 encoder << referrer;
131 encoder << blockedURI;
132 encoder << violatedDirective;
133 encoder << effectiveDirective;
134 encoder << originalPolicy;
135 encoder << sourceFile;
136 encoder << statusCode;
137 encoder << lineNumber;
138 encoder << columnNumber;
139}
140
141template<class Decoder>
142bool SecurityPolicyViolationEvent::Init::decode(Decoder& decoder, SecurityPolicyViolationEvent::Init& eventInit)
143{
144 if (!decoder.decode(static_cast<EventInit&>(eventInit)))
145 return false;
146 if (!decoder.decode(eventInit.documentURI))
147 return false;
148 if (!decoder.decode(eventInit.referrer))
149 return false;
150 if (!decoder.decode(eventInit.blockedURI))
151 return false;
152 if (!decoder.decode(eventInit.violatedDirective))
153 return false;
154 if (!decoder.decode(eventInit.effectiveDirective))
155 return false;
156 if (!decoder.decode(eventInit.originalPolicy))
157 return false;
158 if (!decoder.decode(eventInit.sourceFile))
159 return false;
160 if (!decoder.decode(eventInit.statusCode))
161 return false;
162 if (!decoder.decode(eventInit.lineNumber))
163 return false;
164 if (!decoder.decode(eventInit.columnNumber))
165 return false;
166 return true;
167}
168
169} // namespace WebCore
170