Remove LayoutTestController and WebKitTestRunner support for Hixie76 WebSockets
[WebKit-https.git] / Tools / DumpRenderTree / chromium / WebPreferences.cpp
1 /*
2  * Copyright (C) 2012 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 are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #include "config.h"
32 #include "WebPreferences.h"
33
34 #include "WebView.h"
35
36 using namespace WebKit;
37
38 void WebPreferences::reset()
39 {
40 #if OS(MAC_OS_X)
41     cursiveFontFamily = WebString::fromUTF8("Apple Chancery");
42     fantasyFontFamily = WebString::fromUTF8("Papyrus");
43     WebString serif = WebString::fromUTF8("Times");
44 #else
45     // These two fonts are picked from the intersection of
46     // Win XP font list and Vista font list :
47     //   http://www.microsoft.com/typography/fonts/winxp.htm
48     //   http://blogs.msdn.com/michkap/archive/2006/04/04/567881.aspx
49     // Some of them are installed only with CJK and complex script
50     // support enabled on Windows XP and are out of consideration here.
51     // (although we enabled both on our buildbots.)
52     // They (especially Impact for fantasy) are not typical cursive
53     // and fantasy fonts, but it should not matter for layout tests
54     // as long as they're available.
55     cursiveFontFamily = WebString::fromUTF8("Comic Sans MS");
56     fantasyFontFamily = WebString::fromUTF8("Impact");
57     // NOTE: case matters here, this must be 'times new roman', else
58     // some layout tests fail.
59     WebString serif = WebString::fromUTF8("times new roman");
60 #endif
61     serifFontFamily = serif;
62     standardFontFamily = serif;
63     fixedFontFamily = WebString::fromUTF8("Courier");
64     sansSerifFontFamily = WebString::fromUTF8("Helvetica");
65
66     defaultFontSize = 16;
67     defaultFixedFontSize = 13;
68     minimumFontSize = 0;
69     minimumLogicalFontSize = 9;
70     // Do not disable acceleration for 2d canvas based on size.
71     // This makes having test expectations consistent.
72     minimumAccelerated2dCanvasSize = 0;
73
74     DOMPasteAllowed = true;
75     XSSAuditorEnabled = false;
76     allowDisplayOfInsecureContent = true;
77     allowFileAccessFromFileURLs = true;
78     allowRunningOfInsecureContent = true;
79     authorAndUserStylesEnabled = true;
80     defaultTextEncodingName = WebString::fromUTF8("ISO-8859-1");
81     developerExtrasEnabled = true;
82     experimentalWebGLEnabled = false;
83     experimentalCSSRegionsEnabled = true;
84     experimentalCSSGridLayoutEnabled = false;
85     javaEnabled = false;
86     javaScriptCanAccessClipboard = true;
87     javaScriptCanOpenWindowsAutomatically = true;
88     javaScriptEnabled = true;
89     loadsImagesAutomatically = true;
90     localStorageEnabled = true;
91     offlineWebApplicationCacheEnabled = true;
92     pluginsEnabled = true;
93     shrinksStandaloneImagesToFit = false;
94     textAreasAreResizable = false;
95     userStyleSheetLocation = WebURL();
96     usesPageCache = false;
97     pageCacheSupportsPlugins = false;
98     webSecurityEnabled = true;
99     caretBrowsingEnabled = false;
100
101     // Allow those layout tests running as local files, i.e. under
102     // LayoutTests/http/tests/local, to access http server.
103     allowUniversalAccessFromFileURLs = true;
104
105 #if OS(DARWIN)
106     editingBehavior = WebSettings::EditingBehaviorMac;
107 #else
108     editingBehavior = WebSettings::EditingBehaviorWin;
109 #endif
110
111     tabsToLinks = false;
112     hyperlinkAuditingEnabled = false;
113     acceleratedCompositingForVideoEnabled = false;
114     acceleratedCompositingEnabled = false;
115     accelerated2dCanvasEnabled = false;
116     deferred2dCanvasEnabled = false;
117     acceleratedPaintingEnabled = false;
118     forceCompositingMode = false;
119     mediaPlaybackRequiresUserGesture = false;
120     mockScrollbarsEnabled = false;
121     cssCustomFilterEnabled = false;
122 }
123
124 static void setStandardFontFamilyWrapper(WebSettings* settings, const WebKit::WebString& font, UScriptCode script)
125 {
126     settings->setStandardFontFamily(font, script);
127 }
128
129 static void setFixedFontFamilyWrapper(WebSettings* settings, const WebKit::WebString& font, UScriptCode script)
130 {
131     settings->setFixedFontFamily(font, script);
132 }
133
134 static void setSerifFontFamilyWrapper(WebSettings* settings, const WebKit::WebString& font, UScriptCode script)
135 {
136     settings->setSerifFontFamily(font, script);
137 }
138
139 static void setSansSerifFontFamilyWrapper(WebSettings* settings, const WebKit::WebString& font, UScriptCode script)
140 {
141     settings->setSansSerifFontFamily(font, script);
142 }
143
144 static void setCursiveFontFamilyWrapper(WebSettings* settings, const WebKit::WebString& font, UScriptCode script)
145 {
146     settings->setCursiveFontFamily(font, script);
147 }
148
149 static void setFantasyFontFamilyWrapper(WebSettings* settings, const WebKit::WebString& font, UScriptCode script)
150 {
151     settings->setFantasyFontFamily(font, script);
152 }
153
154 typedef void (*SetFontFamilyWrapper)(WebSettings*, const WebString&, UScriptCode);
155
156 static void applyFontMap(WebSettings* settings, const WebPreferences::ScriptFontFamilyMap& map, SetFontFamilyWrapper setter)
157 {
158     for (WebPreferences::ScriptFontFamilyMap::const_iterator iter = map.begin(); iter != map.end(); ++iter) {
159         const WebString& font = iter->second;
160         if (!font.isNull() && !font.isEmpty())
161             (*setter)(settings, font, static_cast<UScriptCode>(iter->first));
162     }
163 }
164
165 void WebPreferences::applyTo(WebView* webView)
166 {
167     WebSettings* settings = webView->settings();
168     settings->setStandardFontFamily(standardFontFamily);
169     settings->setFixedFontFamily(fixedFontFamily);
170     settings->setSerifFontFamily(serifFontFamily);
171     settings->setSansSerifFontFamily(sansSerifFontFamily);
172     settings->setCursiveFontFamily(cursiveFontFamily);
173     settings->setFantasyFontFamily(fantasyFontFamily);
174
175     applyFontMap(settings, standardFontMap, setStandardFontFamilyWrapper);
176     applyFontMap(settings, fixedFontMap, setFixedFontFamilyWrapper);
177     applyFontMap(settings, serifFontMap, setSerifFontFamilyWrapper);
178     applyFontMap(settings, sansSerifFontMap, setSansSerifFontFamilyWrapper);
179     applyFontMap(settings, cursiveFontMap, setCursiveFontFamilyWrapper);
180     applyFontMap(settings, fantasyFontMap, setFantasyFontFamilyWrapper);
181
182     settings->setDefaultFontSize(defaultFontSize);
183     settings->setDefaultFixedFontSize(defaultFixedFontSize);
184     settings->setMinimumFontSize(minimumFontSize);
185     settings->setMinimumLogicalFontSize(minimumLogicalFontSize);
186     settings->setMinimumAccelerated2dCanvasSize(minimumAccelerated2dCanvasSize);
187
188     settings->setDOMPasteAllowed(DOMPasteAllowed);
189     settings->setXSSAuditorEnabled(XSSAuditorEnabled);
190     settings->setAllowDisplayOfInsecureContent(allowDisplayOfInsecureContent);
191     settings->setAllowFileAccessFromFileURLs(allowFileAccessFromFileURLs);
192     settings->setAllowRunningOfInsecureContent(allowRunningOfInsecureContent);
193     settings->setAuthorAndUserStylesEnabled(authorAndUserStylesEnabled);
194     settings->setDefaultTextEncodingName(defaultTextEncodingName);
195     settings->setDeveloperExtrasEnabled(developerExtrasEnabled);
196     settings->setExperimentalWebGLEnabled(experimentalWebGLEnabled);
197     settings->setExperimentalCSSRegionsEnabled(experimentalCSSRegionsEnabled);
198     settings->setExperimentalCSSGridLayoutEnabled(experimentalCSSGridLayoutEnabled);
199     settings->setExperimentalCSSCustomFilterEnabled(cssCustomFilterEnabled);
200     settings->setJavaEnabled(javaEnabled);
201     settings->setJavaScriptCanAccessClipboard(javaScriptCanAccessClipboard);
202     settings->setJavaScriptCanOpenWindowsAutomatically(javaScriptCanOpenWindowsAutomatically);
203     settings->setJavaScriptEnabled(javaScriptEnabled);
204     settings->setLoadsImagesAutomatically(loadsImagesAutomatically);
205     settings->setLocalStorageEnabled(localStorageEnabled);
206     settings->setOfflineWebApplicationCacheEnabled(offlineWebApplicationCacheEnabled);
207     settings->setPluginsEnabled(pluginsEnabled);
208     settings->setShrinksStandaloneImagesToFit(shrinksStandaloneImagesToFit);
209     settings->setTextAreasAreResizable(textAreasAreResizable);
210     settings->setUserStyleSheetLocation(userStyleSheetLocation);
211     settings->setUsesPageCache(usesPageCache);
212     settings->setPageCacheSupportsPlugins(pageCacheSupportsPlugins);
213     settings->setWebSecurityEnabled(webSecurityEnabled);
214     settings->setAllowUniversalAccessFromFileURLs(allowUniversalAccessFromFileURLs);
215     settings->setEditingBehavior(editingBehavior);
216     settings->setHyperlinkAuditingEnabled(hyperlinkAuditingEnabled);
217     // LayoutTests were written with Safari Mac in mind which does not allow
218     // tabbing to links by default.
219     webView->setTabsToLinks(tabsToLinks);
220     settings->setCaretBrowsingEnabled(caretBrowsingEnabled);
221     settings->setAcceleratedCompositingEnabled(acceleratedCompositingEnabled);
222     settings->setAcceleratedCompositingForVideoEnabled(acceleratedCompositingForVideoEnabled);
223     settings->setForceCompositingMode(forceCompositingMode);
224     settings->setAccelerated2dCanvasEnabled(accelerated2dCanvasEnabled);
225     settings->setDeferred2dCanvasEnabled(deferred2dCanvasEnabled);
226     settings->setAcceleratedPaintingEnabled(acceleratedPaintingEnabled);
227     settings->setMediaPlaybackRequiresUserGesture(mediaPlaybackRequiresUserGesture);
228     settings->setMockScrollbarsEnabled(mockScrollbarsEnabled);
229
230     // Fixed values.
231     settings->setTextDirectionSubmenuInclusionBehaviorNeverIncluded();
232     settings->setDownloadableBinaryFontsEnabled(true);
233     settings->setAllowScriptsToCloseWindows(false);
234     settings->setNeedsSiteSpecificQuirks(true);
235     settings->setEditableLinkBehaviorNeverLive();
236     settings->setEnableScrollAnimator(false);
237     settings->setFontRenderingModeNormal();
238     settings->setTextDirectionSubmenuInclusionBehaviorNeverIncluded();
239     settings->setUsesEncodingDetector(false);
240     settings->setImagesEnabled(true);
241     settings->setInteractiveFormValidationEnabled(true);
242     // Enable fullscreen so the fullscreen layout tests can run.
243     settings->setFullScreenEnabled(true);
244     settings->setValidationMessageTimerMagnification(-1);
245     settings->setVisualWordMovementEnabled(false);
246     settings->setPasswordEchoEnabled(false);
247 }