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 <signal.h> | 7 #include <signal.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/win/win_util.h" | 12 #include "base/win/win_util.h" |
13 #include "content/public/common/content_switches.h" | 13 #include "content/public/common/content_switches.h" |
14 #include "content/public/common/injection_test_win.h" | 14 #include "content/public/common/injection_test_win.h" |
15 #include "content/public/renderer/render_thread.h" | 15 #include "content/public/renderer/render_thread.h" |
16 #include "sandbox/win/src/sandbox.h" | 16 #include "sandbox/win/src/sandbox.h" |
17 #include "skia/ext/skia_sandbox_support_win.h" | 17 #include "skia/ext/skia_sandbox_support_win.h" |
18 #include "unicode/timezone.h" | 18 #include "unicode/timezone.h" |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // In order to have Theme support, we need to connect to the theme service. | |
23 // This needs to be done before we lock down the renderer. Officially this | |
24 // can be done with OpenThemeData() but it fails unless you pass a valid | |
25 // window at least the first time. Interestingly, the very act of creating a | |
26 // window also sets the connection to the theme service. | |
27 void EnableThemeSupportForRenderer(bool no_sandbox) { | |
28 HWINSTA current = NULL; | |
29 HWINSTA winsta0 = NULL; | |
30 | |
31 if (!no_sandbox) { | |
32 current = ::GetProcessWindowStation(); | |
33 winsta0 = ::OpenWindowStationW(L"WinSta0", FALSE, GENERIC_READ); | |
34 if (!winsta0 || !::SetProcessWindowStation(winsta0)) { | |
35 // Could not set the alternate window station. There is a possibility | |
36 // that the theme wont be correctly initialized on XP. | |
37 NOTREACHED() << "Unable to switch to WinSt0"; | |
38 } | |
39 } | |
40 | |
41 HWND window = ::CreateWindowExW(0, L"Static", L"", WS_POPUP | WS_DISABLED, | |
42 CW_USEDEFAULT, 0, 0, 0, HWND_MESSAGE, NULL, | |
43 ::GetModuleHandleA(NULL), NULL); | |
44 if (!window) { | |
45 DLOG(WARNING) << "failed to enable theme support"; | |
46 } else { | |
47 ::DestroyWindow(window); | |
48 } | |
49 | |
50 if (!no_sandbox) { | |
51 // Revert the window station. | |
52 if (!current || !::SetProcessWindowStation(current)) { | |
53 // We failed to switch back to the secure window station. This might | |
54 // confuse the renderer enough that we should kill it now. | |
55 LOG(FATAL) << "Failed to restore alternate window station"; | |
56 } | |
57 | |
58 if (!::CloseWindowStation(winsta0)) { | |
59 // We might be leaking a winsta0 handle. This is a security risk, but | |
60 // since we allow fail over to no desktop protection in low memory | |
61 // condition, this is not a big risk. | |
62 NOTREACHED(); | |
63 } | |
64 } | |
65 } | |
66 | |
67 // Windows-only skia sandbox support | 22 // Windows-only skia sandbox support |
68 void SkiaPreCacheFont(const LOGFONT& logfont) { | 23 void SkiaPreCacheFont(const LOGFONT& logfont) { |
69 content::RenderThread* render_thread = content::RenderThread::Get(); | 24 content::RenderThread* render_thread = content::RenderThread::Get(); |
70 if (render_thread) { | 25 if (render_thread) { |
71 render_thread->PreCacheFont(logfont); | 26 render_thread->PreCacheFont(logfont); |
72 } | 27 } |
73 } | 28 } |
74 | 29 |
75 void __cdecl ForceCrashOnSigAbort(int) { | 30 void __cdecl ForceCrashOnSigAbort(int) { |
76 *((int*)0) = 0x1337; | 31 *((int*)0) = 0x1337; |
(...skipping 28 matching lines...) Expand all Loading... |
105 RendererMainPlatformDelegate::~RendererMainPlatformDelegate() { | 60 RendererMainPlatformDelegate::~RendererMainPlatformDelegate() { |
106 } | 61 } |
107 | 62 |
108 void RendererMainPlatformDelegate::PlatformInitialize() { | 63 void RendererMainPlatformDelegate::PlatformInitialize() { |
109 InitExitInterceptions(); | 64 InitExitInterceptions(); |
110 | 65 |
111 // Be mindful of what resources you acquire here. They can be used by | 66 // Be mindful of what resources you acquire here. They can be used by |
112 // malicious code if the renderer gets compromised. | 67 // malicious code if the renderer gets compromised. |
113 const CommandLine& command_line = parameters_.command_line; | 68 const CommandLine& command_line = parameters_.command_line; |
114 bool no_sandbox = command_line.HasSwitch(switches::kNoSandbox); | 69 bool no_sandbox = command_line.HasSwitch(switches::kNoSandbox); |
115 EnableThemeSupportForRenderer(no_sandbox); | |
116 | 70 |
117 if (!no_sandbox) { | 71 if (!no_sandbox) { |
118 // ICU DateFormat class (used in base/time_format.cc) needs to get the | 72 // ICU DateFormat class (used in base/time_format.cc) needs to get the |
119 // Olson timezone ID by accessing the registry keys under | 73 // Olson timezone ID by accessing the registry keys under |
120 // HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones. | 74 // HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones. |
121 // After TimeZone::createDefault is called once here, the timezone ID is | 75 // After TimeZone::createDefault is called once here, the timezone ID is |
122 // cached and there's no more need to access the registry. If the sandbox | 76 // cached and there's no more need to access the registry. If the sandbox |
123 // is disabled, we don't have to make this dummy call. | 77 // is disabled, we don't have to make this dummy call. |
124 scoped_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault()); | 78 scoped_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault()); |
125 SetSkiaEnsureTypefaceAccessible(SkiaPreCacheFont); | 79 SetSkiaEnsureTypefaceAccessible(SkiaPreCacheFont); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 kRenderTestCall)); | 133 kRenderTestCall)); |
180 DCHECK(run_security_tests); | 134 DCHECK(run_security_tests); |
181 if (run_security_tests) { | 135 if (run_security_tests) { |
182 int test_count = 0; | 136 int test_count = 0; |
183 DVLOG(1) << "Running renderer security tests"; | 137 DVLOG(1) << "Running renderer security tests"; |
184 BOOL result = run_security_tests(&test_count); | 138 BOOL result = run_security_tests(&test_count); |
185 CHECK(result) << "Test number " << test_count << " has failed."; | 139 CHECK(result) << "Test number " << test_count << " has failed."; |
186 } | 140 } |
187 } | 141 } |
188 } | 142 } |
OLD | NEW |