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