| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/glue/webpreferences.h" | 5 #include "webkit/common/webpreferences.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | |
| 8 #include "base/string_util.h" | |
| 9 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 10 #include "third_party/WebKit/public/platform/WebSize.h" | 8 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
| 11 #include "third_party/WebKit/public/platform/WebString.h" | 9 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" |
| 12 #include "third_party/WebKit/public/platform/WebURL.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNetworkStateNotifi
er.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNetworkStateNotifi
er.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" | |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 18 #include "third_party/icu/public/common/unicode/uchar.h" | 15 #include "third_party/icu/public/common/unicode/uchar.h" |
| 19 #include "webkit/glue/webkit_glue.h" | 16 #include "third_party/icu/public/common/unicode/uscript.h" |
| 20 | 17 |
| 21 using WebKit::WebNetworkStateNotifier; | 18 using WebKit::WebNetworkStateNotifier; |
| 22 using WebKit::WebRuntimeFeatures; | 19 using WebKit::WebRuntimeFeatures; |
| 23 using WebKit::WebSettings; | 20 using WebKit::WebSettings; |
| 24 using WebKit::WebSize; | |
| 25 using WebKit::WebString; | 21 using WebKit::WebString; |
| 26 using WebKit::WebURL; | 22 using WebKit::WebURL; |
| 27 using WebKit::WebView; | 23 using WebKit::WebView; |
| 28 | 24 |
| 29 WebPreferences::WebPreferences() | 25 namespace { |
| 30 : default_font_size(16), | |
| 31 default_fixed_font_size(13), | |
| 32 minimum_font_size(0), | |
| 33 minimum_logical_font_size(6), | |
| 34 default_encoding("ISO-8859-1"), | |
| 35 javascript_enabled(true), | |
| 36 web_security_enabled(true), | |
| 37 javascript_can_open_windows_automatically(true), | |
| 38 loads_images_automatically(true), | |
| 39 images_enabled(true), | |
| 40 plugins_enabled(true), | |
| 41 dom_paste_enabled(false), // enables execCommand("paste") | |
| 42 site_specific_quirks_enabled(false), | |
| 43 shrinks_standalone_images_to_fit(true), | |
| 44 uses_universal_detector(false), // Disabled: page cycler regression | |
| 45 text_areas_are_resizable(true), | |
| 46 java_enabled(true), | |
| 47 allow_scripts_to_close_windows(false), | |
| 48 remote_fonts_enabled(true), | |
| 49 javascript_can_access_clipboard(false), | |
| 50 xss_auditor_enabled(true), | |
| 51 dns_prefetching_enabled(true), | |
| 52 local_storage_enabled(false), | |
| 53 databases_enabled(false), | |
| 54 application_cache_enabled(false), | |
| 55 tabs_to_links(true), | |
| 56 caret_browsing_enabled(false), | |
| 57 hyperlink_auditing_enabled(true), | |
| 58 is_online(true), | |
| 59 user_style_sheet_enabled(false), | |
| 60 author_and_user_styles_enabled(true), | |
| 61 allow_universal_access_from_file_urls(false), | |
| 62 allow_file_access_from_file_urls(false), | |
| 63 webaudio_enabled(false), | |
| 64 experimental_webgl_enabled(false), | |
| 65 flash_3d_enabled(true), | |
| 66 flash_stage3d_enabled(false), | |
| 67 flash_stage3d_baseline_enabled(false), | |
| 68 gl_multisampling_enabled(true), | |
| 69 privileged_webgl_extensions_enabled(false), | |
| 70 webgl_errors_to_console_enabled(true), | |
| 71 accelerated_compositing_for_overflow_scroll_enabled(false), | |
| 72 accelerated_compositing_for_scrollable_frames_enabled(false), | |
| 73 composited_scrolling_for_frames_enabled(false), | |
| 74 mock_scrollbars_enabled(false), | |
| 75 threaded_html_parser(true), | |
| 76 show_paint_rects(false), | |
| 77 asynchronous_spell_checking_enabled(true), | |
| 78 unified_textchecker_enabled(false), | |
| 79 accelerated_compositing_enabled(false), | |
| 80 force_compositing_mode(false), | |
| 81 accelerated_compositing_for_3d_transforms_enabled(false), | |
| 82 accelerated_compositing_for_animation_enabled(false), | |
| 83 accelerated_compositing_for_video_enabled(false), | |
| 84 accelerated_2d_canvas_enabled(false), | |
| 85 minimum_accelerated_2d_canvas_size(257 * 256), | |
| 86 antialiased_2d_canvas_disabled(false), | |
| 87 accelerated_filters_enabled(false), | |
| 88 gesture_tap_highlight_enabled(false), | |
| 89 accelerated_compositing_for_plugins_enabled(false), | |
| 90 memory_info_enabled(false), | |
| 91 fullscreen_enabled(false), | |
| 92 allow_displaying_insecure_content(true), | |
| 93 allow_running_insecure_content(false), | |
| 94 password_echo_enabled(false), | |
| 95 should_print_backgrounds(false), | |
| 96 enable_scroll_animator(false), | |
| 97 visual_word_movement_enabled(false), | |
| 98 css_sticky_position_enabled(false), | |
| 99 css_shaders_enabled(false), | |
| 100 css_grid_layout_enabled(false), | |
| 101 lazy_layout_enabled(false), | |
| 102 touch_enabled(false), | |
| 103 device_supports_touch(false), | |
| 104 device_supports_mouse(true), | |
| 105 touch_adjustment_enabled(true), | |
| 106 fixed_position_creates_stacking_context(false), | |
| 107 sync_xhr_in_documents_enabled(true), | |
| 108 deferred_image_decoding_enabled(false), | |
| 109 should_respect_image_orientation(false), | |
| 110 number_of_cpu_cores(1), | |
| 111 #if defined(OS_MACOSX) | |
| 112 editing_behavior(webkit_glue::EDITING_BEHAVIOR_MAC), | |
| 113 #elif defined(OS_WIN) | |
| 114 editing_behavior(webkit_glue::EDITING_BEHAVIOR_WIN), | |
| 115 #elif defined(OS_ANDROID) | |
| 116 editing_behavior(webkit_glue::EDITING_BEHAVIOR_ANDROID), | |
| 117 #elif defined(OS_POSIX) | |
| 118 editing_behavior(webkit_glue::EDITING_BEHAVIOR_UNIX), | |
| 119 #else | |
| 120 editing_behavior(webkit_glue::EDITING_BEHAVIOR_MAC), | |
| 121 #endif | |
| 122 supports_multiple_windows(true), | |
| 123 viewport_enabled(false), | |
| 124 initialize_at_minimum_page_scale(true), | |
| 125 #if defined(OS_MACOSX) | |
| 126 smart_insert_delete_enabled(true), | |
| 127 #else | |
| 128 smart_insert_delete_enabled(false), | |
| 129 #endif | |
| 130 spatial_navigation_enabled(false), | |
| 131 experimental_websocket_enabled(false), | |
| 132 pinch_virtual_viewport_enabled(false), | |
| 133 cookie_enabled(true) | |
| 134 #if defined(OS_ANDROID) | |
| 135 , | |
| 136 text_autosizing_enabled(true), | |
| 137 font_scale_factor(1.0f), | |
| 138 force_enable_zoom(false), | |
| 139 double_tap_to_zoom_enabled(true), | |
| 140 user_gesture_required_for_media_playback(true), | |
| 141 support_deprecated_target_density_dpi(false), | |
| 142 use_wide_viewport(true) | |
| 143 #endif | |
| 144 { | |
| 145 standard_font_family_map[webkit_glue::kCommonScript] = | |
| 146 ASCIIToUTF16("Times New Roman"); | |
| 147 fixed_font_family_map[webkit_glue::kCommonScript] = | |
| 148 ASCIIToUTF16("Courier New"); | |
| 149 serif_font_family_map[webkit_glue::kCommonScript] = | |
| 150 ASCIIToUTF16("Times New Roman"); | |
| 151 sans_serif_font_family_map[webkit_glue::kCommonScript] = | |
| 152 ASCIIToUTF16("Arial"); | |
| 153 cursive_font_family_map[webkit_glue::kCommonScript] = | |
| 154 ASCIIToUTF16("Script"); | |
| 155 fantasy_font_family_map[webkit_glue::kCommonScript] = | |
| 156 ASCIIToUTF16("Impact"); | |
| 157 pictograph_font_family_map[webkit_glue::kCommonScript] = | |
| 158 ASCIIToUTF16("Times New Roman"); | |
| 159 } | |
| 160 | 26 |
| 161 WebPreferences::~WebPreferences() { | 27 typedef void (*SetFontFamilyWrapper)( |
| 162 } | 28 WebKit::WebSettings*, const base::string16&, UScriptCode); |
| 163 | |
| 164 namespace { | |
| 165 | 29 |
| 166 void setStandardFontFamilyWrapper(WebSettings* settings, | 30 void setStandardFontFamilyWrapper(WebSettings* settings, |
| 167 const base::string16& font, | 31 const base::string16& font, |
| 168 UScriptCode script) { | 32 UScriptCode script) { |
| 169 settings->setStandardFontFamily(font, script); | 33 settings->setStandardFontFamily(font, script); |
| 170 } | 34 } |
| 171 | 35 |
| 172 void setFixedFontFamilyWrapper(WebSettings* settings, | 36 void setFixedFontFamilyWrapper(WebSettings* settings, |
| 173 const base::string16& font, | 37 const base::string16& font, |
| 174 UScriptCode script) { | 38 UScriptCode script) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 198 UScriptCode script) { | 62 UScriptCode script) { |
| 199 settings->setFantasyFontFamily(font, script); | 63 settings->setFantasyFontFamily(font, script); |
| 200 } | 64 } |
| 201 | 65 |
| 202 void setPictographFontFamilyWrapper(WebSettings* settings, | 66 void setPictographFontFamilyWrapper(WebSettings* settings, |
| 203 const base::string16& font, | 67 const base::string16& font, |
| 204 UScriptCode script) { | 68 UScriptCode script) { |
| 205 settings->setPictographFontFamily(font, script); | 69 settings->setPictographFontFamily(font, script); |
| 206 } | 70 } |
| 207 | 71 |
| 208 typedef void (*SetFontFamilyWrapper)( | |
| 209 WebKit::WebSettings*, const base::string16&, UScriptCode); | |
| 210 | |
| 211 // If |scriptCode| is a member of a family of "similar" script codes, returns | 72 // If |scriptCode| is a member of a family of "similar" script codes, returns |
| 212 // the script code in that family that is used by WebKit for font selection | 73 // the script code in that family that is used by WebKit for font selection |
| 213 // purposes. For example, USCRIPT_KATAKANA_OR_HIRAGANA and USCRIPT_JAPANESE are | 74 // purposes. For example, USCRIPT_KATAKANA_OR_HIRAGANA and USCRIPT_JAPANESE are |
| 214 // considered equivalent for the purposes of font selection. WebKit uses the | 75 // considered equivalent for the purposes of font selection. WebKit uses the |
| 215 // script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is | 76 // script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is |
| 216 // USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit | 77 // USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit |
| 217 // uses different scripts than the ones in Chrome pref names because the version | 78 // uses different scripts than the ones in Chrome pref names because the version |
| 218 // of ICU included on certain ports does not have some of the newer scripts. If | 79 // of ICU included on certain ports does not have some of the newer scripts. If |
| 219 // |scriptCode| is not a member of such a family, returns |scriptCode|. | 80 // |scriptCode| is not a member of such a family, returns |scriptCode|. |
| 220 UScriptCode GetScriptForWebSettings(UScriptCode scriptCode) { | 81 UScriptCode GetScriptForWebSettings(UScriptCode scriptCode) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 240 UScriptCode code = static_cast<UScriptCode>(script); | 101 UScriptCode code = static_cast<UScriptCode>(script); |
| 241 (*setter)(settings, it->second, GetScriptForWebSettings(code)); | 102 (*setter)(settings, it->second, GetScriptForWebSettings(code)); |
| 242 } | 103 } |
| 243 } | 104 } |
| 244 } | 105 } |
| 245 | 106 |
| 246 } // namespace | 107 } // namespace |
| 247 | 108 |
| 248 namespace webkit_glue { | 109 namespace webkit_glue { |
| 249 | 110 |
| 250 // "Zyyy" is the ISO 15924 script code for undetermined script aka Common. | |
| 251 const char kCommonScript[] = "Zyyy"; | |
| 252 | |
| 253 void ApplyWebPreferences(const WebPreferences& prefs, WebView* web_view) { | 111 void ApplyWebPreferences(const WebPreferences& prefs, WebView* web_view) { |
| 254 WebSettings* settings = web_view->settings(); | 112 WebSettings* settings = web_view->settings(); |
| 255 ApplyFontsFromMap(prefs.standard_font_family_map, | 113 ApplyFontsFromMap(prefs.standard_font_family_map, |
| 256 setStandardFontFamilyWrapper, settings); | 114 setStandardFontFamilyWrapper, settings); |
| 257 ApplyFontsFromMap(prefs.fixed_font_family_map, | 115 ApplyFontsFromMap(prefs.fixed_font_family_map, |
| 258 setFixedFontFamilyWrapper, settings); | 116 setFixedFontFamilyWrapper, settings); |
| 259 ApplyFontsFromMap(prefs.serif_font_family_map, | 117 ApplyFontsFromMap(prefs.serif_font_family_map, |
| 260 setSerifFontFamilyWrapper, settings); | 118 setSerifFontFamilyWrapper, settings); |
| 261 ApplyFontsFromMap(prefs.sans_serif_font_family_map, | 119 ApplyFontsFromMap(prefs.sans_serif_font_family_map, |
| 262 setSansSerifFontFamilyWrapper, settings); | 120 setSansSerifFontFamilyWrapper, settings); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 settings->setUseWideViewport(prefs.use_wide_viewport); | 334 settings->setUseWideViewport(prefs.use_wide_viewport); |
| 477 #endif | 335 #endif |
| 478 | 336 |
| 479 WebNetworkStateNotifier::setOnLine(prefs.is_online); | 337 WebNetworkStateNotifier::setOnLine(prefs.is_online); |
| 480 settings->setExperimentalWebSocketEnabled( | 338 settings->setExperimentalWebSocketEnabled( |
| 481 prefs.experimental_websocket_enabled); | 339 prefs.experimental_websocket_enabled); |
| 482 settings->setPinchVirtualViewportEnabled( | 340 settings->setPinchVirtualViewportEnabled( |
| 483 prefs.pinch_virtual_viewport_enabled); | 341 prefs.pinch_virtual_viewport_enabled); |
| 484 } | 342 } |
| 485 | 343 |
| 486 #define COMPILE_ASSERT_MATCHING_ENUMS(webkit_glue_name, webkit_name) \ | |
| 487 COMPILE_ASSERT( \ | |
| 488 static_cast<int>(webkit_glue_name) == static_cast<int>(webkit_name), \ | |
| 489 mismatching_enums) | |
| 490 | |
| 491 COMPILE_ASSERT_MATCHING_ENUMS( | |
| 492 webkit_glue::EDITING_BEHAVIOR_MAC, WebSettings::EditingBehaviorMac); | |
| 493 COMPILE_ASSERT_MATCHING_ENUMS( | |
| 494 webkit_glue::EDITING_BEHAVIOR_WIN, WebSettings::EditingBehaviorWin); | |
| 495 COMPILE_ASSERT_MATCHING_ENUMS( | |
| 496 webkit_glue::EDITING_BEHAVIOR_UNIX, WebSettings::EditingBehaviorUnix); | |
| 497 COMPILE_ASSERT_MATCHING_ENUMS( | |
| 498 webkit_glue::EDITING_BEHAVIOR_ANDROID, WebSettings::EditingBehaviorAndroid); | |
| 499 | 344 |
| 500 } // namespace webkit_glue | 345 } // namespace webkit_glue |
| OLD | NEW |