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

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

Issue 1378353006: Implementation of dwrite font proxy and removal of dwrite font cache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename locals to match style guide Created 5 years, 1 month 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
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 <dwrite.h>
8
7 #include "base/command_line.h" 9 #include "base/command_line.h"
8 #include "base/logging.h" 10 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
11 #include "base/win/scoped_comptr.h" 13 #include "base/win/scoped_comptr.h"
12 #include "base/win/win_util.h" 14 #include "base/win/win_util.h"
13 #include "base/win/windows_version.h" 15 #include "base/win/windows_version.h"
14 #include "content/common/font_warmup_win.h" 16 #include "content/child/dwrite_font_proxy/dwrite_font_proxy_init_win.h"
15 #include "content/public/common/content_switches.h" 17 #include "content/public/common/content_switches.h"
16 #include "content/public/common/injection_test_win.h" 18 #include "content/public/common/injection_test_win.h"
17 #include "content/public/renderer/render_thread.h" 19 #include "content/public/renderer/render_thread.h"
18 #include "content/renderer/render_thread_impl.h" 20 #include "content/renderer/render_thread_impl.h"
19 #include "sandbox/win/src/sandbox.h" 21 #include "sandbox/win/src/sandbox.h"
20 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" 22 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
21 #include "third_party/WebKit/public/web/win/WebFontRendering.h" 23 #include "third_party/WebKit/public/web/win/WebFontRendering.h"
22 #include "third_party/icu/source/i18n/unicode/timezone.h" 24 #include "third_party/icu/source/i18n/unicode/timezone.h"
23 #include "third_party/skia/include/ports/SkTypeface_win.h" 25 #include "third_party/skia/include/ports/SkTypeface_win.h"
24 #include "ui/gfx/win/direct_write.h" 26 #include "ui/gfx/win/direct_write.h"
25 #include "ui/gfx/win/dpi.h" 27 #include "ui/gfx/win/dpi.h"
26 28
27 #include <dwrite.h>
28
29 namespace content { 29 namespace content {
30 namespace { 30 namespace {
31 31
32 // Windows-only skia sandbox support 32 // Windows-only skia sandbox support
33 // These are used for GDI-path rendering. 33 // These are used for GDI-path rendering.
34 void SkiaPreCacheFont(const LOGFONT& logfont) { 34 void SkiaPreCacheFont(const LOGFONT& logfont) {
35 RenderThread* render_thread = RenderThread::Get(); 35 RenderThread* render_thread = RenderThread::Get();
36 if (render_thread) { 36 if (render_thread) {
37 render_thread->PreCacheFont(logfont); 37 render_thread->PreCacheFont(logfont);
38 } 38 }
39 } 39 }
40 40
41 } // namespace 41 } // namespace
42 42
43 RendererMainPlatformDelegate::RendererMainPlatformDelegate( 43 RendererMainPlatformDelegate::RendererMainPlatformDelegate(
44 const MainFunctionParams& parameters) 44 const MainFunctionParams& parameters)
45 : parameters_(parameters), 45 : parameters_(parameters),
46 sandbox_test_module_(NULL) { 46 sandbox_test_module_(NULL) {
47 } 47 }
48 48
49 RendererMainPlatformDelegate::~RendererMainPlatformDelegate() { 49 RendererMainPlatformDelegate::~RendererMainPlatformDelegate() {
50 } 50 }
51 51
52 // Helper function to cast RenderThred to IPC::Sender so we can Bind() it.
53 IPC::Sender* RenderThreadGetAsSender() {
54 return RenderThread::Get();
55 }
56
52 void RendererMainPlatformDelegate::PlatformInitialize() { 57 void RendererMainPlatformDelegate::PlatformInitialize() {
53 const base::CommandLine& command_line = parameters_.command_line; 58 const base::CommandLine& command_line = parameters_.command_line;
54 59
55 // Be mindful of what resources you acquire here. They can be used by 60 // Be mindful of what resources you acquire here. They can be used by
56 // malicious code if the renderer gets compromised. 61 // malicious code if the renderer gets compromised.
57 bool no_sandbox = command_line.HasSwitch(switches::kNoSandbox); 62 bool no_sandbox = command_line.HasSwitch(switches::kNoSandbox);
58 63
59 bool use_direct_write = gfx::win::ShouldUseDirectWrite(); 64 bool use_direct_write = gfx::win::ShouldUseDirectWrite();
60 if (!no_sandbox) { 65 if (!no_sandbox) {
61 // ICU DateFormat class (used in base/time_format.cc) needs to get the 66 // ICU DateFormat class (used in base/time_format.cc) needs to get the
62 // Olson timezone ID by accessing the registry keys under 67 // Olson timezone ID by accessing the registry keys under
63 // HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones. 68 // HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones.
64 // After TimeZone::createDefault is called once here, the timezone ID is 69 // After TimeZone::createDefault is called once here, the timezone ID is
65 // cached and there's no more need to access the registry. If the sandbox 70 // cached and there's no more need to access the registry. If the sandbox
66 // is disabled, we don't have to make this dummy call. 71 // is disabled, we don't have to make this dummy call.
67 scoped_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault()); 72 scoped_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault());
68 73
69 if (use_direct_write) { 74 if (use_direct_write) {
70 WarmupDirectWrite(); 75 InitializeDWriteFontProxy(base::Bind(&RenderThreadGetAsSender));
71 } else { 76 } else {
72 SkTypeface_SetEnsureLOGFONTAccessibleProc(SkiaPreCacheFont); 77 SkTypeface_SetEnsureLOGFONTAccessibleProc(SkiaPreCacheFont);
73 } 78 }
74 } 79 }
75 blink::WebFontRendering::setUseDirectWrite(use_direct_write); 80 blink::WebFontRendering::setUseDirectWrite(use_direct_write);
76 blink::WebFontRendering::setDeviceScaleFactor(gfx::GetDPIScale()); 81 blink::WebFontRendering::setDeviceScaleFactor(gfx::GetDPIScale());
77 } 82 }
78 83
79 void RendererMainPlatformDelegate::PlatformUninitialize() { 84 void RendererMainPlatformDelegate::PlatformUninitialize() {
85 UninitializeDWriteFontProxy();
80 } 86 }
81 87
82 bool RendererMainPlatformDelegate::EnableSandbox() { 88 bool RendererMainPlatformDelegate::EnableSandbox() {
83 sandbox::TargetServices* target_services = 89 sandbox::TargetServices* target_services =
84 parameters_.sandbox_info->target_services; 90 parameters_.sandbox_info->target_services;
85 91
86 if (target_services) { 92 if (target_services) {
87 // Cause advapi32 to load before the sandbox is turned on. 93 // Cause advapi32 to load before the sandbox is turned on.
88 unsigned int dummy_rand; 94 unsigned int dummy_rand;
89 rand_s(&dummy_rand); 95 rand_s(&dummy_rand);
90 // Warm up language subsystems before the sandbox is turned on. 96 // Warm up language subsystems before the sandbox is turned on.
91 ::GetUserDefaultLangID(); 97 ::GetUserDefaultLangID();
92 ::GetUserDefaultLCID(); 98 ::GetUserDefaultLCID();
93 99
94 target_services->LowerToken(); 100 target_services->LowerToken();
95 return true; 101 return true;
96 } 102 }
97 return false; 103 return false;
98 } 104 }
99 105
100 } // namespace content 106 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698