Merge "[CherryPick] Refactoring: Move the content of HTMLInputElement::subtreeHasChan...
[framework/web/webkit-efl.git] / Source / WebCore / page / ContentSecurityPolicy.h
1 /*
2  * Copyright (C) 2011 Google, Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #ifndef ContentSecurityPolicy_h
27 #define ContentSecurityPolicy_h
28
29 #include "KURL.h"
30 #include <wtf/PassOwnPtr.h>
31 #include <wtf/RefCounted.h>
32 #include <wtf/Vector.h>
33 #include <wtf/text/TextPosition.h>
34 #include <wtf/text/WTFString.h>
35
36 namespace WTF {
37 class OrdinalNumber;
38 }
39
40 namespace WebCore {
41
42 class CSPDirectiveList;
43 class ScriptCallStack;
44 class DOMStringList;
45 class ScriptExecutionContext;
46 class SecurityOrigin;
47
48 typedef int SandboxFlags;
49 typedef Vector<OwnPtr<CSPDirectiveList> > CSPDirectiveListVector;
50
51 class ContentSecurityPolicy {
52 public:
53     static PassOwnPtr<ContentSecurityPolicy> create(ScriptExecutionContext* scriptExecutionContext)
54     {
55         return adoptPtr(new ContentSecurityPolicy(scriptExecutionContext));
56     }
57     ~ContentSecurityPolicy();
58
59     void copyStateFrom(const ContentSecurityPolicy*);
60
61     enum HeaderType {
62         ReportOnly,
63         EnforcePolicy
64     };
65
66     enum ReportingStatus {
67         SendReport,
68         SuppressReport
69     };
70
71     void didReceiveHeader(const String&, HeaderType);
72
73     // These functions are wrong because they assume that there is only one header.
74     // FIXME: Replace them with functions that return vectors.
75     const String& deprecatedHeader() const;
76     HeaderType deprecatedHeaderType() const;
77
78     bool allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber& contextLine, ReportingStatus = SendReport) const;
79     bool allowInlineEventHandlers(const String& contextURL, const WTF::OrdinalNumber& contextLine, ReportingStatus = SendReport) const;
80     bool allowInlineScript(const String& contextURL, const WTF::OrdinalNumber& contextLine, ReportingStatus = SendReport) const;
81     bool allowInlineStyle(const String& contextURL, const WTF::OrdinalNumber& contextLine, ReportingStatus = SendReport) const;
82     bool allowEval(PassRefPtr<ScriptCallStack>, ReportingStatus = SendReport) const;
83     bool allowScriptNonce(const String& nonce, const String& contextURL, const WTF::OrdinalNumber& contextLine, const KURL& = KURL()) const;
84
85     bool allowScriptFromSource(const KURL&, ReportingStatus = SendReport) const;
86     bool allowObjectFromSource(const KURL&, ReportingStatus = SendReport) const;
87     bool allowChildFrameFromSource(const KURL&, ReportingStatus = SendReport) const;
88     bool allowImageFromSource(const KURL&, ReportingStatus = SendReport) const;
89     bool allowStyleFromSource(const KURL&, ReportingStatus = SendReport) const;
90     bool allowFontFromSource(const KURL&, ReportingStatus = SendReport) const;
91     bool allowMediaFromSource(const KURL&, ReportingStatus = SendReport) const;
92     bool allowConnectToSource(const KURL&, ReportingStatus = SendReport) const;
93
94     void setOverrideAllowInlineStyle(bool);
95
96     bool isActive() const;
97     void gatherReportURIs(DOMStringList&) const;
98
99     void reportDuplicateDirective(const String&) const;
100     void reportInvalidNonce(const String&) const;
101     void reportIgnoredPathComponent(const String& directiveName, const String& completeSource, const String& path) const;
102     void reportUnrecognizedDirective(const String&) const;
103     void reportViolation(const String& directiveText, const String& consoleMessage, const KURL& blockedURL, const Vector<KURL>& reportURIs, const String& header, const String& contextURL = String(), const WTF::OrdinalNumber& contextLine = WTF::OrdinalNumber::beforeFirst(), PassRefPtr<ScriptCallStack> = 0) const;
104
105     const KURL& url() const;
106     KURL completeURL(const String&) const;
107     SecurityOrigin* securityOrigin() const;
108     void enforceSandboxFlags(SandboxFlags) const;
109
110 private:
111     explicit ContentSecurityPolicy(ScriptExecutionContext*);
112
113     void logToConsole(const String& message, const String& contextURL = String(), const WTF::OrdinalNumber& contextLine = WTF::OrdinalNumber::beforeFirst(), PassRefPtr<ScriptCallStack> = 0) const;
114
115     ScriptExecutionContext* m_scriptExecutionContext;
116     bool m_overrideInlineStyleAllowed;
117     CSPDirectiveListVector m_policies;
118 };
119
120 }
121
122 #endif