1/*
2 * Copyright (C) 2015, 2016 Apple 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 APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
28#include "APIObject.h"
29#include "WebPreferencesStore.h"
30#include <pal/SessionID.h>
31#include <wtf/Forward.h>
32#include <wtf/GetPtr.h>
33
34namespace WebKit {
35class VisitedLinkStore;
36class WebPageGroup;
37class WebPageProxy;
38class WebPreferences;
39class WebProcessPool;
40class WebURLSchemeHandler;
41class WebUserContentControllerProxy;
42}
43
44namespace API {
45
46class ApplicationManifest;
47class WebsiteDataStore;
48class WebsitePolicies;
49
50class PageConfiguration : public ObjectImpl<Object::Type::PageConfiguration> {
51public:
52 static Ref<PageConfiguration> create();
53
54 explicit PageConfiguration();
55 virtual ~PageConfiguration();
56
57 Ref<PageConfiguration> copy() const;
58
59 // FIXME: The configuration properties should return their default values
60 // rather than nullptr.
61
62 WebKit::WebProcessPool* processPool();
63 void setProcessPool(WebKit::WebProcessPool*);
64
65 WebKit::WebUserContentControllerProxy* userContentController();
66 void setUserContentController(WebKit::WebUserContentControllerProxy*);
67
68 WebKit::WebPageGroup* pageGroup();
69 void setPageGroup(WebKit::WebPageGroup*);
70
71 WebKit::WebPreferences* preferences();
72 void setPreferences(WebKit::WebPreferences*);
73
74 WebKit::WebPreferencesStore::ValueMap& preferenceValues() { return m_preferenceValues; }
75
76 WebKit::WebPageProxy* relatedPage() const;
77 void setRelatedPage(WebKit::WebPageProxy*);
78
79 WebKit::VisitedLinkStore* visitedLinkStore();
80 void setVisitedLinkStore(WebKit::VisitedLinkStore*);
81
82 WebsiteDataStore* websiteDataStore();
83 void setWebsiteDataStore(WebsiteDataStore*);
84
85 WebsitePolicies* defaultWebsitePolicies() const;
86 void setDefaultWebsitePolicies(WebsitePolicies*);
87
88 // FIXME: Once PageConfigurations *always* have a data store, get rid of the separate sessionID.
89 PAL::SessionID sessionID();
90 void setSessionID(PAL::SessionID);
91
92 bool treatsSHA1SignedCertificatesAsInsecure() { return m_treatsSHA1SignedCertificatesAsInsecure; }
93 void setTreatsSHA1SignedCertificatesAsInsecure(bool treatsSHA1SignedCertificatesAsInsecure) { m_treatsSHA1SignedCertificatesAsInsecure = treatsSHA1SignedCertificatesAsInsecure; }
94
95#if PLATFORM(IOS_FAMILY)
96 bool alwaysRunsAtForegroundPriority() { return m_alwaysRunsAtForegroundPriority; }
97 void setAlwaysRunsAtForegroundPriority(bool alwaysRunsAtForegroundPriority) { m_alwaysRunsAtForegroundPriority = alwaysRunsAtForegroundPriority; }
98
99 bool canShowWhileLocked() const { return m_canShowWhileLocked; }
100 void setCanShowWhileLocked(bool canShowWhileLocked) { m_canShowWhileLocked = canShowWhileLocked; }
101#endif
102 bool initialCapitalizationEnabled() { return m_initialCapitalizationEnabled; }
103 void setInitialCapitalizationEnabled(bool initialCapitalizationEnabled) { m_initialCapitalizationEnabled = initialCapitalizationEnabled; }
104
105 Optional<double> cpuLimit() const { return m_cpuLimit; }
106 void setCPULimit(double cpuLimit) { m_cpuLimit = cpuLimit; }
107
108 bool waitsForPaintAfterViewDidMoveToWindow() const { return m_waitsForPaintAfterViewDidMoveToWindow; }
109 void setWaitsForPaintAfterViewDidMoveToWindow(bool shouldSynchronize) { m_waitsForPaintAfterViewDidMoveToWindow = shouldSynchronize; }
110
111 bool drawsBackground() const { return m_drawsBackground; }
112 void setDrawsBackground(bool drawsBackground) { m_drawsBackground = drawsBackground; }
113
114 bool isControlledByAutomation() const { return m_controlledByAutomation; }
115 void setControlledByAutomation(bool controlledByAutomation) { m_controlledByAutomation = controlledByAutomation; }
116
117 const WTF::String& overrideContentSecurityPolicy() const { return m_overrideContentSecurityPolicy; }
118 void setOverrideContentSecurityPolicy(const WTF::String& overrideContentSecurityPolicy) { m_overrideContentSecurityPolicy = overrideContentSecurityPolicy; }
119
120#if PLATFORM(COCOA)
121 const WTF::Vector<WTF::String>& additionalSupportedImageTypes() const { return m_additionalSupportedImageTypes; }
122 void setAdditionalSupportedImageTypes(WTF::Vector<WTF::String>&& additionalSupportedImageTypes) { m_additionalSupportedImageTypes = WTFMove(additionalSupportedImageTypes); }
123#endif
124
125#if ENABLE(APPLICATION_MANIFEST)
126 ApplicationManifest* applicationManifest() const;
127 void setApplicationManifest(ApplicationManifest*);
128#endif
129
130 RefPtr<WebKit::WebURLSchemeHandler> urlSchemeHandlerForURLScheme(const WTF::String&);
131 void setURLSchemeHandlerForURLScheme(Ref<WebKit::WebURLSchemeHandler>&&, const WTF::String&);
132 const HashMap<WTF::String, Ref<WebKit::WebURLSchemeHandler>>& urlSchemeHandlers() { return m_urlSchemeHandlers; }
133
134private:
135
136 RefPtr<WebKit::WebProcessPool> m_processPool;
137 RefPtr<WebKit::WebUserContentControllerProxy> m_userContentController;
138 RefPtr<WebKit::WebPageGroup> m_pageGroup;
139 RefPtr<WebKit::WebPreferences> m_preferences;
140 WebKit::WebPreferencesStore::ValueMap m_preferenceValues;
141 RefPtr<WebKit::WebPageProxy> m_relatedPage;
142 RefPtr<WebKit::VisitedLinkStore> m_visitedLinkStore;
143
144 RefPtr<WebsiteDataStore> m_websiteDataStore;
145 RefPtr<WebsitePolicies> m_defaultWebsitePolicies;
146 // FIXME: We currently have to pass the session ID separately here to support the legacy private browsing session.
147 // Once we get rid of it we should get rid of this configuration parameter as well.
148 PAL::SessionID m_sessionID;
149
150 bool m_treatsSHA1SignedCertificatesAsInsecure { true };
151#if PLATFORM(IOS_FAMILY)
152 bool m_alwaysRunsAtForegroundPriority { false };
153 bool m_canShowWhileLocked { false };
154#endif
155 bool m_initialCapitalizationEnabled { true };
156 bool m_waitsForPaintAfterViewDidMoveToWindow { true };
157 bool m_drawsBackground { true };
158 bool m_controlledByAutomation { false };
159 Optional<double> m_cpuLimit;
160
161 WTF::String m_overrideContentSecurityPolicy;
162
163#if PLATFORM(COCOA)
164 WTF::Vector<WTF::String> m_additionalSupportedImageTypes;
165#endif
166
167#if ENABLE(APPLICATION_MANIFEST)
168 RefPtr<ApplicationManifest> m_applicationManifest;
169#endif
170
171 HashMap<WTF::String, Ref<WebKit::WebURLSchemeHandler>> m_urlSchemeHandlers;
172};
173
174} // namespace API
175