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/browser/ui/zoom/zoom_controller.h"
11 #include "chrome/common/pref_names.h"
12 #include "content/public/browser/host_zoom_map.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"
20 #if defined(TOOLKIT_VIEWS)
21 #include "chrome/browser/defaults.h"
22 #include "ui/views/controls/textfield/textfield.h"
25 #if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS)
26 #include "chrome/browser/themes/theme_service.h"
27 #include "chrome/browser/themes/theme_service_factory.h"
28 #include "ui/views/linux_ui/linux_ui.h"
31 namespace renderer_preferences_util
{
33 void UpdateFromSystemSettings(content::RendererPreferences
* prefs
,
35 content::WebContents
* web_contents
) {
36 const PrefService
* pref_service
= profile
->GetPrefs();
37 prefs
->accept_languages
= pref_service
->GetString(prefs::kAcceptLanguages
);
38 prefs
->enable_referrers
= pref_service
->GetBoolean(prefs::kEnableReferrers
);
39 prefs
->enable_do_not_track
=
40 pref_service
->GetBoolean(prefs::kEnableDoNotTrack
);
41 ZoomController
* zoom_controller
=
42 ZoomController::FromWebContents(web_contents
);
43 if (zoom_controller
) {
44 prefs
->default_zoom_level
= zoom_controller
->GetDefaultZoomLevel();
46 prefs
->default_zoom_level
=
47 content::HostZoomMap::GetDefaultForBrowserContext(
48 web_contents
->GetBrowserContext())->GetDefaultZoomLevel();
51 #if defined(USE_DEFAULT_RENDER_THEME)
52 prefs
->focus_ring_color
= SkColorSetRGB(0x4D, 0x90, 0xFE);
53 #if defined(OS_CHROMEOS)
54 // This color is 0x544d90fe modulated with 0xffffff.
55 prefs
->active_selection_bg_color
= SkColorSetRGB(0xCB, 0xE4, 0xFA);
56 prefs
->active_selection_fg_color
= SK_ColorBLACK
;
57 prefs
->inactive_selection_bg_color
= SkColorSetRGB(0xEA, 0xEA, 0xEA);
58 prefs
->inactive_selection_fg_color
= SK_ColorBLACK
;
62 #if defined(TOOLKIT_VIEWS)
63 prefs
->caret_blink_interval
= views::Textfield::GetCaretBlinkMs() / 1000.0;
64 if (browser_defaults::kShowLinkDisambiguationPopup
) {
65 prefs
->tap_multiple_targets_strategy
=
66 content::TapMultipleTargetsStrategy::
67 TAP_MULTIPLE_TARGETS_STRATEGY_POPUP
;
69 prefs
->tap_multiple_targets_strategy
=
70 content::TapMultipleTargetsStrategy::TAP_MULTIPLE_TARGETS_STRATEGY_NONE
;
74 #if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS)
75 views::LinuxUI
* linux_ui
= views::LinuxUI::instance();
77 if (ThemeServiceFactory::GetForProfile(profile
)->UsingSystemTheme()) {
78 prefs
->focus_ring_color
= linux_ui
->GetFocusRingColor();
79 prefs
->thumb_active_color
= linux_ui
->GetThumbActiveColor();
80 prefs
->thumb_inactive_color
= linux_ui
->GetThumbInactiveColor();
81 prefs
->track_color
= linux_ui
->GetTrackColor();
82 prefs
->active_selection_bg_color
= linux_ui
->GetActiveSelectionBgColor();
83 prefs
->active_selection_fg_color
= linux_ui
->GetActiveSelectionFgColor();
84 prefs
->inactive_selection_bg_color
=
85 linux_ui
->GetInactiveSelectionBgColor();
86 prefs
->inactive_selection_fg_color
=
87 linux_ui
->GetInactiveSelectionFgColor();
90 // If we have a linux_ui object, set the caret blink interval regardless of
91 // whether we're in native theme mode.
92 prefs
->caret_blink_interval
= linux_ui
->GetCursorBlinkInterval();
96 #if defined(OS_LINUX) || defined(OS_ANDROID)
97 CR_DEFINE_STATIC_LOCAL(const gfx::FontRenderParams
, params
,
98 (gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(true), NULL
)));
99 prefs
->should_antialias_text
= params
.antialiasing
;
100 prefs
->use_subpixel_positioning
= params
.subpixel_positioning
;
101 prefs
->hinting
= params
.hinting
;
102 prefs
->use_autohinter
= params
.autohinter
;
103 prefs
->use_bitmaps
= params
.use_bitmaps
;
104 prefs
->subpixel_rendering
= params
.subpixel_rendering
;
107 #if !defined(OS_MACOSX)
108 prefs
->plugin_fullscreen_allowed
=
109 pref_service
->GetBoolean(prefs::kFullscreenAllowed
);
113 } // namespace renderer_preferences_util