Commit 59b9fe7e authored by ananta's avatar ananta Committed by Commit bot

Avoid calling the GetSystemMetrics API in the renderer process on Windows to...

Avoid calling the GetSystemMetrics API in the renderer process on Windows to get the scrollbar metrics.

It appears that this call takes a long time on certain Windows 8 configurations because the call triggers a load
of the uxtheme.dll which fails and retries every time. This is presumably due to the Win32K lockdown mode on Windows 8+.

Fix is to send the scrollbar metrics values we are interested in as part of the RendererPrefs structure. In the renderer
these are saved as static values in the WebThemeEngineImpl class.

1) Note that not all of the cache settings are currently used - SM_CYHSCROLL,
SM_CYVSCROLL, and SM_CXHSCROLL are cached for possible future usage.

2. These repeated attempts to load uxtheme.dll only occur in some (ill-defined)
situations, having to do with what theme is selected and other factors

BUG=472790

Review URL: https://codereview.chromium.org/1054243002

Cr-Commit-Position: refs/heads/master@{#323999}
parent bd58f100
......@@ -31,11 +31,6 @@
#include "ui/views/linux_ui/linux_ui.h"
#endif
#if defined(OS_WIN)
#include "base/win/win_util.h"
#include "ui/gfx/platform_font_win.h"
#endif
namespace renderer_preferences_util {
void UpdateFromSystemSettings(content::RendererPreferences* prefs,
......@@ -121,31 +116,6 @@ void UpdateFromSystemSettings(content::RendererPreferences* prefs,
prefs->plugin_fullscreen_allowed =
pref_service->GetBoolean(prefs::kFullscreenAllowed);
#endif
#if defined(OS_WIN)
NONCLIENTMETRICS_XP metrics = {0};
base::win::GetNonClientMetrics(&metrics);
prefs->caption_font_family_name = metrics.lfCaptionFont.lfFaceName;
prefs->caption_font_height = gfx::PlatformFontWin::GetFontSize(
metrics.lfCaptionFont);
prefs->small_caption_font_family_name = metrics.lfSmCaptionFont.lfFaceName;
prefs->small_caption_font_height = gfx::PlatformFontWin::GetFontSize(
metrics.lfSmCaptionFont);
prefs->menu_font_family_name = metrics.lfMenuFont.lfFaceName;
prefs->menu_font_height = gfx::PlatformFontWin::GetFontSize(
metrics.lfMenuFont);
prefs->status_font_family_name = metrics.lfStatusFont.lfFaceName;
prefs->status_font_height = gfx::PlatformFontWin::GetFontSize(
metrics.lfStatusFont);
prefs->message_font_family_name = metrics.lfMessageFont.lfFaceName;
prefs->message_font_height = gfx::PlatformFontWin::GetFontSize(
metrics.lfMessageFont);
#endif
}
} // namespace renderer_preferences_util
......@@ -89,6 +89,8 @@
#if defined(OS_WIN)
#include "base/win/win_util.h"
#include "ui/gfx/platform_font_win.h"
#include "ui/gfx/win/dpi.h"
#endif
using base::TimeDelta;
......@@ -124,6 +126,40 @@ void DismissVirtualKeyboardTask() {
}
}
}
void GetWindowsSpecificPrefs(RendererPreferences* prefs) {
NONCLIENTMETRICS_XP metrics = {0};
base::win::GetNonClientMetrics(&metrics);
prefs->caption_font_family_name = metrics.lfCaptionFont.lfFaceName;
prefs->caption_font_height = gfx::PlatformFontWin::GetFontSize(
metrics.lfCaptionFont);
prefs->small_caption_font_family_name = metrics.lfSmCaptionFont.lfFaceName;
prefs->small_caption_font_height = gfx::PlatformFontWin::GetFontSize(
metrics.lfSmCaptionFont);
prefs->menu_font_family_name = metrics.lfMenuFont.lfFaceName;
prefs->menu_font_height = gfx::PlatformFontWin::GetFontSize(
metrics.lfMenuFont);
prefs->status_font_family_name = metrics.lfStatusFont.lfFaceName;
prefs->status_font_height = gfx::PlatformFontWin::GetFontSize(
metrics.lfStatusFont);
prefs->message_font_family_name = metrics.lfMessageFont.lfFaceName;
prefs->message_font_height = gfx::PlatformFontWin::GetFontSize(
metrics.lfMessageFont);
prefs->vertical_scroll_bar_width_in_dips =
gfx::win::GetSystemMetricsInDIP(SM_CXVSCROLL);
prefs->horizontal_scroll_bar_height_in_dips =
gfx::win::GetSystemMetricsInDIP(SM_CYHSCROLL);
prefs->arrow_bitmap_height_vertical_scroll_bar_in_dips =
gfx::win::GetSystemMetricsInDIP(SM_CYVSCROLL);
prefs->arrow_bitmap_width_horizontal_scroll_bar_in_dips =
gfx::win::GetSystemMetricsInDIP(SM_CXHSCROLL);
}
#endif
} // namespace
......@@ -268,6 +304,9 @@ bool RenderViewHostImpl::CreateRenderView(
ViewMsg_New_Params params;
params.renderer_preferences =
delegate_->GetRendererPrefs(GetProcess()->GetBrowserContext());
#if defined(OS_WIN)
GetWindowsSpecificPrefs(&params.renderer_preferences);
#endif
params.web_preferences = GetWebkitPreferences();
params.view_id = GetRoutingID();
params.main_frame_routing_id = main_frame_routing_id_;
......
......@@ -15,6 +15,24 @@ using blink::WebRect;
using blink::WebThemeEngine;
namespace content {
namespace {
#if defined(OS_WIN)
// The scrollbar metrics default to 17 dips which is the default value on
// Windows in most cases.
int32 g_vertical_scroll_bar_width = 17;
// The height of a horizontal scroll bar in dips.
int32 g_horizontal_scroll_bar_height = 17;
// The height of the arrow bitmap on a vertical scroll bar in dips.
int32 g_vertical_arrow_bitmap_height = 17;
// The width of the arrow bitmap on a horizontal scroll bar in dips.
int32 g_horizontal_arrow_bitmap_width = 17;
#endif
} // namespace
static ui::NativeTheme::Part NativeThemePart(
WebThemeEngine::Part part) {
......@@ -162,9 +180,28 @@ static void GetNativeThemeExtraParams(
blink::WebSize WebThemeEngineImpl::getSize(WebThemeEngine::Part part) {
ui::NativeTheme::ExtraParams extra;
return ui::NativeTheme::instance()->GetPartSize(NativeThemePart(part),
ui::NativeTheme::kNormal,
extra);
ui::NativeTheme::Part native_theme_part = NativeThemePart(part);
#if defined(OS_WIN)
switch (native_theme_part) {
case ui::NativeTheme::kScrollbarDownArrow:
case ui::NativeTheme::kScrollbarLeftArrow:
case ui::NativeTheme::kScrollbarRightArrow:
case ui::NativeTheme::kScrollbarUpArrow:
case ui::NativeTheme::kScrollbarHorizontalThumb:
case ui::NativeTheme::kScrollbarVerticalThumb:
case ui::NativeTheme::kScrollbarHorizontalTrack:
case ui::NativeTheme::kScrollbarVerticalTrack: {
return gfx::Size(g_vertical_scroll_bar_width,
g_vertical_scroll_bar_width);
}
default:
break;
}
#endif
return ui::NativeTheme::instance()->GetPartSize(native_theme_part,
ui::NativeTheme::kNormal,
extra);
}
void WebThemeEngineImpl::paint(
......@@ -199,4 +236,18 @@ void WebThemeEngineImpl::paintStateTransition(blink::WebCanvas* canvas,
gfx::Rect(rect));
}
#if defined(OS_WIN)
// static
void WebThemeEngineImpl::cacheScrollBarMetrics(
int32 vertical_scroll_bar_width,
int32 horizontal_scroll_bar_height,
int32 vertical_arrow_bitmap_height,
int32 horizontal_arrow_bitmap_width) {
g_vertical_scroll_bar_width = vertical_scroll_bar_width;
g_horizontal_scroll_bar_height = horizontal_scroll_bar_height;
g_vertical_arrow_bitmap_height = vertical_arrow_bitmap_height;
g_horizontal_arrow_bitmap_width = horizontal_arrow_bitmap_width;
}
#endif
} // namespace content
......@@ -25,6 +25,14 @@ class WebThemeEngineImpl : public blink::WebThemeEngine {
blink::WebThemeEngine::State endState,
double progress,
const blink::WebRect& rect);
#if defined(OS_WIN)
// Caches the scrollbar metrics.
static void cacheScrollBarMetrics(int32 vertical_scroll_bar_width,
int32 horizontal_scroll_bar_height,
int32 vertical_arrow_bitmap_height,
int32 horizontal_arrow_bitmap_width);
#endif
};
} // namespace content
......
......@@ -252,6 +252,8 @@ IPC_STRUCT_TRAITS_BEGIN(content::RendererPreferences)
IPC_STRUCT_TRAITS_MEMBER(plugin_fullscreen_allowed)
IPC_STRUCT_TRAITS_MEMBER(use_video_overlay_for_embedded_encrypted_video)
IPC_STRUCT_TRAITS_MEMBER(use_view_overlay_for_all_video)
IPC_STRUCT_TRAITS_MEMBER(network_contry_iso)
#if defined(OS_WIN)
IPC_STRUCT_TRAITS_MEMBER(caption_font_family_name)
IPC_STRUCT_TRAITS_MEMBER(caption_font_height)
IPC_STRUCT_TRAITS_MEMBER(small_caption_font_family_name)
......@@ -262,7 +264,11 @@ IPC_STRUCT_TRAITS_BEGIN(content::RendererPreferences)
IPC_STRUCT_TRAITS_MEMBER(status_font_height)
IPC_STRUCT_TRAITS_MEMBER(message_font_family_name)
IPC_STRUCT_TRAITS_MEMBER(message_font_height)
IPC_STRUCT_TRAITS_MEMBER(network_contry_iso)
IPC_STRUCT_TRAITS_MEMBER(vertical_scroll_bar_width_in_dips)
IPC_STRUCT_TRAITS_MEMBER(horizontal_scroll_bar_height_in_dips)
IPC_STRUCT_TRAITS_MEMBER(arrow_bitmap_height_vertical_scroll_bar_in_dips)
IPC_STRUCT_TRAITS_MEMBER(arrow_bitmap_width_horizontal_scroll_bar_in_dips)
#endif
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(content::CookieData)
......
......@@ -38,13 +38,19 @@ RendererPreferences::RendererPreferences()
disable_client_blocked_error_page(false),
plugin_fullscreen_allowed(true),
use_video_overlay_for_embedded_encrypted_video(false),
use_view_overlay_for_all_video(false),
caption_font_height(0),
use_view_overlay_for_all_video(false)
#if defined(OS_WIN)
, caption_font_height(0),
small_caption_font_height(0),
menu_font_height(0),
status_font_height(0),
message_font_height(0) {
}
message_font_height(0),
vertical_scroll_bar_width_in_dips(0),
horizontal_scroll_bar_height_in_dips(0),
arrow_bitmap_height_vertical_scroll_bar_in_dips(0),
arrow_bitmap_width_horizontal_scroll_bar_in_dips(0)
#endif
{}
RendererPreferences::~RendererPreferences() { }
......
......@@ -135,6 +135,10 @@ struct CONTENT_EXPORT RendererPreferences {
// encrypted video. Currently only used by Android.
bool use_view_overlay_for_all_video;
// Country iso of the mobile network for content detection purpose.
std::string network_contry_iso;
#if defined(OS_WIN)
// The default system font settings for caption, small caption, menu and
// status messages. Used only by Windows.
base::string16 caption_font_family_name;
......@@ -152,8 +156,19 @@ struct CONTENT_EXPORT RendererPreferences {
base::string16 message_font_family_name;
int32 message_font_height;
// Contry iso of the mobile network for content detection purpose.
std::string network_contry_iso;
// The width of a vertical scroll bar in dips.
int32 vertical_scroll_bar_width_in_dips;
// The height of a horizontal scroll bar in dips.
int32 horizontal_scroll_bar_height_in_dips;
// The height of the arrow bitmap on a vertical scroll bar in dips.
int32 arrow_bitmap_height_vertical_scroll_bar_in_dips;
// The width of the arrow bitmap on a horizontal scroll bar in dips.
int32 arrow_bitmap_width_horizontal_scroll_bar_in_dips;
#endif
};
} // namespace content
......
......@@ -2754,7 +2754,9 @@ void RenderViewImpl::OnSetRendererPrefs(
std::string old_accept_languages = renderer_preferences_.accept_languages;
renderer_preferences_ = renderer_prefs;
UpdateFontRenderingFromRendererPrefs();
UpdateThemePrefs();
#if defined(USE_DEFAULT_RENDER_THEME)
if (renderer_prefs.use_custom_colors) {
......
......@@ -766,6 +766,13 @@ class CONTENT_EXPORT RenderViewImpl
navigation_gesture_ = gesture;
}
// Platform specific theme preferences if any are updated here.
#if defined(OS_WIN)
void UpdateThemePrefs();
#else
void UpdateThemePrefs() {}
#endif
// ---------------------------------------------------------------------------
// ADDING NEW FUNCTIONS? Please keep private functions alphabetized and put
// it in the same order in the .cc file as it was in the header.
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "content/public/common/renderer_preferences.h"
#include "content/child/webthemeengine_impl_default.h"
#include "content/renderer/render_view_impl.h"
#include "third_party/WebKit/public/web/win/WebFontRendering.h"
#include "ui/gfx/font_render_params.h"
......@@ -33,4 +34,12 @@ void RenderViewImpl::UpdateFontRenderingFromRendererPrefs() {
prefs.subpixel_rendering));
}
void RenderViewImpl::UpdateThemePrefs() {
WebThemeEngineImpl::cacheScrollBarMetrics(
renderer_preferences_.vertical_scroll_bar_width_in_dips,
renderer_preferences_.horizontal_scroll_bar_height_in_dips,
renderer_preferences_.arrow_bitmap_height_vertical_scroll_bar_in_dips,
renderer_preferences_.arrow_bitmap_width_horizontal_scroll_bar_in_dips);
}
} // namespace content
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment