1 // Copyright 2014 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef THIRD_PARTY_BLINK_PUBLIC_COMMON_WEB_PREFERENCES_WEB_PREFERENCES_H_
6 #define THIRD_PARTY_BLINK_PUBLIC_COMMON_WEB_PREFERENCES_WEB_PREFERENCES_H_
12 #include "build/build_config.h"
13 #include "net/nqe/effective_connection_type.h"
14 #include "third_party/blink/public/common/common_export.h"
15 #include "third_party/blink/public/mojom/css/preferred_color_scheme.mojom-shared.h"
16 #include "third_party/blink/public/mojom/css/preferred_contrast.mojom-shared.h"
17 #include "third_party/blink/public/mojom/v8_cache_options.mojom-forward.h"
18 #include "third_party/blink/public/mojom/webpreferences/web_preferences.mojom-shared.h"
20 #include "url/origin.h"
22 #if defined(ENABLE_WRT_JS)
23 #include "base/files/file_path.h"
32 using blink::mojom::EffectiveConnectionType;
34 // Map of ISO 15924 four-letter script code to font family. For example,
35 // "Arab" to "My Arabic Font".
36 typedef std::map<std::string, std::u16string> ScriptFontFamilyMap;
38 // The ISO 15924 script code for undetermined script aka Common. It's the
39 // default used on WebKit's side to get/set a font setting when no script is
41 BLINK_COMMON_EXPORT extern const char kCommonScript[];
43 // A struct for managing blink's settings.
45 // Adding new values to this class probably involves updating
46 // blink::WebSettings,
47 // browser/profiles/profile.cc, and
48 // content/public/common/common_param_traits_macros.h
49 struct BLINK_COMMON_EXPORT WebPreferences {
50 ScriptFontFamilyMap standard_font_family_map;
51 ScriptFontFamilyMap fixed_font_family_map;
52 ScriptFontFamilyMap serif_font_family_map;
53 ScriptFontFamilyMap sans_serif_font_family_map;
54 ScriptFontFamilyMap cursive_font_family_map;
55 ScriptFontFamilyMap fantasy_font_family_map;
56 ScriptFontFamilyMap math_font_family_map;
57 int default_font_size;
58 int default_fixed_font_size;
59 int minimum_font_size;
60 int minimum_logical_font_size;
61 std::string default_encoding;
62 bool context_menu_on_mouse_up;
63 bool javascript_enabled;
64 bool web_security_enabled;
65 bool loads_images_automatically;
68 bool dom_paste_enabled;
69 bool shrinks_standalone_images_to_fit;
70 bool text_areas_are_resizable;
71 bool allow_scripts_to_close_windows;
72 bool remote_fonts_enabled;
73 bool javascript_can_access_clipboard;
74 // We don't use dns_prefetching_enabled to disable DNS prefetching. Instead,
75 // we disable the feature at a lower layer so that we catch non-WebKit uses
76 // of DNS prefetch as well.
77 bool dns_prefetching_enabled;
78 // Preference to save data. When enabled, requests will contain the header
80 bool data_saver_enabled;
81 bool local_storage_enabled;
82 bool databases_enabled;
84 bool disable_ipc_flooding_protection;
85 bool hyperlink_auditing_enabled;
86 bool allow_universal_access_from_file_urls;
87 bool allow_file_access_from_file_urls;
90 bool pepper_3d_enabled;
91 bool privileged_webgl_extensions_enabled;
92 bool webgl_errors_to_console_enabled;
94 // If false, ignore ::-webkit-scrollbar-* CSS pseudo-elements in stylesheets.
95 bool enable_webkit_scrollbar_styling = true;
96 bool accelerated_2d_canvas_enabled;
97 bool canvas_2d_layers_enabled = false;
98 bool antialiased_2d_canvas_disabled;
99 bool antialiased_clips_2d_canvas_enabled;
100 bool accelerated_filters_enabled;
101 bool deferred_filters_enabled;
102 bool container_culling_enabled;
103 bool allow_running_insecure_content;
104 // If true, taints all <canvas> elements, regardless of origin.
105 bool disable_reading_from_canvas;
106 // Strict mixed content checking disables both displaying and running insecure
107 // mixed content, and disables embedder notifications that such content was
108 // requested (thereby preventing user override).
109 bool strict_mixed_content_checking;
110 // Strict powerful feature restrictions block insecure usage of powerful
111 // features (like device orientation) that we haven't yet disabled for the web
113 bool strict_powerful_feature_restrictions;
114 // TODO(jww): Remove when WebView no longer needs this exception.
115 bool allow_geolocation_on_insecure_origins;
116 // Disallow user opt-in for blockable mixed content.
117 bool strictly_block_blockable_mixed_content;
118 bool block_mixed_plugin_content;
119 bool password_echo_enabled;
120 bool should_print_backgrounds;
121 bool should_clear_document_background;
122 bool enable_scroll_animator;
123 bool prefers_reduced_motion;
124 bool prefers_reduced_transparency;
125 bool inverted_colors;
126 bool touch_event_feature_detection_enabled;
127 int pointer_events_max_touch_points;
128 int available_pointer_types;
129 blink::mojom::PointerType primary_pointer_type;
130 int available_hover_types;
131 blink::mojom::HoverType primary_hover_type;
132 blink::mojom::OutputDeviceUpdateAbilityType output_device_update_ability_type;
133 bool dont_send_key_events_to_javascript;
134 bool barrel_button_for_drag_enabled = false;
135 bool sync_xhr_in_documents_enabled;
136 // TODO(https://crbug.com/1163644): Remove once Chrome Apps are deprecated.
137 bool target_blank_implies_no_opener_enabled_will_be_removed = true;
138 // TODO(https://crbug.com/1172495): Remove once Chrome Apps are deprecated.
139 bool allow_non_empty_navigator_plugins = false;
140 int number_of_cpu_cores;
141 blink::mojom::EditingBehavior editing_behavior;
142 bool supports_multiple_windows;
143 bool viewport_enabled;
144 bool viewport_meta_enabled;
145 bool auto_zoom_focused_editable_to_legible_scale;
147 // If true - Blink will clamp the minimum scale factor to the content width,
148 // preventing zoom beyond the visible content. This is really only needed if
149 // viewport_enabled is on.
150 bool shrinks_viewport_contents_to_fit;
152 blink::mojom::ViewportStyle viewport_style;
153 bool always_show_context_menu_on_touch;
154 bool smooth_scroll_for_find_enabled;
155 bool main_frame_resizes_are_orientation_changes;
156 bool initialize_at_minimum_page_scale;
157 bool smart_insert_delete_enabled;
158 bool spatial_navigation_enabled;
159 bool fake_no_alloc_direct_call_for_testing_enabled;
160 blink::mojom::V8CacheOptions v8_cache_options;
161 bool record_whole_document;
163 // If true, stylus handwriting recognition to text input will be available in
164 // editable input fields which are non-password type.
165 bool stylus_handwriting_enabled;
167 #if defined(ENABLE_WRT_JS)
168 // Begin Electron-specific WebPreferences.
169 bool context_isolation;
173 bool node_integration;
174 bool node_integration_in_worker;
175 bool node_integration_in_sub_frames;
176 bool enable_spellcheck;
180 // End Electron-specific WebPreferences.
183 // This flags corresponds to a Page's Settings' setCookieEnabled state. It
184 // only controls whether or not the "document.cookie" field is properly
185 // connected to the backing store, for instance if you wanted to be able to
186 // define custom getters and setters from within a unique security content
187 // without raising a DOM security exception.
190 // This flag indicates whether H/W accelerated video decode is enabled.
191 // Defaults to false.
192 bool accelerated_video_decode_enabled;
194 #if defined(TIZEN_VIDEO_HOLE)
195 bool video_hole_enabled = false;
198 blink::mojom::ImageAnimationPolicy animation_policy =
199 blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyAllowed;
201 bool user_gesture_required_for_presentation;
203 bool text_tracks_enabled;
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;
210 // These fields specify values for CSS properties used to style WebVTT text
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;
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 radius is in pixels.
225 std::string text_track_window_radius;
227 // Specifies the margin for WebVTT text tracks as a percentage of media
228 // element height/width (for horizontal/vertical text respectively).
229 // Cues will not be placed in this margin area.
230 float text_track_margin_percentage;
232 bool immersive_mode_enabled;
234 #if BUILDFLAG(IS_EFL)
235 float font_scale_factor;
236 bool link_effect_enabled = false;
238 bool force_enable_zoom = false;
239 bool text_zoom_enabled = false;
240 bool selection_magnifier_enabled = false;
241 bool long_press_enabled = false;
242 bool uses_encoding_detector = true;
245 bool double_tap_to_zoom_enabled;
247 bool fullscreen_supported;
249 bool text_autosizing_enabled;
251 // Representation of the Web App Manifest scope if any.
254 #if BUILDFLAG(IS_ANDROID)
255 float font_scale_factor;
256 int font_weight_adjustment;
257 int text_size_contrast_factor;
258 float device_scale_adjustment;
259 bool force_enable_zoom;
260 GURL default_video_poster_url;
261 bool support_deprecated_target_density_dpi;
262 bool use_legacy_background_size_shorthand_behavior;
263 bool wide_viewport_quirk;
264 bool use_wide_viewport;
265 bool force_zero_layout_height;
266 bool viewport_meta_merge_content_quirk;
267 bool viewport_meta_non_user_scalable_quirk;
268 bool viewport_meta_zero_values_quirk;
269 bool clobber_user_agent_initial_scale_quirk;
270 bool ignore_main_frame_overflow_hidden_quirk;
271 bool report_screen_size_in_physical_pixels_quirk;
272 // Used by Android_WebView only to support legacy apps that inject script into
273 // a top-level initial empty document and expect it to persist on navigation.
274 bool reuse_global_for_unowned_main_frame;
275 // Specifies default setting for spellcheck when the spellcheck attribute is
276 // not explicitly specified.
277 bool spellcheck_enabled_by_default;
278 // If enabled, when a video goes fullscreen, the orientation should be locked.
279 bool video_fullscreen_orientation_lock_enabled;
280 // If enabled, fullscreen should be entered/exited when the device is rotated
281 // to/from the orientation of the video.
282 bool video_rotate_to_fullscreen_enabled;
283 bool embedded_media_experience_enabled;
284 // Enable 8 (#RRGGBBAA) and 4 (#RGBA) value hex colors in CSS Android
285 // WebView quirk (http://crbug.com/618472).
286 bool css_hex_alpha_color_enabled;
287 // Enable support for document.scrollingElement
288 // WebView sets this to false to retain old documentElement behaviour
289 // (http://crbug.com/761016).
290 bool scroll_top_left_interop_enabled;
292 // Don't accelerate small canvases to avoid crashes TODO(crbug.com/1004304)
293 bool disable_accelerated_small_canvases;
294 #endif // BUILDFLAG(IS_ANDROID)
296 // TODO(crbug.com/1284805): Remove IS_ANDROID once WebView supports WebAuthn.
297 // TODO(crbug.com/1382970): Remove IS_FUCHSIA and merge with the block above
298 // once all Content embedders on Fuchsia support WebAuthn.
299 #if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_FUCHSIA)
300 // Disable the Web Authentication API.
301 bool disable_webauthn = false;
302 #endif // BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_FUCHSIA)
304 // Enable forcibly modifying content rendering to result in a light on dark
306 bool force_dark_mode_enabled = false;
308 // Default (used if the page or UA doesn't override these) values for page
309 // scale limits. These are set directly on the WebView so there's no analogue
311 float default_minimum_page_scale_factor;
312 float default_maximum_page_scale_factor;
314 #if BUILDFLAG(IS_EFL)
315 bool TizenCompatibilityModeEnabled() const {
316 return (tizen_version_major && tizen_version_major < 3);
318 unsigned tizen_version_major = 7;
319 unsigned tizen_version_minor = 5;
320 unsigned tizen_version_release = 0;
323 #if BUILDFLAG(IS_TIZEN_TV)
324 bool media_playback_notification_enabled = false;
325 bool media_subtitle_notification_enabled = false;
328 // Whether download UI should be hidden on this page.
329 bool hide_download_ui;
331 // Whether it is a presentation receiver.
332 bool presentation_receiver;
334 // If disabled, media controls should never be used.
335 bool media_controls_enabled;
337 // Whether we want to disable updating selection on mutating selection range.
338 // This is to work around Samsung's email app issue. See
339 // https://crbug.com/699943 for details.
340 // TODO(changwan): remove this once we no longer support Android N.
341 bool do_not_update_selection_on_mutating_selection_range;
343 #if BUILDFLAG(IS_TIZEN)
344 int max_refresh_rate;
347 // Defines the current autoplay policy.
348 blink::mojom::AutoplayPolicy autoplay_policy =
349 blink::mojom::AutoplayPolicy::kNoUserGestureRequired;
351 // `getDisplayMedia()`'s transient activation requirement can be bypassed via
352 // `ScreenCaptureWithoutGestureAllowedForOrigins` policy.
353 bool require_transient_activation_for_get_display_media;
355 // `show{OpenFile|SaveFile|Directory}Picker()`'s transient activation
356 // requirement can be bypassed via
357 // `FileOrDirectoryPickerWithoutGestureAllowedForOrigins` policy.
358 bool require_transient_activation_for_show_file_or_directory_picker;
360 // The preferred color scheme for the web content. The scheme is used to
361 // evaluate the prefers-color-scheme media query and resolve UA color scheme
362 // to be used based on the supported-color-schemes META tag and CSS property.
363 blink::mojom::PreferredColorScheme preferred_color_scheme =
364 blink::mojom::PreferredColorScheme::kLight;
366 // The preferred contrast for the web content. The contrast is used to
367 // evaluate the prefers-contrast media query.
368 blink::mojom::PreferredContrast preferred_contrast =
369 blink::mojom::PreferredContrast::kNoPreference;
371 // Network quality threshold below which resources from iframes are assigned
372 // either kVeryLow or kVeryLow Blink priority.
373 EffectiveConnectionType low_priority_iframes_threshold;
375 // Whether Picture-in-Picture is enabled.
376 bool picture_in_picture_enabled;
378 // Whether a translate service is available.
379 // blink's hrefTranslate attribute existence relies on the result.
380 // See https://github.com/dtapuska/html-translate
381 bool translate_service_available;
383 // A value other than
384 // mojom::EffectiveConnectionType::kEffectiveConnectionUnknownType implies
385 // that the network quality estimate related Web APIs are in the holdback
386 // mode. When the holdback is enabled, the related Web APIs return network
387 // quality estimate corresponding to |network_quality_estimator_web_holdback|
388 // regardless of the actual quality.
389 EffectiveConnectionType network_quality_estimator_web_holdback;
391 // Whether lazy loading of frames and images is enabled.
392 bool lazy_load_enabled = true;
394 // Setting to false disables upgrades to HTTPS for HTTP resources in HTTPS
396 bool allow_mixed_content_upgrades;
398 // Whether the focused element should always be indicated (for example, by
399 // forcing :focus-visible to match regardless of focus method).
400 bool always_show_focus;
402 // Whether touch input can trigger HTML drag-and-drop operations. The
403 // default value depends on the platform.
404 bool touch_drag_drop_enabled;
406 // Whether the end of a drag fires a contextmenu event and possibly shows a
407 // context-menu (depends on how the event is handled). Currently touch-drags
408 // cannot show context menus, see crbug.com/1096189.
409 bool touch_dragend_context_menu = false;
411 // By default, WebXR's immersive-ar session creation is allowed, but this can
412 // change depending on the enterprise policy if the platform supports it.
413 bool webxr_immersive_ar_allowed = true;
415 // Whether lookup of frames in the associated WebView (e.g. lookup via
416 // window.open or via <a target=...>) should be renderer-wide (i.e. going
417 // beyond the usual opener-relationship-based BrowsingInstance boundaries).
418 bool renderer_wide_named_frame_lookup = false;
420 // Whether MIME type checking for worker scripts is strict (true) or lax
421 // (false). Used by StrictMimetypeCheckForWorkerScriptsEnabled policy.
422 bool strict_mime_type_check_for_worker_scripts_enabled = true;
424 #if BUILDFLAG(IS_TIZEN_TV)
425 // Hosted app need to get local access privilege when they use tv device api
426 // located in local path(file://usr/apps/pepper/webapis/webapis.js)
427 bool allow_file_access_from_external_urls = false;
429 // Schemes on which SharedArrayBuffer is enabled unconditionally.
430 // Used in WRT for file:// scheme.
431 std::vector<std::string> additional_shared_array_buffer_schemes;
433 bool use_arrow_scroll = false;
434 bool use_scrollbar_thumb_focus_notifications = false;
437 // Whether modal context menu is used. A modal context menu meaning it is
438 // blocking user's access to the background web content.
439 bool modal_context_menu = true;
441 // We try to keep the default values the same as the default values in
442 // chrome, except for the cases where it would require lots of extra work for
443 // the embedder to use the same default value.
445 WebPreferences(const WebPreferences& other);
446 WebPreferences(WebPreferences&& other);
448 WebPreferences& operator=(const WebPreferences& other);
449 WebPreferences& operator=(WebPreferences&& other);
452 } // namespace web_pref
456 #endif // THIRD_PARTY_BLINK_PUBLIC_COMMON_WEB_PREFERENCES_WEB_PREFERENCES_H_