15f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file.
45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
55f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "extensions/shell/browser/shell_content_browser_client.h"
65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/command_line.h"
85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/public/browser/browser_thread.h"
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/public/browser/render_process_host.h"
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/public/browser/site_instance.h"
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/public/common/content_switches.h"
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/public/common/url_constants.h"
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/shell/browser/shell_browser_context.h"
141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "content/shell/browser/shell_devtools_delegate.h"
155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "extensions/browser/extension_message_filter.h"
16a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "extensions/browser/extension_protocols.h"
175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "extensions/browser/extension_registry.h"
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "extensions/browser/info_map.h"
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "extensions/browser/process_map.h"
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "extensions/common/constants.h"
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "extensions/common/extension.h"
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "extensions/common/switches.h"
235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "extensions/shell/browser/shell_browser_context.h"
245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "extensions/shell/browser/shell_browser_main_parts.h"
255f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "extensions/shell/browser/shell_extension_system.h"
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "url/gurl.h"
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#if !defined(DISABLE_NACL)
2903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "components/nacl/browser/nacl_browser.h"
3003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "components/nacl/browser/nacl_host_message_filter.h"
3103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "components/nacl/browser/nacl_process_host.h"
3203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "components/nacl/common/nacl_process_type.h"
3303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "components/nacl/common/nacl_switches.h"
3403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "content/public/browser/browser_child_process_host.h"
3503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "content/public/browser/child_process_data.h"
3603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#endif
3703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
3803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)using base::CommandLine;
3903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)using content::BrowserContext;
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using content::BrowserThread;
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
425f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)namespace extensions {
43c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochnamespace {
44c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
45c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen MurdochShellContentBrowserClient* g_instance = NULL;
46c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
47c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch}  // namespace
485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
49cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)ShellContentBrowserClient::ShellContentBrowserClient(
50cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    ShellBrowserMainDelegate* browser_main_delegate)
51cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    : browser_main_parts_(NULL), browser_main_delegate_(browser_main_delegate) {
52c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  DCHECK(!g_instance);
53c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  g_instance = this;
54c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch}
55c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)ShellContentBrowserClient::~ShellContentBrowserClient() {
575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  g_instance = NULL;
585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)}
59c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
60c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch// static
61c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen MurdochShellContentBrowserClient* ShellContentBrowserClient::Get() {
62c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  return g_instance;
635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
65c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochcontent::BrowserContext* ShellContentBrowserClient::GetBrowserContext() {
66c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  return browser_main_parts_->browser_context();
675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)content::BrowserMainParts* ShellContentBrowserClient::CreateBrowserMainParts(
705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const content::MainFunctionParams& parameters) {
71cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  browser_main_parts_ =
72cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      new ShellBrowserMainParts(parameters, browser_main_delegate_);
735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return browser_main_parts_;
745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void ShellContentBrowserClient::RenderProcessWillLaunch(
775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    content::RenderProcessHost* host) {
785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int render_process_id = host->GetID();
7903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  BrowserContext* browser_context = browser_main_parts_->browser_context();
8003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  host->AddFilter(
8103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      new ExtensionMessageFilter(render_process_id, browser_context));
8203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // PluginInfoMessageFilter is not required because app_shell does not have
8303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // the concept of disabled plugins.
8403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#if !defined(DISABLE_NACL)
8503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  host->AddFilter(new nacl::NaClHostMessageFilter(
8603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      render_process_id,
8703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      browser_context->IsOffTheRecord(),
8803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      browser_context->GetPath(),
8903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      browser_context->GetRequestContextForRenderProcess(render_process_id)));
9003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#endif
915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
93a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool ShellContentBrowserClient::ShouldUseProcessPerSite(
94a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    content::BrowserContext* browser_context,
95a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    const GURL& effective_url) {
96a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // This ensures that all render views created for a single app will use the
97a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // same render process (see content::SiteInstance::GetProcess). Otherwise the
98a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // default behavior of ContentBrowserClient will lead to separate render
99a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // processes for the background page and each app window view.
100a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return true;
101a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
102a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
103a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)net::URLRequestContextGetter* ShellContentBrowserClient::CreateRequestContext(
1045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    content::BrowserContext* content_browser_context,
105a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    content::ProtocolHandlerMap* protocol_handlers,
106cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    content::URLRequestInterceptorScopedVector request_interceptors) {
107a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // Handle only chrome-extension:// requests. app_shell does not support
108a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // chrome-extension-resource:// requests (it does not store shared extension
109a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // data in its installation directory).
1105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  InfoMap* extension_info_map =
1115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      browser_main_parts_->extension_system()->info_map();
1125f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  (*protocol_handlers)[kExtensionScheme] =
1135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      linked_ptr<net::URLRequestJobFactory::ProtocolHandler>(
1145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)          CreateExtensionProtocolHandler(false /* is_incognito */,
1155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                         extension_info_map));
1165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Let content::ShellBrowserContext handle the rest of the setup.
1175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return browser_main_parts_->browser_context()->CreateRequestContext(
118cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      protocol_handlers, request_interceptors.Pass());
1195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
1205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool ShellContentBrowserClient::IsHandledURL(const GURL& url) {
1225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!url.is_valid())
1235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return false;
1245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Keep in sync with ProtocolHandlers added in CreateRequestContext() and in
1255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // content::ShellURLRequestContextGetter::GetURLRequestContext().
1265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static const char* const kProtocolList[] = {
127cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      url::kBlobScheme,
1285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      content::kChromeDevToolsScheme,
1295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      content::kChromeUIScheme,
130cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      url::kDataScheme,
131cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      url::kFileScheme,
132cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      url::kFileSystemScheme,
1335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      kExtensionScheme,
1345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      kExtensionResourceScheme,
1355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  };
1365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  for (size_t i = 0; i < arraysize(kProtocolList); ++i) {
1375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    if (url.scheme() == kProtocolList[i])
1385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return true;
1395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
1405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return false;
1415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
1425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void ShellContentBrowserClient::SiteInstanceGotProcess(
1445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    content::SiteInstance* site_instance) {
1455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // If this isn't an extension renderer there's nothing to do.
1465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  const Extension* extension = GetExtension(site_instance);
1475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!extension)
1485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
1495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  ProcessMap::Get(browser_main_parts_->browser_context())
1515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ->Insert(extension->id(),
1525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)               site_instance->GetProcess()->GetID(),
1535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)               site_instance->GetId());
1545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  BrowserThread::PostTask(
1565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      BrowserThread::IO,
1575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      FROM_HERE,
1585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      base::Bind(&InfoMap::RegisterExtensionProcess,
1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 browser_main_parts_->extension_system()->info_map(),
1605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 extension->id(),
1615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 site_instance->GetProcess()->GetID(),
1625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 site_instance->GetId()));
1635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
1645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void ShellContentBrowserClient::SiteInstanceDeleting(
1665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    content::SiteInstance* site_instance) {
1675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // If this isn't an extension renderer there's nothing to do.
1685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  const Extension* extension = GetExtension(site_instance);
1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!extension)
1705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  ProcessMap::Get(browser_main_parts_->browser_context())
1735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ->Remove(extension->id(),
1745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)               site_instance->GetProcess()->GetID(),
1755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)               site_instance->GetId());
1765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  BrowserThread::PostTask(
1785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      BrowserThread::IO,
1795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      FROM_HERE,
1805f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      base::Bind(&InfoMap::UnregisterExtensionProcess,
1815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 browser_main_parts_->extension_system()->info_map(),
1825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 extension->id(),
1835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 site_instance->GetProcess()->GetID(),
1845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 site_instance->GetId()));
1855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
1865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void ShellContentBrowserClient::AppendExtraCommandLineSwitches(
1885f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    CommandLine* command_line,
1895f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    int child_process_id) {
1905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string process_type =
1915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      command_line->GetSwitchValueASCII(::switches::kProcessType);
19203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  if (process_type == ::switches::kRendererProcess)
19303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    AppendRendererSwitches(command_line);
19403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}
19503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
19603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)content::BrowserPpapiHost*
19703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)ShellContentBrowserClient::GetExternalBrowserPpapiHost(int plugin_process_id) {
19803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#if !defined(DISABLE_NACL)
19903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
20003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  while (!iter.Done()) {
20103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    nacl::NaClProcessHost* host = static_cast<nacl::NaClProcessHost*>(
20203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)        iter.GetDelegate());
20303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    if (host->process() &&
20403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)        host->process()->GetData().id == plugin_process_id) {
20503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      // Found the plugin.
20603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      return host->browser_ppapi_host();
20703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    }
20803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    ++iter;
2095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
21003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#endif
21103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  return NULL;
2125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
2135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
214a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void ShellContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
215a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    std::vector<std::string>* additional_allowed_schemes) {
216a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
217a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      additional_allowed_schemes);
2185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  additional_allowed_schemes->push_back(kExtensionScheme);
219a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
220a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
22103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)void ShellContentBrowserClient::AppendRendererSwitches(
22203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    CommandLine* command_line) {
22303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // TODO(jamescook): Should we check here if the process is in the extension
22403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // service process map, or can we assume all renderers are extension
22503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // renderers?
22603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  command_line->AppendSwitch(switches::kExtensionProcess);
22703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
22803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#if !defined(DISABLE_NACL)
22903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // NOTE: app_shell does not support non-SFI mode, so it does not pass through
23003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // SFI switches either here or for the zygote process.
23103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  static const char* const kSwitchNames[] = {
23203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    ::switches::kEnableNaClDebug,
23303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  };
23403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  command_line->CopySwitchesFrom(*CommandLine::ForCurrentProcess(),
23503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)                                 kSwitchNames,
23603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)                                 arraysize(kSwitchNames));
23703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#endif  // !defined(DISABLE_NACL)
23803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}
23903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
2405f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)const Extension* ShellContentBrowserClient::GetExtension(
2415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    content::SiteInstance* site_instance) {
2425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ExtensionRegistry* registry =
2435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ExtensionRegistry::Get(site_instance->GetBrowserContext());
2445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return registry->enabled_extensions().GetExtensionOrAppByURL(
2455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      site_instance->GetSiteURL());
2465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
2475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccicontent::DevToolsManagerDelegate*
2491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciShellContentBrowserClient::GetDevToolsManagerDelegate() {
2501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return new content::ShellDevToolsManagerDelegate(GetBrowserContext());
2511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
2521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
2535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)}  // namespace extensions
254