shell_main_delegate.cc revision 03b57e008b61dfcb1fbad3aea950ae0e001748b0
1// Copyright 2014 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 "extensions/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 "content/public/browser/browser_main_runner.h" 12#include "content/public/common/content_switches.h" 13#include "extensions/common/extension_paths.h" 14#include "extensions/shell/browser/default_shell_browser_main_delegate.h" 15#include "extensions/shell/browser/shell_content_browser_client.h" 16#include "extensions/shell/common/shell_content_client.h" 17#include "extensions/shell/renderer/shell_content_renderer_client.h" 18#include "ui/base/resource/resource_bundle.h" 19 20#if defined(OS_CHROMEOS) 21#include "chromeos/chromeos_paths.h" 22#endif 23 24#if !defined(DISABLE_NACL) 25#include "components/nacl/common/nacl_paths.h" 26#include "components/nacl/common/nacl_switches.h" 27#include "components/nacl/zygote/nacl_fork_delegate_linux.h" 28#endif 29 30namespace { 31 32void InitLogging() { 33 base::FilePath log_filename; 34 PathService::Get(base::DIR_EXE, &log_filename); 35 log_filename = log_filename.AppendASCII("app_shell.log"); 36 logging::LoggingSettings settings; 37 settings.logging_dest = logging::LOG_TO_ALL; 38 settings.log_file = log_filename.value().c_str(); 39 settings.delete_old = logging::DELETE_OLD_LOG_FILE; 40 logging::InitLogging(settings); 41 logging::SetLogItems(true, true, true, true); 42} 43 44} // namespace 45 46namespace extensions { 47 48ShellMainDelegate::ShellMainDelegate() { 49} 50 51ShellMainDelegate::~ShellMainDelegate() { 52} 53 54bool ShellMainDelegate::BasicStartupComplete(int* exit_code) { 55 InitLogging(); 56 content_client_.reset(CreateContentClient()); 57 SetContentClient(content_client_.get()); 58 59#if defined(OS_CHROMEOS) 60 chromeos::RegisterPathProvider(); 61#endif 62#if !defined(DISABLE_NACL) 63 nacl::RegisterPathProvider(); 64#endif 65 extensions::RegisterPathProvider(); 66 return false; 67} 68 69void ShellMainDelegate::PreSandboxStartup() { 70 std::string process_type = 71 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 72 switches::kProcessType); 73 if (ProcessNeedsResourceBundle(process_type)) 74 InitializeResourceBundle(); 75} 76 77content::ContentBrowserClient* ShellMainDelegate::CreateContentBrowserClient() { 78 browser_client_.reset(CreateShellContentBrowserClient()); 79 return browser_client_.get(); 80} 81 82content::ContentRendererClient* 83ShellMainDelegate::CreateContentRendererClient() { 84 renderer_client_.reset(CreateShellContentRendererClient()); 85 return renderer_client_.get(); 86} 87 88void ShellMainDelegate::ZygoteStarting( 89 ScopedVector<content::ZygoteForkDelegate>* delegates) { 90#if !defined(DISABLE_NACL) 91 nacl::AddNaClZygoteForkDelegates(delegates); 92#endif 93} 94 95content::ContentClient* ShellMainDelegate::CreateContentClient() { 96 return new ShellContentClient(); 97} 98 99content::ContentBrowserClient* 100ShellMainDelegate::CreateShellContentBrowserClient() { 101 return new ShellContentBrowserClient(new DefaultShellBrowserMainDelegate()); 102} 103 104content::ContentRendererClient* 105ShellMainDelegate::CreateShellContentRendererClient() { 106 return new ShellContentRendererClient(); 107} 108 109void ShellMainDelegate::InitializeResourceBundle() { 110 base::FilePath extensions_shell_and_test_pak_path; 111 PathService::Get(base::DIR_MODULE, &extensions_shell_and_test_pak_path); 112 ui::ResourceBundle::InitSharedInstanceWithPakPath( 113 extensions_shell_and_test_pak_path.AppendASCII( 114 "extensions_shell_and_test.pak")); 115} 116 117// static 118bool ShellMainDelegate::ProcessNeedsResourceBundle( 119 const std::string& process_type) { 120 // The browser process has no process type flag, but needs resources. 121 // On Linux the zygote process opens the resources for the renderers. 122 return process_type.empty() || 123 process_type == switches::kZygoteProcess || 124 process_type == switches::kRendererProcess || 125#if !defined(DISABLE_NACL) 126 process_type == switches::kNaClLoaderProcess || 127#endif 128 process_type == switches::kUtilityProcess; 129} 130 131} // namespace extensions 132