blob: 59a6c63674604b586cdf04f7494e504c9d5a47d5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/renderer/renderer_main_platform_delegate.h"
#import <Cocoa/Cocoa.h>
#include <objc/runtime.h>
#include "base/command_line.h"
#include "base/logging.h"
#include "base/sys_string_conversions.h"
#import "chrome/test/security_tests/renderer_sandbox_tests_mac.h"
#include "content/common/sandbox_mac.h"
#include "content/public/common/content_switches.h"
#include "content/common/sandbox_init_mac.h"
#include "third_party/WebKit/Source/WebKit/mac/WebCoreSupport/WebSystemInterface.h"
RendererMainPlatformDelegate::RendererMainPlatformDelegate(
const content::MainFunctionParams& parameters)
: parameters_(parameters) {
}
RendererMainPlatformDelegate::~RendererMainPlatformDelegate() {
}
// TODO(mac-port): Any code needed to initialize a process for purposes of
// running a renderer needs to also be reflected in chrome_main.cc for
// --single-process support.
void RendererMainPlatformDelegate::PlatformInitialize() {
// Initialize NSApplication up front. Without this call, drawing of
// native UI elements (e.g. buttons) in WebKit will explode.
[NSApplication sharedApplication];
// Load WebKit system interfaces.
InitWebCoreSystemInterface();
if (![NSThread isMultiThreaded]) {
NSString* string = @"";
[NSThread detachNewThreadSelector:@selector(length)
toTarget:string
withObject:nil];
}
}
void RendererMainPlatformDelegate::PlatformUninitialize() {
}
static void LogTestMessage(std::string message, bool is_error) {
if (is_error)
LOG(ERROR) << message;
else
LOG(INFO) << message;
}
bool RendererMainPlatformDelegate::InitSandboxTests(bool no_sandbox) {
const CommandLine& command_line = parameters_.command_line;
if (command_line.HasSwitch(switches::kTestSandbox)) {
std::string bundle_path =
command_line.GetSwitchValueNative(switches::kTestSandbox);
if (bundle_path.empty()) {
NOTREACHED() << "Bad bundle path";
return false;
}
NSBundle* tests_bundle =
[NSBundle bundleWithPath:base::SysUTF8ToNSString(bundle_path)];
if (![tests_bundle load]) {
NOTREACHED() << "Failed to load bundle";
return false;
}
sandbox_tests_bundle_ = [tests_bundle retain];
[objc_getClass("RendererSandboxTestsRunner") setLogFunction:LogTestMessage];
}
return true;
}
bool RendererMainPlatformDelegate::EnableSandbox() {
return content::InitializeSandbox();
}
void RendererMainPlatformDelegate::RunSandboxTests() {
Class tests_runner = objc_getClass("RendererSandboxTestsRunner");
if (tests_runner) {
if (![tests_runner runTests])
LOG(ERROR) << "Running renderer with failing sandbox tests!";
[sandbox_tests_bundle_ unload];
[sandbox_tests_bundle_ release];
sandbox_tests_bundle_ = nil;
}
}
|