1 // Copyright 2014 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 #ifndef CONTENT_PUBLIC_COMMON_WEB_PREFERENCES_H_ 6 #define CONTENT_PUBLIC_COMMON_WEB_PREFERENCES_H_ 7 8 #include <map> 9 #include <string> 10 #include <vector> 11 12 #include "base/strings/string16.h" 13 #include "base/time/time.h" 14 #include "build/build_config.h" 15 #include "content/common/content_export.h" 16 #include "net/nqe/effective_connection_type.h" 17 #include "third_party/blink/public/common/css/preferred_color_scheme.h" 18 #include "third_party/blink/public/mojom/v8_cache_options.mojom.h" 19 #include "ui/base/pointer/pointer_device.h" 20 #include "url/gurl.h" 21 22 namespace blink { 23 class WebView; 24 } 25 26 namespace content { 27 28 // Map of ISO 15924 four-letter script code to font family. For example, 29 // "Arab" to "My Arabic Font". 30 typedef std::map<std::string, base::string16> ScriptFontFamilyMap; 31 32 enum EditingBehavior { 33 EDITING_BEHAVIOR_MAC, 34 EDITING_BEHAVIOR_WIN, 35 EDITING_BEHAVIOR_UNIX, 36 EDITING_BEHAVIOR_ANDROID, 37 EDITING_BEHAVIOR_LAST = EDITING_BEHAVIOR_ANDROID 38 }; 39 40 // ImageAnimationPolicy is used for controlling image animation 41 // when image frame is rendered for animation. 42 // See third_party/WebKit/Source/platform/graphics/ImageAnimationPolicy.h 43 // for information on the options. 44 enum ImageAnimationPolicy { 45 IMAGE_ANIMATION_POLICY_ALLOWED, 46 IMAGE_ANIMATION_POLICY_ANIMATION_ONCE, 47 IMAGE_ANIMATION_POLICY_NO_ANIMATION 48 }; 49 50 enum class ViewportStyle { DEFAULT, MOBILE, TELEVISION, LAST = TELEVISION }; 51 52 // Defines the autoplay policy to be used. Should match the class in 53 // WebSettings.h. 54 enum class AutoplayPolicy { 55 kNoUserGestureRequired, 56 kUserGestureRequired, 57 kDocumentUserActivationRequired, 58 }; 59 60 // The ISO 15924 script code for undetermined script aka Common. It's the 61 // default used on WebKit's side to get/set a font setting when no script is 62 // specified. 63 CONTENT_EXPORT extern const char kCommonScript[]; 64 65 // A struct for managing blink's settings. 66 // 67 // Adding new values to this class probably involves updating 68 // blink::WebSettings, content/common/view_messages.h, 69 // browser/profiles/profile.cc, and 70 // content/public/common/common_param_traits_macros.h 71 struct CONTENT_EXPORT WebPreferences { 72 ScriptFontFamilyMap standard_font_family_map; 73 ScriptFontFamilyMap fixed_font_family_map; 74 ScriptFontFamilyMap serif_font_family_map; 75 ScriptFontFamilyMap sans_serif_font_family_map; 76 ScriptFontFamilyMap cursive_font_family_map; 77 ScriptFontFamilyMap fantasy_font_family_map; 78 ScriptFontFamilyMap pictograph_font_family_map; 79 int default_font_size; 80 int default_fixed_font_size; 81 int minimum_font_size; 82 int minimum_logical_font_size; 83 std::string default_encoding; 84 bool context_menu_on_mouse_up; 85 bool javascript_enabled; 86 bool web_security_enabled; 87 bool loads_images_automatically; 88 bool images_enabled; 89 bool plugins_enabled; 90 bool dom_paste_enabled; 91 bool shrinks_standalone_images_to_fit; 92 bool text_areas_are_resizable; 93 bool allow_scripts_to_close_windows; 94 bool remote_fonts_enabled; 95 bool javascript_can_access_clipboard; 96 bool xslt_enabled; 97 // We don't use dns_prefetching_enabled to disable DNS prefetching. Instead, 98 // we disable the feature at a lower layer so that we catch non-WebKit uses 99 // of DNS prefetch as well. 100 bool dns_prefetching_enabled; 101 // Preference to save data. When enabled, requests will contain the header 102 // 'Save-Data: on'. 103 bool data_saver_enabled; 104 // Whether data saver holdback for Web APIs is enabled. If enabled, data saver 105 // appears as disabled to the web consumers even if it has been actually 106 // enabled by the user. 107 bool data_saver_holdback_web_api_enabled; 108 bool local_storage_enabled; 109 bool databases_enabled; 110 bool application_cache_enabled; 111 bool tabs_to_links; 112 bool disable_ipc_flooding_protection; 113 bool hyperlink_auditing_enabled; 114 bool allow_universal_access_from_file_urls; 115 bool allow_file_access_from_file_urls; 116 bool webgl1_enabled; 117 bool webgl2_enabled; 118 bool pepper_3d_enabled; 119 bool flash_3d_enabled; 120 bool flash_stage3d_enabled; 121 bool flash_stage3d_baseline_enabled; 122 bool privileged_webgl_extensions_enabled; 123 bool webgl_errors_to_console_enabled; 124 bool hide_scrollbars; 125 bool accelerated_2d_canvas_enabled; 126 bool antialiased_2d_canvas_disabled; 127 bool antialiased_clips_2d_canvas_enabled; 128 int accelerated_2d_canvas_msaa_sample_count; 129 bool accelerated_filters_enabled; 130 bool deferred_filters_enabled; 131 bool container_culling_enabled; 132 bool allow_running_insecure_content; 133 // If true, taints all <canvas> elements, regardless of origin. 134 bool disable_reading_from_canvas; 135 // Strict mixed content checking disables both displaying and running insecure 136 // mixed content, and disables embedder notifications that such content was 137 // requested (thereby preventing user override). 138 bool strict_mixed_content_checking; 139 // Strict powerful feature restrictions block insecure usage of powerful 140 // features (like device orientation) that we haven't yet disabled for the web 141 // at large. 142 bool strict_powerful_feature_restrictions; 143 // TODO(jww): Remove when WebView no longer needs this exception. 144 bool allow_geolocation_on_insecure_origins; 145 // Disallow user opt-in for blockable mixed content. 146 bool strictly_block_blockable_mixed_content; 147 bool block_mixed_plugin_content; 148 bool password_echo_enabled; 149 bool should_print_backgrounds; 150 bool should_clear_document_background; 151 bool enable_scroll_animator; 152 bool prefers_reduced_motion; 153 bool touch_event_feature_detection_enabled; 154 bool enable_error_page; 155 bool touch_adjustment_enabled; 156 int pointer_events_max_touch_points; 157 int available_pointer_types; 158 ui::PointerType primary_pointer_type; 159 int available_hover_types; 160 ui::HoverType primary_hover_type; 161 bool dont_send_key_events_to_javascript; 162 bool barrel_button_for_drag_enabled = false; 163 bool sync_xhr_in_documents_enabled; 164 bool should_respect_image_orientation; 165 int number_of_cpu_cores; 166 EditingBehavior editing_behavior; 167 bool supports_multiple_windows; 168 bool viewport_enabled; 169 bool viewport_meta_enabled; 170 171 // If true - Blink will clamp the minimum scale factor to the content width, 172 // preventing zoom beyond the visible content. This is really only needed if 173 // viewport_enabled is on. 174 bool shrinks_viewport_contents_to_fit; 175 176 ViewportStyle viewport_style; 177 bool always_show_context_menu_on_touch; 178 bool smooth_scroll_for_find_enabled; 179 bool main_frame_resizes_are_orientation_changes; 180 bool initialize_at_minimum_page_scale; 181 bool smart_insert_delete_enabled; 182 bool spatial_navigation_enabled; 183 bool caret_browsing_enabled; 184 bool navigate_on_drag_drop; 185 blink::mojom::V8CacheOptions v8_cache_options; 186 bool record_whole_document; 187 188 // This flags corresponds to a Page's Settings' setCookieEnabled state. It 189 // only controls whether or not the "document.cookie" field is properly 190 // connected to the backing store, for instance if you wanted to be able to 191 // define custom getters and setters from within a unique security content 192 // without raising a DOM security exception. 193 bool cookie_enabled; 194 195 // This flag indicates whether H/W accelerated video decode is enabled. 196 // Defaults to false. 197 bool accelerated_video_decode_enabled; 198 199 ImageAnimationPolicy animation_policy; 200 201 bool user_gesture_required_for_presentation; 202 203 bool text_tracks_enabled; 204 205 // These fields specify the foreground and background color for WebVTT text 206 // tracks. Their values can be any legal CSS color descriptor. 207 std::string text_track_background_color; 208 std::string text_track_text_color; 209 210 // These fields specify values for CSS properties used to style WebVTT text 211 // tracks. 212 // Specifies CSS font-size property in percentage. 213 std::string text_track_text_size; 214 std::string text_track_text_shadow; 215 std::string text_track_font_family; 216 std::string text_track_font_style; 217 // Specifies the value for CSS font-variant property. 218 std::string text_track_font_variant; 219 220 // These fields specify values for CSS properties used to style the window 221 // around WebVTT text tracks. 222 // Window color can be any legal CSS color descriptor. 223 std::string text_track_window_color; 224 // Window padding is in em. 225 std::string text_track_window_padding; 226 // Window radius is in pixels. 227 std::string text_track_window_radius; 228 229 // Specifies the margin for WebVTT text tracks as a percentage of media 230 // element height/width (for horizontal/vertical text respectively). 231 // Cues will not be placed in this margin area. 232 float text_track_margin_percentage; 233 234 bool immersive_mode_enabled; 235 236 bool double_tap_to_zoom_enabled; 237 238 bool fullscreen_supported; 239 240 bool text_autosizing_enabled; 241 242 // Representation of the Web App Manifest scope if any. 243 GURL web_app_scope; 244 245 #if defined(OS_ANDROID) 246 float font_scale_factor; 247 float device_scale_adjustment; 248 bool force_enable_zoom; 249 GURL default_video_poster_url; 250 bool support_deprecated_target_density_dpi; 251 bool use_legacy_background_size_shorthand_behavior; 252 bool wide_viewport_quirk; 253 bool use_wide_viewport; 254 bool force_zero_layout_height; 255 bool viewport_meta_merge_content_quirk; 256 bool viewport_meta_non_user_scalable_quirk; 257 bool viewport_meta_zero_values_quirk; 258 bool clobber_user_agent_initial_scale_quirk; 259 bool ignore_main_frame_overflow_hidden_quirk; 260 bool report_screen_size_in_physical_pixels_quirk; 261 // Used by Android_WebView only to support legacy apps that inject script into 262 // a top-level initial empty document and expect it to persist on navigation. 263 bool reuse_global_for_unowned_main_frame; 264 // Specifies default setting for spellcheck when the spellcheck attribute is 265 // not explicitly specified. 266 bool spellcheck_enabled_by_default; 267 // If enabled, when a video goes fullscreen, the orientation should be locked. 268 bool video_fullscreen_orientation_lock_enabled; 269 // If enabled, fullscreen should be entered/exited when the device is rotated 270 // to/from the orientation of the video. 271 bool video_rotate_to_fullscreen_enabled; 272 bool embedded_media_experience_enabled; 273 // Enable 8 (#RRGGBBAA) and 4 (#RGBA) value hex colors in CSS Android 274 // WebView quirk (http://crbug.com/618472). 275 bool css_hex_alpha_color_enabled; 276 // Enable support for document.scrollingElement 277 // WebView sets this to false to retain old documentElement behaviour 278 // (http://crbug.com/761016). 279 bool scroll_top_left_interop_enabled; 280 // Disable features such as offscreen canvas that depend on the viz 281 // architecture of surface embedding. Android WebView does not support this 282 // architecture yet. 283 bool disable_features_depending_on_viz; 284 // Don't accelerate small canvases to avoid crashes TODO(crbug.com/1004304) 285 bool disable_accelerated_small_canvases; 286 // Re-enable Web Components v0 on Webview, temporarily. This should get 287 // removed when crbug.com/1021631 gets fixed. 288 bool reenable_web_components_v0; 289 #endif // defined(OS_ANDROID) 290 291 // Enable forcibly modifying content rendering to result in a light on dark 292 // color scheme. 293 bool force_dark_mode_enabled = false; 294 295 // Default (used if the page or UA doesn't override these) values for page 296 // scale limits. These are set directly on the WebView so there's no analogue 297 // in WebSettings. 298 float default_minimum_page_scale_factor; 299 float default_maximum_page_scale_factor; 300 301 // Whether download UI should be hidden on this page. 302 bool hide_download_ui; 303 304 // Whether it is a presentation receiver. 305 bool presentation_receiver; 306 307 // If disabled, media controls should never be used. 308 bool media_controls_enabled; 309 310 // Whether we want to disable updating selection on mutating selection range. 311 // This is to work around Samsung's email app issue. See 312 // https://crbug.com/699943 for details. 313 // TODO(changwan): remove this once we no longer support Android N. 314 bool do_not_update_selection_on_mutating_selection_range; 315 316 // Defines the current autoplay policy. 317 AutoplayPolicy autoplay_policy; 318 319 // The preferred color scheme for the web content. The scheme is used to 320 // evaluate the prefers-color-scheme media query and resolve UA color scheme 321 // to be used based on the supported-color-schemes META tag and CSS property. 322 blink::PreferredColorScheme preferred_color_scheme = 323 blink::PreferredColorScheme::kNoPreference; 324 325 // Network quality threshold below which resources from iframes are assigned 326 // either kVeryLow or kVeryLow Blink priority. 327 net::EffectiveConnectionType low_priority_iframes_threshold; 328 329 // Whether Picture-in-Picture is enabled. 330 bool picture_in_picture_enabled; 331 332 // Whether a translate service is available. 333 // blink's hrefTranslate attribute existence relies on the result. 334 // See https://github.com/dtapuska/html-translate 335 bool translate_service_available; 336 337 // A value other than net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN implies that the 338 // network quality estimate related Web APIs are in the holdback mode. When 339 // the holdback is enabled, the related Web APIs return network quality 340 // estimate corresponding to |network_quality_estimator_web_holdback| 341 // regardless of the actual quality. 342 net::EffectiveConnectionType network_quality_estimator_web_holdback; 343 344 // Whether lazy loading of frames and images is enabled. 345 bool lazy_load_enabled = true; 346 347 // Specifies how close a lazily loaded iframe or image should be from the 348 // viewport before it should start being loaded in, depending on the effective 349 // connection type of the current network. Blink will use the default distance 350 // threshold for effective connection types that aren't specified here. 351 std::map<net::EffectiveConnectionType, int> 352 lazy_frame_loading_distance_thresholds_px; 353 std::map<net::EffectiveConnectionType, int> 354 lazy_image_loading_distance_thresholds_px; 355 std::map<net::EffectiveConnectionType, int> lazy_image_first_k_fully_load; 356 357 // Setting to false disables upgrades to HTTPS for HTTP resources in HTTPS 358 // sites. 359 bool allow_mixed_content_upgrades; 360 361 // We try to keep the default values the same as the default values in 362 // chrome, except for the cases where it would require lots of extra work for 363 // the embedder to use the same default value. 364 WebPreferences(); 365 WebPreferences(const WebPreferences& other); 366 ~WebPreferences(); 367 }; 368 369 } // namespace content 370 371 #endif // CONTENT_PUBLIC_COMMON_WEB_PREFERENCES_H_ 372