Fix auto-uninstall of legacy multi-install Chrome Frame.
[chromium-blink-merge.git] / content / renderer / web_preferences.cc
blob2c4e41b7a8d54e691098d5d9b7d24e7a42e4f258
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/public/renderer/web_preferences.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "third_party/WebKit/public/platform/WebString.h"
9 #include "third_party/WebKit/public/platform/WebURL.h"
10 #include "third_party/WebKit/public/web/WebKit.h"
11 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h"
12 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
13 #include "third_party/WebKit/public/web/WebSettings.h"
14 #include "third_party/WebKit/public/web/WebView.h"
15 #include "third_party/icu/source/common/unicode/uchar.h"
16 #include "third_party/icu/source/common/unicode/uscript.h"
17 #include "webkit/common/webpreferences.h"
19 using blink::WebNetworkStateNotifier;
20 using blink::WebRuntimeFeatures;
21 using blink::WebSettings;
22 using blink::WebString;
23 using blink::WebURL;
24 using blink::WebView;
26 namespace content {
28 namespace {
30 typedef void (*SetFontFamilyWrapper)(blink::WebSettings*,
31 const base::string16&,
32 UScriptCode);
34 void setStandardFontFamilyWrapper(WebSettings* settings,
35 const base::string16& font,
36 UScriptCode script) {
37 settings->setStandardFontFamily(font, script);
40 void setFixedFontFamilyWrapper(WebSettings* settings,
41 const base::string16& font,
42 UScriptCode script) {
43 settings->setFixedFontFamily(font, script);
46 void setSerifFontFamilyWrapper(WebSettings* settings,
47 const base::string16& font,
48 UScriptCode script) {
49 settings->setSerifFontFamily(font, script);
52 void setSansSerifFontFamilyWrapper(WebSettings* settings,
53 const base::string16& font,
54 UScriptCode script) {
55 settings->setSansSerifFontFamily(font, script);
58 void setCursiveFontFamilyWrapper(WebSettings* settings,
59 const base::string16& font,
60 UScriptCode script) {
61 settings->setCursiveFontFamily(font, script);
64 void setFantasyFontFamilyWrapper(WebSettings* settings,
65 const base::string16& font,
66 UScriptCode script) {
67 settings->setFantasyFontFamily(font, script);
70 void setPictographFontFamilyWrapper(WebSettings* settings,
71 const base::string16& font,
72 UScriptCode script) {
73 settings->setPictographFontFamily(font, script);
76 // If |scriptCode| is a member of a family of "similar" script codes, returns
77 // the script code in that family that is used by WebKit for font selection
78 // purposes. For example, USCRIPT_KATAKANA_OR_HIRAGANA and USCRIPT_JAPANESE are
79 // considered equivalent for the purposes of font selection. WebKit uses the
80 // script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is
81 // USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit
82 // uses different scripts than the ones in Chrome pref names because the version
83 // of ICU included on certain ports does not have some of the newer scripts. If
84 // |scriptCode| is not a member of such a family, returns |scriptCode|.
85 UScriptCode GetScriptForWebSettings(UScriptCode scriptCode) {
86 switch (scriptCode) {
87 case USCRIPT_HIRAGANA:
88 case USCRIPT_KATAKANA:
89 case USCRIPT_JAPANESE:
90 return USCRIPT_KATAKANA_OR_HIRAGANA;
91 case USCRIPT_KOREAN:
92 return USCRIPT_HANGUL;
93 default:
94 return scriptCode;
98 void ApplyFontsFromMap(const webkit_glue::ScriptFontFamilyMap& map,
99 SetFontFamilyWrapper setter,
100 WebSettings* settings) {
101 for (webkit_glue::ScriptFontFamilyMap::const_iterator it = map.begin();
102 it != map.end();
103 ++it) {
104 int32 script = u_getPropertyValueEnum(UCHAR_SCRIPT, (it->first).c_str());
105 if (script >= 0 && script < USCRIPT_CODE_LIMIT) {
106 UScriptCode code = static_cast<UScriptCode>(script);
107 (*setter)(settings, it->second, GetScriptForWebSettings(code));
112 } // namespace
114 void ApplyWebPreferences(const WebPreferences& prefs, WebView* web_view) {
115 WebSettings* settings = web_view->settings();
116 ApplyFontsFromMap(prefs.standard_font_family_map,
117 setStandardFontFamilyWrapper, settings);
118 ApplyFontsFromMap(prefs.fixed_font_family_map,
119 setFixedFontFamilyWrapper, settings);
120 ApplyFontsFromMap(prefs.serif_font_family_map,
121 setSerifFontFamilyWrapper, settings);
122 ApplyFontsFromMap(prefs.sans_serif_font_family_map,
123 setSansSerifFontFamilyWrapper, settings);
124 ApplyFontsFromMap(prefs.cursive_font_family_map,
125 setCursiveFontFamilyWrapper, settings);
126 ApplyFontsFromMap(prefs.fantasy_font_family_map,
127 setFantasyFontFamilyWrapper, settings);
128 ApplyFontsFromMap(prefs.pictograph_font_family_map,
129 setPictographFontFamilyWrapper, settings);
130 settings->setDefaultFontSize(prefs.default_font_size);
131 settings->setDefaultFixedFontSize(prefs.default_fixed_font_size);
132 settings->setMinimumFontSize(prefs.minimum_font_size);
133 settings->setMinimumLogicalFontSize(prefs.minimum_logical_font_size);
134 settings->setDefaultTextEncodingName(
135 base::ASCIIToUTF16(prefs.default_encoding));
136 settings->setJavaScriptEnabled(prefs.javascript_enabled);
137 settings->setWebSecurityEnabled(prefs.web_security_enabled);
138 settings->setJavaScriptCanOpenWindowsAutomatically(
139 prefs.javascript_can_open_windows_automatically);
140 settings->setLoadsImagesAutomatically(prefs.loads_images_automatically);
141 settings->setImagesEnabled(prefs.images_enabled);
142 settings->setPluginsEnabled(prefs.plugins_enabled);
143 settings->setDOMPasteAllowed(prefs.dom_paste_enabled);
144 settings->setNeedsSiteSpecificQuirks(prefs.site_specific_quirks_enabled);
145 settings->setShrinksStandaloneImagesToFit(
146 prefs.shrinks_standalone_images_to_fit);
147 settings->setUsesEncodingDetector(prefs.uses_universal_detector);
148 settings->setTextAreasAreResizable(prefs.text_areas_are_resizable);
149 settings->setAllowScriptsToCloseWindows(prefs.allow_scripts_to_close_windows);
150 settings->setDownloadableBinaryFontsEnabled(prefs.remote_fonts_enabled);
151 settings->setJavaScriptCanAccessClipboard(
152 prefs.javascript_can_access_clipboard);
153 WebRuntimeFeatures::enableXSLT(prefs.xslt_enabled);
154 settings->setXSSAuditorEnabled(prefs.xss_auditor_enabled);
155 settings->setDNSPrefetchingEnabled(prefs.dns_prefetching_enabled);
156 settings->setLocalStorageEnabled(prefs.local_storage_enabled);
157 settings->setSyncXHRInDocumentsEnabled(prefs.sync_xhr_in_documents_enabled);
158 WebRuntimeFeatures::enableDatabase(prefs.databases_enabled);
159 settings->setOfflineWebApplicationCacheEnabled(
160 prefs.application_cache_enabled);
161 settings->setCaretBrowsingEnabled(prefs.caret_browsing_enabled);
162 settings->setHyperlinkAuditingEnabled(prefs.hyperlink_auditing_enabled);
163 settings->setCookieEnabled(prefs.cookie_enabled);
164 settings->setNavigateOnDragDrop(prefs.navigate_on_drag_drop);
166 settings->setJavaEnabled(prefs.java_enabled);
168 // By default, allow_universal_access_from_file_urls is set to false and thus
169 // we mitigate attacks from local HTML files by not granting file:// URLs
170 // universal access. Only test shell will enable this.
171 settings->setAllowUniversalAccessFromFileURLs(
172 prefs.allow_universal_access_from_file_urls);
173 settings->setAllowFileAccessFromFileURLs(
174 prefs.allow_file_access_from_file_urls);
176 // Enable the web audio API if requested on the command line.
177 settings->setWebAudioEnabled(prefs.webaudio_enabled);
179 // Enable experimental WebGL support if requested on command line
180 // and support is compiled in.
181 settings->setExperimentalWebGLEnabled(prefs.experimental_webgl_enabled);
183 // Disable GL multisampling if requested on command line.
184 settings->setOpenGLMultisamplingEnabled(prefs.gl_multisampling_enabled);
186 // Enable privileged WebGL extensions for Chrome extensions or if requested
187 // on command line.
188 settings->setPrivilegedWebGLExtensionsEnabled(
189 prefs.privileged_webgl_extensions_enabled);
191 // Enable WebGL errors to the JS console if requested.
192 settings->setWebGLErrorsToConsoleEnabled(
193 prefs.webgl_errors_to_console_enabled);
195 // Uses the mock theme engine for scrollbars.
196 settings->setMockScrollbarsEnabled(prefs.mock_scrollbars_enabled);
198 settings->setLayerSquashingEnabled(prefs.layer_squashing_enabled);
200 settings->setThreadedHTMLParser(prefs.threaded_html_parser);
202 // Enable gpu-accelerated compositing always.
203 settings->setAcceleratedCompositingEnabled(true);
205 // Enable gpu-accelerated 2d canvas if requested on the command line.
206 settings->setAccelerated2dCanvasEnabled(prefs.accelerated_2d_canvas_enabled);
208 settings->setMinimumAccelerated2dCanvasSize(
209 prefs.minimum_accelerated_2d_canvas_size);
211 // Disable antialiasing for 2d canvas if requested on the command line.
212 settings->setAntialiased2dCanvasEnabled(
213 !prefs.antialiased_2d_canvas_disabled);
215 // Set MSAA sample count for 2d canvas if requested on the command line (or
216 // default value if not).
217 settings->setAccelerated2dCanvasMSAASampleCount(
218 prefs.accelerated_2d_canvas_msaa_sample_count);
220 // Enable deferred filter rendering if requested on the command line.
221 settings->setDeferredFiltersEnabled(prefs.deferred_filters_enabled);
223 // Enable container culling if requested on the command line.
224 settings->setContainerCullingEnabled(prefs.container_culling_enabled);
226 // Enable gesture tap highlight if requested on the command line.
227 settings->setGestureTapHighlightEnabled(prefs.gesture_tap_highlight_enabled);
229 // Enabling accelerated layers from the command line enabled accelerated
230 // Video.
231 settings->setAcceleratedCompositingForVideoEnabled(
232 prefs.accelerated_compositing_for_video_enabled);
234 // WebGL and accelerated 2D canvas are always gpu composited.
235 settings->setAcceleratedCompositingForCanvasEnabled(
236 prefs.experimental_webgl_enabled || prefs.accelerated_2d_canvas_enabled);
238 settings->setAsynchronousSpellCheckingEnabled(
239 prefs.asynchronous_spell_checking_enabled);
240 settings->setUnifiedTextCheckerEnabled(prefs.unified_textchecker_enabled);
242 for (webkit_glue::WebInspectorPreferences::const_iterator it =
243 prefs.inspector_settings.begin();
244 it != prefs.inspector_settings.end();
245 ++it) {
246 web_view->setInspectorSetting(WebString::fromUTF8(it->first),
247 WebString::fromUTF8(it->second));
250 // Tabs to link is not part of the settings. WebCore calls
251 // ChromeClient::tabsToLinks which is part of the glue code.
252 web_view->setTabsToLinks(prefs.tabs_to_links);
254 settings->setAllowDisplayOfInsecureContent(
255 prefs.allow_displaying_insecure_content);
256 settings->setAllowRunningOfInsecureContent(
257 prefs.allow_running_insecure_content);
258 settings->setPasswordEchoEnabled(prefs.password_echo_enabled);
259 settings->setShouldPrintBackgrounds(prefs.should_print_backgrounds);
260 settings->setShouldClearDocumentBackground(
261 prefs.should_clear_document_background);
262 settings->setEnableScrollAnimator(prefs.enable_scroll_animator);
264 settings->setRegionBasedColumnsEnabled(prefs.region_based_columns_enabled);
266 WebRuntimeFeatures::enableLazyLayout(prefs.lazy_layout_enabled);
267 WebRuntimeFeatures::enableTouch(prefs.touch_enabled);
268 settings->setMaxTouchPoints(prefs.pointer_events_max_touch_points);
269 settings->setDeviceSupportsTouch(prefs.device_supports_touch);
270 settings->setDeviceSupportsMouse(prefs.device_supports_mouse);
271 settings->setEnableTouchAdjustment(prefs.touch_adjustment_enabled);
273 settings->setFixedPositionCreatesStackingContext(
274 prefs.fixed_position_creates_stacking_context);
276 settings->setDeferredImageDecodingEnabled(
277 prefs.deferred_image_decoding_enabled);
278 settings->setShouldRespectImageOrientation(
279 prefs.should_respect_image_orientation);
281 settings->setUnsafePluginPastingEnabled(false);
282 settings->setEditingBehavior(
283 static_cast<WebSettings::EditingBehavior>(prefs.editing_behavior));
285 settings->setSupportsMultipleWindows(prefs.supports_multiple_windows);
287 settings->setViewportEnabled(prefs.viewport_enabled);
288 settings->setLoadWithOverviewMode(prefs.initialize_at_minimum_page_scale);
289 settings->setViewportMetaEnabled(prefs.viewport_meta_enabled);
290 settings->setMainFrameResizesAreOrientationChanges(
291 prefs.main_frame_resizes_are_orientation_changes);
293 settings->setSmartInsertDeleteEnabled(prefs.smart_insert_delete_enabled);
295 settings->setSpatialNavigationEnabled(prefs.spatial_navigation_enabled);
297 settings->setSelectionIncludesAltImageText(true);
299 #if defined(OS_ANDROID)
300 settings->setAllowCustomScrollbarInMainFrame(false);
301 settings->setTextAutosizingEnabled(prefs.text_autosizing_enabled);
302 settings->setAccessibilityFontScaleFactor(prefs.font_scale_factor);
303 settings->setDeviceScaleAdjustment(prefs.device_scale_adjustment);
304 web_view->setIgnoreViewportTagScaleLimits(prefs.force_enable_zoom);
305 settings->setAutoZoomFocusedNodeToLegibleScale(true);
306 settings->setDoubleTapToZoomEnabled(prefs.double_tap_to_zoom_enabled);
307 settings->setMediaControlsOverlayPlayButtonEnabled(true);
308 settings->setMediaPlaybackRequiresUserGesture(
309 prefs.user_gesture_required_for_media_playback);
310 settings->setDefaultVideoPosterURL(
311 base::ASCIIToUTF16(prefs.default_video_poster_url.spec()));
312 settings->setSupportDeprecatedTargetDensityDPI(
313 prefs.support_deprecated_target_density_dpi);
314 settings->setUseLegacyBackgroundSizeShorthandBehavior(
315 prefs.use_legacy_background_size_shorthand_behavior);
316 settings->setWideViewportQuirkEnabled(prefs.wide_viewport_quirk);
317 settings->setUseWideViewport(prefs.use_wide_viewport);
318 settings->setViewportMetaLayoutSizeQuirk(
319 prefs.viewport_meta_layout_size_quirk);
320 settings->setViewportMetaMergeContentQuirk(
321 prefs.viewport_meta_merge_content_quirk);
322 settings->setViewportMetaNonUserScalableQuirk(
323 prefs.viewport_meta_non_user_scalable_quirk);
324 settings->setViewportMetaZeroValuesQuirk(
325 prefs.viewport_meta_zero_values_quirk);
326 settings->setClobberUserAgentInitialScaleQuirk(
327 prefs.clobber_user_agent_initial_scale_quirk);
328 settings->setIgnoreMainFrameOverflowHiddenQuirk(
329 prefs.ignore_main_frame_overflow_hidden_quirk);
330 settings->setReportScreenSizeInPhysicalPixelsQuirk(
331 prefs.report_screen_size_in_physical_pixels_quirk);
332 settings->setMainFrameClipsContent(false);
333 settings->setShrinksStandaloneImagesToFit(false);
334 settings->setShrinksViewportContentToFit(true);
335 #endif
337 WebNetworkStateNotifier::setOnLine(prefs.is_online);
338 settings->setPinchVirtualViewportEnabled(
339 prefs.pinch_virtual_viewport_enabled);
341 settings->setPinchOverlayScrollbarThickness(
342 prefs.pinch_overlay_scrollbar_thickness);
343 settings->setUseSolidColorScrollbars(prefs.use_solid_color_scrollbars);
344 settings->setCompositorTouchHitTesting(prefs.compositor_touch_hit_testing);
347 } // namespace content