| 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" |
| 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 // Helper function to cast RenderThred to IPC::Sender so we can Bind() it. |
| 42 IPC::Sender* GetRenderThreadSender() { |
| 43 return RenderThread::Get(); |
| 44 } |
| 45 |
| 41 } // namespace | 46 } // namespace |
| 42 | 47 |
| 43 RendererMainPlatformDelegate::RendererMainPlatformDelegate( | 48 RendererMainPlatformDelegate::RendererMainPlatformDelegate( |
| 44 const MainFunctionParams& parameters) | 49 const MainFunctionParams& parameters) |
| 45 : parameters_(parameters), | 50 : parameters_(parameters), |
| 46 sandbox_test_module_(NULL) { | 51 sandbox_test_module_(NULL) { |
| 47 } | 52 } |
| 48 | 53 |
| 49 RendererMainPlatformDelegate::~RendererMainPlatformDelegate() { | 54 RendererMainPlatformDelegate::~RendererMainPlatformDelegate() { |
| 50 } | 55 } |
| 51 | 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(&GetRenderThreadSender)); |
| 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 | 96 |
| 91 target_services->LowerToken(); | 97 target_services->LowerToken(); |
| 92 return true; | 98 return true; |
| 93 } | 99 } |
| 94 return false; | 100 return false; |
| 95 } | 101 } |
| 96 | 102 |
| 97 } // namespace content | 103 } // namespace content |
| OLD | NEW |