OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/renderer/renderer_main_platform_delegate.h" | 5 #include "content/renderer/renderer_main_platform_delegate.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
11 #include "base/win/scoped_comptr.h" | |
11 #include "base/win/win_util.h" | 12 #include "base/win/win_util.h" |
13 #include "base/win/windows_version.h" | |
12 #include "content/public/common/content_switches.h" | 14 #include "content/public/common/content_switches.h" |
13 #include "content/public/common/injection_test_win.h" | 15 #include "content/public/common/injection_test_win.h" |
14 #include "content/public/renderer/render_thread.h" | 16 #include "content/public/renderer/render_thread.h" |
15 #include "content/renderer/render_thread_impl.h" | 17 #include "content/renderer/render_thread_impl.h" |
16 #include "sandbox/win/src/sandbox.h" | 18 #include "sandbox/win/src/sandbox.h" |
17 #include "skia/ext/vector_platform_device_emf_win.h" | 19 #include "skia/ext/vector_platform_device_emf_win.h" |
18 #include "third_party/icu/source/i18n/unicode/timezone.h" | 20 #include "third_party/icu/source/i18n/unicode/timezone.h" |
19 #include "third_party/skia/include/ports/SkTypeface_win.h" | 21 #include "third_party/skia/include/ports/SkTypeface_win.h" |
20 | 22 |
21 #ifdef ENABLE_VTUNE_JIT_INTERFACE | 23 #ifdef ENABLE_VTUNE_JIT_INTERFACE |
22 #include "v8/src/third_party/vtune/v8-vtune.h" | 24 #include "v8/src/third_party/vtune/v8-vtune.h" |
23 #endif | 25 #endif |
24 | 26 |
27 #include <dwrite.h> | |
28 | |
25 namespace content { | 29 namespace content { |
26 namespace { | 30 namespace { |
27 | 31 |
28 // Windows-only skia sandbox support | 32 // Windows-only skia sandbox support |
33 // These are used for GDI-path rendering. | |
29 void SkiaPreCacheFont(const LOGFONT& logfont) { | 34 void SkiaPreCacheFont(const LOGFONT& logfont) { |
30 RenderThread* render_thread = RenderThread::Get(); | 35 RenderThread* render_thread = RenderThread::Get(); |
31 if (render_thread) { | 36 if (render_thread) { |
32 render_thread->PreCacheFont(logfont); | 37 render_thread->PreCacheFont(logfont); |
33 } | 38 } |
34 } | 39 } |
35 | 40 |
36 void SkiaPreCacheFontCharacters(const LOGFONT& logfont, | 41 void SkiaPreCacheFontCharacters(const LOGFONT& logfont, |
37 const wchar_t* text, | 42 const wchar_t* text, |
38 unsigned int text_length) { | 43 unsigned int text_length) { |
39 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current(); | 44 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current(); |
40 if (render_thread_impl) { | 45 if (render_thread_impl) { |
41 render_thread_impl->PreCacheFontCharacters( | 46 render_thread_impl->PreCacheFontCharacters( |
42 logfont, | 47 logfont, |
43 base::string16(text, text_length)); | 48 base::string16(text, text_length)); |
44 } | 49 } |
45 } | 50 } |
46 | 51 |
52 // Windows-only DirectWrite support. These warm up the DirectWrite paths | |
53 // before sandbox lock down to allow Skia access to font data. | |
jschuh
2014/03/25 04:03:48
Nit: s/font data/the Font Manager service/
scottmg
2014/03/25 05:43:18
Done.
| |
54 bool CreateDirectWriteFactory(IDWriteFactory** factory) { | |
55 typedef decltype(DWriteCreateFactory) * DWriteCreateFactoryProc; | |
jschuh
2014/03/25 04:03:48
Nit: loose *
scottmg
2014/03/25 05:43:18
clang-format. But Done.
jschuh
2014/03/25 12:42:02
Yep, I've been bitten by clang-format repeatedly o
| |
56 DWriteCreateFactoryProc dwrite_create_factory_proc = | |
57 reinterpret_cast<DWriteCreateFactoryProc>( | |
58 GetProcAddress(LoadLibraryW(L"dwrite.dll"), "DWriteCreateFactory")); | |
59 if (!dwrite_create_factory_proc) | |
60 return false; | |
61 CHECK(SUCCEEDED( | |
62 dwrite_create_factory_proc(DWRITE_FACTORY_TYPE_SHARED, | |
63 __uuidof(IDWriteFactory), | |
64 reinterpret_cast<IUnknown**>(factory)))); | |
65 return true; | |
66 } | |
67 | |
68 void WarmupDirectWrite() { | |
69 if (base::win::GetVersion() < base::win::VERSION_VISTA) | |
70 return; | |
71 | |
72 base::win::ScopedComPtr<IDWriteFactory> factory; | |
73 if (!CreateDirectWriteFactory(factory.Receive())) | |
74 return; | |
75 | |
76 base::win::ScopedComPtr<IDWriteFontCollection> font_collection; | |
77 CHECK(SUCCEEDED( | |
78 factory->GetSystemFontCollection(font_collection.Receive(), FALSE))); | |
79 base::win::ScopedComPtr<IDWriteFontFamily> font_family; | |
80 | |
81 UINT32 index; | |
82 BOOL exists; | |
83 CHECK(SUCCEEDED( | |
84 font_collection->FindFamilyName(L"Times New Roman", &index, &exists))); | |
85 CHECK(exists); | |
86 CHECK( | |
87 SUCCEEDED(font_collection->GetFontFamily(index, font_family.Receive()))); | |
88 const DWRITE_FONT_WEIGHT weights[] = {DWRITE_FONT_WEIGHT_NORMAL, | |
89 DWRITE_FONT_WEIGHT_BOLD}; | |
90 base::win::ScopedComPtr<IDWriteFont> fonts[ARRAYSIZE(weights)]; | |
91 base::win::ScopedComPtr<IDWriteFontFace> font_faces[ARRAYSIZE(weights)]; | |
92 for (size_t i = 0; i < ARRAYSIZE(weights); ++i) { | |
jschuh
2014/03/25 04:03:48
Do you really needed to enumerate through the weig
scottmg
2014/03/25 05:43:18
Oops, thanks, probably not any more. Done. I'll re
| |
93 CHECK( | |
94 SUCCEEDED(font_family->GetFirstMatchingFont(weights[i], | |
95 DWRITE_FONT_STRETCH_NORMAL, | |
96 DWRITE_FONT_STYLE_NORMAL, | |
97 fonts[i].Receive()))); | |
98 CHECK(SUCCEEDED(fonts[i]->CreateFontFace(font_faces[i].Receive()))); | |
99 DWRITE_GLYPH_METRICS gm; | |
100 UINT16 glyph = L'S'; | |
101 CHECK(SUCCEEDED(font_faces[i]->GetDesignGlyphMetrics(&glyph, 1, &gm))); | |
102 } | |
103 } | |
104 | |
47 } // namespace | 105 } // namespace |
48 | 106 |
49 RendererMainPlatformDelegate::RendererMainPlatformDelegate( | 107 RendererMainPlatformDelegate::RendererMainPlatformDelegate( |
50 const MainFunctionParams& parameters) | 108 const MainFunctionParams& parameters) |
51 : parameters_(parameters), | 109 : parameters_(parameters), |
52 sandbox_test_module_(NULL) { | 110 sandbox_test_module_(NULL) { |
53 } | 111 } |
54 | 112 |
55 RendererMainPlatformDelegate::~RendererMainPlatformDelegate() { | 113 RendererMainPlatformDelegate::~RendererMainPlatformDelegate() { |
56 } | 114 } |
(...skipping 11 matching lines...) Expand all Loading... | |
68 bool no_sandbox = command_line.HasSwitch(switches::kNoSandbox); | 126 bool no_sandbox = command_line.HasSwitch(switches::kNoSandbox); |
69 | 127 |
70 if (!no_sandbox) { | 128 if (!no_sandbox) { |
71 // ICU DateFormat class (used in base/time_format.cc) needs to get the | 129 // ICU DateFormat class (used in base/time_format.cc) needs to get the |
72 // Olson timezone ID by accessing the registry keys under | 130 // Olson timezone ID by accessing the registry keys under |
73 // HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones. | 131 // HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones. |
74 // After TimeZone::createDefault is called once here, the timezone ID is | 132 // After TimeZone::createDefault is called once here, the timezone ID is |
75 // cached and there's no more need to access the registry. If the sandbox | 133 // cached and there's no more need to access the registry. If the sandbox |
76 // is disabled, we don't have to make this dummy call. | 134 // is disabled, we don't have to make this dummy call. |
77 scoped_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault()); | 135 scoped_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault()); |
78 SkTypeface_SetEnsureLOGFONTAccessibleProc(SkiaPreCacheFont); | 136 SkTypeface_SetEnsureLOGFONTAccessibleProc(SkiaPreCacheFont); |
jschuh
2014/03/25 04:03:48
You'll need to disable the GDI setup and both ends
scottmg
2014/03/25 05:43:18
At the moment, the about:flag isn't conditionalize
jschuh
2014/03/25 12:42:02
Yeah, that works. As long as the browser makes the
| |
79 skia::SetSkiaEnsureTypefaceCharactersAccessible( | 137 skia::SetSkiaEnsureTypefaceCharactersAccessible( |
80 SkiaPreCacheFontCharacters); | 138 SkiaPreCacheFontCharacters); |
139 | |
140 WarmupDirectWrite(); | |
jschuh
2014/03/25 04:03:48
This should be scoped to run only when DW is enabl
| |
81 } | 141 } |
82 } | 142 } |
83 | 143 |
84 void RendererMainPlatformDelegate::PlatformUninitialize() { | 144 void RendererMainPlatformDelegate::PlatformUninitialize() { |
85 } | 145 } |
86 | 146 |
87 bool RendererMainPlatformDelegate::InitSandboxTests(bool no_sandbox) { | 147 bool RendererMainPlatformDelegate::InitSandboxTests(bool no_sandbox) { |
88 const CommandLine& command_line = parameters_.command_line; | 148 const CommandLine& command_line = parameters_.command_line; |
89 | 149 |
90 DVLOG(1) << "Started renderer with " << command_line.GetCommandLineString(); | 150 DVLOG(1) << "Started renderer with " << command_line.GetCommandLineString(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 if (run_security_tests) { | 193 if (run_security_tests) { |
134 int test_count = 0; | 194 int test_count = 0; |
135 DVLOG(1) << "Running renderer security tests"; | 195 DVLOG(1) << "Running renderer security tests"; |
136 BOOL result = run_security_tests(&test_count); | 196 BOOL result = run_security_tests(&test_count); |
137 CHECK(result) << "Test number " << test_count << " has failed."; | 197 CHECK(result) << "Test number " << test_count << " has failed."; |
138 } | 198 } |
139 } | 199 } |
140 } | 200 } |
141 | 201 |
142 } // namespace content | 202 } // namespace content |
OLD | NEW |