| 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/common/sandbox_win.h" | 5 #include "content/common/sandbox_win.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/debug/profiler.h" | 11 #include "base/debug/profiler.h" |
| 12 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
| 13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/hash.h" | 14 #include "base/hash.h" |
| 15 #include "base/metrics/field_trial.h" |
| 15 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 16 #include "base/process/launch.h" | 17 #include "base/process/launch.h" |
| 17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 18 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
| 19 #include "base/win/iat_patch_function.h" | 20 #include "base/win/iat_patch_function.h" |
| 20 #include "base/win/scoped_handle.h" | 21 #include "base/win/scoped_handle.h" |
| 21 #include "base/win/scoped_process_information.h" | 22 #include "base/win/scoped_process_information.h" |
| 22 #include "base/win/windows_version.h" | 23 #include "base/win/windows_version.h" |
| 23 #include "content/public/common/content_client.h" | 24 #include "content/public/common/content_client.h" |
| 24 #include "content/public/common/content_switches.h" | 25 #include "content/public/common/content_switches.h" |
| 25 #include "content/public/common/sandbox_init.h" | 26 #include "content/public/common/sandbox_init.h" |
| 26 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 27 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
| 27 #include "sandbox/win/src/process_mitigations.h" | 28 #include "sandbox/win/src/process_mitigations.h" |
| 28 #include "sandbox/win/src/sandbox.h" | 29 #include "sandbox/win/src/sandbox.h" |
| 29 #include "sandbox/win/src/sandbox_nt_util.h" | 30 #include "sandbox/win/src/sandbox_nt_util.h" |
| 30 #include "sandbox/win/src/win_utils.h" | 31 #include "sandbox/win/src/win_utils.h" |
| 32 #include "ui/gfx/win/dpi.h" |
| 31 | 33 |
| 32 static sandbox::BrokerServices* g_broker_services = NULL; | 34 static sandbox::BrokerServices* g_broker_services = NULL; |
| 33 static sandbox::TargetServices* g_target_services = NULL; | 35 static sandbox::TargetServices* g_target_services = NULL; |
| 34 | 36 |
| 35 namespace content { | 37 namespace content { |
| 36 namespace { | 38 namespace { |
| 37 | 39 |
| 38 // The DLLs listed here are known (or under strong suspicion) of causing crashes | 40 // The DLLs listed here are known (or under strong suspicion) of causing crashes |
| 39 // when they are loaded in the renderer. Note: at runtime we generate short | 41 // when they are loaded in the renderer. Note: at runtime we generate short |
| 40 // versions of the dll name only if the dll has an extension. | 42 // versions of the dll name only if the dll has an extension. |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 sandbox::ResultCode result = target_services->Init(); | 561 sandbox::ResultCode result = target_services->Init(); |
| 560 g_target_services = target_services; | 562 g_target_services = target_services; |
| 561 return sandbox::SBOX_ALL_OK == result; | 563 return sandbox::SBOX_ALL_OK == result; |
| 562 } | 564 } |
| 563 | 565 |
| 564 bool ShouldUseDirectWrite() { | 566 bool ShouldUseDirectWrite() { |
| 565 // If the flag is currently on, and we're on Win7 or above, we enable | 567 // If the flag is currently on, and we're on Win7 or above, we enable |
| 566 // DirectWrite. Skia does not require the additions to DirectWrite in QFE | 568 // DirectWrite. Skia does not require the additions to DirectWrite in QFE |
| 567 // 2670838, so a Win7 check is sufficient. We do not currently attempt to | 569 // 2670838, so a Win7 check is sufficient. We do not currently attempt to |
| 568 // support Vista, where SP2 and the Platform Update are required. | 570 // support Vista, where SP2 and the Platform Update are required. |
| 571 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
| 572 return false; |
| 573 |
| 574 // If forced off, don't use it. |
| 569 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 575 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 570 return !command_line.HasSwitch(switches::kDisableDirectWrite) && | 576 if (command_line.HasSwitch(switches::kDisableDirectWrite)) |
| 571 base::win::GetVersion() >= base::win::VERSION_WIN7; | 577 return false; |
| 578 |
| 579 // Can't use GDI on HiDPI. |
| 580 if (gfx::GetDPIScale() > 1.0f) |
| 581 return true; |
| 582 |
| 583 // Otherwise, Finch. |
| 584 const std::string group_name = |
| 585 base::FieldTrialList::FindFullName("DirectWrite"); |
| 586 return group_name == "Enabled"; |
| 572 } | 587 } |
| 573 | 588 |
| 574 base::ProcessHandle StartSandboxedProcess( | 589 base::ProcessHandle StartSandboxedProcess( |
| 575 SandboxedProcessLauncherDelegate* delegate, | 590 SandboxedProcessLauncherDelegate* delegate, |
| 576 CommandLine* cmd_line) { | 591 CommandLine* cmd_line) { |
| 577 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | 592 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
| 578 std::string type_str = cmd_line->GetSwitchValueASCII(switches::kProcessType); | 593 std::string type_str = cmd_line->GetSwitchValueASCII(switches::kProcessType); |
| 579 | 594 |
| 580 TRACE_EVENT_BEGIN_ETW("StartProcessWithAccess", 0, type_str); | 595 TRACE_EVENT_BEGIN_ETW("StartProcessWithAccess", 0, type_str); |
| 581 | 596 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 } | 764 } |
| 750 | 765 |
| 751 return false; | 766 return false; |
| 752 } | 767 } |
| 753 | 768 |
| 754 bool BrokerAddTargetPeer(HANDLE peer_process) { | 769 bool BrokerAddTargetPeer(HANDLE peer_process) { |
| 755 return g_broker_services->AddTargetPeer(peer_process) == sandbox::SBOX_ALL_OK; | 770 return g_broker_services->AddTargetPeer(peer_process) == sandbox::SBOX_ALL_OK; |
| 756 } | 771 } |
| 757 | 772 |
| 758 } // namespace content | 773 } // namespace content |
| OLD | NEW |