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