| Index: webkit/plugins/ppapi/ppapi_plugin_list.cc
|
| ===================================================================
|
| --- webkit/plugins/ppapi/ppapi_plugin_list.cc (revision 0)
|
| +++ webkit/plugins/ppapi/ppapi_plugin_list.cc (revision 0)
|
| @@ -0,0 +1,175 @@
|
| +// Copyright (c) 2011 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 "webkit/plugins/ppapi/ppapi_plugin_list.h"
|
| +
|
| +#include "base/command_line.h"
|
| +#include "base/file_util.h"
|
| +#include "base/native_library.h"
|
| +#include "base/string_split.h"
|
| +#include "base/utf_string_conversions.h"
|
| +#include "webkit/plugins/plugin_switches.h"
|
| +
|
| +namespace webkit {
|
| +namespace ppapi {
|
| +
|
| +void PluginList::LoadModules() {
|
| + // 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 PluginInfo& current = plugin_list_[i];
|
| + if (current.is_out_of_process)
|
| + continue; // Out of process plugins need no special pre-initialization.
|
| +
|
| + scoped_refptr<PluginModule> module = NULL;
|
| + //new PluginModule(current.name, current.path, this);
|
| + AddLiveModule(current.path, module);
|
| + 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;
|
| + }
|
| +}
|
| +
|
| +void PluginList::PreloadModules() {
|
| + for (size_t i = 0; i < plugin_list_.size(); ++i) {
|
| + if (!plugin_list_[i].is_internal) {
|
| + std::string error;
|
| + base::NativeLibrary library = base::LoadNativeLibrary(
|
| + plugin_list_[i].path, &error);
|
| + LOG_IF(WARNING, !library) << "Unable to load plugin "
|
| + << plugin_list_[i].path.value() << " "
|
| + << error;
|
| + }
|
| + }
|
| +}
|
| +
|
| +const PluginInfo* PluginList::GetInfoForPlugin(const FilePath& plugin_path) {
|
| + for (size_t i = 0; i < plugin_list_.size(); ++i) {
|
| + if (plugin_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.
|
| + /*PluginInfo plugin;
|
| + if (!WebToPepperPluginInfo(info, &plugin))
|
| + return NULL;
|
| +
|
| + plugin_list_.push_back(plugin);
|
| + return &plugin_list_[plugin_list_.size() - 1];*/
|
| + return NULL;
|
| +}
|
| +
|
| +PluginModule* PluginList::GetLiveModule(const FilePath& path) {
|
| + NonOwningModuleMap::iterator it = live_modules_.find(path);
|
| + if (it == live_modules_.end())
|
| + return NULL;
|
| + return it->second;
|
| +}
|
| +
|
| +void PluginList::AddLiveModule(const FilePath& path, PluginModule* module) {
|
| + DCHECK(live_modules_.find(path) == live_modules_.end());
|
| + live_modules_[path] = module;
|
| +}
|
| +
|
| +void PluginList::PluginModuleDead(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;
|
| + }
|
| + }
|
| + NOTREACHED(); // Should have always found the module above.
|
| +}
|
| +
|
| +PluginList::PluginList() {
|
| + AddFromCommandLine();
|
| +}
|
| +
|
| +PluginList::~PluginList() {
|
| + // 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());
|
| +}
|
| +
|
| +void PluginList::AddFromCommandLine() {
|
| + bool out_of_process =
|
| + CommandLine::ForCurrentProcess()->HasSwitch(switches::kPpapiOutOfProcess);
|
| + 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);
|
| +
|
| + PluginInfo 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 = FilePath(ASCIIToUTF16(name_parts[0]));
|
| +#else
|
| + plugin.path = 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) {
|
| + webkit::WebPluginMimeType mime_type(parts[j],
|
| + std::string(),
|
| + plugin.description);
|
| + plugin.mime_types.push_back(mime_type);
|
| + }
|
| +
|
| + plugin_list_.push_back(plugin);
|
| + }
|
| +}
|
| +
|
| +} // namespace ppapi
|
| +} // namespace webkit
|
|
|
| Property changes on: webkit\plugins\ppapi\ppapi_plugin_list.cc
|
| ___________________________________________________________________
|
| Added: svn:eol-style
|
| + LF
|
|
|
|
|