13551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
53551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "content/shell/browser/shell_content_browser_client.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
71e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/base_switches.h"
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/command_line.h"
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/file_util.h"
10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/files/file.h"
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/path_service.h"
12a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "base/strings/utf_string_conversions.h"
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/render_process_host.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/resource_dispatcher_host.h"
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/storage_partition.h"
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/common/content_switches.h"
17b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "content/public/common/url_constants.h"
183551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "content/shell/browser/shell.h"
193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "content/shell/browser/shell_browser_context.h"
203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "content/shell/browser/shell_browser_main_parts.h"
213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "content/shell/browser/shell_devtools_delegate.h"
223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "content/shell/browser/shell_message_filter.h"
233551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "content/shell/browser/shell_net_log.h"
243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "content/shell/browser/shell_quota_permission_context.h"
253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "content/shell/browser/shell_resource_dispatcher_host_delegate.h"
263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "content/shell/browser/shell_web_contents_view_delegate_creator.h"
273551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "content/shell/browser/webkit_test_controller.h"
28b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "content/shell/common/shell_messages.h"
29b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "content/shell/common/shell_switches.h"
30b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "content/shell/common/webkit_test_helpers.h"
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/shell/geolocation/shell_access_token_store.h"
327dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "net/url_request/url_request_context_getter.h"
337dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "url/gurl.h"
34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "webkit/common/webpreferences.h"
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_ANDROID)
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/android/path_utils.h"
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/path_service.h"
391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "components/breakpad/browser/crash_dump_manager_android.h"
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/shell/android/shell_descriptors.h"
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#if defined(OS_POSIX) && !defined(OS_MACOSX)
441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/debug/leak_annotations.h"
451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "components/breakpad/app/breakpad_linux.h"
461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "components/breakpad/browser/crash_handler_host_linux.h"
471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "content/public/common/content_descriptors.h"
481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#endif
491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
50a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#if defined(OS_WIN)
51a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "content/common/sandbox_win.h"
52a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "sandbox/win/src/sandbox.h"
53a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#endif
54a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content {
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace {
582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
59c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)ShellContentBrowserClient* g_browser_client;
60c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdochbool g_swap_processes_for_redirect = false;
612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
62f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    const std::string& process_type) {
651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  base::FilePath dumps_path =
661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      CommandLine::ForCurrentProcess()->GetSwitchValuePath(
671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)          switches::kCrashDumpsDir);
681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  {
691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    ANNOTATE_SCOPED_MEMORY_LEAK;
701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    breakpad::CrashHandlerHostLinux* crash_handler =
711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        new breakpad::CrashHandlerHostLinux(
721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)            process_type, dumps_path, false);
731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    crash_handler->StartUploaderThread();
741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    return crash_handler;
751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)int GetCrashSignalFD(const CommandLine& command_line) {
791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  if (!breakpad::IsCrashReporterEnabled())
801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    return -1;
811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  std::string process_type =
831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      command_line.GetSwitchValueASCII(switches::kProcessType);
841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  if (process_type == switches::kRendererProcess) {
861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    if (!crash_handler)
881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      crash_handler = CreateCrashHandlerHost(process_type);
891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    return crash_handler->GetDeathSignalSocket();
901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  if (process_type == switches::kPluginProcess) {
931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    if (!crash_handler)
951e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      crash_handler = CreateCrashHandlerHost(process_type);
961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    return crash_handler->GetDeathSignalSocket();
971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  if (process_type == switches::kPpapiPluginProcess) {
1001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
1011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    if (!crash_handler)
1021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      crash_handler = CreateCrashHandlerHost(process_type);
1031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    return crash_handler->GetDeathSignalSocket();
1041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
1051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  if (process_type == switches::kGpuProcess) {
1071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
1081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    if (!crash_handler)
1091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      crash_handler = CreateCrashHandlerHost(process_type);
1101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    return crash_handler->GetDeathSignalSocket();
1111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
1121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  return -1;
1141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
115f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif  // defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
1161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace
1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
119c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)ShellContentBrowserClient* ShellContentBrowserClient::Get() {
120c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return g_browser_client;
121c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
122c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
123c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdochvoid ShellContentBrowserClient::SetSwapProcessesForRedirect(bool swap) {
124c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch  g_swap_processes_for_redirect = swap;
125c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch}
126c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ShellContentBrowserClient::ShellContentBrowserClient()
128a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    : shell_browser_main_parts_(NULL) {
129c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  DCHECK(!g_browser_client);
130c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  g_browser_client = this;
1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree))
1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return;
1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  webkit_source_dir_ = GetWebKitRootDirFilePath();
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ShellContentBrowserClient::~ShellContentBrowserClient() {
137c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  g_browser_client = NULL;
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)BrowserMainParts* ShellContentBrowserClient::CreateBrowserMainParts(
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const MainFunctionParams& parameters) {
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  shell_browser_main_parts_ = new ShellBrowserMainParts(parameters);
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return shell_browser_main_parts_;
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void ShellContentBrowserClient::RenderProcessWillLaunch(
1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    RenderProcessHost* host) {
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree))
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
1504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  host->AddFilter(new ShellMessageFilter(
1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      host->GetID(),
1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      BrowserContext::GetDefaultStoragePartition(browser_context())
1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          ->GetDatabaseTracker(),
1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      BrowserContext::GetDefaultStoragePartition(browser_context())
1557dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch          ->GetQuotaManager(),
1567dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      BrowserContext::GetDefaultStoragePartition(browser_context())
1577dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch          ->GetURLRequestContext()));
1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  host->Send(new ShellViewMsg_SetWebKitSourceDir(webkit_source_dir_));
1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)net::URLRequestContextGetter* ShellContentBrowserClient::CreateRequestContext(
1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    BrowserContext* content_browser_context,
163a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    ProtocolHandlerMap* protocol_handlers,
164cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    URLRequestInterceptorScopedVector request_interceptors) {
1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ShellBrowserContext* shell_browser_context =
1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      ShellBrowserContextForBrowserContext(content_browser_context);
167a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return shell_browser_context->CreateRequestContext(
168cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      protocol_handlers, request_interceptors.Pass());
1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
1702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)net::URLRequestContextGetter*
1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ShellContentBrowserClient::CreateRequestContextForStoragePartition(
1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    BrowserContext* content_browser_context,
1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const base::FilePath& partition_path,
1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    bool in_memory,
176a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    ProtocolHandlerMap* protocol_handlers,
177cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    URLRequestInterceptorScopedVector request_interceptors) {
1782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ShellBrowserContext* shell_browser_context =
1792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      ShellBrowserContextForBrowserContext(content_browser_context);
1802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return shell_browser_context->CreateRequestContextForStoragePartition(
181a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      partition_path,
182a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      in_memory,
183a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      protocol_handlers,
184cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      request_interceptors.Pass());
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
187b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)bool ShellContentBrowserClient::IsHandledURL(const GURL& url) {
188b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  if (!url.is_valid())
189b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    return false;
190b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  DCHECK_EQ(url.scheme(), StringToLowerASCII(url.scheme()));
191b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // Keep in sync with ProtocolHandlers added by
192b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // ShellURLRequestContextGetter::GetURLRequestContext().
193b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  static const char* const kProtocolList[] = {
194cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      url::kBlobScheme,
195cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      url::kFileSystemScheme,
1965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      kChromeUIScheme,
1975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      kChromeDevToolsScheme,
198cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      url::kDataScheme,
199cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      url::kFileScheme,
200b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  };
201b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  for (size_t i = 0; i < arraysize(kProtocolList); ++i) {
202b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    if (url.scheme() == kProtocolList[i])
203b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      return true;
204b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  }
205b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  return false;
206b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}
207b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ShellContentBrowserClient::AppendExtraCommandLineSwitches(
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    CommandLine* command_line, int child_process_id) {
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree))
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    command_line->AppendSwitch(switches::kDumpRenderTree);
212ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  if (CommandLine::ForCurrentProcess()->HasSwitch(
213010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      switches::kEnableFontAntialiasing))
214010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    command_line->AppendSwitch(switches::kEnableFontAntialiasing);
215c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  if (CommandLine::ForCurrentProcess()->HasSwitch(
216ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      switches::kExposeInternalsForTesting))
217ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    command_line->AppendSwitch(switches::kExposeInternalsForTesting);
2183551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kStableReleaseMode))
2193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    command_line->AppendSwitch(switches::kStableReleaseMode);
2201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  if (CommandLine::ForCurrentProcess()->HasSwitch(
2211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)          switches::kEnableCrashReporter)) {
2221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    command_line->AppendSwitch(switches::kEnableCrashReporter);
2231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
2241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kCrashDumpsDir)) {
2251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    command_line->AppendSwitchPath(
2261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        switches::kCrashDumpsDir,
2271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        CommandLine::ForCurrentProcess()->GetSwitchValuePath(
2281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)            switches::kCrashDumpsDir));
2291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
2305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (CommandLine::ForCurrentProcess()->HasSwitch(
2315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          switches::kEnableLeakDetection))
2325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    command_line->AppendSwitch(switches::kEnableLeakDetection);
233a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  if (CommandLine::ForCurrentProcess()->HasSwitch(
234a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        switches::kRegisterFontFiles)) {
235a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    command_line->AppendSwitchASCII(
236a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        switches::kRegisterFontFiles,
237a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
238a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch            switches::kRegisterFontFiles));
239a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  }
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ShellContentBrowserClient::OverrideWebkitPrefs(
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    RenderViewHost* render_view_host,
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const GURL& url,
245c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    WebPreferences* prefs) {
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree))
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
2482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  WebKitTestController::Get()->OverrideWebkitPrefs(prefs);
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ShellContentBrowserClient::ResourceDispatcherHostCreated() {
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  resource_dispatcher_host_delegate_.reset(
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      new ShellResourceDispatcherHostDelegate());
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ResourceDispatcherHost::Get()->SetDelegate(
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      resource_dispatcher_host_delegate_.get());
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)std::string ShellContentBrowserClient::GetDefaultDownloadName() {
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return "download";
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)WebContentsViewDelegate* ShellContentBrowserClient::GetWebContentsViewDelegate(
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    WebContents* web_contents) {
2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if !defined(USE_AURA)
2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return CreateShellWebContentsViewDelegate(web_contents);
2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#else
2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return NULL;
2682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
2692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)QuotaPermissionContext*
2722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ShellContentBrowserClient::CreateQuotaPermissionContext() {
2732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return new ShellQuotaPermissionContext();
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
276424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)SpeechRecognitionManagerDelegate*
277424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    ShellContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
278424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  return new ShellSpeechRecognitionManagerDelegate();
279424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)}
280424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
281eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochnet::NetLog* ShellContentBrowserClient::GetNetLog() {
282eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return shell_browser_main_parts_->net_log();
283eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
284eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
285c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdochbool ShellContentBrowserClient::ShouldSwapProcessesForRedirect(
286c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch    ResourceContext* resource_context,
287c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch    const GURL& current_url,
288c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch    const GURL& new_url) {
289c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch  return g_swap_processes_for_redirect;
290c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch}
291c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch
2921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#if defined(OS_POSIX) && !defined(OS_MACOSX)
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ShellContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const CommandLine& command_line,
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    int child_process_id,
296cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    std::vector<FileDescriptorInfo>* mappings) {
2971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#if defined(OS_ANDROID)
29846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  int flags = base::File::FLAG_OPEN | base::File::FLAG_READ;
2992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::FilePath pak_file;
3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool r = PathService::Get(base::DIR_ANDROID_APP_DATA, &pak_file);
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CHECK(r);
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  pak_file = pak_file.Append(FILE_PATH_LITERAL("paks"));
3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  pak_file = pak_file.Append(FILE_PATH_LITERAL("content_shell.pak"));
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
305a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  base::File f(pak_file, flags);
306a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (!f.IsValid()) {
3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    NOTREACHED() << "Failed to open file when creating renderer process: "
3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                 << "content_shell.pak";
3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  mappings->push_back(
311cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      FileDescriptorInfo(kShellPakDescriptor, base::FileDescriptor(f.Pass())));
3121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
3131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  if (breakpad::IsCrashReporterEnabled()) {
3141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    f = breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile(
3151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        child_process_id);
316a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    if (!f.IsValid()) {
3171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
3181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                 << "be disabled for this process.";
3191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    } else {
320a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      mappings->push_back(
321a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)          FileDescriptorInfo(kAndroidMinidumpDescriptor,
322a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                             base::FileDescriptor(f.Pass())));
3231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    }
3241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
3251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#else  // !defined(OS_ANDROID)
3261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  int crash_signal_fd = GetCrashSignalFD(command_line);
3271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  if (crash_signal_fd >= 0) {
3281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    mappings->push_back(FileDescriptorInfo(
3291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        kCrashDumpSignal, base::FileDescriptor(crash_signal_fd, false)));
3301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
3311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#endif  // defined(OS_ANDROID)
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#endif  // defined(OS_POSIX) && !defined(OS_MACOSX)
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
335a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#if defined(OS_WIN)
336a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochvoid ShellContentBrowserClient::PreSpawnRenderer(sandbox::TargetPolicy* policy,
337a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch                                                 bool* success) {
338a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // Add sideloaded font files for testing. See also DIR_WINDOWS_FONTS
339a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // addition in |StartSandboxedProcess|.
340a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  std::vector<std::string> font_files = GetSideloadFontFiles();
341a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  for (std::vector<std::string>::const_iterator i(font_files.begin());
342a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      i != font_files.end();
343a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      ++i) {
344a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES,
345a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        sandbox::TargetPolicy::FILES_ALLOW_READONLY,
346a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        base::UTF8ToWide(*i).c_str());
347a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  }
348a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
349a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#endif  // OS_WIN
350a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ShellBrowserContext* ShellContentBrowserClient::browser_context() {
3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return shell_browser_main_parts_->browser_context();
3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ShellBrowserContext*
3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ShellContentBrowserClient::off_the_record_browser_context() {
3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return shell_browser_main_parts_->off_the_record_browser_context();
3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)AccessTokenStore* ShellContentBrowserClient::CreateAccessTokenStore() {
361c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return new ShellAccessTokenStore(browser_context());
3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ShellBrowserContext*
3652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ShellContentBrowserClient::ShellBrowserContextForBrowserContext(
3662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    BrowserContext* content_browser_context) {
3672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (content_browser_context == browser_context())
3682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return browser_context();
3692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DCHECK_EQ(content_browser_context, off_the_record_browser_context());
3702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return off_the_record_browser_context();
3712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
3722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace content
374