cc: Use GetSize instead of recorded_viewport_
[chromium-blink-merge.git] / content / common / sandbox_init_win.cc
blobfe67bda7e31395d2b6f053e6870533ab4982bf86
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
3 // found in the LICENSE file.
5 #include "content/public/common/sandbox_init.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "content/common/sandbox_win.h"
10 #include "content/public/common/content_switches.h"
11 #include "sandbox/win/src/sandbox.h"
12 #include "sandbox/win/src/sandbox_types.h"
14 namespace content {
16 bool InitializeSandbox(sandbox::SandboxInterfaceInfo* sandbox_info) {
17 const base::CommandLine& command_line =
18 *base::CommandLine::ForCurrentProcess();
19 sandbox::BrokerServices* broker_services = sandbox_info->broker_services;
20 if (broker_services) {
21 if (!InitBrokerServices(broker_services))
22 return false;
24 // IMPORTANT: This piece of code needs to run as early as possible in the
25 // process because it will initialize the sandbox broker, which requires the
26 // process to swap its window station. During this time all the UI will be
27 // broken. This has to run before threads and windows are created.
28 if (!command_line.HasSwitch(switches::kNoSandbox)) {
29 #if defined(ADDRESS_SANITIZER) && defined(OS_WIN)
30 LOG(FATAL) << "AddressSanitizer for Windows doesn't support sandboxing "
31 "yet (http://crbug.com/382867). "
32 "Please rerun with sandbox disabled.";
33 #endif
34 // Precreate the desktop and window station used by the renderers.
35 sandbox::TargetPolicy* policy = broker_services->CreatePolicy();
36 sandbox::ResultCode result = policy->CreateAlternateDesktop(true);
37 CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result);
38 policy->Release();
40 return true;
43 if (command_line.HasSwitch(switches::kNoSandbox))
44 return true;
46 sandbox::TargetServices* target_services = sandbox_info->target_services;
47 return InitTargetServices(target_services);
50 } // namespace content