| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "webkit/renderer/webpreferences_renderer.h" | |
| 6 | |
| 7 #include "base/utf_string_conversions.h" | |
| 8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" | |
| 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNetworkStateNotifi
er.h" | |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" | |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h" | |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | |
| 13 #include "third_party/WebKit/public/platform/WebString.h" | |
| 14 #include "third_party/WebKit/public/platform/WebURL.h" | |
| 15 #include "third_party/icu/public/common/unicode/uchar.h" | |
| 16 #include "third_party/icu/public/common/unicode/uscript.h" | |
| 17 #include "webkit/common/webpreferences.h" | |
| 18 | |
| 19 using WebKit::WebNetworkStateNotifier; | |
| 20 using WebKit::WebRuntimeFeatures; | |
| 21 using WebKit::WebSettings; | |
| 22 using WebKit::WebString; | |
| 23 using WebKit::WebURL; | |
| 24 using WebKit::WebView; | |
| 25 | |
| 26 namespace { | |
| 27 | |
| 28 typedef void (*SetFontFamilyWrapper)( | |
| 29 WebKit::WebSettings*, const base::string16&, UScriptCode); | |
| 30 | |
| 31 void setStandardFontFamilyWrapper(WebSettings* settings, | |
| 32 const base::string16& font, | |
| 33 UScriptCode script) { | |
| 34 settings->setStandardFontFamily(font, script); | |
| 35 } | |
| 36 | |
| 37 void setFixedFontFamilyWrapper(WebSettings* settings, | |
| 38 const base::string16& font, | |
| 39 UScriptCode script) { | |
| 40 settings->setFixedFontFamily(font, script); | |
| 41 } | |
| 42 | |
| 43 void setSerifFontFamilyWrapper(WebSettings* settings, | |
| 44 const base::string16& font, | |
| 45 UScriptCode script) { | |
| 46 settings->setSerifFontFamily(font, script); | |
| 47 } | |
| 48 | |
| 49 void setSansSerifFontFamilyWrapper(WebSettings* settings, | |
| 50 const base::string16& font, | |
| 51 UScriptCode script) { | |
| 52 settings->setSansSerifFontFamily(font, script); | |
| 53 } | |
| 54 | |
| 55 void setCursiveFontFamilyWrapper(WebSettings* settings, | |
| 56 const base::string16& font, | |
| 57 UScriptCode script) { | |
| 58 settings->setCursiveFontFamily(font, script); | |
| 59 } | |
| 60 | |
| 61 void setFantasyFontFamilyWrapper(WebSettings* settings, | |
| 62 const base::string16& font, | |
| 63 UScriptCode script) { | |
| 64 settings->setFantasyFontFamily(font, script); | |
| 65 } | |
| 66 | |
| 67 void setPictographFontFamilyWrapper(WebSettings* settings, | |
| 68 const base::string16& font, | |
| 69 UScriptCode script) { | |
| 70 settings->setPictographFontFamily(font, script); | |
| 71 } | |
| 72 | |
| 73 // If |scriptCode| is a member of a family of "similar" script codes, returns | |
| 74 // the script code in that family that is used by WebKit for font selection | |
| 75 // purposes. For example, USCRIPT_KATAKANA_OR_HIRAGANA and USCRIPT_JAPANESE are | |
| 76 // considered equivalent for the purposes of font selection. WebKit uses the | |
| 77 // script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is | |
| 78 // USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit | |
| 79 // uses different scripts than the ones in Chrome pref names because the version | |
| 80 // of ICU included on certain ports does not have some of the newer scripts. If | |
| 81 // |scriptCode| is not a member of such a family, returns |scriptCode|. | |
| 82 UScriptCode GetScriptForWebSettings(UScriptCode scriptCode) { | |
| 83 switch (scriptCode) { | |
| 84 case USCRIPT_HIRAGANA: | |
| 85 case USCRIPT_KATAKANA: | |
| 86 case USCRIPT_JAPANESE: | |
| 87 return USCRIPT_KATAKANA_OR_HIRAGANA; | |
| 88 case USCRIPT_KOREAN: | |
| 89 return USCRIPT_HANGUL; | |
| 90 default: | |
| 91 return scriptCode; | |
| 92 } | |
| 93 } | |
| 94 | |
| 95 void ApplyFontsFromMap(const webkit_glue::ScriptFontFamilyMap& map, | |
| 96 SetFontFamilyWrapper setter, | |
| 97 WebSettings* settings) { | |
| 98 for (webkit_glue::ScriptFontFamilyMap::const_iterator it = map.begin(); | |
| 99 it != map.end(); ++it) { | |
| 100 int32 script = u_getPropertyValueEnum(UCHAR_SCRIPT, (it->first).c_str()); | |
| 101 if (script >= 0 && script < USCRIPT_CODE_LIMIT) { | |
| 102 UScriptCode code = static_cast<UScriptCode>(script); | |
| 103 (*setter)(settings, it->second, GetScriptForWebSettings(code)); | |
| 104 } | |
| 105 } | |
| 106 } | |
| 107 | |
| 108 } // namespace | |
| 109 | |
| 110 namespace webkit_glue { | |
| 111 | |
| 112 void ApplyWebPreferences(const WebPreferences& prefs, WebView* web_view) { | |
| 113 WebSettings* settings = web_view->settings(); | |
| 114 ApplyFontsFromMap(prefs.standard_font_family_map, | |
| 115 setStandardFontFamilyWrapper, settings); | |
| 116 ApplyFontsFromMap(prefs.fixed_font_family_map, | |
| 117 setFixedFontFamilyWrapper, settings); | |
| 118 ApplyFontsFromMap(prefs.serif_font_family_map, | |
| 119 setSerifFontFamilyWrapper, settings); | |
| 120 ApplyFontsFromMap(prefs.sans_serif_font_family_map, | |
| 121 setSansSerifFontFamilyWrapper, settings); | |
| 122 ApplyFontsFromMap(prefs.cursive_font_family_map, | |
| 123 setCursiveFontFamilyWrapper, settings); | |
| 124 ApplyFontsFromMap(prefs.fantasy_font_family_map, | |
| 125 setFantasyFontFamilyWrapper, settings); | |
| 126 ApplyFontsFromMap(prefs.pictograph_font_family_map, | |
| 127 setPictographFontFamilyWrapper, settings); | |
| 128 settings->setDefaultFontSize(prefs.default_font_size); | |
| 129 settings->setDefaultFixedFontSize(prefs.default_fixed_font_size); | |
| 130 settings->setMinimumFontSize(prefs.minimum_font_size); | |
| 131 settings->setMinimumLogicalFontSize(prefs.minimum_logical_font_size); | |
| 132 settings->setDefaultTextEncodingName(ASCIIToUTF16(prefs.default_encoding)); | |
| 133 settings->setJavaScriptEnabled(prefs.javascript_enabled); | |
| 134 settings->setWebSecurityEnabled(prefs.web_security_enabled); | |
| 135 settings->setJavaScriptCanOpenWindowsAutomatically( | |
| 136 prefs.javascript_can_open_windows_automatically); | |
| 137 settings->setLoadsImagesAutomatically(prefs.loads_images_automatically); | |
| 138 settings->setImagesEnabled(prefs.images_enabled); | |
| 139 settings->setPluginsEnabled(prefs.plugins_enabled); | |
| 140 settings->setDOMPasteAllowed(prefs.dom_paste_enabled); | |
| 141 settings->setNeedsSiteSpecificQuirks(prefs.site_specific_quirks_enabled); | |
| 142 settings->setShrinksStandaloneImagesToFit( | |
| 143 prefs.shrinks_standalone_images_to_fit); | |
| 144 settings->setUsesEncodingDetector(prefs.uses_universal_detector); | |
| 145 settings->setTextAreasAreResizable(prefs.text_areas_are_resizable); | |
| 146 settings->setAllowScriptsToCloseWindows(prefs.allow_scripts_to_close_windows); | |
| 147 if (prefs.user_style_sheet_enabled) | |
| 148 settings->setUserStyleSheetLocation(prefs.user_style_sheet_location); | |
| 149 else | |
| 150 settings->setUserStyleSheetLocation(WebURL()); | |
| 151 settings->setAuthorAndUserStylesEnabled(prefs.author_and_user_styles_enabled); | |
| 152 settings->setDownloadableBinaryFontsEnabled(prefs.remote_fonts_enabled); | |
| 153 settings->setJavaScriptCanAccessClipboard( | |
| 154 prefs.javascript_can_access_clipboard); | |
| 155 settings->setXSSAuditorEnabled(prefs.xss_auditor_enabled); | |
| 156 settings->setDNSPrefetchingEnabled(prefs.dns_prefetching_enabled); | |
| 157 settings->setLocalStorageEnabled(prefs.local_storage_enabled); | |
| 158 settings->setSyncXHRInDocumentsEnabled(prefs.sync_xhr_in_documents_enabled); | |
| 159 WebRuntimeFeatures::enableDatabase(prefs.databases_enabled); | |
| 160 settings->setOfflineWebApplicationCacheEnabled( | |
| 161 prefs.application_cache_enabled); | |
| 162 settings->setCaretBrowsingEnabled(prefs.caret_browsing_enabled); | |
| 163 settings->setHyperlinkAuditingEnabled(prefs.hyperlink_auditing_enabled); | |
| 164 settings->setCookieEnabled(prefs.cookie_enabled); | |
| 165 | |
| 166 // This setting affects the behavior of links in an editable region: | |
| 167 // clicking the link should select it rather than navigate to it. | |
| 168 // Safari uses the same default. It is unlikley an embedder would want to | |
| 169 // change this, since it would break existing rich text editors. | |
| 170 settings->setEditableLinkBehaviorNeverLive(); | |
| 171 | |
| 172 settings->setFontRenderingModeNormal(); | |
| 173 settings->setJavaEnabled(prefs.java_enabled); | |
| 174 | |
| 175 // By default, allow_universal_access_from_file_urls is set to false and thus | |
| 176 // we mitigate attacks from local HTML files by not granting file:// URLs | |
| 177 // universal access. Only test shell will enable this. | |
| 178 settings->setAllowUniversalAccessFromFileURLs( | |
| 179 prefs.allow_universal_access_from_file_urls); | |
| 180 settings->setAllowFileAccessFromFileURLs( | |
| 181 prefs.allow_file_access_from_file_urls); | |
| 182 | |
| 183 // Enable the web audio API if requested on the command line. | |
| 184 settings->setWebAudioEnabled(prefs.webaudio_enabled); | |
| 185 | |
| 186 // Enable experimental WebGL support if requested on command line | |
| 187 // and support is compiled in. | |
| 188 settings->setExperimentalWebGLEnabled(prefs.experimental_webgl_enabled); | |
| 189 | |
| 190 // Disable GL multisampling if requested on command line. | |
| 191 settings->setOpenGLMultisamplingEnabled(prefs.gl_multisampling_enabled); | |
| 192 | |
| 193 // Enable privileged WebGL extensions for Chrome extensions or if requested | |
| 194 // on command line. | |
| 195 settings->setPrivilegedWebGLExtensionsEnabled( | |
| 196 prefs.privileged_webgl_extensions_enabled); | |
| 197 | |
| 198 // Enable WebGL errors to the JS console if requested. | |
| 199 settings->setWebGLErrorsToConsoleEnabled( | |
| 200 prefs.webgl_errors_to_console_enabled); | |
| 201 | |
| 202 // Enables accelerated compositing for overflow scroll. | |
| 203 settings->setAcceleratedCompositingForOverflowScrollEnabled( | |
| 204 prefs.accelerated_compositing_for_overflow_scroll_enabled); | |
| 205 | |
| 206 // Enables accelerated compositing for scrollable frames if requested on | |
| 207 // command line. | |
| 208 settings->setAcceleratedCompositingForScrollableFramesEnabled( | |
| 209 prefs.accelerated_compositing_for_scrollable_frames_enabled); | |
| 210 | |
| 211 // Enables composited scrolling for frames if requested on command line. | |
| 212 settings->setCompositedScrollingForFramesEnabled( | |
| 213 prefs.composited_scrolling_for_frames_enabled); | |
| 214 | |
| 215 // Uses the mock theme engine for scrollbars. | |
| 216 settings->setMockScrollbarsEnabled(prefs.mock_scrollbars_enabled); | |
| 217 | |
| 218 settings->setThreadedHTMLParser(prefs.threaded_html_parser); | |
| 219 | |
| 220 // Display visualization of what has changed on the screen using an | |
| 221 // overlay of rects, if requested on the command line. | |
| 222 settings->setShowPaintRects(prefs.show_paint_rects); | |
| 223 | |
| 224 // Enable gpu-accelerated compositing if requested on the command line. | |
| 225 settings->setAcceleratedCompositingEnabled( | |
| 226 prefs.accelerated_compositing_enabled); | |
| 227 | |
| 228 // Enable gpu-accelerated 2d canvas if requested on the command line. | |
| 229 settings->setAccelerated2dCanvasEnabled(prefs.accelerated_2d_canvas_enabled); | |
| 230 | |
| 231 settings->setMinimumAccelerated2dCanvasSize( | |
| 232 prefs.minimum_accelerated_2d_canvas_size); | |
| 233 | |
| 234 // Disable antialiasing for 2d canvas if requested on the command line. | |
| 235 settings->setAntialiased2dCanvasEnabled( | |
| 236 !prefs.antialiased_2d_canvas_disabled); | |
| 237 | |
| 238 // Enable gpu-accelerated filters if requested on the command line. | |
| 239 settings->setAcceleratedFiltersEnabled(prefs.accelerated_filters_enabled); | |
| 240 | |
| 241 // Enable gesture tap highlight if requested on the command line. | |
| 242 settings->setGestureTapHighlightEnabled(prefs.gesture_tap_highlight_enabled); | |
| 243 | |
| 244 // Enabling accelerated layers from the command line enabled accelerated | |
| 245 // 3D CSS, Video, and Animations. | |
| 246 settings->setAcceleratedCompositingFor3DTransformsEnabled( | |
| 247 prefs.accelerated_compositing_for_3d_transforms_enabled); | |
| 248 settings->setAcceleratedCompositingForVideoEnabled( | |
| 249 prefs.accelerated_compositing_for_video_enabled); | |
| 250 settings->setAcceleratedCompositingForAnimationEnabled( | |
| 251 prefs.accelerated_compositing_for_animation_enabled); | |
| 252 | |
| 253 // Enabling accelerated plugins if specified from the command line. | |
| 254 settings->setAcceleratedCompositingForPluginsEnabled( | |
| 255 prefs.accelerated_compositing_for_plugins_enabled); | |
| 256 | |
| 257 // WebGL and accelerated 2D canvas are always gpu composited. | |
| 258 settings->setAcceleratedCompositingForCanvasEnabled( | |
| 259 prefs.experimental_webgl_enabled || prefs.accelerated_2d_canvas_enabled); | |
| 260 | |
| 261 // Enable memory info reporting to page if requested on the command line. | |
| 262 settings->setMemoryInfoEnabled(prefs.memory_info_enabled); | |
| 263 | |
| 264 settings->setAsynchronousSpellCheckingEnabled( | |
| 265 prefs.asynchronous_spell_checking_enabled); | |
| 266 settings->setUnifiedTextCheckerEnabled(prefs.unified_textchecker_enabled); | |
| 267 | |
| 268 for (webkit_glue::WebInspectorPreferences::const_iterator it = | |
| 269 prefs.inspector_settings.begin(); | |
| 270 it != prefs.inspector_settings.end(); ++it) | |
| 271 web_view->setInspectorSetting(WebString::fromUTF8(it->first), | |
| 272 WebString::fromUTF8(it->second)); | |
| 273 | |
| 274 // Tabs to link is not part of the settings. WebCore calls | |
| 275 // ChromeClient::tabsToLinks which is part of the glue code. | |
| 276 web_view->setTabsToLinks(prefs.tabs_to_links); | |
| 277 | |
| 278 settings->setFullScreenEnabled(prefs.fullscreen_enabled); | |
| 279 settings->setAllowDisplayOfInsecureContent( | |
| 280 prefs.allow_displaying_insecure_content); | |
| 281 settings->setAllowRunningOfInsecureContent( | |
| 282 prefs.allow_running_insecure_content); | |
| 283 settings->setPasswordEchoEnabled(prefs.password_echo_enabled); | |
| 284 settings->setShouldPrintBackgrounds(prefs.should_print_backgrounds); | |
| 285 settings->setEnableScrollAnimator(prefs.enable_scroll_animator); | |
| 286 settings->setVisualWordMovementEnabled(prefs.visual_word_movement_enabled); | |
| 287 | |
| 288 settings->setCSSStickyPositionEnabled(prefs.css_sticky_position_enabled); | |
| 289 settings->setExperimentalCSSCustomFilterEnabled(prefs.css_shaders_enabled); | |
| 290 settings->setExperimentalCSSGridLayoutEnabled(prefs.css_grid_layout_enabled); | |
| 291 | |
| 292 WebRuntimeFeatures::enableLazyLayout(prefs.lazy_layout_enabled); | |
| 293 WebRuntimeFeatures::enableTouch(prefs.touch_enabled); | |
| 294 settings->setDeviceSupportsTouch(prefs.device_supports_touch); | |
| 295 settings->setDeviceSupportsMouse(prefs.device_supports_mouse); | |
| 296 settings->setEnableTouchAdjustment(prefs.touch_adjustment_enabled); | |
| 297 | |
| 298 settings->setFixedPositionCreatesStackingContext( | |
| 299 prefs.fixed_position_creates_stacking_context); | |
| 300 | |
| 301 settings->setDeferredImageDecodingEnabled( | |
| 302 prefs.deferred_image_decoding_enabled); | |
| 303 settings->setShouldRespectImageOrientation( | |
| 304 prefs.should_respect_image_orientation); | |
| 305 | |
| 306 settings->setUnsafePluginPastingEnabled(false); | |
| 307 settings->setEditingBehavior( | |
| 308 static_cast<WebSettings::EditingBehavior>(prefs.editing_behavior)); | |
| 309 | |
| 310 settings->setSupportsMultipleWindows(prefs.supports_multiple_windows); | |
| 311 | |
| 312 settings->setViewportEnabled(prefs.viewport_enabled); | |
| 313 settings->setInitializeAtMinimumPageScale( | |
| 314 prefs.initialize_at_minimum_page_scale); | |
| 315 | |
| 316 settings->setSmartInsertDeleteEnabled(prefs.smart_insert_delete_enabled); | |
| 317 | |
| 318 settings->setSpatialNavigationEnabled(prefs.spatial_navigation_enabled); | |
| 319 | |
| 320 settings->setSelectionIncludesAltImageText(true); | |
| 321 | |
| 322 #if defined(OS_ANDROID) | |
| 323 settings->setAllowCustomScrollbarInMainFrame(false); | |
| 324 settings->setTextAutosizingEnabled(prefs.text_autosizing_enabled); | |
| 325 settings->setTextAutosizingFontScaleFactor(prefs.font_scale_factor); | |
| 326 web_view->setIgnoreViewportTagMaximumScale(prefs.force_enable_zoom); | |
| 327 settings->setAutoZoomFocusedNodeToLegibleScale(true); | |
| 328 settings->setDoubleTapToZoomEnabled(prefs.double_tap_to_zoom_enabled); | |
| 329 settings->setMediaPlaybackRequiresUserGesture( | |
| 330 prefs.user_gesture_required_for_media_playback); | |
| 331 settings->setDefaultVideoPosterURL( | |
| 332 ASCIIToUTF16(prefs.default_video_poster_url.spec())); | |
| 333 settings->setSupportDeprecatedTargetDensityDPI( | |
| 334 prefs.support_deprecated_target_density_dpi); | |
| 335 settings->setUseWideViewport(prefs.use_wide_viewport); | |
| 336 #endif | |
| 337 | |
| 338 WebNetworkStateNotifier::setOnLine(prefs.is_online); | |
| 339 settings->setExperimentalWebSocketEnabled( | |
| 340 prefs.experimental_websocket_enabled); | |
| 341 settings->setPinchVirtualViewportEnabled( | |
| 342 prefs.pinch_virtual_viewport_enabled); | |
| 343 } | |
| 344 | |
| 345 | |
| 346 } // namespace webkit_glue | |
| OLD | NEW |