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/public/browser/browser_main_runner.h" | 5 #include "content/public/browser/browser_main_runner.h" |
6 | 6 |
7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/leak_annotations.h" | 9 #include "base/debug/leak_annotations.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 16 matching lines...) Expand all Loading... | |
27 #include "content/public/common/content_switches.h" | 27 #include "content/public/common/content_switches.h" |
28 #include "content/public/common/main_function_params.h" | 28 #include "content/public/common/main_function_params.h" |
29 #include "third_party/skia/include/core/SkGraphics.h" | 29 #include "third_party/skia/include/core/SkGraphics.h" |
30 #include "ui/base/ime/input_method_initializer.h" | 30 #include "ui/base/ime/input_method_initializer.h" |
31 | 31 |
32 #if defined(OS_ANDROID) | 32 #if defined(OS_ANDROID) |
33 #include "content/browser/android/tracing_controller_android.h" | 33 #include "content/browser/android/tracing_controller_android.h" |
34 #endif | 34 #endif |
35 | 35 |
36 #if defined(OS_WIN) | 36 #if defined(OS_WIN) |
37 #include "base/win/win_util.h" | |
38 #include "base/win/windows_version.h" | 37 #include "base/win/windows_version.h" |
39 #include "net/cert/sha256_legacy_support_win.h" | |
40 #include "sandbox/win/src/sidestep/preamble_patcher.h" | |
41 #include "ui/base/win/scoped_ole_initializer.h" | 38 #include "ui/base/win/scoped_ole_initializer.h" |
42 #include "ui/gfx/switches.h" | |
43 #include "ui/gfx/win/direct_write.h" | 39 #include "ui/gfx/win/direct_write.h" |
44 #endif | 40 #endif |
45 | 41 |
46 namespace content { | 42 namespace content { |
47 | 43 |
48 namespace { | 44 namespace { |
49 | 45 |
50 bool g_exited_main_message_loop = false; | 46 bool g_exited_main_message_loop = false; |
51 | 47 |
52 #if defined(OS_WIN) | |
53 #if !defined(_WIN64) | |
54 // Pointer to the original CryptVerifyCertificateSignatureEx function. | |
55 net::sha256_interception::CryptVerifyCertificateSignatureExFunc | |
56 g_real_crypt_verify_signature_stub = NULL; | |
57 | |
58 // Stub function that is called whenever the Crypt32 function | |
59 // CryptVerifyCertificateSignatureEx is called. It just defers to net to perform | |
60 // the actual verification. | |
61 BOOL WINAPI CryptVerifyCertificateSignatureExStub( | |
62 HCRYPTPROV_LEGACY provider, | |
63 DWORD encoding_type, | |
64 DWORD subject_type, | |
65 void* subject_data, | |
66 DWORD issuer_type, | |
67 void* issuer_data, | |
68 DWORD flags, | |
69 void* extra) { | |
70 return net::sha256_interception::CryptVerifyCertificateSignatureExHook( | |
71 g_real_crypt_verify_signature_stub, provider, encoding_type, subject_type, | |
72 subject_data, issuer_type, issuer_data, flags, extra); | |
73 } | |
74 #endif // !defined(_WIN64) | |
75 | |
76 // If necessary, install an interception | |
77 void InstallSha256LegacyHooks() { | |
78 #if defined(_WIN64) | |
79 // Interception on x64 is not supported. | |
80 return; | |
81 #else | |
82 if (base::win::MaybeHasSHA256Support()) | |
83 return; | |
84 | |
85 net::sha256_interception::CryptVerifyCertificateSignatureExFunc | |
86 cert_verify_signature_ptr = reinterpret_cast< | |
87 net::sha256_interception::CryptVerifyCertificateSignatureExFunc>( | |
88 ::GetProcAddress(::GetModuleHandle(L"crypt32.dll"), | |
89 "CryptVerifyCertificateSignatureEx")); | |
90 CHECK(cert_verify_signature_ptr); | |
91 | |
92 DWORD old_protect = 0; | |
93 if (!::VirtualProtect(cert_verify_signature_ptr, 5, PAGE_EXECUTE_READWRITE, | |
94 &old_protect)) { | |
95 return; | |
96 } | |
97 | |
98 g_real_crypt_verify_signature_stub = | |
99 reinterpret_cast< | |
100 net::sha256_interception::CryptVerifyCertificateSignatureExFunc>( | |
101 VirtualAllocEx(::GetCurrentProcess(), NULL, | |
102 sidestep::kMaxPreambleStubSize, MEM_COMMIT, | |
103 PAGE_EXECUTE_READWRITE)); | |
104 if (g_real_crypt_verify_signature_stub == NULL) { | |
105 CHECK(::VirtualProtect(cert_verify_signature_ptr, 5, old_protect, | |
106 &old_protect)); | |
107 return; | |
108 } | |
109 | |
110 sidestep::SideStepError patch_result = | |
111 sidestep::PreamblePatcher::Patch( | |
112 cert_verify_signature_ptr, CryptVerifyCertificateSignatureExStub, | |
113 g_real_crypt_verify_signature_stub, sidestep::kMaxPreambleStubSize); | |
114 if (patch_result != sidestep::SIDESTEP_SUCCESS) { | |
115 CHECK(::VirtualFreeEx(::GetCurrentProcess(), | |
116 g_real_crypt_verify_signature_stub, 0, | |
117 MEM_RELEASE)); | |
118 CHECK(::VirtualProtect(cert_verify_signature_ptr, 5, old_protect, | |
119 &old_protect)); | |
120 return; | |
121 } | |
122 | |
123 DWORD dummy = 0; | |
124 CHECK(::VirtualProtect(cert_verify_signature_ptr, 5, old_protect, &dummy)); | |
125 CHECK(::VirtualProtect(g_real_crypt_verify_signature_stub, | |
126 sidestep::kMaxPreambleStubSize, old_protect, | |
127 &old_protect)); | |
128 #endif // _WIN64 | |
129 } | |
130 #endif // OS_WIN | |
131 | |
132 } // namespace | 48 } // namespace |
133 | 49 |
134 class BrowserMainRunnerImpl : public BrowserMainRunner { | 50 class BrowserMainRunnerImpl : public BrowserMainRunner { |
135 public: | 51 public: |
136 BrowserMainRunnerImpl() | 52 BrowserMainRunnerImpl() |
137 : initialization_started_(false), is_shutdown_(false) {} | 53 : initialization_started_(false), is_shutdown_(false) {} |
138 | 54 |
139 ~BrowserMainRunnerImpl() override { | 55 ~BrowserMainRunnerImpl() override { |
140 if (initialization_started_ && !is_shutdown_) | 56 if (initialization_started_ && !is_shutdown_) |
141 Shutdown(); | 57 Shutdown(); |
(...skipping 20 matching lines...) Expand all Loading... | |
162 const base::TimeTicks start_time_step1 = base::TimeTicks::Now(); | 78 const base::TimeTicks start_time_step1 = base::TimeTicks::Now(); |
163 | 79 |
164 SkGraphics::Init(); | 80 SkGraphics::Init(); |
165 | 81 |
166 #if !defined(OS_IOS) | 82 #if !defined(OS_IOS) |
167 if (parameters.command_line.HasSwitch(switches::kWaitForDebugger)) | 83 if (parameters.command_line.HasSwitch(switches::kWaitForDebugger)) |
168 base::debug::WaitForDebugger(60, true); | 84 base::debug::WaitForDebugger(60, true); |
169 #endif | 85 #endif |
170 | 86 |
171 #if defined(OS_WIN) | 87 #if defined(OS_WIN) |
172 if (base::win::GetVersion() < base::win::VERSION_VISTA) { | 88 if (base::win::GetVersion() < base::win::VERSION_VISTA) { |
Ryan Sleevi
2016/01/21 22:43:06
Oooh, we can delete this code too.
But not in thi
davidben
2016/01/21 22:50:46
Oh, didn't even notice that. I'll go upload that C
| |
173 // When "Extend support of advanced text services to all programs" | 89 // When "Extend support of advanced text services to all programs" |
174 // (a.k.a. Cicero Unaware Application Support; CUAS) is enabled on | 90 // (a.k.a. Cicero Unaware Application Support; CUAS) is enabled on |
175 // Windows XP and handwriting modules shipped with Office 2003 are | 91 // Windows XP and handwriting modules shipped with Office 2003 are |
176 // installed, "penjpn.dll" and "skchui.dll" will be loaded and then | 92 // installed, "penjpn.dll" and "skchui.dll" will be loaded and then |
177 // crash unless a user installs Office 2003 SP3. To prevent these | 93 // crash unless a user installs Office 2003 SP3. To prevent these |
178 // modules from being loaded, disable TSF entirely. crbug.com/160914. | 94 // modules from being loaded, disable TSF entirely. crbug.com/160914. |
179 // TODO(yukawa): Add a high-level wrapper for this instead of calling | 95 // TODO(yukawa): Add a high-level wrapper for this instead of calling |
180 // Win32 API here directly. | 96 // Win32 API here directly. |
181 ImmDisableTextFrameService(static_cast<DWORD>(-1)); | 97 ImmDisableTextFrameService(static_cast<DWORD>(-1)); |
182 } | 98 } |
183 InstallSha256LegacyHooks(); | |
184 #endif // OS_WIN | 99 #endif // OS_WIN |
185 | 100 |
186 base::StatisticsRecorder::Initialize(); | 101 base::StatisticsRecorder::Initialize(); |
187 | 102 |
188 notification_service_.reset(new NotificationServiceImpl); | 103 notification_service_.reset(new NotificationServiceImpl); |
189 | 104 |
190 #if defined(OS_WIN) | 105 #if defined(OS_WIN) |
191 // Ole must be initialized before starting message pump, so that TSF | 106 // Ole must be initialized before starting message pump, so that TSF |
192 // (Text Services Framework) module can interact with the message pump | 107 // (Text Services Framework) module can interact with the message pump |
193 // on Windows 8 Metro mode. | 108 // on Windows 8 Metro mode. |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 BrowserMainRunner* BrowserMainRunner::Create() { | 247 BrowserMainRunner* BrowserMainRunner::Create() { |
333 return new BrowserMainRunnerImpl(); | 248 return new BrowserMainRunnerImpl(); |
334 } | 249 } |
335 | 250 |
336 // static | 251 // static |
337 bool BrowserMainRunner::ExitedMainMessageLoop() { | 252 bool BrowserMainRunner::ExitedMainMessageLoop() { |
338 return g_exited_main_message_loop; | 253 return g_exited_main_message_loop; |
339 } | 254 } |
340 | 255 |
341 } // namespace content | 256 } // namespace content |
OLD | NEW |