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 "base/command_line.h" 6 #include "base/debug/debugger.h" 7 #include "base/i18n/rtl.h" 8 #include "base/message_loop/message_loop.h" 9 #include "base/threading/platform_thread.h" 10 #include "build/build_config.h" 11 #include "content/child/child_process.h" 12 #include "content/common/content_constants_internal.h" 13 #include "content/common/sandbox_linux.h" 14 #include "content/ppapi_plugin/ppapi_thread.h" 15 #include "content/public/common/content_client.h" 16 #include "content/public/common/content_switches.h" 17 #include "content/public/common/main_function_params.h" 18 #include "content/public/plugin/content_plugin_client.h" 19 #include "crypto/nss_util.h" 20 #include "ppapi/proxy/proxy_module.h" 21 #include "ui/base/ui_base_switches.h" 22 23 #if defined(OS_WIN) 24 #include "sandbox/win/src/sandbox.h" 25 #endif 26 27 #if defined(OS_LINUX) 28 #include "content/public/common/sandbox_init.h" 29 #endif 30 31 #if defined(OS_POSIX) && !defined(OS_ANDROID) 32 #include <stdlib.h> 33 #endif 34 35 #if defined(OS_WIN) 36 sandbox::TargetServices* g_target_services = NULL; 37 #else 38 void* g_target_services = 0; 39 #endif 40 41 namespace content { 42 43 // Main function for starting the PPAPI plugin process. 44 int PpapiPluginMain(const MainFunctionParams& parameters) { 45 const CommandLine& command_line = parameters.command_line; 46 47 #if defined(OS_WIN) 48 g_target_services = parameters.sandbox_info->target_services; 49 #endif 50 51 // If |g_target_services| is not null this process is sandboxed. One side 52 // effect is that we can't pop dialogs like ChildProcess::WaitForDebugger() 53 // does. 54 if (command_line.HasSwitch(switches::kPpapiStartupDialog)) { 55 if (g_target_services) 56 base::debug::WaitForDebugger(2*60, false); 57 else 58 ChildProcess::WaitForDebugger("Ppapi"); 59 } 60 61 // Set the default locale to be the current UI language. WebKit uses ICU's 62 // default locale for some font settings (especially switching between 63 // Japanese and Chinese fonts for the same characters). 64 if (command_line.HasSwitch(switches::kLang)) { 65 std::string locale = command_line.GetSwitchValueASCII(switches::kLang); 66 base::i18n::SetICUDefaultLocale(locale); 67 68 #if defined(OS_POSIX) && !defined(OS_ANDROID) 69 // TODO(shess): Flash appears to have a POSIX locale dependency 70 // outside of the existing PPAPI ICU support. Certain games hang 71 // while loading, and it seems related to datetime formatting. 72 // http://crbug.com/155396 73 // http://crbug.com/155671 74 // 75 // ICU can accept "en-US" or "en_US", but POSIX wants "en_US". 76 std::replace(locale.begin(), locale.end(), '-', '_'); 77 locale.append(".UTF-8"); 78 setlocale(LC_ALL, locale.c_str()); 79 setenv("LANG", locale.c_str(), 0); 80 #endif 81 } 82 83 base::MessageLoop main_message_loop; 84 base::PlatformThread::SetName("CrPPAPIMain"); 85 base::debug::TraceLog::GetInstance()->SetProcessName("PPAPI Process"); 86 base::debug::TraceLog::GetInstance()->SetProcessSortIndex( 87 kTraceEventPpapiProcessSortIndex); 88 89 #if defined(OS_LINUX) && defined(USE_NSS) 90 // Some out-of-process PPAPI plugins use NSS. 91 // NSS must be initialized before enabling the sandbox below. 92 crypto::InitNSSSafely(); 93 #endif 94 95 // Allow the embedder to perform any necessary per-process initialization 96 // before the sandbox is initialized. 97 if (GetContentClient()->plugin()) 98 GetContentClient()->plugin()->PreSandboxInitialization(); 99 100 #if defined(OS_LINUX) 101 LinuxSandbox::InitializeSandbox(); 102 #endif 103 104 ChildProcess ppapi_process; 105 ppapi_process.set_main_thread( 106 new PpapiThread(parameters.command_line, false)); // Not a broker. 107 108 main_message_loop.Run(); 109 return 0; 110 } 111 112 } // namespace content 113