Removed unused VideoCaptureCapability parameters.
[chromium-blink-merge.git] / content / shell / app / shell_main_delegate.cc
blobc6d578a90f430aba25348431c49a5a4b63796195
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/shell/app/shell_main_delegate.h"
7 #include "base/base_switches.h"
8 #include "base/command_line.h"
9 #include "base/files/file_path.h"
10 #include "base/lazy_instance.h"
11 #include "base/logging.h"
12 #include "base/path_service.h"
13 #include "cc/base/switches.h"
14 #include "content/public/browser/browser_main_runner.h"
15 #include "content/public/common/content_switches.h"
16 #include "content/public/common/url_constants.h"
17 #include "content/public/test/layouttest_support.h"
18 #include "content/shell/app/shell_breakpad_client.h"
19 #include "content/shell/app/webkit_test_platform_support.h"
20 #include "content/shell/browser/shell_browser_main.h"
21 #include "content/shell/browser/shell_content_browser_client.h"
22 #include "content/shell/common/shell_switches.h"
23 #include "content/shell/renderer/shell_content_renderer_client.h"
24 #include "net/cookies/cookie_monster.h"
25 #include "ui/base/resource/resource_bundle.h"
26 #include "ui/base/ui_base_paths.h"
27 #include "ui/base/ui_base_switches.h"
28 #include "ui/events/event_switches.h"
29 #include "ui/gfx/switches.h"
30 #include "ui/gl/gl_switches.h"
32 #include "ipc/ipc_message.h" // For IPC_MESSAGE_LOG_ENABLED.
34 #if defined(IPC_MESSAGE_LOG_ENABLED)
35 #define IPC_MESSAGE_MACROS_LOG_ENABLED
36 #include "content/public/common/content_ipc_logging.h"
37 #define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger) \
38 content::RegisterIPCLogger(msg_id, logger)
39 #include "content/shell/common/shell_messages.h"
40 #endif
42 #if defined(OS_ANDROID)
43 #include "base/posix/global_descriptors.h"
44 #include "content/shell/android/shell_descriptors.h"
45 #endif
47 #if defined(OS_MACOSX)
48 #include "base/mac/os_crash_dumps.h"
49 #include "components/breakpad/app/breakpad_mac.h"
50 #include "content/shell/app/paths_mac.h"
51 #include "content/shell/app/shell_main_delegate_mac.h"
52 #endif // OS_MACOSX
54 #if defined(OS_WIN)
55 #include <initguid.h>
56 #include <windows.h>
57 #include "base/logging_win.h"
58 #include "components/breakpad/app/breakpad_win.h"
59 #endif
61 #if defined(OS_POSIX) && !defined(OS_MACOSX)
62 #include "components/breakpad/app/breakpad_linux.h"
63 #endif
65 namespace {
67 base::LazyInstance<content::ShellBreakpadClient>::Leaky
68 g_shell_breakpad_client = LAZY_INSTANCE_INITIALIZER;
70 #if defined(OS_WIN)
71 // If "Content Shell" doesn't show up in your list of trace providers in
72 // Sawbuck, add these registry entries to your machine (NOTE the optional
73 // Wow6432Node key for x64 machines):
74 // 1. Find: HKLM\SOFTWARE\[Wow6432Node\]Google\Sawbuck\Providers
75 // 2. Add a subkey with the name "{6A3E50A4-7E15-4099-8413-EC94D8C2A4B6}"
76 // 3. Add these values:
77 // "default_flags"=dword:00000001
78 // "default_level"=dword:00000004
79 // @="Content Shell"
81 // {6A3E50A4-7E15-4099-8413-EC94D8C2A4B6}
82 const GUID kContentShellProviderName = {
83 0x6a3e50a4, 0x7e15, 0x4099,
84 { 0x84, 0x13, 0xec, 0x94, 0xd8, 0xc2, 0xa4, 0xb6 } };
85 #endif
87 void InitLogging() {
88 base::FilePath log_filename;
89 PathService::Get(base::DIR_EXE, &log_filename);
90 log_filename = log_filename.AppendASCII("content_shell.log");
91 logging::LoggingSettings settings;
92 settings.logging_dest = logging::LOG_TO_ALL;
93 settings.log_file = log_filename.value().c_str();
94 settings.delete_old = logging::DELETE_OLD_LOG_FILE;
95 logging::InitLogging(settings);
96 logging::SetLogItems(true, true, true, true);
99 } // namespace
101 namespace content {
103 ShellMainDelegate::ShellMainDelegate() {
106 ShellMainDelegate::~ShellMainDelegate() {
109 bool ShellMainDelegate::BasicStartupComplete(int* exit_code) {
110 #if defined(OS_WIN)
111 // Enable trace control and transport through event tracing for Windows.
112 logging::LogEventProvider::Initialize(kContentShellProviderName);
113 #endif
114 #if defined(OS_MACOSX)
115 // Needs to happen before InitializeResourceBundle() and before
116 // WebKitTestPlatformInitialize() are called.
117 OverrideFrameworkBundlePath();
118 OverrideChildProcessPath();
119 EnsureCorrectResolutionSettings();
120 #endif // OS_MACOSX
122 InitLogging();
123 CommandLine& command_line = *CommandLine::ForCurrentProcess();
124 if (command_line.HasSwitch(switches::kCheckLayoutTestSysDeps)) {
125 if (!CheckLayoutSystemDeps()) {
126 if (exit_code)
127 *exit_code = 1;
128 return true;
132 #if defined(OS_ANDROID)
133 // Disable <canvas> path antialiasing for consistency with Android Chrome.
134 command_line.AppendSwitch(switches::kDisable2dCanvasAntialiasing);
135 #endif
137 if (command_line.HasSwitch(switches::kDumpRenderTree)) {
138 EnableBrowserLayoutTestMode();
140 command_line.AppendSwitch(switches::kProcessPerTab);
141 command_line.AppendSwitch(switches::kEnableLogging);
142 command_line.AppendSwitch(switches::kAllowFileAccessFromFiles);
143 #if !defined(OS_ANDROID)
144 // OSMesa is not yet available for Android. http://crbug.com/248925
145 command_line.AppendSwitchASCII(
146 switches::kUseGL, gfx::kGLImplementationOSMesaName);
147 #endif
148 command_line.AppendSwitch(switches::kSkipGpuDataLoading);
149 command_line.AppendSwitchASCII(switches::kTouchEvents,
150 switches::kTouchEventsEnabled);
151 command_line.AppendSwitch(switches::kEnableGestureTapHighlight);
152 command_line.AppendSwitchASCII(switches::kForceDeviceScaleFactor, "1.0");
153 #if defined(OS_ANDROID)
154 command_line.AppendSwitch(
155 switches::kDisableGestureRequirementForMediaPlayback);
156 // Capturing pixel results does not yet work when implementation-side
157 // painting is enabled. See http://crbug.com/250777
158 command_line.AppendSwitch(cc::switches::kDisableImplSidePainting);
159 #endif
161 if (!command_line.HasSwitch(switches::kStableReleaseMode)) {
162 command_line.AppendSwitch(
163 switches::kEnableExperimentalWebPlatformFeatures);
166 if (!command_line.HasSwitch(switches::kEnableThreadedCompositing))
167 command_line.AppendSwitch(cc::switches::kDisableThreadedAnimation);
169 command_line.AppendSwitch(switches::kEnableInbandTextTracks);
170 command_line.AppendSwitch(switches::kMuteAudio);
172 net::CookieMonster::EnableFileScheme();
174 // Unless/until WebM files are added to the media layout tests, we need to
175 // avoid removing MP4/H264/AAC so that layout tests can run on Android.
176 #if !defined(OS_ANDROID)
177 net::RemoveProprietaryMediaTypesAndCodecsForTests();
178 #endif
180 if (!WebKitTestPlatformInitialize()) {
181 if (exit_code)
182 *exit_code = 1;
183 return true;
186 SetContentClient(&content_client_);
187 return false;
190 void ShellMainDelegate::PreSandboxStartup() {
191 if (CommandLine::ForCurrentProcess()->HasSwitch(
192 switches::kEnableCrashReporter)) {
193 breakpad::SetBreakpadClient(g_shell_breakpad_client.Pointer());
194 #if defined(OS_MACOSX)
195 base::mac::DisableOSCrashDumps();
196 breakpad::InitCrashReporter();
197 breakpad::InitCrashProcessInfo();
198 #elif defined(OS_POSIX) && !defined(OS_MACOSX)
199 std::string process_type =
200 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
201 switches::kProcessType);
202 if (!process_type.empty() && process_type != switches::kZygoteProcess) {
203 #if defined(OS_ANDROID)
204 breakpad::InitNonBrowserCrashReporterForAndroid();
205 #else
206 breakpad::InitCrashReporter();
207 #endif
209 #elif defined(OS_WIN)
210 UINT new_flags =
211 SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX;
212 UINT existing_flags = SetErrorMode(new_flags);
213 SetErrorMode(existing_flags | new_flags);
214 breakpad::InitCrashReporter();
215 #endif
218 InitializeResourceBundle();
221 int ShellMainDelegate::RunProcess(
222 const std::string& process_type,
223 const MainFunctionParams& main_function_params) {
224 if (!process_type.empty())
225 return -1;
227 #if !defined(OS_ANDROID)
228 // Android stores the BrowserMainRunner instance as a scoped member pointer
229 // on the ShellMainDelegate class because of different object lifetime.
230 scoped_ptr<BrowserMainRunner> browser_runner_;
231 #endif
233 browser_runner_.reset(BrowserMainRunner::Create());
234 return ShellBrowserMain(main_function_params, browser_runner_);
237 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
238 void ShellMainDelegate::ZygoteForked() {
239 if (CommandLine::ForCurrentProcess()->HasSwitch(
240 switches::kEnableCrashReporter)) {
241 breakpad::InitCrashReporter();
244 #endif
246 void ShellMainDelegate::InitializeResourceBundle() {
247 #if defined(OS_ANDROID)
248 // In the Android case, the renderer runs with a different UID and can never
249 // access the file system. So we are passed a file descriptor to the
250 // ResourceBundle pak at launch time.
251 int pak_fd =
252 base::GlobalDescriptors::GetInstance()->MaybeGet(kShellPakDescriptor);
253 if (pak_fd != base::kInvalidPlatformFileValue) {
254 ui::ResourceBundle::InitSharedInstanceWithPakFile(pak_fd, false);
255 ResourceBundle::GetSharedInstance().AddDataPackFromFile(
256 pak_fd, ui::SCALE_FACTOR_100P);
257 return;
259 #endif
261 base::FilePath pak_file;
262 #if defined(OS_MACOSX)
263 pak_file = GetResourcesPakFilePath();
264 #else
265 base::FilePath pak_dir;
267 #if defined(OS_ANDROID)
268 bool got_path = PathService::Get(base::DIR_ANDROID_APP_DATA, &pak_dir);
269 DCHECK(got_path);
270 pak_dir = pak_dir.Append(FILE_PATH_LITERAL("paks"));
271 #else
272 PathService::Get(base::DIR_MODULE, &pak_dir);
273 #endif
275 pak_file = pak_dir.Append(FILE_PATH_LITERAL("content_shell.pak"));
276 #endif
277 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file);
280 ContentBrowserClient* ShellMainDelegate::CreateContentBrowserClient() {
281 browser_client_.reset(new ShellContentBrowserClient);
282 return browser_client_.get();
285 ContentRendererClient* ShellMainDelegate::CreateContentRendererClient() {
286 renderer_client_.reset(new ShellContentRendererClient);
287 return renderer_client_.get();
290 } // namespace content