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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
// Copyright (c) 2012 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 "ui/views/examples/content_client/examples_main_delegate.h"
#include <string>
#include "base/command_line.h"
#include "base/file_path.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "content/public/browser/browser_main_runner.h"
#include "content/public/common/content_switches.h"
#include "content/shell/shell_content_plugin_client.h"
#include "content/shell/shell_content_renderer_client.h"
#include "content/shell/shell_content_utility_client.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_paths.h"
#include "ui/views/examples/content_client/examples_content_browser_client.h"
#if defined(OS_WIN)
#include "base/logging_win.h"
#endif
namespace views {
namespace examples {
namespace {
#if defined(OS_WIN)
// {83FAC8EE-7A0E-4dbb-A3F6-6F500D7CAB1A}
const GUID kViewsExamplesProviderName =
{ 0x83fac8ee, 0x7a0e, 0x4dbb,
{ 0xa3, 0xf6, 0x6f, 0x50, 0xd, 0x7c, 0xab, 0x1a } };
#endif
int ExamplesBrowserMain(
const content::MainFunctionParams& main_function_params) {
scoped_ptr<content::BrowserMainRunner> main_runner(
content::BrowserMainRunner::Create());
int exit_code = main_runner->Initialize(main_function_params);
if (exit_code >= 0)
return exit_code;
exit_code = main_runner->Run();
main_runner->Shutdown();
return exit_code;
}
} // namespace
ExamplesMainDelegate::ExamplesMainDelegate() {
}
ExamplesMainDelegate::~ExamplesMainDelegate() {
}
bool ExamplesMainDelegate::BasicStartupComplete(int* exit_code) {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
std::string process_type =
command_line.GetSwitchValueASCII(switches::kProcessType);
content::SetContentClient(&content_client_);
InitializeShellContentClient(process_type);
bool success = logging::InitLogging(NULL,
logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG,
logging::LOCK_LOG_FILE,
logging::DELETE_OLD_LOG_FILE,
logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS);
CHECK(success);
#if defined(OS_WIN)
logging::LogEventProvider::Initialize(kViewsExamplesProviderName);
#endif
return false;
}
void ExamplesMainDelegate::PreSandboxStartup() {
InitializeResourceBundle();
}
void ExamplesMainDelegate::SandboxInitialized(const std::string& process_type) {
}
int ExamplesMainDelegate::RunProcess(
const std::string& process_type,
const content::MainFunctionParams& main_function_params) {
if (process_type != "")
return -1;
return ExamplesBrowserMain(main_function_params);
}
void ExamplesMainDelegate::ProcessExiting(const std::string& process_type) {
}
#if defined(OS_POSIX)
content::ZygoteForkDelegate* ExamplesMainDelegate::ZygoteStarting() {
return NULL;
}
void ExamplesMainDelegate::ZygoteForked() {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
std::string process_type =
command_line.GetSwitchValueASCII(switches::kProcessType);
InitializeShellContentClient(process_type);
}
#endif
void ExamplesMainDelegate::InitializeShellContentClient(
const std::string& process_type) {
if (process_type.empty()) {
browser_client_.reset(new ExamplesContentBrowserClient);
content::GetContentClient()->set_browser(browser_client_.get());
} else if (process_type == switches::kRendererProcess) {
renderer_client_.reset(new content::ShellContentRendererClient);
content::GetContentClient()->set_renderer(renderer_client_.get());
} else if (process_type == switches::kPluginProcess) {
plugin_client_.reset(new content::ShellContentPluginClient);
content::GetContentClient()->set_plugin(plugin_client_.get());
} else if (process_type == switches::kUtilityProcess) {
utility_client_.reset(new content::ShellContentUtilityClient);
content::GetContentClient()->set_utility(utility_client_.get());
}
}
void ExamplesMainDelegate::InitializeResourceBundle() {
ui::ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL);
}
} // namespace examples
} // namespace views
|