shell_main_delegate.cc revision 68043e1e95eeb07d5cae7aca370b26518b0867d6
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. 4 5#include "content/shell/app/shell_main_delegate.h" 6 7#include "base/command_line.h" 8#include "base/files/file_path.h" 9#include "base/logging.h" 10#include "base/path_service.h" 11#include "cc/base/switches.h" 12#include "content/public/browser/browser_main_runner.h" 13#include "content/public/common/content_switches.h" 14#include "content/public/common/url_constants.h" 15#include "content/public/test/layouttest_support.h" 16#include "content/shell/app/webkit_test_platform_support.h" 17#include "content/shell/browser/shell_browser_main.h" 18#include "content/shell/browser/shell_content_browser_client.h" 19#include "content/shell/common/shell_switches.h" 20#include "content/shell/renderer/shell_content_renderer_client.h" 21#include "net/cookies/cookie_monster.h" 22#include "ui/base/resource/resource_bundle.h" 23#include "ui/base/ui_base_paths.h" 24#include "ui/base/ui_base_switches.h" 25#include "ui/events/event_switches.h" 26#include "ui/gfx/switches.h" 27#include "ui/gl/gl_switches.h" 28 29#include "ipc/ipc_message.h" // For IPC_MESSAGE_LOG_ENABLED. 30 31#if defined(IPC_MESSAGE_LOG_ENABLED) 32#define IPC_MESSAGE_MACROS_LOG_ENABLED 33#include "content/public/common/content_ipc_logging.h" 34#define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger) \ 35 content::RegisterIPCLogger(msg_id, logger) 36#include "content/shell/common/shell_messages.h" 37#endif 38 39#if defined(OS_ANDROID) 40#include "base/posix/global_descriptors.h" 41#include "content/shell/android/shell_descriptors.h" 42#endif 43 44#if defined(OS_MACOSX) 45#include "content/shell/app/paths_mac.h" 46#include "content/shell/app/shell_main_delegate_mac.h" 47#endif // OS_MACOSX 48 49#if defined(OS_WIN) 50#include <initguid.h> 51#include "base/logging_win.h" 52#endif 53 54namespace { 55 56#if defined(OS_WIN) 57// If "Content Shell" doesn't show up in your list of trace providers in 58// Sawbuck, add these registry entries to your machine (NOTE the optional 59// Wow6432Node key for x64 machines): 60// 1. Find: HKLM\SOFTWARE\[Wow6432Node\]Google\Sawbuck\Providers 61// 2. Add a subkey with the name "{6A3E50A4-7E15-4099-8413-EC94D8C2A4B6}" 62// 3. Add these values: 63// "default_flags"=dword:00000001 64// "default_level"=dword:00000004 65// @="Content Shell" 66 67// {6A3E50A4-7E15-4099-8413-EC94D8C2A4B6} 68const GUID kContentShellProviderName = { 69 0x6a3e50a4, 0x7e15, 0x4099, 70 { 0x84, 0x13, 0xec, 0x94, 0xd8, 0xc2, 0xa4, 0xb6 } }; 71#endif 72 73void InitLogging() { 74 base::FilePath log_filename; 75 PathService::Get(base::DIR_EXE, &log_filename); 76 log_filename = log_filename.AppendASCII("content_shell.log"); 77 logging::LoggingSettings settings; 78 settings.logging_dest = logging::LOG_TO_ALL; 79 settings.log_file = log_filename.value().c_str(); 80 settings.delete_old = logging::DELETE_OLD_LOG_FILE; 81 logging::InitLogging(settings); 82 logging::SetLogItems(true, true, true, true); 83} 84 85} // namespace 86 87namespace content { 88 89ShellMainDelegate::ShellMainDelegate() { 90} 91 92ShellMainDelegate::~ShellMainDelegate() { 93} 94 95bool ShellMainDelegate::BasicStartupComplete(int* exit_code) { 96#if defined(OS_WIN) 97 // Enable trace control and transport through event tracing for Windows. 98 logging::LogEventProvider::Initialize(kContentShellProviderName); 99#endif 100#if defined(OS_MACOSX) 101 // Needs to happen before InitializeResourceBundle() and before 102 // WebKitTestPlatformInitialize() are called. 103 OverrideFrameworkBundlePath(); 104 OverrideChildProcessPath(); 105 EnsureCorrectResolutionSettings(); 106#endif // OS_MACOSX 107 108 InitLogging(); 109 CommandLine& command_line = *CommandLine::ForCurrentProcess(); 110 if (command_line.HasSwitch(switches::kCheckLayoutTestSysDeps)) { 111 if (!CheckLayoutSystemDeps()) { 112 if (exit_code) 113 *exit_code = 1; 114 return true; 115 } 116 } 117 if (command_line.HasSwitch(switches::kDumpRenderTree)) { 118 EnableBrowserLayoutTestMode(); 119 120 command_line.AppendSwitch(switches::kProcessPerTab); 121 command_line.AppendSwitch(switches::kEnableLogging); 122 command_line.AppendSwitch(switches::kAllowFileAccessFromFiles); 123#if !defined(OS_ANDROID) 124 // OSMesa is not yet available for Android. http://crbug.com/248925 125 command_line.AppendSwitchASCII( 126 switches::kUseGL, gfx::kGLImplementationOSMesaName); 127#endif 128 command_line.AppendSwitch(switches::kSkipGpuDataLoading); 129 command_line.AppendSwitchASCII(switches::kTouchEvents, 130 switches::kTouchEventsEnabled); 131 command_line.AppendSwitch(switches::kEnableGestureTapHighlight); 132 command_line.AppendSwitchASCII(switches::kForceDeviceScaleFactor, "1.0"); 133#if defined(OS_ANDROID) 134 command_line.AppendSwitch( 135 switches::kDisableGestureRequirementForMediaPlayback); 136 // Capturing pixel results does not yet work when implementation-side 137 // painting is enabled. See http://crbug.com/250777 138 command_line.AppendSwitch(cc::switches::kDisableImplSidePainting); 139#endif 140 141 if (!command_line.HasSwitch(switches::kStableReleaseMode)) { 142 command_line.AppendSwitch( 143 switches::kEnableExperimentalWebPlatformFeatures); 144 command_line.AppendSwitch(switches::kEnableCssShaders); 145 } 146 147 if (!command_line.HasSwitch(switches::kEnableThreadedCompositing)) 148 command_line.AppendSwitch(cc::switches::kDisableThreadedAnimation); 149 150 command_line.AppendSwitch(switches::kEnableInbandTextTracks); 151 command_line.AppendSwitch(switches::kMuteAudio); 152 153 net::CookieMonster::EnableFileScheme(); 154 155 // Unless/until WebM files are added to the media layout tests, we need to 156 // avoid removing MP4/H264/AAC so that layout tests can run on Android. 157#if !defined(OS_ANDROID) 158 net::RemoveProprietaryMediaTypesAndCodecsForTests(); 159#endif 160 161 if (!WebKitTestPlatformInitialize()) { 162 if (exit_code) 163 *exit_code = 1; 164 return true; 165 } 166 } 167 SetContentClient(&content_client_); 168 return false; 169} 170 171void ShellMainDelegate::PreSandboxStartup() { 172 InitializeResourceBundle(); 173} 174 175int ShellMainDelegate::RunProcess( 176 const std::string& process_type, 177 const MainFunctionParams& main_function_params) { 178 if (!process_type.empty()) 179 return -1; 180 181#if !defined(OS_ANDROID) 182 // Android stores the BrowserMainRunner instance as a scoped member pointer 183 // on the ShellMainDelegate class because of different object lifetime. 184 scoped_ptr<BrowserMainRunner> browser_runner_; 185#endif 186 187 browser_runner_.reset(BrowserMainRunner::Create()); 188 return ShellBrowserMain(main_function_params, browser_runner_); 189} 190 191void ShellMainDelegate::InitializeResourceBundle() { 192#if defined(OS_ANDROID) 193 // In the Android case, the renderer runs with a different UID and can never 194 // access the file system. So we are passed a file descriptor to the 195 // ResourceBundle pak at launch time. 196 int pak_fd = 197 base::GlobalDescriptors::GetInstance()->MaybeGet(kShellPakDescriptor); 198 if (pak_fd != base::kInvalidPlatformFileValue) { 199 ui::ResourceBundle::InitSharedInstanceWithPakFile(pak_fd, false); 200 ResourceBundle::GetSharedInstance().AddDataPackFromFile( 201 pak_fd, ui::SCALE_FACTOR_100P); 202 return; 203 } 204#endif 205 206 base::FilePath pak_file; 207#if defined(OS_MACOSX) 208 pak_file = GetResourcesPakFilePath(); 209#else 210 base::FilePath pak_dir; 211 212#if defined(OS_ANDROID) 213 bool got_path = PathService::Get(base::DIR_ANDROID_APP_DATA, &pak_dir); 214 DCHECK(got_path); 215 pak_dir = pak_dir.Append(FILE_PATH_LITERAL("paks")); 216#else 217 PathService::Get(base::DIR_MODULE, &pak_dir); 218#endif 219 220 pak_file = pak_dir.Append(FILE_PATH_LITERAL("content_shell.pak")); 221#endif 222 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); 223} 224 225ContentBrowserClient* ShellMainDelegate::CreateContentBrowserClient() { 226 browser_client_.reset(new ShellContentBrowserClient); 227 return browser_client_.get(); 228} 229 230ContentRendererClient* ShellMainDelegate::CreateContentRendererClient() { 231 renderer_client_.reset(new ShellContentRendererClient); 232 return renderer_client_.get(); 233} 234 235} // namespace content 236