Removing uses of X11 native key events.
[chromium-blink-merge.git] / content / ppapi_plugin / ppapi_plugin_main.cc
blobfb0beda4ab334ba19d6811fb8a9f336cf440de93
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.
5 #include "base/base_paths.h"
6 #include "base/command_line.h"
7 #include "base/debug/debugger.h"
8 #include "base/files/file_path.h"
9 #include "base/i18n/rtl.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/path_service.h"
12 #include "base/threading/platform_thread.h"
13 #include "build/build_config.h"
14 #include "content/child/child_process.h"
15 #include "content/common/content_constants_internal.h"
16 #include "content/common/sandbox_linux/sandbox_linux.h"
17 #include "content/ppapi_plugin/ppapi_thread.h"
18 #include "content/public/common/content_client.h"
19 #include "content/public/common/content_switches.h"
20 #include "content/public/common/main_function_params.h"
21 #include "content/public/plugin/content_plugin_client.h"
22 #include "crypto/nss_util.h"
23 #include "ppapi/proxy/plugin_globals.h"
24 #include "ppapi/proxy/proxy_module.h"
25 #include "ui/base/ui_base_switches.h"
27 #if defined(OS_WIN)
28 #include "sandbox/win/src/sandbox.h"
29 #include "third_party/skia/include/ports/SkTypeface_win.h"
30 #endif
32 #if defined(OS_CHROMEOS)
33 #include "base/files/file_util.h"
34 #endif
36 #if defined(OS_LINUX)
37 #include "content/public/common/sandbox_init.h"
38 #endif
40 #if defined(OS_POSIX) && !defined(OS_ANDROID)
41 #include <stdlib.h>
42 #endif
44 #if defined(OS_WIN)
45 sandbox::TargetServices* g_target_services = NULL;
46 #else
47 void* g_target_services = 0;
48 #endif
50 namespace content {
52 namespace {
54 #if defined(OS_WIN)
55 // Windows-only skia sandbox support
56 void SkiaPreCacheFont(const LOGFONT& logfont) {
57 ppapi::proxy::PluginGlobals::Get()->PreCacheFontForFlash(
58 reinterpret_cast<const void*>(&logfont));
60 #endif
62 } // namespace
64 // Main function for starting the PPAPI plugin process.
65 int PpapiPluginMain(const MainFunctionParams& parameters) {
66 const CommandLine& command_line = parameters.command_line;
68 #if defined(OS_WIN)
69 g_target_services = parameters.sandbox_info->target_services;
70 #endif
72 // If |g_target_services| is not null this process is sandboxed. One side
73 // effect is that we can't pop dialogs like ChildProcess::WaitForDebugger()
74 // does.
75 if (command_line.HasSwitch(switches::kPpapiStartupDialog)) {
76 if (g_target_services)
77 base::debug::WaitForDebugger(2*60, false);
78 else
79 ChildProcess::WaitForDebugger("Ppapi");
82 // Set the default locale to be the current UI language. WebKit uses ICU's
83 // default locale for some font settings (especially switching between
84 // Japanese and Chinese fonts for the same characters).
85 if (command_line.HasSwitch(switches::kLang)) {
86 std::string locale = command_line.GetSwitchValueASCII(switches::kLang);
87 base::i18n::SetICUDefaultLocale(locale);
89 #if defined(OS_POSIX) && !defined(OS_ANDROID)
90 // TODO(shess): Flash appears to have a POSIX locale dependency
91 // outside of the existing PPAPI ICU support. Certain games hang
92 // while loading, and it seems related to datetime formatting.
93 // http://crbug.com/155396
94 // http://crbug.com/155671
96 // ICU can accept "en-US" or "en_US", but POSIX wants "en_US".
97 std::replace(locale.begin(), locale.end(), '-', '_');
98 locale.append(".UTF-8");
99 setlocale(LC_ALL, locale.c_str());
100 setenv("LANG", locale.c_str(), 0);
101 #endif
104 #if defined(OS_CHROMEOS)
105 // Specifies $HOME explicitly because some plugins rely on $HOME but
106 // no other part of Chrome OS uses that. See crbug.com/335290.
107 base::FilePath homedir;
108 PathService::Get(base::DIR_HOME, &homedir);
109 setenv("HOME", homedir.value().c_str(), 1);
110 #endif
112 base::MessageLoop main_message_loop;
113 base::PlatformThread::SetName("CrPPAPIMain");
114 base::debug::TraceLog::GetInstance()->SetProcessName("PPAPI Process");
115 base::debug::TraceLog::GetInstance()->SetProcessSortIndex(
116 kTraceEventPpapiProcessSortIndex);
118 #if defined(OS_LINUX) && defined(USE_NSS)
119 // Some out-of-process PPAPI plugins use NSS.
120 // NSS must be initialized before enabling the sandbox below.
121 crypto::InitNSSSafely();
122 #endif
124 // Allow the embedder to perform any necessary per-process initialization
125 // before the sandbox is initialized.
126 if (GetContentClient()->plugin())
127 GetContentClient()->plugin()->PreSandboxInitialization();
129 #if defined(OS_LINUX)
130 LinuxSandbox::InitializeSandbox();
131 #endif
133 ChildProcess ppapi_process;
134 ppapi_process.set_main_thread(
135 new PpapiThread(parameters.command_line, false)); // Not a broker.
137 #if defined(OS_WIN)
138 SkTypeface_SetEnsureLOGFONTAccessibleProc(SkiaPreCacheFont);
139 #endif
141 main_message_loop.Run();
142 return 0;
145 } // namespace content