[Mac] PepperFlash default on canary, opt-in on dev.
[chromium-blink-merge.git] / chrome / nacl / nacl_main_platform_delegate_mac.mm
blob973b1f9fcc1afbdc7bbd2baead747df254b8d43c
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
3 // found in the LICENSE file.
5 #include "chrome/nacl/nacl_main_platform_delegate.h"
7 #import <Cocoa/Cocoa.h>
8 #include "base/command_line.h"
9 #include "base/file_path.h"
10 #include "base/logging.h"
11 #include "base/native_library.h"
12 #include "chrome/common/chrome_sandbox_type_mac.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "content/public/common/sandbox_init.h"
16 NaClMainPlatformDelegate::NaClMainPlatformDelegate(
17     const content::MainFunctionParams& parameters)
18     : parameters_(parameters), sandbox_test_module_(NULL) {
21 NaClMainPlatformDelegate::~NaClMainPlatformDelegate() {
24 // TODO(jvoung): see if this old comment (from renderer_main_platform...)
25 // is relevant to the nacl loader.
26 // TODO(mac-port): Any code needed to initialize a process for purposes of
27 // running a NaClLoader needs to also be reflected in chrome_main.cc for
28 // --single-process support.
29 void NaClMainPlatformDelegate::PlatformInitialize() {
32 void NaClMainPlatformDelegate::PlatformUninitialize() {
35 void NaClMainPlatformDelegate::InitSandboxTests(bool no_sandbox) {
36   const CommandLine& command_line = parameters_.command_line;
38   DVLOG(1) << "Started NaClLdr with ";
39   const std::vector<std::string>& argstrings = command_line.argv();
40   for (std::vector<std::string>::const_iterator ii = argstrings.begin();
41        ii != argstrings.end(); ++ii)
42     DVLOG(1) << *ii;
44   // Be sure not to load the sandbox test DLL if the sandbox isn't on.
45   // Comment-out guard and recompile if you REALLY want to test w/out the SB.
46   // TODO(jvoung): allow testing without sandbox, but change expected ret vals.
47   if (!no_sandbox) {
48     FilePath test_dll_name =
49       command_line.GetSwitchValuePath(switches::kTestNaClSandbox);
50     if (!test_dll_name.empty()) {
51       sandbox_test_module_ = base::LoadNativeLibrary(test_dll_name, NULL);
52       CHECK(sandbox_test_module_);
53     }
54   }
57 void NaClMainPlatformDelegate::EnableSandbox() {
58   CHECK(content::InitializeSandbox(CHROME_SANDBOX_TYPE_NACL_LOADER, FilePath()))
59       << "Error initializing sandbox for " << switches::kNaClLoaderProcess;
62 bool NaClMainPlatformDelegate::RunSandboxTests() {
63   // TODO(jvoung): Win and mac should share this identical code.
64   bool result = true;
65   if (sandbox_test_module_) {
66     RunNaClLoaderTests run_security_tests =
67       reinterpret_cast<RunNaClLoaderTests>(
68         base::GetFunctionPointerFromNativeLibrary(sandbox_test_module_,
69                                                   kNaClLoaderTestCall));
70     if (run_security_tests) {
71       DVLOG(1) << "Running NaCl Loader security tests";
72       result = (*run_security_tests)();
73     } else {
74       VLOG(1) << "Failed to get NaCl sandbox test function";
75       result = false;
76     }
77     base::UnloadNativeLibrary(sandbox_test_module_);
78     sandbox_test_module_ = NULL;
79   }
80   return result;