Linux: bit hacky way to ensure Pepper plugins get loaded by zygote.

BUG=49702
TEST=Integrated PDF plugin should work on Linux Chrome, and --register-pepper-plugins works on Linux even with sandbox enabled.

Review URL: http://codereview.chromium.org/3031011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53977 0039d316-1c4b-4281-b951-d872f2087c98
parent 8eb8a60b
// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -84,33 +84,28 @@ void ZygoteHost::Init(const std::string& sandbox_cmd) { ...@@ -84,33 +84,28 @@ void ZygoteHost::Init(const std::string& sandbox_cmd) {
// Append any switches from the browser process that need to be forwarded on // Append any switches from the browser process that need to be forwarded on
// to the zygote/renderers. // to the zygote/renderers.
// Should this list be obtained from browser_render_process_host.cc? // Should this list be obtained from browser_render_process_host.cc?
if (browser_command_line.HasSwitch(switches::kAllowSandboxDebugging)) { static const char* kForwardSwitches[] = {
cmd_line.AppendSwitch(switches::kAllowSandboxDebugging); switches::kAllowSandboxDebugging,
} switches::kLoggingLevel,
if (browser_command_line.HasSwitch(switches::kLoggingLevel)) { switches::kEnableLogging, // Support, e.g., --enable-logging=stderr.
cmd_line.AppendSwitchWithValue(switches::kLoggingLevel, switches::kUserDataDir, // Make logs go to the right file.
browser_command_line.GetSwitchValueASCII( // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
switches::kLoggingLevel)); switches::kRegisterPepperPlugins,
}
if (browser_command_line.HasSwitch(switches::kEnableLogging)) {
// Append with value to support --enable-logging=stderr.
cmd_line.AppendSwitchWithValue(switches::kEnableLogging,
browser_command_line.GetSwitchValueASCII(
switches::kEnableLogging));
}
if (browser_command_line.HasSwitch(switches::kUserDataDir)) {
// Append with value so logs go to the right file.
cmd_line.AppendSwitchWithValue(switches::kUserDataDir,
browser_command_line.GetSwitchValueASCII(
switches::kUserDataDir));
}
#if defined(USE_SECCOMP_SANDBOX) #if defined(USE_SECCOMP_SANDBOX)
if (browser_command_line.HasSwitch(switches::kDisableSeccompSandbox)) switches::kDisableSeccompSandbox,
cmd_line.AppendSwitch(switches::kDisableSeccompSandbox);
#else #else
if (browser_command_line.HasSwitch(switches::kEnableSeccompSandbox)) switches::kEnableSeccompSandbox,
cmd_line.AppendSwitch(switches::kEnableSeccompSandbox);
#endif #endif
NULL
};
for (const char** sw = kForwardSwitches; *sw; sw++) {
if (browser_command_line.HasSwitch(*sw)) {
// Always append with value for those switches which need it; it does no
// harm for those which don't.
cmd_line.AppendSwitchWithValue(*sw,
browser_command_line.GetSwitchValueASCII(*sw));
}
}
sandbox_binary_ = sandbox_cmd.c_str(); sandbox_binary_ = sandbox_cmd.c_str();
struct stat st; struct stat st;
......
// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "chrome/common/chrome_descriptors.h" #include "chrome/common/chrome_descriptors.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/main_function_params.h" #include "chrome/common/main_function_params.h"
#include "chrome/common/pepper_plugin_registry.h"
#include "chrome/common/process_watcher.h" #include "chrome/common/process_watcher.h"
#include "chrome/common/sandbox_methods_linux.h" #include "chrome/common/sandbox_methods_linux.h"
...@@ -547,6 +548,9 @@ static void PreSandboxInit() { ...@@ -547,6 +548,9 @@ static void PreSandboxInit() {
FilePath module_path; FilePath module_path;
if (PathService::Get(base::DIR_MODULE, &module_path)) if (PathService::Get(base::DIR_MODULE, &module_path))
media::InitializeMediaLibrary(module_path); media::InitializeMediaLibrary(module_path);
// Ensure access to the Pepper plugins before the sandbox is turned on.
PepperPluginRegistry::PreloadModules();
} }
#if !defined(CHROMIUM_SELINUX) #if !defined(CHROMIUM_SELINUX)
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/file_util.h" #include "base/file_util.h"
#include "base/native_library.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/string_util.h" #include "base/string_util.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
...@@ -13,6 +14,9 @@ ...@@ -13,6 +14,9 @@
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "remoting/client/plugin/pepper_entrypoints.h" #include "remoting/client/plugin/pepper_entrypoints.h"
PepperPluginInfo::PepperPluginInfo() : is_internal(false) {
}
// static // static
PepperPluginRegistry* PepperPluginRegistry::GetInstance() { PepperPluginRegistry* PepperPluginRegistry::GetInstance() {
static PepperPluginRegistry registry; static PepperPluginRegistry registry;
...@@ -34,6 +38,19 @@ void PepperPluginRegistry::GetList(std::vector<PepperPluginInfo>* plugins) { ...@@ -34,6 +38,19 @@ void PepperPluginRegistry::GetList(std::vector<PepperPluginInfo>* plugins) {
GetExtraPlugins(plugins); GetExtraPlugins(plugins);
} }
// static
void PepperPluginRegistry::PreloadModules() {
std::vector<PepperPluginInfo> plugins;
GetList(&plugins);
for (size_t i = 0; i < plugins.size(); ++i) {
if (!plugins[i].is_internal) {
base::NativeLibrary library = base::LoadNativeLibrary(plugins[i].path);
LOG_IF(WARNING, !library) << "Unable to load plugin "
<< plugins[i].path.value();
}
}
}
// static // static
void PepperPluginRegistry::GetPluginInfoFromSwitch( void PepperPluginRegistry::GetPluginInfoFromSwitch(
std::vector<PepperPluginInfo>* plugins) { std::vector<PepperPluginInfo>* plugins) {
...@@ -89,6 +106,10 @@ void PepperPluginRegistry::GetExtraPlugins( ...@@ -89,6 +106,10 @@ void PepperPluginRegistry::GetExtraPlugins(
} }
} }
PepperPluginRegistry::InternalPluginInfo::InternalPluginInfo() {
is_internal = true;
}
// static // static
void PepperPluginRegistry::GetInternalPluginInfo( void PepperPluginRegistry::GetInternalPluginInfo(
InternalPluginInfoList* plugin_info) { InternalPluginInfoList* plugin_info) {
...@@ -108,6 +129,7 @@ void PepperPluginRegistry::GetInternalPluginInfo( ...@@ -108,6 +129,7 @@ void PepperPluginRegistry::GetInternalPluginInfo(
switches::kEnableChromoting)) { switches::kEnableChromoting)) {
InternalPluginInfo info; InternalPluginInfo info;
// Add the chromoting plugin. // Add the chromoting plugin.
DCHECK(info.is_internal);
info.path = info.path =
FilePath(FILE_PATH_LITERAL("internal-chromoting")); FilePath(FILE_PATH_LITERAL("internal-chromoting"));
info.mime_types.push_back("pepper-application/x-chromoting"); info.mime_types.push_back("pepper-application/x-chromoting");
......
...@@ -13,7 +13,10 @@ ...@@ -13,7 +13,10 @@
#include "webkit/glue/plugins/pepper_plugin_module.h" #include "webkit/glue/plugins/pepper_plugin_module.h"
struct PepperPluginInfo { struct PepperPluginInfo {
FilePath path; // Internal plugins are of the form "internal-[name]". PepperPluginInfo(); // Needed to initialize |is_internal|.
bool is_internal; // Defaults to false (see constructor).
FilePath path; // Internal plugins have "internal-[name]" as path.
std::vector<std::string> mime_types; std::vector<std::string> mime_types;
std::string name; std::string name;
std::string description; std::string description;
...@@ -31,6 +34,11 @@ class PepperPluginRegistry { ...@@ -31,6 +34,11 @@ class PepperPluginRegistry {
// pepper plugin modules. // pepper plugin modules.
static void GetList(std::vector<PepperPluginInfo>* plugins); static void GetList(std::vector<PepperPluginInfo>* plugins);
// Loads the (native) libraries but does not initialize them (i.e., does not
// call PPP_InitializeModule). This is needed by the zygote on Linux to get
// access to the plugins before entering the sandbox.
static void PreloadModules();
pepper::PluginModule* GetModule(const FilePath& path) const; pepper::PluginModule* GetModule(const FilePath& path) const;
private: private:
...@@ -38,6 +46,7 @@ class PepperPluginRegistry { ...@@ -38,6 +46,7 @@ class PepperPluginRegistry {
static void GetExtraPlugins(std::vector<PepperPluginInfo>* plugins); static void GetExtraPlugins(std::vector<PepperPluginInfo>* plugins);
struct InternalPluginInfo : public PepperPluginInfo { struct InternalPluginInfo : public PepperPluginInfo {
InternalPluginInfo(); // Sets |is_internal|.
pepper::PluginModule::EntryPoints entry_points; pepper::PluginModule::EntryPoints entry_points;
}; };
typedef std::vector<InternalPluginInfo> InternalPluginInfoList; typedef std::vector<InternalPluginInfo> InternalPluginInfoList;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment