Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / renderer_preferences_util.cc
blobce174ef34c6375bea36ef73df2423d1df201c96f
1 // Copyright (c) 2012 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 "chrome/browser/renderer_preferences_util.h"
7 #include "base/macros.h"
8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/pref_names.h"
11 #include "content/public/browser/host_zoom_map.h"
12 #include "content/public/browser/web_contents.h"
13 #include "content/public/common/renderer_preferences.h"
14 #include "third_party/skia/include/core/SkColor.h"
16 #if defined(OS_LINUX) || defined(OS_ANDROID)
17 #include "ui/gfx/font_render_params.h"
18 #endif
20 #if !defined(OS_ANDROID)
21 #include "components/ui/zoom/zoom_controller.h"
22 #endif
24 #if defined(TOOLKIT_VIEWS)
25 #include "ui/views/controls/textfield/textfield.h"
26 #endif
28 #if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS)
29 #include "chrome/browser/themes/theme_service.h"
30 #include "chrome/browser/themes/theme_service_factory.h"
31 #include "ui/views/linux_ui/linux_ui.h"
32 #endif
34 #if defined(OS_WIN)
35 #include "base/win/win_util.h"
36 #include "ui/gfx/platform_font_win.h"
37 #endif
39 namespace renderer_preferences_util {
41 void UpdateFromSystemSettings(content::RendererPreferences* prefs,
42 Profile* profile,
43 content::WebContents* web_contents) {
44 const PrefService* pref_service = profile->GetPrefs();
45 prefs->accept_languages = pref_service->GetString(prefs::kAcceptLanguages);
46 prefs->enable_referrers = pref_service->GetBoolean(prefs::kEnableReferrers);
47 prefs->enable_do_not_track =
48 pref_service->GetBoolean(prefs::kEnableDoNotTrack);
49 #if defined(ENABLE_WEBRTC)
50 prefs->enable_webrtc_multiple_routes =
51 pref_service->GetBoolean(prefs::kWebRTCMultipleRoutesEnabled);
52 #endif
54 double default_zoom_level = 0;
55 bool default_zoom_level_set = false;
56 #if !defined(OS_ANDROID)
57 ui_zoom::ZoomController* zoom_controller =
58 ui_zoom::ZoomController::FromWebContents(web_contents);
59 if (zoom_controller) {
60 default_zoom_level = zoom_controller->GetDefaultZoomLevel();
61 default_zoom_level_set = true;
63 #endif
65 if (!default_zoom_level_set) {
66 default_zoom_level =
67 content::HostZoomMap::Get(web_contents->GetSiteInstance())
68 ->GetDefaultZoomLevel();
70 prefs->default_zoom_level = default_zoom_level;
72 #if defined(USE_DEFAULT_RENDER_THEME)
73 prefs->focus_ring_color = SkColorSetRGB(0x4D, 0x90, 0xFE);
74 #if defined(OS_CHROMEOS)
75 // This color is 0x544d90fe modulated with 0xffffff.
76 prefs->active_selection_bg_color = SkColorSetRGB(0xCB, 0xE4, 0xFA);
77 prefs->active_selection_fg_color = SK_ColorBLACK;
78 prefs->inactive_selection_bg_color = SkColorSetRGB(0xEA, 0xEA, 0xEA);
79 prefs->inactive_selection_fg_color = SK_ColorBLACK;
80 #endif
81 #endif
83 #if defined(TOOLKIT_VIEWS)
84 prefs->caret_blink_interval = views::Textfield::GetCaretBlinkMs() / 1000.0;
85 #endif
87 #if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS)
88 views::LinuxUI* linux_ui = views::LinuxUI::instance();
89 if (linux_ui) {
90 if (ThemeServiceFactory::GetForProfile(profile)->UsingSystemTheme()) {
91 prefs->focus_ring_color = linux_ui->GetFocusRingColor();
92 prefs->thumb_active_color = linux_ui->GetThumbActiveColor();
93 prefs->thumb_inactive_color = linux_ui->GetThumbInactiveColor();
94 prefs->track_color = linux_ui->GetTrackColor();
95 prefs->active_selection_bg_color = linux_ui->GetActiveSelectionBgColor();
96 prefs->active_selection_fg_color = linux_ui->GetActiveSelectionFgColor();
97 prefs->inactive_selection_bg_color =
98 linux_ui->GetInactiveSelectionBgColor();
99 prefs->inactive_selection_fg_color =
100 linux_ui->GetInactiveSelectionFgColor();
103 // If we have a linux_ui object, set the caret blink interval regardless of
104 // whether we're in native theme mode.
105 prefs->caret_blink_interval = linux_ui->GetCursorBlinkInterval();
107 #endif
109 #if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_WIN)
110 CR_DEFINE_STATIC_LOCAL(const gfx::FontRenderParams, params,
111 (gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(true), NULL)));
112 prefs->should_antialias_text = params.antialiasing;
113 prefs->use_subpixel_positioning = params.subpixel_positioning;
114 prefs->hinting = params.hinting;
115 prefs->use_autohinter = params.autohinter;
116 prefs->use_bitmaps = params.use_bitmaps;
117 prefs->subpixel_rendering = params.subpixel_rendering;
118 #endif
120 #if !defined(OS_MACOSX)
121 prefs->plugin_fullscreen_allowed =
122 pref_service->GetBoolean(prefs::kFullscreenAllowed);
123 #endif
125 #if defined(OS_WIN)
126 NONCLIENTMETRICS_XP metrics = {0};
127 base::win::GetNonClientMetrics(&metrics);
129 prefs->caption_font_family_name = metrics.lfCaptionFont.lfFaceName;
130 prefs->caption_font_height = gfx::PlatformFontWin::GetFontSize(
131 metrics.lfCaptionFont);
133 prefs->small_caption_font_family_name = metrics.lfSmCaptionFont.lfFaceName;
134 prefs->small_caption_font_height = gfx::PlatformFontWin::GetFontSize(
135 metrics.lfSmCaptionFont);
137 prefs->menu_font_family_name = metrics.lfMenuFont.lfFaceName;
138 prefs->menu_font_height = gfx::PlatformFontWin::GetFontSize(
139 metrics.lfMenuFont);
141 prefs->status_font_family_name = metrics.lfStatusFont.lfFaceName;
142 prefs->status_font_height = gfx::PlatformFontWin::GetFontSize(
143 metrics.lfStatusFont);
145 prefs->message_font_family_name = metrics.lfMessageFont.lfFaceName;
146 prefs->message_font_height = gfx::PlatformFontWin::GetFontSize(
147 metrics.lfMessageFont);
148 #endif
151 } // namespace renderer_preferences_util