diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-25 05:06:48 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-25 05:06:48 +0000 |
commit | dac6a5ac4fff22f2070a99c71472146aebe0192d (patch) | |
tree | e311e966952ea95f242e1b56c33354a5532206c7 /content | |
parent | 977a14f06dbb9e9371332e5d7952e923095558fb (diff) | |
download | chromium_src-dac6a5ac4fff22f2070a99c71472146aebe0192d.zip chromium_src-dac6a5ac4fff22f2070a99c71472146aebe0192d.tar.gz chromium_src-dac6a5ac4fff22f2070a99c71472146aebe0192d.tar.bz2 |
Split PepperPluginRegistry into the pieces that are needed in each process. content/common only needed a simple method to get the list of pepper plugins. The zygote specific method moves to content/zygote. The rest moves to content/renderer, as that has dependencies on the pepper implementation which depends on blink.
BUG=263054
R=scottmg@chromium.org
Review URL: https://codereview.chromium.org/20172004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213593 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/browser/plugin_service_impl.cc | 5 | ||||
-rw-r--r-- | content/browser/plugin_service_impl.h | 1 | ||||
-rw-r--r-- | content/common/DEPS | 3 | ||||
-rw-r--r-- | content/common/pepper_plugin_list.cc | 112 | ||||
-rw-r--r-- | content/common/pepper_plugin_list.h | 25 | ||||
-rw-r--r-- | content/common/pepper_plugin_registry.cc | 231 | ||||
-rw-r--r-- | content/content_common.gypi | 8 | ||||
-rw-r--r-- | content/content_renderer.gypi | 2 | ||||
-rw-r--r-- | content/renderer/pepper/pepper_plugin_delegate_impl.cc | 2 | ||||
-rw-r--r-- | content/renderer/pepper/pepper_plugin_registry.cc | 115 | ||||
-rw-r--r-- | content/renderer/pepper/pepper_plugin_registry.h (renamed from content/common/pepper_plugin_registry.h) | 34 | ||||
-rw-r--r-- | content/renderer/pepper/plugin_module.cc | 2 | ||||
-rw-r--r-- | content/renderer/render_view_impl.cc | 2 | ||||
-rw-r--r-- | content/renderer/renderer_main.cc | 2 | ||||
-rw-r--r-- | content/zygote/zygote_main_linux.cc | 27 |
15 files changed, 299 insertions, 272 deletions
diff --git a/content/browser/plugin_service_impl.cc b/content/browser/plugin_service_impl.cc index 64efebc..f596977 100644 --- a/content/browser/plugin_service_impl.cc +++ b/content/browser/plugin_service_impl.cc @@ -19,7 +19,7 @@ #include "content/browser/ppapi_plugin_process_host.h" #include "content/browser/renderer_host/render_process_host_impl.h" #include "content/browser/renderer_host/render_view_host_impl.h" -#include "content/common/pepper_plugin_registry.h" +#include "content/common/pepper_plugin_list.h" #include "content/common/plugin_list.h" #include "content/common/view_messages.h" #include "content/public/browser/browser_thread.h" @@ -650,8 +650,7 @@ void PluginServiceImpl::OnWaitableEventSignaled( } void PluginServiceImpl::RegisterPepperPlugins() { - // TODO(abarth): It seems like the PepperPluginRegistry should do this work. - PepperPluginRegistry::ComputeList(&ppapi_plugins_); + ComputePepperPluginList(&ppapi_plugins_); for (size_t i = 0; i < ppapi_plugins_.size(); ++i) { RegisterInternalPlugin(ppapi_plugins_[i].ToWebPluginInfo(), true); } diff --git a/content/browser/plugin_service_impl.h b/content/browser/plugin_service_impl.h index d71cacc..6d358fd 100644 --- a/content/browser/plugin_service_impl.h +++ b/content/browser/plugin_service_impl.h @@ -24,6 +24,7 @@ #include "content/browser/ppapi_plugin_process_host.h" #include "content/common/content_export.h" #include "content/public/browser/plugin_service.h" +#include "content/public/common/pepper_plugin_info.h" #include "ipc/ipc_channel_handle.h" #include "url/gurl.h" diff --git a/content/common/DEPS b/content/common/DEPS index d60a74e..2e11e26 100644 --- a/content/common/DEPS +++ b/content/common/DEPS @@ -6,9 +6,6 @@ include_rules = [ "-webkit/child", "-webkit/renderer", - # TODO(jam): remove this - "+content/renderer/pepper/plugin_module.h", - # TODO(ananta|jamesr|scottmg) http://crbug.com/237249 "!webkit/child/websocketstreamhandle_impl.h", diff --git a/content/common/pepper_plugin_list.cc b/content/common/pepper_plugin_list.cc new file mode 100644 index 0000000..a398ad2 --- /dev/null +++ b/content/common/pepper_plugin_list.cc @@ -0,0 +1,112 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/common/pepper_plugin_list.h" + +#include "base/command_line.h" +#include "base/strings/string_split.h" +#include "base/strings/string_util.h" +#include "base/strings/utf_string_conversions.h" +#include "content/public/common/content_client.h" +#include "content/public/common/content_switches.h" +#include "content/public/common/pepper_plugin_info.h" +#include "ppapi/shared_impl/ppapi_permissions.h" + +namespace content { +namespace { + +// Appends any plugins from the command line to the given vector. +void ComputePluginsFromCommandLine(std::vector<PepperPluginInfo>* plugins) { + bool out_of_process = true; + if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kPpapiInProcess)) + out_of_process = false; + + const std::string value = + CommandLine::ForCurrentProcess()->GetSwitchValueASCII( + switches::kRegisterPepperPlugins); + if (value.empty()) + return; + + // FORMAT: + // command-line = <plugin-entry> + *( LWS + "," + LWS + <plugin-entry> ) + // plugin-entry = + // <file-path> + + // ["#" + <name> + ["#" + <description> + ["#" + <version>]]] + + // *1( LWS + ";" + LWS + <mime-type> ) + std::vector<std::string> modules; + base::SplitString(value, ',', &modules); + for (size_t i = 0; i < modules.size(); ++i) { + std::vector<std::string> parts; + base::SplitString(modules[i], ';', &parts); + if (parts.size() < 2) { + DLOG(ERROR) << "Required mime-type not found"; + continue; + } + + std::vector<std::string> name_parts; + base::SplitString(parts[0], '#', &name_parts); + + PepperPluginInfo plugin; + plugin.is_out_of_process = out_of_process; +#if defined(OS_WIN) + // This means we can't provide plugins from non-ASCII paths, but + // since this switch is only for development I don't think that's + // too awful. + plugin.path = base::FilePath(ASCIIToUTF16(name_parts[0])); +#else + plugin.path = base::FilePath(name_parts[0]); +#endif + if (name_parts.size() > 1) + plugin.name = name_parts[1]; + if (name_parts.size() > 2) + plugin.description = name_parts[2]; + if (name_parts.size() > 3) + plugin.version = name_parts[3]; + for (size_t j = 1; j < parts.size(); ++j) { + WebPluginMimeType mime_type(parts[j], + std::string(), + plugin.description); + plugin.mime_types.push_back(mime_type); + } + + // If the plugin name is empty, use the filename. + if (plugin.name.empty()) + plugin.name = UTF16ToUTF8(plugin.path.BaseName().LossyDisplayName()); + + // Command-line plugins get full permissions. + plugin.permissions = ppapi::PERMISSION_ALL_BITS; + + plugins->push_back(plugin); + } +} + +} // namespace + +bool MakePepperPluginInfo(const WebPluginInfo& webplugin_info, + PepperPluginInfo* pepper_info) { + if (!webplugin_info.is_pepper_plugin()) + return false; + + pepper_info->is_out_of_process = + webplugin_info.type == WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS || + webplugin_info.type == WebPluginInfo::PLUGIN_TYPE_PEPPER_UNSANDBOXED; + pepper_info->is_sandboxed = webplugin_info.type != + WebPluginInfo::PLUGIN_TYPE_PEPPER_UNSANDBOXED; + + pepper_info->path = base::FilePath(webplugin_info.path); + pepper_info->name = UTF16ToASCII(webplugin_info.name); + pepper_info->description = UTF16ToASCII(webplugin_info.desc); + pepper_info->version = UTF16ToASCII(webplugin_info.version); + pepper_info->mime_types = webplugin_info.mime_types; + pepper_info->permissions = webplugin_info.pepper_permissions; + + return true; +} + +void ComputePepperPluginList(std::vector<PepperPluginInfo>* plugins) { + GetContentClient()->AddPepperPlugins(plugins); + ComputePluginsFromCommandLine(plugins); +} + +} // namespace content diff --git a/content/common/pepper_plugin_list.h b/content/common/pepper_plugin_list.h new file mode 100644 index 0000000..d460e08 --- /dev/null +++ b/content/common/pepper_plugin_list.h @@ -0,0 +1,25 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_COMMON_PEPPER_PLUGIN_LIST_H_ +#define CONTENT_COMMON_PEPPER_PLUGIN_LIST_H_ + +#include <vector> + +namespace content { +struct PepperPluginInfo; +struct WebPluginInfo; + +// Constructs a PepperPluginInfo from a WebPluginInfo. Returns false if +// the operation is not possible, in particular the WebPluginInfo::type +// must be one of the pepper types. +bool MakePepperPluginInfo(const WebPluginInfo& webplugin_info, + PepperPluginInfo* pepper_info); + +// Computes the list of known pepper plugins. +void ComputePepperPluginList(std::vector<PepperPluginInfo>* plugins); + +} // namespace content + +#endif // CONTENT_COMMON_PEPPER_PLUGIN_LIST_H_ diff --git a/content/common/pepper_plugin_registry.cc b/content/common/pepper_plugin_registry.cc deleted file mode 100644 index 041c50d..0000000 --- a/content/common/pepper_plugin_registry.cc +++ /dev/null @@ -1,231 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/common/pepper_plugin_registry.h" - -#include "base/command_line.h" -#include "base/native_library.h" -#include "base/strings/string_split.h" -#include "base/strings/string_util.h" -#include "base/strings/utf_string_conversions.h" -#include "content/public/common/content_client.h" -#include "content/public/common/content_switches.h" -#include "ppapi/shared_impl/ppapi_permissions.h" - -namespace content { -namespace { - -// Appends any plugins from the command line to the given vector. -void ComputePluginsFromCommandLine(std::vector<PepperPluginInfo>* plugins) { - bool out_of_process = true; - if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kPpapiInProcess)) - out_of_process = false; - - const std::string value = - CommandLine::ForCurrentProcess()->GetSwitchValueASCII( - switches::kRegisterPepperPlugins); - if (value.empty()) - return; - - // FORMAT: - // command-line = <plugin-entry> + *( LWS + "," + LWS + <plugin-entry> ) - // plugin-entry = - // <file-path> + - // ["#" + <name> + ["#" + <description> + ["#" + <version>]]] + - // *1( LWS + ";" + LWS + <mime-type> ) - std::vector<std::string> modules; - base::SplitString(value, ',', &modules); - for (size_t i = 0; i < modules.size(); ++i) { - std::vector<std::string> parts; - base::SplitString(modules[i], ';', &parts); - if (parts.size() < 2) { - DLOG(ERROR) << "Required mime-type not found"; - continue; - } - - std::vector<std::string> name_parts; - base::SplitString(parts[0], '#', &name_parts); - - PepperPluginInfo plugin; - plugin.is_out_of_process = out_of_process; -#if defined(OS_WIN) - // This means we can't provide plugins from non-ASCII paths, but - // since this switch is only for development I don't think that's - // too awful. - plugin.path = base::FilePath(ASCIIToUTF16(name_parts[0])); -#else - plugin.path = base::FilePath(name_parts[0]); -#endif - if (name_parts.size() > 1) - plugin.name = name_parts[1]; - if (name_parts.size() > 2) - plugin.description = name_parts[2]; - if (name_parts.size() > 3) - plugin.version = name_parts[3]; - for (size_t j = 1; j < parts.size(); ++j) { - WebPluginMimeType mime_type(parts[j], - std::string(), - plugin.description); - plugin.mime_types.push_back(mime_type); - } - - // If the plugin name is empty, use the filename. - if (plugin.name.empty()) - plugin.name = UTF16ToUTF8(plugin.path.BaseName().LossyDisplayName()); - - // Command-line plugins get full permissions. - plugin.permissions = ppapi::PERMISSION_ALL_BITS; - - plugins->push_back(plugin); - } -} - -} // namespace - -bool MakePepperPluginInfo(const WebPluginInfo& webplugin_info, - PepperPluginInfo* pepper_info) { - if (!webplugin_info.is_pepper_plugin()) - return false; - - pepper_info->is_out_of_process = - webplugin_info.type == WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS || - webplugin_info.type == WebPluginInfo::PLUGIN_TYPE_PEPPER_UNSANDBOXED; - pepper_info->is_sandboxed = webplugin_info.type != - WebPluginInfo::PLUGIN_TYPE_PEPPER_UNSANDBOXED; - - pepper_info->path = base::FilePath(webplugin_info.path); - pepper_info->name = UTF16ToASCII(webplugin_info.name); - pepper_info->description = UTF16ToASCII(webplugin_info.desc); - pepper_info->version = UTF16ToASCII(webplugin_info.version); - pepper_info->mime_types = webplugin_info.mime_types; - pepper_info->permissions = webplugin_info.pepper_permissions; - - return true; -} - -// static -PepperPluginRegistry* PepperPluginRegistry::GetInstance() { - static PepperPluginRegistry* registry = NULL; - // This object leaks. It is a temporary hack to work around a crash. - // http://code.google.com/p/chromium/issues/detail?id=63234 - if (!registry) - registry = new PepperPluginRegistry; - return registry; -} - -// static -void PepperPluginRegistry::ComputeList(std::vector<PepperPluginInfo>* plugins) { - GetContentClient()->AddPepperPlugins(plugins); - ComputePluginsFromCommandLine(plugins); -} - -// static -void PepperPluginRegistry::PreloadModules() { - std::vector<PepperPluginInfo> plugins; - ComputeList(&plugins); - for (size_t i = 0; i < plugins.size(); ++i) { - if (!plugins[i].is_internal && plugins[i].is_sandboxed) { - std::string error; - base::NativeLibrary library = base::LoadNativeLibrary(plugins[i].path, - &error); - DLOG_IF(WARNING, !library) << "Unable to load plugin " - << plugins[i].path.value() << " " - << error; - (void)library; // Prevent release-mode warning. - } - } -} - -const PepperPluginInfo* PepperPluginRegistry::GetInfoForPlugin( - const WebPluginInfo& info) { - for (size_t i = 0; i < plugin_list_.size(); ++i) { - if (info.path == plugin_list_[i].path) - return &plugin_list_[i]; - } - // We did not find the plugin in our list. But wait! the plugin can also - // be a latecomer, as it happens with pepper flash. This information - // is actually in |info| and we can use it to construct it and add it to - // the list. This same deal needs to be done in the browser side in - // PluginService. - PepperPluginInfo plugin; - if (!MakePepperPluginInfo(info, &plugin)) - return NULL; - - plugin_list_.push_back(plugin); - return &plugin_list_[plugin_list_.size() - 1]; -} - -webkit::ppapi::PluginModule* PepperPluginRegistry::GetLiveModule( - const base::FilePath& path) { - NonOwningModuleMap::iterator it = live_modules_.find(path); - if (it == live_modules_.end()) - return NULL; - return it->second; -} - -void PepperPluginRegistry::AddLiveModule(const base::FilePath& path, - webkit::ppapi::PluginModule* module) { - DCHECK(live_modules_.find(path) == live_modules_.end()); - live_modules_[path] = module; -} - -void PepperPluginRegistry::PluginModuleDead( - webkit::ppapi::PluginModule* dead_module) { - // DANGER: Don't dereference the dead_module pointer! It may be in the - // process of being deleted. - - // Modules aren't destroyed very often and there are normally at most a - // couple of them. So for now we just do a brute-force search. - for (NonOwningModuleMap::iterator i = live_modules_.begin(); - i != live_modules_.end(); ++i) { - if (i->second == dead_module) { - live_modules_.erase(i); - return; - } - } - // Can occur in tests. -} - -PepperPluginRegistry::~PepperPluginRegistry() { - // Explicitly clear all preloaded modules first. This will cause callbacks - // to erase these modules from the live_modules_ list, and we don't want - // that to happen implicitly out-of-order. - preloaded_modules_.clear(); - - DCHECK(live_modules_.empty()); -} - -PepperPluginRegistry::PepperPluginRegistry() { - ComputeList(&plugin_list_); - - // Note that in each case, AddLiveModule must be called before completing - // initialization. If we bail out (in the continue clauses) before saving - // the initialized module, it will still try to unregister itself in its - // destructor. - for (size_t i = 0; i < plugin_list_.size(); i++) { - const PepperPluginInfo& current = plugin_list_[i]; - if (current.is_out_of_process) - continue; // Out of process plugins need no special pre-initialization. - - scoped_refptr<webkit::ppapi::PluginModule> module = - new webkit::ppapi::PluginModule(current.name, current.path, - ppapi::PpapiPermissions(current.permissions)); - AddLiveModule(current.path, module.get()); - if (current.is_internal) { - if (!module->InitAsInternalPlugin(current.internal_entry_points)) { - DLOG(ERROR) << "Failed to load pepper module: " << current.path.value(); - continue; - } - } else { - // Preload all external plugins we're not running out of process. - if (!module->InitAsLibrary(current.path)) { - DLOG(ERROR) << "Failed to load pepper module: " << current.path.value(); - continue; - } - } - preloaded_modules_[current.path] = module; - } -} - -} // namespace content diff --git a/content/content_common.gypi b/content/content_common.gypi index 900aa36..b9eb787 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -284,8 +284,8 @@ 'common/page_state_serialization.h', 'common/page_zoom.cc', 'common/pepper_messages.h', - 'common/pepper_plugin_registry.cc', - 'common/pepper_plugin_registry.h', + 'common/pepper_plugin_list.cc', + 'common/pepper_plugin_list.h', 'common/pepper_renderer_instance_data.cc', 'common/pepper_renderer_instance_data.h', 'common/plugin_carbon_interpose_constants_mac.cc', @@ -455,8 +455,8 @@ ], }, { # enable_plugins == 0 'sources!': [ - 'common/pepper_plugin_registry.cc', - 'common/pepper_plugin_registry.h', + 'common/pepper_plugin_list.cc', + 'common/pepper_plugin_list.h', ], }], ['enable_gpu==1', { diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi index e260a50..d947875 100644 --- a/content/content_renderer.gypi +++ b/content/content_renderer.gypi @@ -318,6 +318,8 @@ 'renderer/pepper/pepper_platform_video_capture_impl.h', 'renderer/pepper/pepper_plugin_delegate_impl.cc', 'renderer/pepper/pepper_plugin_delegate_impl.h', + 'renderer/pepper/pepper_plugin_registry.cc', + 'renderer/pepper/pepper_plugin_registry.h', 'renderer/pepper/pepper_proxy_channel_delegate_impl.cc', 'renderer/pepper/pepper_proxy_channel_delegate_impl.h', 'renderer/pepper/pepper_truetype_font.h', diff --git a/content/renderer/pepper/pepper_plugin_delegate_impl.cc b/content/renderer/pepper/pepper_plugin_delegate_impl.cc index 7beb399..9eaa2ab 100644 --- a/content/renderer/pepper/pepper_plugin_delegate_impl.cc +++ b/content/renderer/pepper/pepper_plugin_delegate_impl.cc @@ -28,7 +28,6 @@ #include "content/common/gpu/client/context_provider_command_buffer.h" #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" #include "content/common/pepper_messages.h" -#include "content/common/pepper_plugin_registry.h" #include "content/common/sandbox_util.h" #include "content/common/view_messages.h" #include "content/public/common/content_switches.h" @@ -55,6 +54,7 @@ #include "content/renderer/pepper/pepper_platform_context_3d_impl.h" #include "content/renderer/pepper/pepper_platform_image_2d_impl.h" #include "content/renderer/pepper/pepper_platform_video_capture_impl.h" +#include "content/renderer/pepper/pepper_plugin_registry.h" #include "content/renderer/pepper/pepper_proxy_channel_delegate_impl.h" #include "content/renderer/pepper/pepper_url_loader_host.h" #include "content/renderer/pepper/plugin_module.h" diff --git a/content/renderer/pepper/pepper_plugin_registry.cc b/content/renderer/pepper/pepper_plugin_registry.cc new file mode 100644 index 0000000..96634d1 --- /dev/null +++ b/content/renderer/pepper/pepper_plugin_registry.cc @@ -0,0 +1,115 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/renderer/pepper/pepper_plugin_registry.h" + +#include "base/logging.h" +#include "content/common/pepper_plugin_list.h" +#include "content/renderer/pepper/plugin_module.h" +#include "ppapi/shared_impl/ppapi_permissions.h" + +namespace content { + +// static +PepperPluginRegistry* PepperPluginRegistry::GetInstance() { + static PepperPluginRegistry* registry = NULL; + // This object leaks. It is a temporary hack to work around a crash. + // http://code.google.com/p/chromium/issues/detail?id=63234 + if (!registry) + registry = new PepperPluginRegistry; + return registry; +} + +const PepperPluginInfo* PepperPluginRegistry::GetInfoForPlugin( + const WebPluginInfo& info) { + for (size_t i = 0; i < plugin_list_.size(); ++i) { + if (info.path == plugin_list_[i].path) + return &plugin_list_[i]; + } + // We did not find the plugin in our list. But wait! the plugin can also + // be a latecomer, as it happens with pepper flash. This information + // is actually in |info| and we can use it to construct it and add it to + // the list. This same deal needs to be done in the browser side in + // PluginService. + PepperPluginInfo plugin; + if (!MakePepperPluginInfo(info, &plugin)) + return NULL; + + plugin_list_.push_back(plugin); + return &plugin_list_[plugin_list_.size() - 1]; +} + +webkit::ppapi::PluginModule* PepperPluginRegistry::GetLiveModule( + const base::FilePath& path) { + NonOwningModuleMap::iterator it = live_modules_.find(path); + if (it == live_modules_.end()) + return NULL; + return it->second; +} + +void PepperPluginRegistry::AddLiveModule(const base::FilePath& path, + webkit::ppapi::PluginModule* module) { + DCHECK(live_modules_.find(path) == live_modules_.end()); + live_modules_[path] = module; +} + +void PepperPluginRegistry::PluginModuleDead( + webkit::ppapi::PluginModule* dead_module) { + // DANGER: Don't dereference the dead_module pointer! It may be in the + // process of being deleted. + + // Modules aren't destroyed very often and there are normally at most a + // couple of them. So for now we just do a brute-force search. + for (NonOwningModuleMap::iterator i = live_modules_.begin(); + i != live_modules_.end(); ++i) { + if (i->second == dead_module) { + live_modules_.erase(i); + return; + } + } + // Can occur in tests. +} + +PepperPluginRegistry::~PepperPluginRegistry() { + // Explicitly clear all preloaded modules first. This will cause callbacks + // to erase these modules from the live_modules_ list, and we don't want + // that to happen implicitly out-of-order. + preloaded_modules_.clear(); + + DCHECK(live_modules_.empty()); +} + +PepperPluginRegistry::PepperPluginRegistry() { + ComputePepperPluginList(&plugin_list_); + + // Note that in each case, AddLiveModule must be called before completing + // initialization. If we bail out (in the continue clauses) before saving + // the initialized module, it will still try to unregister itself in its + // destructor. + for (size_t i = 0; i < plugin_list_.size(); i++) { + const PepperPluginInfo& current = plugin_list_[i]; + if (current.is_out_of_process) + continue; // Out of process plugins need no special pre-initialization. + + scoped_refptr<webkit::ppapi::PluginModule> module = + new webkit::ppapi::PluginModule(current.name, current.path, + ppapi::PpapiPermissions(current.permissions)); + AddLiveModule(current.path, module.get()); + if (current.is_internal) { + if (!module->InitAsInternalPlugin(current.internal_entry_points)) { + DLOG(ERROR) << "Failed to load pepper module: " << current.path.value(); + continue; + } + } else { + // Preload all external plugins we're not running out of process. + if (!module->InitAsLibrary(current.path)) { + DLOG(ERROR) << "Failed to load pepper module: " << current.path.value(); + continue; + } + } + preloaded_modules_[current.path] = module; + } +} + +} // namespace content diff --git a/content/common/pepper_plugin_registry.h b/content/renderer/pepper/pepper_plugin_registry.h index 6a94725..ee8fd7cb 100644 --- a/content/common/pepper_plugin_registry.h +++ b/content/renderer/pepper/pepper_plugin_registry.h @@ -2,25 +2,23 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CONTENT_COMMON_PEPPER_PLUGIN_REGISTRY_H_ -#define CONTENT_COMMON_PEPPER_PLUGIN_REGISTRY_H_ +#ifndef CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_REGISTRY_H_ +#define CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_REGISTRY_H_ #include <list> #include <map> +#include "base/memory/ref_counted.h" #include "content/public/common/pepper_plugin_info.h" -// TODO(jam): refactor -#include "content/renderer/pepper/plugin_module.h" +namespace webkit { +namespace ppapi { +class PluginModule; +} +} namespace content { -// Constructs a PepperPluginInfo from a WebPluginInfo. Returns false if -// the operation is not possible, in particular the WebPluginInfo::type -// must be one of the pepper types. -bool MakePepperPluginInfo(const WebPluginInfo& webplugin_info, - PepperPluginInfo* pepper_info); - // This class holds references to all of the known pepper plugin modules. // // It keeps two lists. One list of preloaded in-process modules, and one list @@ -32,20 +30,6 @@ class PepperPluginRegistry { static PepperPluginRegistry* GetInstance(); - // Computes the list of known pepper plugins. - // - // This method is static so that it can be used by the browser process, which - // has no need to load the pepper plugin modules. It will re-compute the - // plugin list every time it is called. Generally, code in the registry should - // be using the cached plugin_list_ instead. - CONTENT_EXPORT static void ComputeList( - 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(); - // Retrieves the information associated with the given plugin info. The // return value will be NULL if there is no such plugin. // @@ -95,4 +79,4 @@ class PepperPluginRegistry { } // namespace content -#endif // CONTENT_COMMON_PEPPER_PLUGIN_REGISTRY_H_ +#endif // CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_REGISTRY_H_ diff --git a/content/renderer/pepper/plugin_module.cc b/content/renderer/pepper/plugin_module.cc index 820ba56..44253b2 100644 --- a/content/renderer/pepper/plugin_module.cc +++ b/content/renderer/pepper/plugin_module.cc @@ -13,9 +13,9 @@ #include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop_proxy.h" #include "base/time/time.h" -#include "content/common/pepper_plugin_registry.h" #include "content/renderer/pepper/common.h" #include "content/renderer/pepper/host_globals.h" +#include "content/renderer/pepper/pepper_plugin_registry.h" #include "content/renderer/pepper/ppapi_interface_factory.h" #include "content/renderer/pepper/ppapi_plugin_instance_impl.h" #include "content/renderer/pepper/ppb_gpu_blacklist_private_impl.h" diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index d9612ec..f924813 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -44,7 +44,6 @@ #include "content/common/input_messages.h" #include "content/common/java_bridge_messages.h" #include "content/common/pepper_messages.h" -#include "content/common/pepper_plugin_registry.h" #include "content/common/socket_stream_handle_data.h" #include "content/common/ssl_status_serialization.h" #include "content/common/view_messages.h" @@ -107,6 +106,7 @@ #include "content/renderer/mhtml_generator.h" #include "content/renderer/notification_provider.h" #include "content/renderer/pepper/pepper_plugin_delegate_impl.h" +#include "content/renderer/pepper/pepper_plugin_registry.h" #include "content/renderer/render_frame_impl.h" #include "content/renderer/render_process.h" #include "content/renderer/render_thread_impl.h" diff --git a/content/renderer/renderer_main.cc b/content/renderer/renderer_main.cc index 5d34342..b179545 100644 --- a/content/renderer/renderer_main.cc +++ b/content/renderer/renderer_main.cc @@ -23,11 +23,11 @@ #include "base/timer/hi_res_timer_manager.h" #include "content/child/child_process.h" #include "content/common/content_constants_internal.h" -#include "content/common/pepper_plugin_registry.h" #include "content/public/common/content_switches.h" #include "content/public/common/main_function_params.h" #include "content/public/renderer/content_renderer_client.h" #include "content/renderer/browser_plugin/browser_plugin_manager_impl.h" +#include "content/renderer/pepper/pepper_plugin_registry.h" #include "content/renderer/pepper/ppapi_interface_factory.h" #include "content/renderer/render_process_impl.h" #include "content/renderer/render_thread_impl.h" diff --git a/content/zygote/zygote_main_linux.cc b/content/zygote/zygote_main_linux.cc index dcea4c0..0df288f 100644 --- a/content/zygote/zygote_main_linux.cc +++ b/content/zygote/zygote_main_linux.cc @@ -20,6 +20,7 @@ #include "base/files/file_path.h" #include "base/linux_util.h" #include "base/memory/scoped_ptr.h" +#include "base/native_library.h" #include "base/pickle.h" #include "base/posix/eintr_wrapper.h" #include "base/posix/unix_domain_socket_linux.h" @@ -28,11 +29,12 @@ #include "base/sys_info.h" #include "build/build_config.h" #include "content/common/font_config_ipc_linux.h" -#include "content/common/pepper_plugin_registry.h" +#include "content/common/pepper_plugin_list.h" #include "content/common/sandbox_linux.h" #include "content/common/zygote_commands_linux.h" #include "content/public/common/content_switches.h" #include "content/public/common/main_function_params.h" +#include "content/public/common/pepper_plugin_info.h" #include "content/public/common/sandbox_linux.h" #include "content/public/common/zygote_fork_delegate_linux.h" #include "content/zygote/zygote_linux.h" @@ -249,6 +251,27 @@ struct tm* localtime64_r_override(const time_t* timep, struct tm* result) { } } +#if defined(ENABLE_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. +void PreloadPepperPlugins() { + std::vector<PepperPluginInfo> plugins; + ComputePepperPluginList(&plugins); + for (size_t i = 0; i < plugins.size(); ++i) { + if (!plugins[i].is_internal && plugins[i].is_sandboxed) { + std::string error; + base::NativeLibrary library = base::LoadNativeLibrary(plugins[i].path, + &error); + DLOG_IF(WARNING, !library) << "Unable to load plugin " + << plugins[i].path.value() << " " + << error; + (void)library; // Prevent release-mode warning. + } + } +} +#endif + // This function triggers the static and lazy construction of objects that need // to be created before imposing the sandbox. static void PreSandboxInit() { @@ -277,7 +300,7 @@ static void PreSandboxInit() { #endif #if defined(ENABLE_PLUGINS) // Ensure access to the Pepper plugins before the sandbox is turned on. - PepperPluginRegistry::PreloadModules(); + PreloadPepperPlugins(); #endif #if defined(ENABLE_WEBRTC) InitializeWebRtcModule(); |