Chromium Code Reviews| 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/renderer/webpreferences_renderer.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" |
|
jamesr
2013/05/30 21:17:37
FYI abarth recently replaced "third_party/WebKit/S
scottmg
2013/05/30 21:23:58
hmm, i just pulled. i guess it hasn't rolled yet?
| |
| 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" |
| 17 #include "webkit/common/webpreferences.h" | |
| 20 | 18 |
| 21 using WebKit::WebNetworkStateNotifier; | 19 using WebKit::WebNetworkStateNotifier; |
| 22 using WebKit::WebRuntimeFeatures; | 20 using WebKit::WebRuntimeFeatures; |
| 23 using WebKit::WebSettings; | 21 using WebKit::WebSettings; |
| 24 using WebKit::WebSize; | |
| 25 using WebKit::WebString; | 22 using WebKit::WebString; |
| 26 using WebKit::WebURL; | 23 using WebKit::WebURL; |
| 27 using WebKit::WebView; | 24 using WebKit::WebView; |
| 28 | 25 |
| 29 WebPreferences::WebPreferences() | 26 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 | 27 |
| 161 WebPreferences::~WebPreferences() { | 28 typedef void (*SetFontFamilyWrapper)( |
| 162 } | 29 WebKit::WebSettings*, const base::string16&, UScriptCode); |
| 163 | |
| 164 namespace { | |
| 165 | 30 |
| 166 void setStandardFontFamilyWrapper(WebSettings* settings, | 31 void setStandardFontFamilyWrapper(WebSettings* settings, |
| 167 const base::string16& font, | 32 const base::string16& font, |
| 168 UScriptCode script) { | 33 UScriptCode script) { |
| 169 settings->setStandardFontFamily(font, script); | 34 settings->setStandardFontFamily(font, script); |
| 170 } | 35 } |
| 171 | 36 |
| 172 void setFixedFontFamilyWrapper(WebSettings* settings, | 37 void setFixedFontFamilyWrapper(WebSettings* settings, |
| 173 const base::string16& font, | 38 const base::string16& font, |
| 174 UScriptCode script) { | 39 UScriptCode script) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 198 UScriptCode script) { | 63 UScriptCode script) { |
| 199 settings->setFantasyFontFamily(font, script); | 64 settings->setFantasyFontFamily(font, script); |
| 200 } | 65 } |
| 201 | 66 |
| 202 void setPictographFontFamilyWrapper(WebSettings* settings, | 67 void setPictographFontFamilyWrapper(WebSettings* settings, |
| 203 const base::string16& font, | 68 const base::string16& font, |
| 204 UScriptCode script) { | 69 UScriptCode script) { |
| 205 settings->setPictographFontFamily(font, script); | 70 settings->setPictographFontFamily(font, script); |
| 206 } | 71 } |
| 207 | 72 |
| 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 | 73 // 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 | 74 // 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 | 75 // purposes. For example, USCRIPT_KATAKANA_OR_HIRAGANA and USCRIPT_JAPANESE are |
| 214 // considered equivalent for the purposes of font selection. WebKit uses the | 76 // considered equivalent for the purposes of font selection. WebKit uses the |
| 215 // script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is | 77 // script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is |
| 216 // USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit | 78 // USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit |
| 217 // uses different scripts than the ones in Chrome pref names because the version | 79 // 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 | 80 // 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|. | 81 // |scriptCode| is not a member of such a family, returns |scriptCode|. |
| 220 UScriptCode GetScriptForWebSettings(UScriptCode scriptCode) { | 82 UScriptCode GetScriptForWebSettings(UScriptCode scriptCode) { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 240 UScriptCode code = static_cast<UScriptCode>(script); | 102 UScriptCode code = static_cast<UScriptCode>(script); |
| 241 (*setter)(settings, it->second, GetScriptForWebSettings(code)); | 103 (*setter)(settings, it->second, GetScriptForWebSettings(code)); |
| 242 } | 104 } |
| 243 } | 105 } |
| 244 } | 106 } |
| 245 | 107 |
| 246 } // namespace | 108 } // namespace |
| 247 | 109 |
| 248 namespace webkit_glue { | 110 namespace webkit_glue { |
| 249 | 111 |
| 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) { | 112 void ApplyWebPreferences(const WebPreferences& prefs, WebView* web_view) { |
| 254 WebSettings* settings = web_view->settings(); | 113 WebSettings* settings = web_view->settings(); |
| 255 ApplyFontsFromMap(prefs.standard_font_family_map, | 114 ApplyFontsFromMap(prefs.standard_font_family_map, |
| 256 setStandardFontFamilyWrapper, settings); | 115 setStandardFontFamilyWrapper, settings); |
| 257 ApplyFontsFromMap(prefs.fixed_font_family_map, | 116 ApplyFontsFromMap(prefs.fixed_font_family_map, |
| 258 setFixedFontFamilyWrapper, settings); | 117 setFixedFontFamilyWrapper, settings); |
| 259 ApplyFontsFromMap(prefs.serif_font_family_map, | 118 ApplyFontsFromMap(prefs.serif_font_family_map, |
| 260 setSerifFontFamilyWrapper, settings); | 119 setSerifFontFamilyWrapper, settings); |
| 261 ApplyFontsFromMap(prefs.sans_serif_font_family_map, | 120 ApplyFontsFromMap(prefs.sans_serif_font_family_map, |
| 262 setSansSerifFontFamilyWrapper, settings); | 121 setSansSerifFontFamilyWrapper, settings); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 476 settings->setUseWideViewport(prefs.use_wide_viewport); | 335 settings->setUseWideViewport(prefs.use_wide_viewport); |
| 477 #endif | 336 #endif |
| 478 | 337 |
| 479 WebNetworkStateNotifier::setOnLine(prefs.is_online); | 338 WebNetworkStateNotifier::setOnLine(prefs.is_online); |
| 480 settings->setExperimentalWebSocketEnabled( | 339 settings->setExperimentalWebSocketEnabled( |
| 481 prefs.experimental_websocket_enabled); | 340 prefs.experimental_websocket_enabled); |
| 482 settings->setPinchVirtualViewportEnabled( | 341 settings->setPinchVirtualViewportEnabled( |
| 483 prefs.pinch_virtual_viewport_enabled); | 342 prefs.pinch_virtual_viewport_enabled); |
| 484 } | 343 } |
| 485 | 344 |
| 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 | 345 |
| 500 } // namespace webkit_glue | 346 } // namespace webkit_glue |
| OLD | NEW |