| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/shell/browser/shell_content_browser_client.h" | 5 #include "content/shell/browser/shell_content_browser_client.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 namespace { | 58 namespace { |
| 59 | 59 |
| 60 ShellContentBrowserClient* g_browser_client; | 60 ShellContentBrowserClient* g_browser_client; |
| 61 bool g_swap_processes_for_redirect = false; | 61 bool g_swap_processes_for_redirect = false; |
| 62 | 62 |
| 63 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 63 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 64 breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost( | 64 breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost( |
| 65 const std::string& process_type) { | 65 const std::string& process_type) { |
| 66 base::FilePath dumps_path = | 66 base::FilePath dumps_path = |
| 67 CommandLine::ForCurrentProcess()->GetSwitchValuePath( | 67 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath( |
| 68 switches::kCrashDumpsDir); | 68 switches::kCrashDumpsDir); |
| 69 { | 69 { |
| 70 ANNOTATE_SCOPED_MEMORY_LEAK; | 70 ANNOTATE_SCOPED_MEMORY_LEAK; |
| 71 breakpad::CrashHandlerHostLinux* crash_handler = | 71 breakpad::CrashHandlerHostLinux* crash_handler = |
| 72 new breakpad::CrashHandlerHostLinux( | 72 new breakpad::CrashHandlerHostLinux( |
| 73 process_type, dumps_path, false); | 73 process_type, dumps_path, false); |
| 74 crash_handler->StartUploaderThread(); | 74 crash_handler->StartUploaderThread(); |
| 75 return crash_handler; | 75 return crash_handler; |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 | 78 |
| 79 int GetCrashSignalFD(const CommandLine& command_line) { | 79 int GetCrashSignalFD(const base::CommandLine& command_line) { |
| 80 if (!breakpad::IsCrashReporterEnabled()) | 80 if (!breakpad::IsCrashReporterEnabled()) |
| 81 return -1; | 81 return -1; |
| 82 | 82 |
| 83 std::string process_type = | 83 std::string process_type = |
| 84 command_line.GetSwitchValueASCII(switches::kProcessType); | 84 command_line.GetSwitchValueASCII(switches::kProcessType); |
| 85 | 85 |
| 86 if (process_type == switches::kRendererProcess) { | 86 if (process_type == switches::kRendererProcess) { |
| 87 static breakpad::CrashHandlerHostLinux* crash_handler = NULL; | 87 static breakpad::CrashHandlerHostLinux* crash_handler = NULL; |
| 88 if (!crash_handler) | 88 if (!crash_handler) |
| 89 crash_handler = CreateCrashHandlerHost(process_type); | 89 crash_handler = CreateCrashHandlerHost(process_type); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 DCHECK(!g_browser_client); | 130 DCHECK(!g_browser_client); |
| 131 g_browser_client = this; | 131 g_browser_client = this; |
| 132 } | 132 } |
| 133 | 133 |
| 134 ShellContentBrowserClient::~ShellContentBrowserClient() { | 134 ShellContentBrowserClient::~ShellContentBrowserClient() { |
| 135 g_browser_client = NULL; | 135 g_browser_client = NULL; |
| 136 } | 136 } |
| 137 | 137 |
| 138 BrowserMainParts* ShellContentBrowserClient::CreateBrowserMainParts( | 138 BrowserMainParts* ShellContentBrowserClient::CreateBrowserMainParts( |
| 139 const MainFunctionParams& parameters) { | 139 const MainFunctionParams& parameters) { |
| 140 shell_browser_main_parts_ = | 140 shell_browser_main_parts_ = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 141 CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree) | 141 switches::kDumpRenderTree) |
| 142 ? new LayoutTestBrowserMainParts(parameters) | 142 ? new LayoutTestBrowserMainParts(parameters) |
| 143 : new ShellBrowserMainParts(parameters); | 143 : new ShellBrowserMainParts(parameters); |
| 144 return shell_browser_main_parts_; | 144 return shell_browser_main_parts_; |
| 145 } | 145 } |
| 146 | 146 |
| 147 void ShellContentBrowserClient::RenderProcessWillLaunch( | 147 void ShellContentBrowserClient::RenderProcessWillLaunch( |
| 148 RenderProcessHost* host) { | 148 RenderProcessHost* host) { |
| 149 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kExposeIpcEcho)) | 149 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 150 switches::kExposeIpcEcho)) |
| 150 host->AddFilter(new IPCEchoMessageFilter()); | 151 host->AddFilter(new IPCEchoMessageFilter()); |
| 151 } | 152 } |
| 152 | 153 |
| 153 net::URLRequestContextGetter* ShellContentBrowserClient::CreateRequestContext( | 154 net::URLRequestContextGetter* ShellContentBrowserClient::CreateRequestContext( |
| 154 BrowserContext* content_browser_context, | 155 BrowserContext* content_browser_context, |
| 155 ProtocolHandlerMap* protocol_handlers, | 156 ProtocolHandlerMap* protocol_handlers, |
| 156 URLRequestInterceptorScopedVector request_interceptors) { | 157 URLRequestInterceptorScopedVector request_interceptors) { |
| 157 ShellBrowserContext* shell_browser_context = | 158 ShellBrowserContext* shell_browser_context = |
| 158 ShellBrowserContextForBrowserContext(content_browser_context); | 159 ShellBrowserContextForBrowserContext(content_browser_context); |
| 159 return shell_browser_context->CreateRequestContext( | 160 return shell_browser_context->CreateRequestContext( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 url::kFileScheme, | 192 url::kFileScheme, |
| 192 }; | 193 }; |
| 193 for (size_t i = 0; i < arraysize(kProtocolList); ++i) { | 194 for (size_t i = 0; i < arraysize(kProtocolList); ++i) { |
| 194 if (url.scheme() == kProtocolList[i]) | 195 if (url.scheme() == kProtocolList[i]) |
| 195 return true; | 196 return true; |
| 196 } | 197 } |
| 197 return false; | 198 return false; |
| 198 } | 199 } |
| 199 | 200 |
| 200 void ShellContentBrowserClient::AppendExtraCommandLineSwitches( | 201 void ShellContentBrowserClient::AppendExtraCommandLineSwitches( |
| 201 CommandLine* command_line, int child_process_id) { | 202 base::CommandLine* command_line, |
| 202 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) | 203 int child_process_id) { |
| 204 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 205 switches::kDumpRenderTree)) |
| 203 command_line->AppendSwitch(switches::kDumpRenderTree); | 206 command_line->AppendSwitch(switches::kDumpRenderTree); |
| 204 if (CommandLine::ForCurrentProcess()->HasSwitch( | 207 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 205 switches::kEnableFontAntialiasing)) | 208 switches::kEnableFontAntialiasing)) |
| 206 command_line->AppendSwitch(switches::kEnableFontAntialiasing); | 209 command_line->AppendSwitch(switches::kEnableFontAntialiasing); |
| 207 if (CommandLine::ForCurrentProcess()->HasSwitch( | 210 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 208 switches::kExposeInternalsForTesting)) | 211 switches::kExposeInternalsForTesting)) |
| 209 command_line->AppendSwitch(switches::kExposeInternalsForTesting); | 212 command_line->AppendSwitch(switches::kExposeInternalsForTesting); |
| 210 if (CommandLine::ForCurrentProcess()->HasSwitch( | 213 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 211 switches::kExposeIpcEcho)) | 214 switches::kExposeIpcEcho)) |
| 212 command_line->AppendSwitch(switches::kExposeIpcEcho); | 215 command_line->AppendSwitch(switches::kExposeIpcEcho); |
| 213 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kStableReleaseMode)) | 216 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 217 switches::kStableReleaseMode)) |
| 214 command_line->AppendSwitch(switches::kStableReleaseMode); | 218 command_line->AppendSwitch(switches::kStableReleaseMode); |
| 215 if (CommandLine::ForCurrentProcess()->HasSwitch( | 219 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 216 switches::kEnableCrashReporter)) { | 220 switches::kEnableCrashReporter)) { |
| 217 command_line->AppendSwitch(switches::kEnableCrashReporter); | 221 command_line->AppendSwitch(switches::kEnableCrashReporter); |
| 218 } | 222 } |
| 219 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kCrashDumpsDir)) { | 223 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 224 switches::kCrashDumpsDir)) { |
| 220 command_line->AppendSwitchPath( | 225 command_line->AppendSwitchPath( |
| 221 switches::kCrashDumpsDir, | 226 switches::kCrashDumpsDir, |
| 222 CommandLine::ForCurrentProcess()->GetSwitchValuePath( | 227 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath( |
| 223 switches::kCrashDumpsDir)); | 228 switches::kCrashDumpsDir)); |
| 224 } | 229 } |
| 225 if (CommandLine::ForCurrentProcess()->HasSwitch( | 230 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 226 switches::kEnableLeakDetection)) { | 231 switches::kEnableLeakDetection)) { |
| 227 command_line->AppendSwitchASCII( | 232 command_line->AppendSwitchASCII( |
| 228 switches::kEnableLeakDetection, | 233 switches::kEnableLeakDetection, |
| 229 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 234 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 230 switches::kEnableLeakDetection)); | 235 switches::kEnableLeakDetection)); |
| 231 } | 236 } |
| 232 if (CommandLine::ForCurrentProcess()->HasSwitch( | 237 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 233 switches::kRegisterFontFiles)) { | 238 switches::kRegisterFontFiles)) { |
| 234 command_line->AppendSwitchASCII( | 239 command_line->AppendSwitchASCII( |
| 235 switches::kRegisterFontFiles, | 240 switches::kRegisterFontFiles, |
| 236 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 241 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 237 switches::kRegisterFontFiles)); | 242 switches::kRegisterFontFiles)); |
| 238 } | 243 } |
| 239 } | 244 } |
| 240 | 245 |
| 241 void ShellContentBrowserClient::OverrideWebkitPrefs( | 246 void ShellContentBrowserClient::OverrideWebkitPrefs( |
| 242 RenderViewHost* render_view_host, | 247 RenderViewHost* render_view_host, |
| 243 const GURL& url, | 248 const GURL& url, |
| 244 WebPreferences* prefs) { | 249 WebPreferences* prefs) { |
| 245 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) | 250 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 251 switches::kDumpRenderTree)) |
| 246 return; | 252 return; |
| 247 WebKitTestController::Get()->OverrideWebkitPrefs(prefs); | 253 WebKitTestController::Get()->OverrideWebkitPrefs(prefs); |
| 248 } | 254 } |
| 249 | 255 |
| 250 void ShellContentBrowserClient::ResourceDispatcherHostCreated() { | 256 void ShellContentBrowserClient::ResourceDispatcherHostCreated() { |
| 251 resource_dispatcher_host_delegate_.reset( | 257 resource_dispatcher_host_delegate_.reset( |
| 252 CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree) | 258 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 259 switches::kDumpRenderTree) |
| 253 ? new LayoutTestResourceDispatcherHostDelegate | 260 ? new LayoutTestResourceDispatcherHostDelegate |
| 254 : new ShellResourceDispatcherHostDelegate); | 261 : new ShellResourceDispatcherHostDelegate); |
| 255 ResourceDispatcherHost::Get()->SetDelegate( | 262 ResourceDispatcherHost::Get()->SetDelegate( |
| 256 resource_dispatcher_host_delegate_.get()); | 263 resource_dispatcher_host_delegate_.get()); |
| 257 } | 264 } |
| 258 | 265 |
| 259 std::string ShellContentBrowserClient::GetDefaultDownloadName() { | 266 std::string ShellContentBrowserClient::GetDefaultDownloadName() { |
| 260 return "download"; | 267 return "download"; |
| 261 } | 268 } |
| 262 | 269 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 290 return g_swap_processes_for_redirect; | 297 return g_swap_processes_for_redirect; |
| 291 } | 298 } |
| 292 | 299 |
| 293 DevToolsManagerDelegate* | 300 DevToolsManagerDelegate* |
| 294 ShellContentBrowserClient::GetDevToolsManagerDelegate() { | 301 ShellContentBrowserClient::GetDevToolsManagerDelegate() { |
| 295 return new ShellDevToolsManagerDelegate(browser_context()); | 302 return new ShellDevToolsManagerDelegate(browser_context()); |
| 296 } | 303 } |
| 297 | 304 |
| 298 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 305 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 299 void ShellContentBrowserClient::GetAdditionalMappedFilesForChildProcess( | 306 void ShellContentBrowserClient::GetAdditionalMappedFilesForChildProcess( |
| 300 const CommandLine& command_line, | 307 const base::CommandLine& command_line, |
| 301 int child_process_id, | 308 int child_process_id, |
| 302 FileDescriptorInfo* mappings) { | 309 FileDescriptorInfo* mappings) { |
| 303 #if defined(OS_ANDROID) | 310 #if defined(OS_ANDROID) |
| 304 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ; | 311 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ; |
| 305 base::FilePath pak_file; | 312 base::FilePath pak_file; |
| 306 bool r = PathService::Get(base::DIR_ANDROID_APP_DATA, &pak_file); | 313 bool r = PathService::Get(base::DIR_ANDROID_APP_DATA, &pak_file); |
| 307 CHECK(r); | 314 CHECK(r); |
| 308 pak_file = pak_file.Append(FILE_PATH_LITERAL("paks")); | 315 pak_file = pak_file.Append(FILE_PATH_LITERAL("paks")); |
| 309 pak_file = pak_file.Append(FILE_PATH_LITERAL("content_shell.pak")); | 316 pak_file = pak_file.Append(FILE_PATH_LITERAL("content_shell.pak")); |
| 310 | 317 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 ShellBrowserContext* | 375 ShellBrowserContext* |
| 369 ShellContentBrowserClient::ShellBrowserContextForBrowserContext( | 376 ShellContentBrowserClient::ShellBrowserContextForBrowserContext( |
| 370 BrowserContext* content_browser_context) { | 377 BrowserContext* content_browser_context) { |
| 371 if (content_browser_context == browser_context()) | 378 if (content_browser_context == browser_context()) |
| 372 return browser_context(); | 379 return browser_context(); |
| 373 DCHECK_EQ(content_browser_context, off_the_record_browser_context()); | 380 DCHECK_EQ(content_browser_context, off_the_record_browser_context()); |
| 374 return off_the_record_browser_context(); | 381 return off_the_record_browser_context(); |
| 375 } | 382 } |
| 376 | 383 |
| 377 } // namespace content | 384 } // namespace content |
| OLD | NEW |