Print Preview: Refactoring print/cancel button and print summary.
[chromium-blink-merge.git] / content / common / pepper_plugin_registry.h
blob5e6389e33d550293d26029a2704fdae6bc0143dc
1 // Copyright (c) 2011 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 #ifndef CONTENT_COMMON_PEPPER_PLUGIN_REGISTRY_H_
6 #define CONTENT_COMMON_PEPPER_PLUGIN_REGISTRY_H_
7 #pragma once
9 #include <list>
10 #include <map>
11 #include <string>
12 #include <vector>
14 #include "base/file_path.h"
15 #include "ppapi/proxy/proxy_channel.h"
16 #include "webkit/plugins/npapi/webplugininfo.h"
17 #include "webkit/plugins/ppapi/plugin_delegate.h"
18 #include "webkit/plugins/ppapi/plugin_module.h"
20 struct PepperPluginInfo {
21 PepperPluginInfo();
22 ~PepperPluginInfo();
24 webkit::npapi::WebPluginInfo ToWebPluginInfo() const;
26 // Indicates internal plugins for which there's not actually a library.
27 // These plugins are implemented in the Chrome binary using a separate set
28 // of entry points (see internal_entry_points below).
29 // Defaults to false.
30 bool is_internal;
32 // True when this plugin should be run out of process. Defaults to false.
33 bool is_out_of_process;
35 // Whether the plugin is enabled. Defaults to true.
36 bool enabled;
38 FilePath path; // Internal plugins have "internal-[name]" as path.
39 std::string name;
40 std::string description;
41 std::string version;
42 std::vector<webkit::npapi::WebPluginMimeType> mime_types;
44 // When is_internal is set, this contains the function pointers to the
45 // entry points for the internal plugins.
46 webkit::ppapi::PluginModule::EntryPoints internal_entry_points;
49 // This class holds references to all of the known pepper plugin modules.
51 // It keeps two lists. One list of preloaded in-process modules, and one list
52 // is a list of all live modules (some of which may be out-of-process and hence
53 // not preloaded).
54 class PepperPluginRegistry
55 : public webkit::ppapi::PluginDelegate::ModuleLifetime,
56 public pp::proxy::ProxyChannel::Delegate {
57 public:
58 ~PepperPluginRegistry();
60 static PepperPluginRegistry* GetInstance();
62 // Computes the list of known pepper plugins.
64 // This method is static so that it can be used by the browser process, which
65 // has no need to load the pepper plugin modules. It will re-compute the
66 // plugin list every time it is called. Generally, code in the registry should
67 // be using the cached plugin_list_ instead.
68 static void ComputeList(std::vector<PepperPluginInfo>* plugins);
70 // Loads the (native) libraries but does not initialize them (i.e., does not
71 // call PPP_InitializeModule). This is needed by the zygote on Linux to get
72 // access to the plugins before entering the sandbox.
73 static void PreloadModules();
75 // Retrieves the information associated with the given plugin path. The
76 // return value will be NULL if there is no such plugin.
78 // The returned pointer is owned by the PluginRegistry.
79 const PepperPluginInfo* GetInfoForPlugin(const FilePath& path) const;
81 // Returns an existing loaded module for the given path. It will search for
82 // both preloaded in-process or currently active (non crashed) out-of-process
83 // plugins matching the given name. Returns NULL if the plugin hasn't been
84 // loaded.
85 webkit::ppapi::PluginModule* GetLiveModule(const FilePath& path);
87 // Notifies the registry that a new non-preloaded module has been created.
88 // This is normally called for out-of-process plugins. Once this is called,
89 // the module is available to be returned by GetModule(). The module will
90 // automatically unregister itself by calling PluginModuleDestroyed().
91 void AddLiveModule(const FilePath& path, webkit::ppapi::PluginModule* module);
93 // ModuleLifetime implementation.
94 virtual void PluginModuleDead(webkit::ppapi::PluginModule* dead_module);
96 private:
97 PepperPluginRegistry();
99 // ProxyChannel::Delegate implementation.
100 virtual base::MessageLoopProxy* GetIPCMessageLoop();
101 virtual base::WaitableEvent* GetShutdownEvent();
103 // All known pepper plugins.
104 std::vector<PepperPluginInfo> plugin_list_;
106 // Plugins that have been preloaded so they can be executed in-process in
107 // the renderer (the sandbox prevents on-demand loading).
108 typedef std::map<FilePath, scoped_refptr<webkit::ppapi::PluginModule> >
109 OwningModuleMap;
110 OwningModuleMap preloaded_modules_;
112 // A list of non-owning pointers to all currently-live plugin modules. This
113 // includes both preloaded ones in preloaded_modules_, and out-of-process
114 // modules whose lifetime is managed externally. This will contain only
115 // non-crashed modules. If an out-of-process module crashes, it may
116 // continue as long as there are WebKit references to it, but it will not
117 // appear in this list.
118 typedef std::map<FilePath, webkit::ppapi::PluginModule*> NonOwningModuleMap;
119 NonOwningModuleMap live_modules_;
121 DISALLOW_COPY_AND_ASSIGN(PepperPluginRegistry);
124 #endif // CONTENT_COMMON_PEPPER_PLUGIN_REGISTRY_H_