OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/shell/app/webkit_test_platform_support.h" | 5 #include "content/shell/app/webkit_test_platform_support.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <iostream> | 8 #include <iostream> |
9 #include <list> | 9 #include <list> |
10 #include <string> | 10 #include <string> |
11 | 11 |
| 12 #include "base/command_line.h" |
12 #include "base/file_util.h" | 13 #include "base/file_util.h" |
13 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
14 #include "base/logging.h" | 15 #include "base/logging.h" |
15 #include "base/path_service.h" | 16 #include "base/path_service.h" |
16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "content/shell/common/shell_switches.h" |
17 | 19 |
18 #define SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(struct_name, member) \ | 20 #define SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(struct_name, member) \ |
19 offsetof(struct_name, member) + \ | 21 offsetof(struct_name, member) + \ |
20 (sizeof static_cast<struct_name*>(0)->member) | 22 (sizeof static_cast<struct_name*>(0)->member) |
21 #define NONCLIENTMETRICS_SIZE_PRE_VISTA \ | 23 #define NONCLIENTMETRICS_SIZE_PRE_VISTA \ |
22 SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(NONCLIENTMETRICS, lfMessageFont) | 24 SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(NONCLIENTMETRICS, lfMessageFont) |
23 | 25 |
24 namespace content { | 26 namespace content { |
25 | 27 |
26 namespace { | 28 namespace { |
27 | 29 |
28 bool SetupFonts() { | 30 bool SetupFonts() { |
29 // Load Ahem font. | 31 // Load Ahem font. |
30 // AHEM____.TTF is copied to the directory of DumpRenderTree.exe by | 32 // AHEM____.TTF is copied to the directory of DumpRenderTree.exe by |
31 // WebKit.gyp. | 33 // WebKit.gyp. |
32 base::FilePath base_path; | 34 base::FilePath base_path; |
33 PathService::Get(base::DIR_MODULE, &base_path); | 35 PathService::Get(base::DIR_MODULE, &base_path); |
34 base::FilePath font_path = | 36 base::FilePath font_path = |
35 base_path.Append(FILE_PATH_LITERAL("/AHEM____.TTF")); | 37 base_path.Append(FILE_PATH_LITERAL("/AHEM____.TTF")); |
36 | 38 |
| 39 // We do two registrations: |
| 40 // 1. For GDI font rendering via ::AddFontMemResourceEx. |
| 41 // 2. For DirectWrite rendering by appending a command line flag that tells |
| 42 // the sandbox policy/warmup to grant access to the given path. |
| 43 |
| 44 // GDI registration. |
37 std::string font_buffer; | 45 std::string font_buffer; |
38 if (!base::ReadFileToString(font_path, &font_buffer)) { | 46 if (!base::ReadFileToString(font_path, &font_buffer)) { |
39 std::cerr << "Failed to load font " << base::WideToUTF8(font_path.value()) | 47 std::cerr << "Failed to load font " << base::WideToUTF8(font_path.value()) |
40 << "\n"; | 48 << "\n"; |
41 return false; | 49 return false; |
42 } | 50 } |
43 | 51 |
44 DWORD num_fonts = 1; | 52 DWORD num_fonts = 1; |
45 HANDLE font_handle = | 53 HANDLE font_handle = |
46 ::AddFontMemResourceEx(const_cast<char*>(font_buffer.c_str()), | 54 ::AddFontMemResourceEx(const_cast<char*>(font_buffer.c_str()), |
47 font_buffer.length(), | 55 font_buffer.length(), |
48 0, | 56 0, |
49 &num_fonts); | 57 &num_fonts); |
50 if (!font_handle) { | 58 if (!font_handle) { |
51 std::cerr << "Failed to register Ahem font\n"; | 59 std::cerr << "Failed to register Ahem font\n"; |
52 return false; | 60 return false; |
53 } | 61 } |
| 62 |
| 63 // DirectWrite sandbox registration. |
| 64 CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); |
| 65 command_line.AppendSwitchASCII(switches::kRegisterFontFiles, |
| 66 base::WideToUTF8(font_path.value())); |
| 67 |
54 return true; | 68 return true; |
55 } | 69 } |
56 | 70 |
57 } // namespace | 71 } // namespace |
58 | 72 |
59 bool CheckLayoutSystemDeps() { | 73 bool CheckLayoutSystemDeps() { |
60 std::list<std::string> errors; | 74 std::list<std::string> errors; |
61 | 75 |
62 // This metric will be 17 when font size is "Normal". | 76 // This metric will be 17 when font size is "Normal". |
63 // The size of drop-down menus depends on it. | 77 // The size of drop-down menus depends on it. |
(...skipping 30 matching lines...) Expand all Loading... |
94 std::cerr << *it << "\n"; | 108 std::cerr << *it << "\n"; |
95 } | 109 } |
96 return errors.empty(); | 110 return errors.empty(); |
97 } | 111 } |
98 | 112 |
99 bool WebKitTestPlatformInitialize() { | 113 bool WebKitTestPlatformInitialize() { |
100 return SetupFonts(); | 114 return SetupFonts(); |
101 } | 115 } |
102 | 116 |
103 } // namespace content | 117 } // namespace content |
OLD | NEW |