| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "content/common/injection_test_dll.h" | 10 #include "content/common/injection_test_dll.h" |
| 11 #include "content/public/common/content_switches.h" | 11 #include "content/public/common/content_switches.h" |
| 12 #include "content/public/renderer/render_thread.h" |
| 12 #include "sandbox/src/sandbox.h" | 13 #include "sandbox/src/sandbox.h" |
| 14 #include "skia/ext/skia_sandbox_support_win.h" |
| 13 #include "unicode/timezone.h" | 15 #include "unicode/timezone.h" |
| 14 | 16 |
| 15 namespace { | 17 namespace { |
| 16 | 18 |
| 17 // In order to have Theme support, we need to connect to the theme service. | 19 // In order to have Theme support, we need to connect to the theme service. |
| 18 // This needs to be done before we lock down the renderer. Officially this | 20 // This needs to be done before we lock down the renderer. Officially this |
| 19 // can be done with OpenThemeData() but it fails unless you pass a valid | 21 // can be done with OpenThemeData() but it fails unless you pass a valid |
| 20 // window at least the first time. Interestingly, the very act of creating a | 22 // window at least the first time. Interestingly, the very act of creating a |
| 21 // window also sets the connection to the theme service. | 23 // window also sets the connection to the theme service. |
| 22 void EnableThemeSupportForRenderer(bool no_sandbox) { | 24 void EnableThemeSupportForRenderer(bool no_sandbox) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 52 | 54 |
| 53 if (!::CloseWindowStation(winsta0)) { | 55 if (!::CloseWindowStation(winsta0)) { |
| 54 // We might be leaking a winsta0 handle. This is a security risk, but | 56 // We might be leaking a winsta0 handle. This is a security risk, but |
| 55 // since we allow fail over to no desktop protection in low memory | 57 // since we allow fail over to no desktop protection in low memory |
| 56 // condition, this is not a big risk. | 58 // condition, this is not a big risk. |
| 57 NOTREACHED(); | 59 NOTREACHED(); |
| 58 } | 60 } |
| 59 } | 61 } |
| 60 } | 62 } |
| 61 | 63 |
| 64 // Windows-only skia sandbox support |
| 65 void SkiaPreCacheFont(LOGFONT logfont) { |
| 66 content::RenderThread* render_thread = content::RenderThread::Get(); |
| 67 if (render_thread) { |
| 68 render_thread->PreCacheFont(logfont); |
| 69 } |
| 70 } |
| 71 |
| 62 } // namespace | 72 } // namespace |
| 63 | 73 |
| 64 RendererMainPlatformDelegate::RendererMainPlatformDelegate( | 74 RendererMainPlatformDelegate::RendererMainPlatformDelegate( |
| 65 const content::MainFunctionParams& parameters) | 75 const content::MainFunctionParams& parameters) |
| 66 : parameters_(parameters), | 76 : parameters_(parameters), |
| 67 sandbox_test_module_(NULL) { | 77 sandbox_test_module_(NULL) { |
| 68 } | 78 } |
| 69 | 79 |
| 70 RendererMainPlatformDelegate::~RendererMainPlatformDelegate() { | 80 RendererMainPlatformDelegate::~RendererMainPlatformDelegate() { |
| 71 } | 81 } |
| 72 | 82 |
| 73 void RendererMainPlatformDelegate::PlatformInitialize() { | 83 void RendererMainPlatformDelegate::PlatformInitialize() { |
| 74 // Be mindful of what resources you acquire here. They can be used by | 84 // Be mindful of what resources you acquire here. They can be used by |
| 75 // malicious code if the renderer gets compromised. | 85 // malicious code if the renderer gets compromised. |
| 76 const CommandLine& command_line = parameters_.command_line; | 86 const CommandLine& command_line = parameters_.command_line; |
| 77 bool no_sandbox = command_line.HasSwitch(switches::kNoSandbox); | 87 bool no_sandbox = command_line.HasSwitch(switches::kNoSandbox); |
| 78 EnableThemeSupportForRenderer(no_sandbox); | 88 EnableThemeSupportForRenderer(no_sandbox); |
| 79 | 89 |
| 80 if (!no_sandbox) { | 90 if (!no_sandbox) { |
| 81 // ICU DateFormat class (used in base/time_format.cc) needs to get the | 91 // ICU DateFormat class (used in base/time_format.cc) needs to get the |
| 82 // Olson timezone ID by accessing the registry keys under | 92 // Olson timezone ID by accessing the registry keys under |
| 83 // HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones. | 93 // HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones. |
| 84 // After TimeZone::createDefault is called once here, the timezone ID is | 94 // After TimeZone::createDefault is called once here, the timezone ID is |
| 85 // cached and there's no more need to access the registry. If the sandbox | 95 // cached and there's no more need to access the registry. If the sandbox |
| 86 // is disabled, we don't have to make this dummy call. | 96 // is disabled, we don't have to make this dummy call. |
| 87 scoped_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault()); | 97 scoped_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault()); |
| 98 SetSkiaEnsureTypefaceAccessible(SkiaPreCacheFont); |
| 88 } | 99 } |
| 89 } | 100 } |
| 90 | 101 |
| 91 void RendererMainPlatformDelegate::PlatformUninitialize() { | 102 void RendererMainPlatformDelegate::PlatformUninitialize() { |
| 92 } | 103 } |
| 93 | 104 |
| 94 bool RendererMainPlatformDelegate::InitSandboxTests(bool no_sandbox) { | 105 bool RendererMainPlatformDelegate::InitSandboxTests(bool no_sandbox) { |
| 95 const CommandLine& command_line = parameters_.command_line; | 106 const CommandLine& command_line = parameters_.command_line; |
| 96 | 107 |
| 97 DVLOG(1) << "Started renderer with " << command_line.GetCommandLineString(); | 108 DVLOG(1) << "Started renderer with " << command_line.GetCommandLineString(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 kRenderTestCall)); | 149 kRenderTestCall)); |
| 139 DCHECK(run_security_tests); | 150 DCHECK(run_security_tests); |
| 140 if (run_security_tests) { | 151 if (run_security_tests) { |
| 141 int test_count = 0; | 152 int test_count = 0; |
| 142 DVLOG(1) << "Running renderer security tests"; | 153 DVLOG(1) << "Running renderer security tests"; |
| 143 BOOL result = run_security_tests(&test_count); | 154 BOOL result = run_security_tests(&test_count); |
| 144 CHECK(result) << "Test number " << test_count << " has failed."; | 155 CHECK(result) << "Test number " << test_count << " has failed."; |
| 145 } | 156 } |
| 146 } | 157 } |
| 147 } | 158 } |
| OLD | NEW |