2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
32 #include "WebPreferences.h"
36 using namespace WebKit;
38 void WebPreferences::reset()
41 cursiveFontFamily = WebString::fromUTF8("Apple Chancery");
42 fantasyFontFamily = WebString::fromUTF8("Papyrus");
43 WebString serif = WebString::fromUTF8("Times");
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");
61 serifFontFamily = serif;
62 standardFontFamily = serif;
63 fixedFontFamily = WebString::fromUTF8("Courier");
64 sansSerifFontFamily = WebString::fromUTF8("Helvetica");
67 defaultFixedFontSize = 13;
69 minimumLogicalFontSize = 9;
70 // Do not disable acceleration for 2d canvas based on size.
71 // This makes having test expectations consistent.
72 minimumAccelerated2dCanvasSize = 0;
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;
84 javaScriptCanAccessClipboard = true;
85 javaScriptCanOpenWindowsAutomatically = true;
86 javaScriptEnabled = true;
87 loadsImagesAutomatically = true;
88 localStorageEnabled = true;
89 offlineWebApplicationCacheEnabled = true;
90 pluginsEnabled = true;
91 shrinksStandaloneImagesToFit = false;
92 textAreasAreResizable = false;
93 userStyleSheetLocation = WebURL();
94 usesPageCache = false;
95 webSecurityEnabled = true;
96 caretBrowsingEnabled = false;
98 // Allow those layout tests running as local files, i.e. under
99 // LayoutTests/http/tests/local, to access http server.
100 allowUniversalAccessFromFileURLs = true;
103 editingBehavior = WebSettings::EditingBehaviorMac;
105 editingBehavior = WebSettings::EditingBehaviorWin;
109 hyperlinkAuditingEnabled = false;
110 acceleratedCompositingForVideoEnabled = false;
111 acceleratedCompositingEnabled = false;
112 threadedCompositingEnabled = false;
113 compositeToTexture = false;
114 accelerated2dCanvasEnabled = false;
115 legacyAccelerated2dCanvasEnabled = false;
116 acceleratedDrawingEnabled = false;
117 forceCompositingMode = false;
118 hixie76WebSocketProtocolEnabled = true;
121 static void setStandardFontFamilyWrapper(WebSettings* settings, const WebKit::WebString& font, UScriptCode script)
123 settings->setStandardFontFamily(font, script);
126 static void setFixedFontFamilyWrapper(WebSettings* settings, const WebKit::WebString& font, UScriptCode script)
128 settings->setFixedFontFamily(font, script);
131 static void setSerifFontFamilyWrapper(WebSettings* settings, const WebKit::WebString& font, UScriptCode script)
133 settings->setSerifFontFamily(font, script);
136 static void setSansSerifFontFamilyWrapper(WebSettings* settings, const WebKit::WebString& font, UScriptCode script)
138 settings->setSansSerifFontFamily(font, script);
141 static void setCursiveFontFamilyWrapper(WebSettings* settings, const WebKit::WebString& font, UScriptCode script)
143 settings->setCursiveFontFamily(font, script);
146 static void setFantasyFontFamilyWrapper(WebSettings* settings, const WebKit::WebString& font, UScriptCode script)
148 settings->setFantasyFontFamily(font, script);
151 typedef void (*SetFontFamilyWrapper)(WebSettings*, const WebString&, UScriptCode);
153 static void applyFontMap(WebSettings* settings, const WebPreferences::ScriptFontFamilyMap& map, SetFontFamilyWrapper setter)
155 for (WebPreferences::ScriptFontFamilyMap::const_iterator iter = map.begin(); iter != map.end(); ++iter) {
156 const WebString& font = iter->second;
157 if (!font.isNull() && !font.isEmpty())
158 (*setter)(settings, font, static_cast<UScriptCode>(iter->first));
162 void WebPreferences::applyTo(WebView* webView)
164 WebSettings* settings = webView->settings();
165 settings->setStandardFontFamily(standardFontFamily);
166 settings->setFixedFontFamily(fixedFontFamily);
167 settings->setSerifFontFamily(serifFontFamily);
168 settings->setSansSerifFontFamily(sansSerifFontFamily);
169 settings->setCursiveFontFamily(cursiveFontFamily);
170 settings->setFantasyFontFamily(fantasyFontFamily);
172 applyFontMap(settings, standardFontMap, setStandardFontFamilyWrapper);
173 applyFontMap(settings, fixedFontMap, setFixedFontFamilyWrapper);
174 applyFontMap(settings, serifFontMap, setSerifFontFamilyWrapper);
175 applyFontMap(settings, sansSerifFontMap, setSansSerifFontFamilyWrapper);
176 applyFontMap(settings, cursiveFontMap, setCursiveFontFamilyWrapper);
177 applyFontMap(settings, fantasyFontMap, setFantasyFontFamilyWrapper);
179 settings->setDefaultFontSize(defaultFontSize);
180 settings->setDefaultFixedFontSize(defaultFixedFontSize);
181 settings->setMinimumFontSize(minimumFontSize);
182 settings->setMinimumLogicalFontSize(minimumLogicalFontSize);
183 settings->setMinimumAccelerated2dCanvasSize(minimumAccelerated2dCanvasSize);
185 settings->setDOMPasteAllowed(DOMPasteAllowed);
186 settings->setXSSAuditorEnabled(XSSAuditorEnabled);
187 settings->setAllowDisplayOfInsecureContent(allowDisplayOfInsecureContent);
188 settings->setAllowFileAccessFromFileURLs(allowFileAccessFromFileURLs);
189 settings->setAllowRunningOfInsecureContent(allowRunningOfInsecureContent);
190 settings->setAuthorAndUserStylesEnabled(authorAndUserStylesEnabled);
191 settings->setDefaultTextEncodingName(defaultTextEncodingName);
192 settings->setDeveloperExtrasEnabled(developerExtrasEnabled);
193 settings->setExperimentalWebGLEnabled(experimentalWebGLEnabled);
194 settings->setJavaEnabled(javaEnabled);
195 settings->setJavaScriptCanAccessClipboard(javaScriptCanAccessClipboard);
196 settings->setJavaScriptCanOpenWindowsAutomatically(javaScriptCanOpenWindowsAutomatically);
197 settings->setJavaScriptEnabled(javaScriptEnabled);
198 settings->setLoadsImagesAutomatically(loadsImagesAutomatically);
199 settings->setLocalStorageEnabled(localStorageEnabled);
200 settings->setOfflineWebApplicationCacheEnabled(offlineWebApplicationCacheEnabled);
201 settings->setPluginsEnabled(pluginsEnabled);
202 settings->setShrinksStandaloneImagesToFit(shrinksStandaloneImagesToFit);
203 settings->setTextAreasAreResizable(textAreasAreResizable);
204 settings->setUserStyleSheetLocation(userStyleSheetLocation);
205 settings->setUsesPageCache(usesPageCache);
206 settings->setWebSecurityEnabled(webSecurityEnabled);
207 settings->setAllowUniversalAccessFromFileURLs(allowUniversalAccessFromFileURLs);
208 settings->setEditingBehavior(editingBehavior);
209 settings->setHyperlinkAuditingEnabled(hyperlinkAuditingEnabled);
210 // LayoutTests were written with Safari Mac in mind which does not allow
211 // tabbing to links by default.
212 webView->setTabsToLinks(tabsToLinks);
213 settings->setCaretBrowsingEnabled(caretBrowsingEnabled);
214 settings->setAcceleratedCompositingEnabled(acceleratedCompositingEnabled);
215 settings->setAcceleratedCompositingForVideoEnabled(acceleratedCompositingForVideoEnabled);
216 settings->setUseThreadedCompositor(threadedCompositingEnabled);
217 settings->setCompositeToTextureEnabled(compositeToTexture);
218 settings->setForceCompositingMode(forceCompositingMode);
219 settings->setAccelerated2dCanvasEnabled(accelerated2dCanvasEnabled);
220 settings->setLegacyAccelerated2dCanvasEnabled(legacyAccelerated2dCanvasEnabled);
221 settings->setAcceleratedDrawingEnabled(acceleratedDrawingEnabled);
222 settings->setHixie76WebSocketProtocolEnabled(hixie76WebSocketProtocolEnabled);
225 settings->setTextDirectionSubmenuInclusionBehaviorNeverIncluded();
226 settings->setDownloadableBinaryFontsEnabled(true);
227 settings->setAllowScriptsToCloseWindows(false);
228 settings->setNeedsSiteSpecificQuirks(true);
229 settings->setEditableLinkBehaviorNeverLive();
230 settings->setEnableScrollAnimator(false);
231 settings->setFontRenderingModeNormal();
232 settings->setMockScrollbarsEnabled(false);
233 settings->setTextDirectionSubmenuInclusionBehaviorNeverIncluded();
234 settings->setUsesEncodingDetector(false);
235 settings->setImagesEnabled(true);
236 settings->setInteractiveFormValidationEnabled(true);
237 // Enable fullscreen so the fullscreen layout tests can run.
238 settings->setFullScreenEnabled(true);
239 settings->setValidationMessageTimerMagnification(-1);
240 settings->setVisualWordMovementEnabled(false);