Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Side by Side Diff: content/renderer/renderer_main_platform_delegate_mac.mm

Issue 8414020: Expose the sandbox related code through the content API. I did a bit of cleanup while I was doing... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 #include <objc/runtime.h> 8 #include <objc/runtime.h>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/sys_string_conversions.h" 12 #include "base/sys_string_conversions.h"
13 #import "chrome/test/security_tests/renderer_sandbox_tests_mac.h" 13 #import "chrome/test/security_tests/renderer_sandbox_tests_mac.h"
14 #import "content/common/chrome_application_mac.h" 14 #import "content/common/chrome_application_mac.h"
15 #include "content/common/sandbox_mac.h" 15 #include "content/common/sandbox_mac.h"
16 #include "content/public/common/content_switches.h" 16 #include "content/public/common/content_switches.h"
17 #include "content/public/common/sandbox_init.h"
17 #include "third_party/WebKit/Source/WebKit/mac/WebCoreSupport/WebSystemInterface .h" 18 #include "third_party/WebKit/Source/WebKit/mac/WebCoreSupport/WebSystemInterface .h"
18 19
19 RendererMainPlatformDelegate::RendererMainPlatformDelegate( 20 RendererMainPlatformDelegate::RendererMainPlatformDelegate(
20 const MainFunctionParams& parameters) 21 const MainFunctionParams& parameters)
21 : parameters_(parameters) { 22 : parameters_(parameters) {
22 } 23 }
23 24
24 RendererMainPlatformDelegate::~RendererMainPlatformDelegate() { 25 RendererMainPlatformDelegate::~RendererMainPlatformDelegate() {
25 } 26 }
26 27
(...skipping 20 matching lines...) Expand all
47 } 48 }
48 49
49 static void LogTestMessage(std::string message, bool is_error) { 50 static void LogTestMessage(std::string message, bool is_error) {
50 if (is_error) 51 if (is_error)
51 LOG(ERROR) << message; 52 LOG(ERROR) << message;
52 else 53 else
53 LOG(INFO) << message; 54 LOG(INFO) << message;
54 } 55 }
55 56
56 bool RendererMainPlatformDelegate::InitSandboxTests(bool no_sandbox) { 57 bool RendererMainPlatformDelegate::InitSandboxTests(bool no_sandbox) {
57 const CommandLine& command_line = parameters_.command_line_; 58 const CommandLine& command_line = parameters_.command_line;
58 59
59 if (command_line.HasSwitch(switches::kTestSandbox)) { 60 if (command_line.HasSwitch(switches::kTestSandbox)) {
60 std::string bundle_path = 61 std::string bundle_path =
61 command_line.GetSwitchValueNative(switches::kTestSandbox); 62 command_line.GetSwitchValueNative(switches::kTestSandbox);
62 if (bundle_path.empty()) { 63 if (bundle_path.empty()) {
63 NOTREACHED() << "Bad bundle path"; 64 NOTREACHED() << "Bad bundle path";
64 return false; 65 return false;
65 } 66 }
66 NSBundle* tests_bundle = 67 NSBundle* tests_bundle =
67 [NSBundle bundleWithPath:base::SysUTF8ToNSString(bundle_path)]; 68 [NSBundle bundleWithPath:base::SysUTF8ToNSString(bundle_path)];
68 if (![tests_bundle load]) { 69 if (![tests_bundle load]) {
69 NOTREACHED() << "Failed to load bundle"; 70 NOTREACHED() << "Failed to load bundle";
70 return false; 71 return false;
71 } 72 }
72 sandbox_tests_bundle_ = [tests_bundle retain]; 73 sandbox_tests_bundle_ = [tests_bundle retain];
73 [objc_getClass("RendererSandboxTestsRunner") setLogFunction:LogTestMessage]; 74 [objc_getClass("RendererSandboxTestsRunner") setLogFunction:LogTestMessage];
74 } 75 }
75 return true; 76 return true;
76 } 77 }
77 78
78 bool RendererMainPlatformDelegate::EnableSandbox() { 79 bool RendererMainPlatformDelegate::EnableSandbox() {
79 CommandLine* parsed_command_line = CommandLine::ForCurrentProcess(); 80 return content::InitializeSandbox();
80 SandboxInitWrapper sandbox_wrapper;
81 return sandbox_wrapper.InitializeSandbox(*parsed_command_line,
82 switches::kRendererProcess);
83 } 81 }
84 82
85 void RendererMainPlatformDelegate::RunSandboxTests() { 83 void RendererMainPlatformDelegate::RunSandboxTests() {
86 Class tests_runner = objc_getClass("RendererSandboxTestsRunner"); 84 Class tests_runner = objc_getClass("RendererSandboxTestsRunner");
87 if (tests_runner) { 85 if (tests_runner) {
88 if (![tests_runner runTests]) 86 if (![tests_runner runTests])
89 LOG(ERROR) << "Running renderer with failing sandbox tests!"; 87 LOG(ERROR) << "Running renderer with failing sandbox tests!";
90 [sandbox_tests_bundle_ unload]; 88 [sandbox_tests_bundle_ unload];
91 [sandbox_tests_bundle_ release]; 89 [sandbox_tests_bundle_ release];
92 sandbox_tests_bundle_ = nil; 90 sandbox_tests_bundle_ = nil;
93 } 91 }
94 } 92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698