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