Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: content/renderer/renderer_main_platform_delegate_win.cc

Issue 209163002: Support DirectWrite with sandbox on (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add todo Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« content/common/sandbox_win.cc ('K') | « content/common/sandbox_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
14 #include "content/common/sandbox_win.h"
12 #include "content/public/common/content_switches.h" 15 #include "content/public/common/content_switches.h"
13 #include "content/public/common/injection_test_win.h" 16 #include "content/public/common/injection_test_win.h"
14 #include "content/public/renderer/render_thread.h" 17 #include "content/public/renderer/render_thread.h"
15 #include "content/renderer/render_thread_impl.h" 18 #include "content/renderer/render_thread_impl.h"
16 #include "sandbox/win/src/sandbox.h" 19 #include "sandbox/win/src/sandbox.h"
17 #include "skia/ext/vector_platform_device_emf_win.h" 20 #include "skia/ext/vector_platform_device_emf_win.h"
18 #include "third_party/icu/source/i18n/unicode/timezone.h" 21 #include "third_party/icu/source/i18n/unicode/timezone.h"
19 #include "third_party/skia/include/ports/SkTypeface_win.h" 22 #include "third_party/skia/include/ports/SkTypeface_win.h"
20 23
21 #ifdef ENABLE_VTUNE_JIT_INTERFACE 24 #ifdef ENABLE_VTUNE_JIT_INTERFACE
22 #include "v8/src/third_party/vtune/v8-vtune.h" 25 #include "v8/src/third_party/vtune/v8-vtune.h"
23 #endif 26 #endif
24 27
28 #include <dwrite.h>
29
25 namespace content { 30 namespace content {
26 namespace { 31 namespace {
27 32
28 // Windows-only skia sandbox support 33 // Windows-only skia sandbox support
34 // These are used for GDI-path rendering.
29 void SkiaPreCacheFont(const LOGFONT& logfont) { 35 void SkiaPreCacheFont(const LOGFONT& logfont) {
30 RenderThread* render_thread = RenderThread::Get(); 36 RenderThread* render_thread = RenderThread::Get();
31 if (render_thread) { 37 if (render_thread) {
32 render_thread->PreCacheFont(logfont); 38 render_thread->PreCacheFont(logfont);
33 } 39 }
34 } 40 }
35 41
36 void SkiaPreCacheFontCharacters(const LOGFONT& logfont, 42 void SkiaPreCacheFontCharacters(const LOGFONT& logfont,
37 const wchar_t* text, 43 const wchar_t* text,
38 unsigned int text_length) { 44 unsigned int text_length) {
39 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current(); 45 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
40 if (render_thread_impl) { 46 if (render_thread_impl) {
41 render_thread_impl->PreCacheFontCharacters( 47 render_thread_impl->PreCacheFontCharacters(
42 logfont, 48 logfont,
43 base::string16(text, text_length)); 49 base::string16(text, text_length));
44 } 50 }
45 } 51 }
46 52
53 // Windows-only DirectWrite support. These warm up the DirectWrite paths
54 // before sandbox lock down to allow Skia access to the Font Manager service.
55 bool CreateDirectWriteFactory(IDWriteFactory** factory) {
56 typedef decltype(DWriteCreateFactory)* DWriteCreateFactoryProc;
57 DWriteCreateFactoryProc dwrite_create_factory_proc =
58 reinterpret_cast<DWriteCreateFactoryProc>(
59 GetProcAddress(LoadLibraryW(L"dwrite.dll"), "DWriteCreateFactory"));
60 if (!dwrite_create_factory_proc)
61 return false;
62 CHECK(SUCCEEDED(
63 dwrite_create_factory_proc(DWRITE_FACTORY_TYPE_SHARED,
64 __uuidof(IDWriteFactory),
65 reinterpret_cast<IUnknown**>(factory))));
66 return true;
67 }
68
69 void WarmupDirectWrite() {
70 base::win::ScopedComPtr<IDWriteFactory> factory;
71 if (!CreateDirectWriteFactory(factory.Receive()))
72 return;
73
74 base::win::ScopedComPtr<IDWriteFontCollection> font_collection;
75 CHECK(SUCCEEDED(
76 factory->GetSystemFontCollection(font_collection.Receive(), FALSE)));
77 base::win::ScopedComPtr<IDWriteFontFamily> font_family;
78
79 UINT32 index;
80 BOOL exists;
81 CHECK(SUCCEEDED(
82 font_collection->FindFamilyName(L"Times New Roman", &index, &exists)));
83 CHECK(exists);
84 CHECK(
85 SUCCEEDED(font_collection->GetFontFamily(index, font_family.Receive())));
86 base::win::ScopedComPtr<IDWriteFont> font;
87 base::win::ScopedComPtr<IDWriteFontFace> font_face;
88 CHECK(SUCCEEDED(font_family->GetFirstMatchingFont(DWRITE_FONT_WEIGHT_NORMAL,
89 DWRITE_FONT_STRETCH_NORMAL,
90 DWRITE_FONT_STYLE_NORMAL,
91 font.Receive())));
92 CHECK(SUCCEEDED(font->CreateFontFace(font_face.Receive())));
93 DWRITE_GLYPH_METRICS gm;
94 UINT16 glyph = L'S';
95 CHECK(SUCCEEDED(font_face->GetDesignGlyphMetrics(&glyph, 1, &gm)));
96 }
97
47 } // namespace 98 } // namespace
48 99
49 RendererMainPlatformDelegate::RendererMainPlatformDelegate( 100 RendererMainPlatformDelegate::RendererMainPlatformDelegate(
50 const MainFunctionParams& parameters) 101 const MainFunctionParams& parameters)
51 : parameters_(parameters), 102 : parameters_(parameters),
52 sandbox_test_module_(NULL) { 103 sandbox_test_module_(NULL) {
53 } 104 }
54 105
55 RendererMainPlatformDelegate::~RendererMainPlatformDelegate() { 106 RendererMainPlatformDelegate::~RendererMainPlatformDelegate() {
56 } 107 }
(...skipping 11 matching lines...) Expand all
68 bool no_sandbox = command_line.HasSwitch(switches::kNoSandbox); 119 bool no_sandbox = command_line.HasSwitch(switches::kNoSandbox);
69 120
70 if (!no_sandbox) { 121 if (!no_sandbox) {
71 // ICU DateFormat class (used in base/time_format.cc) needs to get the 122 // ICU DateFormat class (used in base/time_format.cc) needs to get the
72 // Olson timezone ID by accessing the registry keys under 123 // Olson timezone ID by accessing the registry keys under
73 // HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones. 124 // HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones.
74 // After TimeZone::createDefault is called once here, the timezone ID is 125 // 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 126 // 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. 127 // is disabled, we don't have to make this dummy call.
77 scoped_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault()); 128 scoped_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault());
78 SkTypeface_SetEnsureLOGFONTAccessibleProc(SkiaPreCacheFont); 129
79 skia::SetSkiaEnsureTypefaceCharactersAccessible( 130 if (content::ShouldUseDirectWrite()) {
jam 2014/03/25 22:57:26 ditto
80 SkiaPreCacheFontCharacters); 131 WarmupDirectWrite();
132 } else {
133 SkTypeface_SetEnsureLOGFONTAccessibleProc(SkiaPreCacheFont);
134 skia::SetSkiaEnsureTypefaceCharactersAccessible(
135 SkiaPreCacheFontCharacters);
136 }
81 } 137 }
82 } 138 }
83 139
84 void RendererMainPlatformDelegate::PlatformUninitialize() { 140 void RendererMainPlatformDelegate::PlatformUninitialize() {
85 } 141 }
86 142
87 bool RendererMainPlatformDelegate::InitSandboxTests(bool no_sandbox) { 143 bool RendererMainPlatformDelegate::InitSandboxTests(bool no_sandbox) {
88 const CommandLine& command_line = parameters_.command_line; 144 const CommandLine& command_line = parameters_.command_line;
89 145
90 DVLOG(1) << "Started renderer with " << command_line.GetCommandLineString(); 146 DVLOG(1) << "Started renderer with " << command_line.GetCommandLineString();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 if (run_security_tests) { 189 if (run_security_tests) {
134 int test_count = 0; 190 int test_count = 0;
135 DVLOG(1) << "Running renderer security tests"; 191 DVLOG(1) << "Running renderer security tests";
136 BOOL result = run_security_tests(&test_count); 192 BOOL result = run_security_tests(&test_count);
137 CHECK(result) << "Test number " << test_count << " has failed."; 193 CHECK(result) << "Test number " << test_count << " has failed.";
138 } 194 }
139 } 195 }
140 } 196 }
141 197
142 } // namespace content 198 } // namespace content
OLDNEW
« content/common/sandbox_win.cc ('K') | « content/common/sandbox_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698