shell_main_delegate.cc revision 4e180b6a0b4720a9b8e9e959a882386f690f08ff
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 118#if defined(OS_ANDROID) 119 // Disable <canvas> path antialiasing for consistency with Android Chrome. 120 command_line.AppendSwitch(switches::kDisable2dCanvasAntialiasing); 121#endif 122 123 if (command_line.HasSwitch(switches::kDumpRenderTree)) { 124 EnableBrowserLayoutTestMode(); 125 126 command_line.AppendSwitch(switches::kProcessPerTab); 127 command_line.AppendSwitch(switches::kEnableLogging); 128 command_line.AppendSwitch(switches::kAllowFileAccessFromFiles); 129#if !defined(OS_ANDROID) 130 // OSMesa is not yet available for Android. http://crbug.com/248925 131 command_line.AppendSwitchASCII( 132 switches::kUseGL, gfx::kGLImplementationOSMesaName); 133#endif 134 command_line.AppendSwitch(switches::kSkipGpuDataLoading); 135 command_line.AppendSwitchASCII(switches::kTouchEvents, 136 switches::kTouchEventsEnabled); 137 command_line.AppendSwitch(switches::kEnableGestureTapHighlight); 138 command_line.AppendSwitchASCII(switches::kForceDeviceScaleFactor, "1.0"); 139#if defined(OS_ANDROID) 140 command_line.AppendSwitch( 141 switches::kDisableGestureRequirementForMediaPlayback); 142 // Capturing pixel results does not yet work when implementation-side 143 // painting is enabled. See http://crbug.com/250777 144 command_line.AppendSwitch(cc::switches::kDisableImplSidePainting); 145#endif 146 147 if (!command_line.HasSwitch(switches::kStableReleaseMode)) { 148 command_line.AppendSwitch( 149 switches::kEnableExperimentalWebPlatformFeatures); 150 } 151 152 if (!command_line.HasSwitch(switches::kEnableThreadedCompositing)) 153 command_line.AppendSwitch(cc::switches::kDisableThreadedAnimation); 154 155 command_line.AppendSwitch(switches::kEnableInbandTextTracks); 156 command_line.AppendSwitch(switches::kMuteAudio); 157 158 net::CookieMonster::EnableFileScheme(); 159 160 // Unless/until WebM files are added to the media layout tests, we need to 161 // avoid removing MP4/H264/AAC so that layout tests can run on Android. 162#if !defined(OS_ANDROID) 163 net::RemoveProprietaryMediaTypesAndCodecsForTests(); 164#endif 165 166 if (!WebKitTestPlatformInitialize()) { 167 if (exit_code) 168 *exit_code = 1; 169 return true; 170 } 171 } 172 SetContentClient(&content_client_); 173 return false; 174} 175 176void ShellMainDelegate::PreSandboxStartup() { 177 InitializeResourceBundle(); 178} 179 180int ShellMainDelegate::RunProcess( 181 const std::string& process_type, 182 const MainFunctionParams& main_function_params) { 183 if (!process_type.empty()) 184 return -1; 185 186#if !defined(OS_ANDROID) 187 // Android stores the BrowserMainRunner instance as a scoped member pointer 188 // on the ShellMainDelegate class because of different object lifetime. 189 scoped_ptr<BrowserMainRunner> browser_runner_; 190#endif 191 192 browser_runner_.reset(BrowserMainRunner::Create()); 193 return ShellBrowserMain(main_function_params, browser_runner_); 194} 195 196void ShellMainDelegate::InitializeResourceBundle() { 197#if defined(OS_ANDROID) 198 // In the Android case, the renderer runs with a different UID and can never 199 // access the file system. So we are passed a file descriptor to the 200 // ResourceBundle pak at launch time. 201 int pak_fd = 202 base::GlobalDescriptors::GetInstance()->MaybeGet(kShellPakDescriptor); 203 if (pak_fd != base::kInvalidPlatformFileValue) { 204 ui::ResourceBundle::InitSharedInstanceWithPakFile(pak_fd, false); 205 ResourceBundle::GetSharedInstance().AddDataPackFromFile( 206 pak_fd, ui::SCALE_FACTOR_100P); 207 return; 208 } 209#endif 210 211 base::FilePath pak_file; 212#if defined(OS_MACOSX) 213 pak_file = GetResourcesPakFilePath(); 214#else 215 base::FilePath pak_dir; 216 217#if defined(OS_ANDROID) 218 bool got_path = PathService::Get(base::DIR_ANDROID_APP_DATA, &pak_dir); 219 DCHECK(got_path); 220 pak_dir = pak_dir.Append(FILE_PATH_LITERAL("paks")); 221#else 222 PathService::Get(base::DIR_MODULE, &pak_dir); 223#endif 224 225 pak_file = pak_dir.Append(FILE_PATH_LITERAL("content_shell.pak")); 226#endif 227 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); 228} 229 230ContentBrowserClient* ShellMainDelegate::CreateContentBrowserClient() { 231 browser_client_.reset(new ShellContentBrowserClient); 232 return browser_client_.get(); 233} 234 235ContentRendererClient* ShellMainDelegate::CreateContentRendererClient() { 236 renderer_client_.reset(new ShellContentRendererClient); 237 return renderer_client_.get(); 238} 239 240} // namespace content 241