This source file includes following definitions.
- GetInstance
- GetInfoForPlugin
- GetLiveModule
- AddLiveModule
- PluginModuleDead
- Initialize
#include "content/renderer/pepper/pepper_plugin_registry.h"
#include "base/logging.h"
#include "content/common/pepper_plugin_list.h"
#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
#include "content/renderer/pepper/plugin_module.h"
#include "ppapi/shared_impl/ppapi_permissions.h"
namespace content {
PepperPluginRegistry* PepperPluginRegistry::GetInstance() {
static PepperPluginRegistry* registry = NULL;
if (!registry) {
registry = new PepperPluginRegistry;
registry->Initialize();
}
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];
}
PepperPluginInfo plugin;
if (!MakePepperPluginInfo(info, &plugin))
return NULL;
plugin_list_.push_back(plugin);
return &plugin_list_[plugin_list_.size() - 1];
}
PluginModule* PepperPluginRegistry::GetLiveModule(const base::FilePath& path) {
NonOwningModuleMap::iterator module_iter = live_modules_.find(path);
if (module_iter == live_modules_.end())
return NULL;
const PluginModule::PluginInstanceSet& instance_set =
module_iter->second->GetAllInstances();
if (instance_set.empty())
return module_iter->second;
PluginModule::PluginInstanceSet::const_iterator instance_iter =
instance_set.begin();
while (instance_iter != instance_set.end()) {
if (!(*instance_iter)->is_deleted())
return module_iter->second;
++instance_iter;
}
return NULL;
}
void PepperPluginRegistry::AddLiveModule(const base::FilePath& path,
PluginModule* module) {
DCHECK(live_modules_.find(path) == live_modules_.end());
live_modules_[path] = module;
}
void PepperPluginRegistry::PluginModuleDead(PluginModule* dead_module) {
for (NonOwningModuleMap::iterator i = live_modules_.begin();
i != live_modules_.end(); ++i) {
if (i->second == dead_module) {
live_modules_.erase(i);
return;
}
}
}
PepperPluginRegistry::~PepperPluginRegistry() {
preloaded_modules_.clear();
DCHECK(live_modules_.empty());
}
PepperPluginRegistry::PepperPluginRegistry() {
}
void PepperPluginRegistry::Initialize() {
ComputePepperPluginList(&plugin_list_);
for (size_t i = 0; i < plugin_list_.size(); i++) {
const PepperPluginInfo& current = plugin_list_[i];
if (current.is_out_of_process)
continue;
scoped_refptr<PluginModule> module = new 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 {
if (!module->InitAsLibrary(current.path)) {
DLOG(ERROR) << "Failed to load pepper module: " << current.path.value();
continue;
}
}
preloaded_modules_[current.path] = module;
}
}
}