Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2867)

Unified Diff: content/renderer/render_view_impl.cc

Issue 357203003: Move webpreferences.* from webkit/ to content/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: android fix - webview() -> web_view Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/render_view_impl.h ('k') | content/renderer/render_view_impl_params.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/render_view_impl.cc
diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc
index b664fd6dc6761e5018e6325fe1d3a845f829af51..44bacadc7560bdecf8bc389ba02da93ba067e479 100644
--- a/content/renderer/render_view_impl.cc
+++ b/content/renderer/render_view_impl.cc
@@ -62,12 +62,12 @@
#include "content/public/common/three_d_api_types.h"
#include "content/public/common/url_constants.h"
#include "content/public/common/url_utils.h"
+#include "content/public/common/web_preferences.h"
#include "content/public/renderer/content_renderer_client.h"
#include "content/public/renderer/document_state.h"
#include "content/public/renderer/navigation_state.h"
#include "content/public/renderer/render_view_observer.h"
#include "content/public/renderer/render_view_visitor.h"
-#include "content/public/renderer/web_preferences.h"
#include "content/renderer/accessibility/renderer_accessibility.h"
#include "content/renderer/accessibility/renderer_accessibility_complete.h"
#include "content/renderer/accessibility/renderer_accessibility_focus_only.h"
@@ -92,6 +92,7 @@
#include "content/renderer/media/webrtc/peer_connection_dependency_factory.h"
#include "content/renderer/memory_benchmarking_extension.h"
#include "content/renderer/mhtml_generator.h"
+#include "content/renderer/net_info_helper.h"
#include "content/renderer/render_frame_impl.h"
#include "content/renderer/render_frame_proxy.h"
#include "content/renderer/render_process.h"
@@ -123,6 +124,7 @@
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "net/http/http_util.h"
#include "third_party/WebKit/public/platform/WebCString.h"
+#include "third_party/WebKit/public/platform/WebConnectionType.h"
#include "third_party/WebKit/public/platform/WebDragData.h"
#include "third_party/WebKit/public/platform/WebHTTPBody.h"
#include "third_party/WebKit/public/platform/WebImage.h"
@@ -161,6 +163,7 @@
#include "third_party/WebKit/public/web/WebLocalFrame.h"
#include "third_party/WebKit/public/web/WebMediaPlayerAction.h"
#include "third_party/WebKit/public/web/WebNavigationPolicy.h"
+#include "third_party/WebKit/public/web/WebNetworkStateNotifier.h"
#include "third_party/WebKit/public/web/WebNodeList.h"
#include "third_party/WebKit/public/web/WebPageSerializer.h"
#include "third_party/WebKit/public/web/WebPlugin.h"
@@ -168,6 +171,7 @@
#include "third_party/WebKit/public/web/WebPluginContainer.h"
#include "third_party/WebKit/public/web/WebPluginDocument.h"
#include "third_party/WebKit/public/web/WebRange.h"
+#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
#include "third_party/WebKit/public/web/WebScriptSource.h"
#include "third_party/WebKit/public/web/WebSearchableFormData.h"
#include "third_party/WebKit/public/web/WebSecurityOrigin.h"
@@ -178,6 +182,8 @@
#include "third_party/WebKit/public/web/WebView.h"
#include "third_party/WebKit/public/web/WebWindowFeatures.h"
#include "third_party/WebKit/public/web/default/WebRenderTheme.h"
+#include "third_party/icu/source/common/unicode/uchar.h"
+#include "third_party/icu/source/common/unicode/uscript.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/ui_base_switches_util.h"
#include "ui/events/latency_info.h"
@@ -299,6 +305,8 @@ using blink::WebVector;
using blink::WebView;
using blink::WebWidget;
using blink::WebWindowFeatures;
+using blink::WebNetworkStateNotifier;
+using blink::WebRuntimeFeatures;
using base::Time;
using base::TimeDelta;
using webkit_glue::WebURLResponseExtraDataImpl;
@@ -608,6 +616,87 @@ WebDragData DropDataToWebDragData(const DropData& drop_data) {
return result;
}
+typedef void (*SetFontFamilyWrapper)(blink::WebSettings*,
+ const base::string16&,
+ UScriptCode);
+
+void SetStandardFontFamilyWrapper(WebSettings* settings,
+ const base::string16& font,
+ UScriptCode script) {
+ settings->setStandardFontFamily(font, script);
+}
+
+void SetFixedFontFamilyWrapper(WebSettings* settings,
+ const base::string16& font,
+ UScriptCode script) {
+ settings->setFixedFontFamily(font, script);
+}
+
+void SetSerifFontFamilyWrapper(WebSettings* settings,
+ const base::string16& font,
+ UScriptCode script) {
+ settings->setSerifFontFamily(font, script);
+}
+
+void SetSansSerifFontFamilyWrapper(WebSettings* settings,
+ const base::string16& font,
+ UScriptCode script) {
+ settings->setSansSerifFontFamily(font, script);
+}
+
+void SetCursiveFontFamilyWrapper(WebSettings* settings,
+ const base::string16& font,
+ UScriptCode script) {
+ settings->setCursiveFontFamily(font, script);
+}
+
+void SetFantasyFontFamilyWrapper(WebSettings* settings,
+ const base::string16& font,
+ UScriptCode script) {
+ settings->setFantasyFontFamily(font, script);
+}
+
+void SetPictographFontFamilyWrapper(WebSettings* settings,
+ const base::string16& font,
+ UScriptCode script) {
+ settings->setPictographFontFamily(font, script);
+}
+
+// If |scriptCode| is a member of a family of "similar" script codes, returns
+// the script code in that family that is used by WebKit for font selection
+// purposes. For example, USCRIPT_KATAKANA_OR_HIRAGANA and USCRIPT_JAPANESE are
+// considered equivalent for the purposes of font selection. WebKit uses the
+// script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is
+// USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit
+// uses different scripts than the ones in Chrome pref names because the version
+// of ICU included on certain ports does not have some of the newer scripts. If
+// |scriptCode| is not a member of such a family, returns |scriptCode|.
+UScriptCode GetScriptForWebSettings(UScriptCode scriptCode) {
+ switch (scriptCode) {
+ case USCRIPT_HIRAGANA:
+ case USCRIPT_KATAKANA:
+ case USCRIPT_JAPANESE:
+ return USCRIPT_KATAKANA_OR_HIRAGANA;
+ case USCRIPT_KOREAN:
+ return USCRIPT_HANGUL;
+ default:
+ return scriptCode;
+ }
+}
+
+void ApplyFontsFromMap(const ScriptFontFamilyMap& map,
+ SetFontFamilyWrapper setter,
+ WebSettings* settings) {
+ for (ScriptFontFamilyMap::const_iterator it = map.begin(); it != map.end();
+ ++it) {
+ int32 script = u_getPropertyValueEnum(UCHAR_SCRIPT, (it->first).c_str());
+ if (script >= 0 && script < USCRIPT_CODE_LIMIT) {
+ UScriptCode code = static_cast<UScriptCode>(script);
+ (*setter)(settings, it->second, GetScriptForWebSettings(code));
+ }
+ }
+}
+
} // namespace
RenderViewImpl::RenderViewImpl(RenderViewImplParams* params)
@@ -886,6 +975,232 @@ void RenderView::ForEach(RenderViewVisitor* visitor) {
}
/*static*/
+void RenderView::ApplyWebPreferences(const WebPreferences& prefs,
+ WebView* web_view) {
+ WebSettings* settings = web_view->settings();
+ ApplyFontsFromMap(prefs.standard_font_family_map,
+ SetStandardFontFamilyWrapper, settings);
+ ApplyFontsFromMap(prefs.fixed_font_family_map,
+ SetFixedFontFamilyWrapper, settings);
+ ApplyFontsFromMap(prefs.serif_font_family_map,
+ SetSerifFontFamilyWrapper, settings);
+ ApplyFontsFromMap(prefs.sans_serif_font_family_map,
+ SetSansSerifFontFamilyWrapper, settings);
+ ApplyFontsFromMap(prefs.cursive_font_family_map,
+ SetCursiveFontFamilyWrapper, settings);
+ ApplyFontsFromMap(prefs.fantasy_font_family_map,
+ SetFantasyFontFamilyWrapper, settings);
+ ApplyFontsFromMap(prefs.pictograph_font_family_map,
+ SetPictographFontFamilyWrapper, settings);
+ settings->setDefaultFontSize(prefs.default_font_size);
+ settings->setDefaultFixedFontSize(prefs.default_fixed_font_size);
+ settings->setMinimumFontSize(prefs.minimum_font_size);
+ settings->setMinimumLogicalFontSize(prefs.minimum_logical_font_size);
+ settings->setDefaultTextEncodingName(
+ base::ASCIIToUTF16(prefs.default_encoding));
+ settings->setJavaScriptEnabled(prefs.javascript_enabled);
+ settings->setWebSecurityEnabled(prefs.web_security_enabled);
+ settings->setJavaScriptCanOpenWindowsAutomatically(
+ prefs.javascript_can_open_windows_automatically);
+ settings->setLoadsImagesAutomatically(prefs.loads_images_automatically);
+ settings->setImagesEnabled(prefs.images_enabled);
+ settings->setPluginsEnabled(prefs.plugins_enabled);
+ settings->setDOMPasteAllowed(prefs.dom_paste_enabled);
+ settings->setNeedsSiteSpecificQuirks(prefs.site_specific_quirks_enabled);
+ settings->setShrinksStandaloneImagesToFit(
+ prefs.shrinks_standalone_images_to_fit);
+ settings->setUsesEncodingDetector(prefs.uses_universal_detector);
+ settings->setTextAreasAreResizable(prefs.text_areas_are_resizable);
+ settings->setAllowScriptsToCloseWindows(prefs.allow_scripts_to_close_windows);
+ settings->setDownloadableBinaryFontsEnabled(prefs.remote_fonts_enabled);
+ settings->setJavaScriptCanAccessClipboard(
+ prefs.javascript_can_access_clipboard);
+ WebRuntimeFeatures::enableXSLT(prefs.xslt_enabled);
+ settings->setXSSAuditorEnabled(prefs.xss_auditor_enabled);
+ settings->setDNSPrefetchingEnabled(prefs.dns_prefetching_enabled);
+ settings->setLocalStorageEnabled(prefs.local_storage_enabled);
+ settings->setSyncXHRInDocumentsEnabled(prefs.sync_xhr_in_documents_enabled);
+ WebRuntimeFeatures::enableDatabase(prefs.databases_enabled);
+ settings->setOfflineWebApplicationCacheEnabled(
+ prefs.application_cache_enabled);
+ settings->setCaretBrowsingEnabled(prefs.caret_browsing_enabled);
+ settings->setHyperlinkAuditingEnabled(prefs.hyperlink_auditing_enabled);
+ settings->setCookieEnabled(prefs.cookie_enabled);
+ settings->setNavigateOnDragDrop(prefs.navigate_on_drag_drop);
+
+ settings->setJavaEnabled(prefs.java_enabled);
+
+ // By default, allow_universal_access_from_file_urls is set to false and thus
+ // we mitigate attacks from local HTML files by not granting file:// URLs
+ // universal access. Only test shell will enable this.
+ settings->setAllowUniversalAccessFromFileURLs(
+ prefs.allow_universal_access_from_file_urls);
+ settings->setAllowFileAccessFromFileURLs(
+ prefs.allow_file_access_from_file_urls);
+
+ // Enable the web audio API if requested on the command line.
+ settings->setWebAudioEnabled(prefs.webaudio_enabled);
+
+ // Enable experimental WebGL support if requested on command line
+ // and support is compiled in.
+ settings->setExperimentalWebGLEnabled(prefs.experimental_webgl_enabled);
+
+ // Disable GL multisampling if requested on command line.
+ settings->setOpenGLMultisamplingEnabled(prefs.gl_multisampling_enabled);
+
+ // Enable WebGL errors to the JS console if requested.
+ settings->setWebGLErrorsToConsoleEnabled(
+ prefs.webgl_errors_to_console_enabled);
+
+ // Uses the mock theme engine for scrollbars.
+ settings->setMockScrollbarsEnabled(prefs.mock_scrollbars_enabled);
+
+ settings->setLayerSquashingEnabled(prefs.layer_squashing_enabled);
+
+ // Enable gpu-accelerated compositing always.
+ settings->setAcceleratedCompositingEnabled(true);
+
+ // Enable gpu-accelerated 2d canvas if requested on the command line.
+ settings->setAccelerated2dCanvasEnabled(prefs.accelerated_2d_canvas_enabled);
+
+ settings->setMinimumAccelerated2dCanvasSize(
+ prefs.minimum_accelerated_2d_canvas_size);
+
+ // Disable antialiasing for 2d canvas if requested on the command line.
+ settings->setAntialiased2dCanvasEnabled(
+ !prefs.antialiased_2d_canvas_disabled);
+
+ // Set MSAA sample count for 2d canvas if requested on the command line (or
+ // default value if not).
+ settings->setAccelerated2dCanvasMSAASampleCount(
+ prefs.accelerated_2d_canvas_msaa_sample_count);
+
+ // Enable deferred filter rendering if requested on the command line.
+ settings->setDeferredFiltersEnabled(prefs.deferred_filters_enabled);
+
+ // Enable container culling if requested on the command line.
+ settings->setContainerCullingEnabled(prefs.container_culling_enabled);
+
+ // Enable gesture tap highlight if requested on the command line.
+ settings->setGestureTapHighlightEnabled(prefs.gesture_tap_highlight_enabled);
+
+ // Enabling accelerated layers from the command line enabled accelerated
+ // Video.
+ settings->setAcceleratedCompositingForVideoEnabled(
+ prefs.accelerated_compositing_for_video_enabled);
+
+ // WebGL and accelerated 2D canvas are always gpu composited.
+ settings->setAcceleratedCompositingForCanvasEnabled(
+ prefs.experimental_webgl_enabled || prefs.accelerated_2d_canvas_enabled);
+
+ settings->setAsynchronousSpellCheckingEnabled(
+ prefs.asynchronous_spell_checking_enabled);
+ settings->setUnifiedTextCheckerEnabled(prefs.unified_textchecker_enabled);
+
+ for (WebInspectorPreferences::const_iterator it =
+ prefs.inspector_settings.begin();
+ it != prefs.inspector_settings.end();
+ ++it) {
+ web_view->setInspectorSetting(WebString::fromUTF8(it->first),
+ WebString::fromUTF8(it->second));
+ }
+
+ // Tabs to link is not part of the settings. WebCore calls
+ // ChromeClient::tabsToLinks which is part of the glue code.
+ web_view->setTabsToLinks(prefs.tabs_to_links);
+
+ settings->setAllowDisplayOfInsecureContent(
+ prefs.allow_displaying_insecure_content);
+ settings->setAllowRunningOfInsecureContent(
+ prefs.allow_running_insecure_content);
+ settings->setPasswordEchoEnabled(prefs.password_echo_enabled);
+ settings->setShouldPrintBackgrounds(prefs.should_print_backgrounds);
+ settings->setShouldClearDocumentBackground(
+ prefs.should_clear_document_background);
+ settings->setEnableScrollAnimator(prefs.enable_scroll_animator);
+
+ settings->setRegionBasedColumnsEnabled(prefs.region_based_columns_enabled);
+
+ WebRuntimeFeatures::enableTouch(prefs.touch_enabled);
+ settings->setMaxTouchPoints(prefs.pointer_events_max_touch_points);
+ settings->setDeviceSupportsTouch(prefs.device_supports_touch);
+ settings->setDeviceSupportsMouse(prefs.device_supports_mouse);
+ settings->setEnableTouchAdjustment(prefs.touch_adjustment_enabled);
+
+ settings->setDeferredImageDecodingEnabled(
+ prefs.deferred_image_decoding_enabled);
+ settings->setShouldRespectImageOrientation(
+ prefs.should_respect_image_orientation);
+
+ settings->setUnsafePluginPastingEnabled(false);
+ settings->setEditingBehavior(
+ static_cast<WebSettings::EditingBehavior>(prefs.editing_behavior));
+
+ settings->setSupportsMultipleWindows(prefs.supports_multiple_windows);
+
+ settings->setViewportEnabled(prefs.viewport_enabled);
+ settings->setLoadWithOverviewMode(prefs.initialize_at_minimum_page_scale);
+ settings->setViewportMetaEnabled(prefs.viewport_meta_enabled);
+ settings->setMainFrameResizesAreOrientationChanges(
+ prefs.main_frame_resizes_are_orientation_changes);
+
+ settings->setSmartInsertDeleteEnabled(prefs.smart_insert_delete_enabled);
+
+ settings->setSpatialNavigationEnabled(prefs.spatial_navigation_enabled);
+
+ settings->setSelectionIncludesAltImageText(true);
+
+#if defined(OS_ANDROID)
+ settings->setAllowCustomScrollbarInMainFrame(false);
+ settings->setTextAutosizingEnabled(prefs.text_autosizing_enabled);
+ settings->setAccessibilityFontScaleFactor(prefs.font_scale_factor);
+ settings->setDeviceScaleAdjustment(prefs.device_scale_adjustment);
+ web_view->setIgnoreViewportTagScaleLimits(prefs.force_enable_zoom);
+ settings->setAutoZoomFocusedNodeToLegibleScale(true);
+ settings->setDoubleTapToZoomEnabled(prefs.double_tap_to_zoom_enabled);
+ settings->setMediaControlsOverlayPlayButtonEnabled(true);
+ settings->setMediaPlaybackRequiresUserGesture(
+ prefs.user_gesture_required_for_media_playback);
+ settings->setDefaultVideoPosterURL(
+ base::ASCIIToUTF16(prefs.default_video_poster_url.spec()));
+ settings->setSupportDeprecatedTargetDensityDPI(
+ prefs.support_deprecated_target_density_dpi);
+ settings->setUseLegacyBackgroundSizeShorthandBehavior(
+ prefs.use_legacy_background_size_shorthand_behavior);
+ settings->setWideViewportQuirkEnabled(prefs.wide_viewport_quirk);
+ settings->setUseWideViewport(prefs.use_wide_viewport);
+ settings->setViewportMetaLayoutSizeQuirk(
+ prefs.viewport_meta_layout_size_quirk);
+ settings->setViewportMetaMergeContentQuirk(
+ prefs.viewport_meta_merge_content_quirk);
+ settings->setViewportMetaNonUserScalableQuirk(
+ prefs.viewport_meta_non_user_scalable_quirk);
+ settings->setViewportMetaZeroValuesQuirk(
+ prefs.viewport_meta_zero_values_quirk);
+ settings->setClobberUserAgentInitialScaleQuirk(
+ prefs.clobber_user_agent_initial_scale_quirk);
+ settings->setIgnoreMainFrameOverflowHiddenQuirk(
+ prefs.ignore_main_frame_overflow_hidden_quirk);
+ settings->setReportScreenSizeInPhysicalPixelsQuirk(
+ prefs.report_screen_size_in_physical_pixels_quirk);
+ settings->setMainFrameClipsContent(false);
+ settings->setShrinksStandaloneImagesToFit(false);
+ settings->setShrinksViewportContentToFit(true);
+#endif
+
+ WebNetworkStateNotifier::setOnLine(prefs.is_online);
+ WebNetworkStateNotifier::setWebConnectionType(
+ NetConnectionTypeToWebConnectionType(prefs.connection_type));
+ settings->setPinchVirtualViewportEnabled(
+ prefs.pinch_virtual_viewport_enabled);
+
+ settings->setPinchOverlayScrollbarThickness(
+ prefs.pinch_overlay_scrollbar_thickness);
+ settings->setUseSolidColorScrollbars(prefs.use_solid_color_scrollbars);
+ settings->setCompositorTouchHitTesting(prefs.compositor_touch_hit_testing);
+}
+
+/*static*/
RenderViewImpl* RenderViewImpl::Create(
int32 opener_id,
bool window_was_created_with_opener,
« no previous file with comments | « content/renderer/render_view_impl.h ('k') | content/renderer/render_view_impl_params.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698