Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / public / common / web_preferences.cc
blobb61e1dc839067d3d922429cb68fcc4c2978d85b3
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.
5 #include "content/public/common/web_preferences.h"
7 #include "base/basictypes.h"
8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "third_party/WebKit/public/web/WebSettings.h"
11 #include "third_party/icu/source/common/unicode/uchar.h"
13 using blink::WebSettings;
15 namespace content {
17 // "Zyyy" is the ISO 15924 script code for undetermined script aka Common.
18 const char kCommonScript[] = "Zyyy";
20 #define STATIC_ASSERT_MATCHING_ENUMS(content_name, blink_name) \
21 static_assert( \
22 static_cast<int>(content_name) == static_cast<int>(blink_name), \
23 "mismatching enums: " #content_name)
25 STATIC_ASSERT_MATCHING_ENUMS(EDITING_BEHAVIOR_MAC,
26 WebSettings::EditingBehaviorMac);
27 STATIC_ASSERT_MATCHING_ENUMS(EDITING_BEHAVIOR_WIN,
28 WebSettings::EditingBehaviorWin);
29 STATIC_ASSERT_MATCHING_ENUMS(EDITING_BEHAVIOR_UNIX,
30 WebSettings::EditingBehaviorUnix);
31 STATIC_ASSERT_MATCHING_ENUMS(EDITING_BEHAVIOR_ANDROID,
32 WebSettings::EditingBehaviorAndroid);
34 STATIC_ASSERT_MATCHING_ENUMS(V8_CACHE_OPTIONS_DEFAULT,
35 WebSettings::V8CacheOptionsDefault);
36 STATIC_ASSERT_MATCHING_ENUMS(V8_CACHE_OPTIONS_PARSE,
37 WebSettings::V8CacheOptionsParse);
38 STATIC_ASSERT_MATCHING_ENUMS(V8_CACHE_OPTIONS_CODE,
39 WebSettings::V8CacheOptionsCode);
40 STATIC_ASSERT_MATCHING_ENUMS(V8_CACHE_OPTIONS_CODE_COMPRESSED,
41 WebSettings::V8CacheOptionsCodeCompressed);
42 STATIC_ASSERT_MATCHING_ENUMS(V8_CACHE_OPTIONS_NONE,
43 WebSettings::V8CacheOptionsNone);
44 STATIC_ASSERT_MATCHING_ENUMS(V8_CACHE_OPTIONS_PARSE_MEMORY,
45 WebSettings::V8CacheOptionsParseMemory);
46 STATIC_ASSERT_MATCHING_ENUMS(V8_CACHE_OPTIONS_HEURISTICS,
47 WebSettings::V8CacheOptionsHeuristics);
48 STATIC_ASSERT_MATCHING_ENUMS(V8_CACHE_OPTIONS_HEURISTICS_MOBILE,
49 WebSettings::V8CacheOptionsHeuristicsMobile);
50 STATIC_ASSERT_MATCHING_ENUMS(V8_CACHE_OPTIONS_HEURISTICS_DEFAULT,
51 WebSettings::V8CacheOptionsHeuristicsDefault);
52 STATIC_ASSERT_MATCHING_ENUMS(
53 V8_CACHE_OPTIONS_HEURISTICS_DEFAULT_MOBILE,
54 WebSettings::V8CacheOptionsHeuristicsDefaultMobile);
55 STATIC_ASSERT_MATCHING_ENUMS(V8_CACHE_OPTIONS_RECENT,
56 WebSettings::V8CacheOptionsRecent);
57 STATIC_ASSERT_MATCHING_ENUMS(V8_CACHE_OPTIONS_RECENT_SMALL,
58 WebSettings::V8CacheOptionsRecentSmall);
59 STATIC_ASSERT_MATCHING_ENUMS(V8_CACHE_OPTIONS_LAST,
60 WebSettings::V8CacheOptionsRecentSmall);
62 STATIC_ASSERT_MATCHING_ENUMS(IMAGE_ANIMATION_POLICY_ALLOWED,
63 WebSettings::ImageAnimationPolicyAllowed);
64 STATIC_ASSERT_MATCHING_ENUMS(IMAGE_ANIMATION_POLICY_ANIMATION_ONCE,
65 WebSettings::ImageAnimationPolicyAnimateOnce);
66 STATIC_ASSERT_MATCHING_ENUMS(IMAGE_ANIMATION_POLICY_NO_ANIMATION,
67 WebSettings::ImageAnimationPolicyNoAnimation);
69 STATIC_ASSERT_MATCHING_ENUMS(ui::POINTER_TYPE_NONE,
70 WebSettings::PointerTypeNone);
71 STATIC_ASSERT_MATCHING_ENUMS(ui::POINTER_TYPE_COARSE,
72 WebSettings::PointerTypeCoarse);
73 STATIC_ASSERT_MATCHING_ENUMS(ui::POINTER_TYPE_FINE,
74 WebSettings::PointerTypeFine);
76 STATIC_ASSERT_MATCHING_ENUMS(ui::HOVER_TYPE_NONE,
77 WebSettings::HoverTypeNone);
78 STATIC_ASSERT_MATCHING_ENUMS(ui::HOVER_TYPE_ON_DEMAND,
79 WebSettings::HoverTypeOnDemand);
80 STATIC_ASSERT_MATCHING_ENUMS(ui::HOVER_TYPE_HOVER,
81 WebSettings::HoverTypeHover);
83 WebPreferences::WebPreferences()
84 : default_font_size(16),
85 default_fixed_font_size(13),
86 minimum_font_size(0),
87 minimum_logical_font_size(6),
88 default_encoding("ISO-8859-1"),
89 #if defined(OS_WIN)
90 context_menu_on_mouse_up(true),
91 #else
92 context_menu_on_mouse_up(false),
93 #endif
94 javascript_enabled(true),
95 web_security_enabled(true),
96 javascript_can_open_windows_automatically(true),
97 loads_images_automatically(true),
98 images_enabled(true),
99 plugins_enabled(true),
100 dom_paste_enabled(false), // enables execCommand("paste")
101 shrinks_standalone_images_to_fit(true),
102 uses_universal_detector(false), // Disabled: page cycler regression
103 text_areas_are_resizable(true),
104 java_enabled(true),
105 allow_scripts_to_close_windows(false),
106 remote_fonts_enabled(true),
107 javascript_can_access_clipboard(false),
108 xslt_enabled(true),
109 xss_auditor_enabled(true),
110 dns_prefetching_enabled(true),
111 local_storage_enabled(false),
112 databases_enabled(false),
113 application_cache_enabled(false),
114 tabs_to_links(true),
115 caret_browsing_enabled(false),
116 hyperlink_auditing_enabled(true),
117 is_online(true),
118 connection_type(net::NetworkChangeNotifier::CONNECTION_NONE),
119 allow_universal_access_from_file_urls(false),
120 allow_file_access_from_file_urls(false),
121 webaudio_enabled(false),
122 experimental_webgl_enabled(false),
123 pepper_3d_enabled(false),
124 flash_3d_enabled(true),
125 flash_stage3d_enabled(false),
126 flash_stage3d_baseline_enabled(false),
127 gl_multisampling_enabled(true),
128 privileged_webgl_extensions_enabled(false),
129 webgl_errors_to_console_enabled(true),
130 mock_scrollbars_enabled(false),
131 asynchronous_spell_checking_enabled(true),
132 unified_textchecker_enabled(false),
133 accelerated_2d_canvas_enabled(false),
134 minimum_accelerated_2d_canvas_size(257 * 256),
135 antialiased_2d_canvas_disabled(false),
136 antialiased_clips_2d_canvas_enabled(false),
137 accelerated_2d_canvas_msaa_sample_count(0),
138 accelerated_filters_enabled(false),
139 deferred_filters_enabled(false),
140 container_culling_enabled(false),
141 text_blobs_enabled(false),
142 allow_displaying_insecure_content(true),
143 allow_running_insecure_content(false),
144 disable_reading_from_canvas(false),
145 strict_mixed_content_checking(false),
146 strict_powerful_feature_restrictions(false),
147 password_echo_enabled(false),
148 should_print_backgrounds(false),
149 should_clear_document_background(true),
150 enable_scroll_animator(false),
151 region_based_columns_enabled(false),
152 touch_enabled(false),
153 device_supports_touch(false),
154 device_supports_mouse(true),
155 touch_adjustment_enabled(true),
156 pointer_events_max_touch_points(0),
157 available_pointer_types(0),
158 primary_pointer_type(ui::POINTER_TYPE_NONE),
159 available_hover_types(0),
160 primary_hover_type(ui::HOVER_TYPE_NONE),
161 sync_xhr_in_documents_enabled(true),
162 deferred_image_decoding_enabled(false),
163 image_color_profiles_enabled(false),
164 should_respect_image_orientation(false),
165 number_of_cpu_cores(1),
166 #if defined(OS_MACOSX)
167 editing_behavior(EDITING_BEHAVIOR_MAC),
168 #elif defined(OS_WIN)
169 editing_behavior(EDITING_BEHAVIOR_WIN),
170 #elif defined(OS_ANDROID)
171 editing_behavior(EDITING_BEHAVIOR_ANDROID),
172 #elif defined(OS_POSIX)
173 editing_behavior(EDITING_BEHAVIOR_UNIX),
174 #else
175 editing_behavior(EDITING_BEHAVIOR_MAC),
176 #endif
177 supports_multiple_windows(true),
178 viewport_enabled(false),
179 viewport_meta_enabled(false),
180 main_frame_resizes_are_orientation_changes(false),
181 initialize_at_minimum_page_scale(true),
182 #if defined(OS_MACOSX)
183 smart_insert_delete_enabled(true),
184 #else
185 smart_insert_delete_enabled(false),
186 #endif
187 spatial_navigation_enabled(false),
188 pinch_virtual_viewport_enabled(false),
189 pinch_overlay_scrollbar_thickness(0),
190 use_solid_color_scrollbars(false),
191 navigate_on_drag_drop(true),
192 v8_cache_options(V8_CACHE_OPTIONS_DEFAULT),
193 slimming_paint_enabled(false),
194 cookie_enabled(true),
195 pepper_accelerated_video_decode_enabled(false),
196 animation_policy(IMAGE_ANIMATION_POLICY_ALLOWED),
197 #if defined(OS_ANDROID)
198 text_autosizing_enabled(true),
199 font_scale_factor(1.0f),
200 device_scale_adjustment(1.0f),
201 force_enable_zoom(false),
202 fullscreen_supported(true),
203 double_tap_to_zoom_enabled(true),
204 user_gesture_required_for_media_playback(true),
205 support_deprecated_target_density_dpi(false),
206 use_legacy_background_size_shorthand_behavior(false),
207 wide_viewport_quirk(false),
208 use_wide_viewport(true),
209 force_zero_layout_height(false),
210 viewport_meta_layout_size_quirk(false),
211 viewport_meta_merge_content_quirk(false),
212 viewport_meta_non_user_scalable_quirk(false),
213 viewport_meta_zero_values_quirk(false),
214 clobber_user_agent_initial_scale_quirk(false),
215 ignore_main_frame_overflow_hidden_quirk(false),
216 report_screen_size_in_physical_pixels_quirk(false),
217 #endif
218 #if defined(OS_ANDROID)
219 default_minimum_page_scale_factor(0.25f),
220 default_maximum_page_scale_factor(5.f)
221 #else
222 default_minimum_page_scale_factor(1.f),
223 default_maximum_page_scale_factor(4.f)
224 #endif
226 standard_font_family_map[kCommonScript] =
227 base::ASCIIToUTF16("Times New Roman");
228 fixed_font_family_map[kCommonScript] = base::ASCIIToUTF16("Courier New");
229 serif_font_family_map[kCommonScript] = base::ASCIIToUTF16("Times New Roman");
230 sans_serif_font_family_map[kCommonScript] = base::ASCIIToUTF16("Arial");
231 cursive_font_family_map[kCommonScript] = base::ASCIIToUTF16("Script");
232 fantasy_font_family_map[kCommonScript] = base::ASCIIToUTF16("Impact");
233 pictograph_font_family_map[kCommonScript] =
234 base::ASCIIToUTF16("Times New Roman");
237 WebPreferences::~WebPreferences() {
240 } // namespace content