Process Alt-Svc headers.
[chromium-blink-merge.git] / content / shell / app / blink_test_platform_support_win.cc
blobd61223271f0387f7d6dac0456dea30be801522ee
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
3 // found in the LICENSE file.
5 #include "content/shell/app/blink_test_platform_support.h"
7 #include <windows.h>
8 #include <iostream>
9 #include <list>
10 #include <string>
12 #include "base/command_line.h"
13 #include "base/files/file_path.h"
14 #include "base/files/file_util.h"
15 #include "base/logging.h"
16 #include "base/path_service.h"
17 #include "base/strings/utf_string_conversions.h"
18 #include "content/shell/common/shell_switches.h"
19 #include "ui/gfx/win/direct_write.h"
21 #define SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(struct_name, member) \
22 offsetof(struct_name, member) + \
23 (sizeof static_cast<struct_name*>(0)->member)
24 #define NONCLIENTMETRICS_SIZE_PRE_VISTA \
25 SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(NONCLIENTMETRICS, lfMessageFont)
27 namespace content {
29 namespace {
31 bool SetupFonts() {
32 // Load Ahem font.
33 // AHEM____.TTF is copied to the directory of DumpRenderTree.exe by
34 // WebKit.gyp.
35 base::FilePath base_path;
36 PathService::Get(base::DIR_MODULE, &base_path);
37 base::FilePath font_path =
38 base_path.Append(FILE_PATH_LITERAL("/AHEM____.TTF"));
40 // We do one of two registrations:
41 // 1. For GDI font rendering via ::AddFontMemResourceEx.
42 // 2. For DirectWrite rendering by appending a command line flag that tells
43 // the sandbox policy/warmup to grant access to the given path.
44 if (gfx::win::ShouldUseDirectWrite()) {
45 // DirectWrite sandbox registration.
46 base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
47 command_line.AppendSwitchASCII(switches::kRegisterFontFiles,
48 base::WideToUTF8(font_path.value()));
49 } else {
50 // GDI registration.
51 std::string font_buffer;
52 if (!base::ReadFileToString(font_path, &font_buffer)) {
53 std::cerr << "Failed to load font " << base::WideToUTF8(font_path.value())
54 << "\n";
55 return false;
58 DWORD num_fonts = 1;
59 HANDLE font_handle =
60 ::AddFontMemResourceEx(const_cast<char*>(font_buffer.c_str()),
61 font_buffer.length(),
63 &num_fonts);
64 if (!font_handle) {
65 std::cerr << "Failed to register Ahem font\n";
66 return false;
70 return true;
73 } // namespace
75 bool CheckLayoutSystemDeps() {
76 std::list<std::string> errors;
78 // This metric will be 17 when font size is "Normal".
79 // The size of drop-down menus depends on it.
80 if (::GetSystemMetrics(SM_CXVSCROLL) != 17)
81 errors.push_back("Must use normal size fonts (96 dpi).");
83 // Check that we're using the default system fonts.
84 OSVERSIONINFO version_info = {0};
85 version_info.dwOSVersionInfoSize = sizeof(version_info);
86 ::GetVersionEx(&version_info);
87 bool is_vista_or_later = (version_info.dwMajorVersion >= 6);
88 NONCLIENTMETRICS metrics = {0};
89 metrics.cbSize = is_vista_or_later ? sizeof(NONCLIENTMETRICS)
90 : NONCLIENTMETRICS_SIZE_PRE_VISTA;
91 bool success = !!::SystemParametersInfo(
92 SPI_GETNONCLIENTMETRICS, metrics.cbSize, &metrics, 0);
93 CHECK(success);
94 LOGFONTW* system_fonts[] =
95 {&metrics.lfStatusFont, &metrics.lfMenuFont, &metrics.lfSmCaptionFont};
96 const wchar_t* required_font = is_vista_or_later ? L"Segoe UI" : L"Tahoma";
97 int required_font_size = is_vista_or_later ? -12 : -11;
98 for (size_t i = 0; i < arraysize(system_fonts); ++i) {
99 if (system_fonts[i]->lfHeight != required_font_size ||
100 wcscmp(required_font, system_fonts[i]->lfFaceName)) {
101 errors.push_back(is_vista_or_later
102 ? "Must use either the Aero or Basic theme."
103 : "Must use the default XP theme (Luna).");
104 break;
108 for (std::list<std::string>::iterator it = errors.begin(); it != errors.end();
109 ++it) {
110 std::cerr << *it << "\n";
112 return errors.empty();
115 bool BlinkTestPlatformInitialize() {
116 return SetupFonts();
119 } // namespace content