- add sources.
[platform/framework/web/crosswalk.git] / src / content / renderer / pepper / pepper_plugin_registry.h
1 // Copyright (c) 2012 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.
4
5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_REGISTRY_H_
6 #define CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_REGISTRY_H_
7
8 #include <list>
9 #include <map>
10
11 #include "base/memory/ref_counted.h"
12 #include "content/public/common/pepper_plugin_info.h"
13
14 namespace content {
15 class PluginModule;
16
17 // This class holds references to all of the known pepper plugin modules.
18 //
19 // It keeps two lists. One list of preloaded in-process modules, and one list
20 // is a list of all live modules (some of which may be out-of-process and hence
21 // not preloaded).
22 class PepperPluginRegistry {
23  public:
24   ~PepperPluginRegistry();
25
26   static PepperPluginRegistry* GetInstance();
27
28   // Retrieves the information associated with the given plugin info. The
29   // return value will be NULL if there is no such plugin.
30   //
31   // The returned pointer is owned by the PluginRegistry.
32   const PepperPluginInfo* GetInfoForPlugin(const WebPluginInfo& info);
33
34   // Returns an existing loaded module for the given path. It will search for
35   // both preloaded in-process or currently active (non crashed) out-of-process
36   // plugins matching the given name. Returns NULL if the plugin hasn't been
37   // loaded.
38   PluginModule* GetLiveModule(const base::FilePath& path);
39
40   // Notifies the registry that a new non-preloaded module has been created.
41   // This is normally called for out-of-process plugins. Once this is called,
42   // the module is available to be returned by GetModule(). The module will
43   // automatically unregister itself by calling PluginModuleDestroyed().
44   void AddLiveModule(const base::FilePath& path, PluginModule* module);
45
46   void PluginModuleDead(PluginModule* dead_module);
47
48  private:
49   PepperPluginRegistry();
50   void Initialize();
51
52   // All known pepper plugins.
53   std::vector<PepperPluginInfo> plugin_list_;
54
55   // Plugins that have been preloaded so they can be executed in-process in
56   // the renderer (the sandbox prevents on-demand loading).
57   typedef std::map<base::FilePath, scoped_refptr<PluginModule> >
58       OwningModuleMap;
59   OwningModuleMap preloaded_modules_;
60
61   // A list of non-owning pointers to all currently-live plugin modules. This
62   // includes both preloaded ones in preloaded_modules_, and out-of-process
63   // modules whose lifetime is managed externally. This will contain only
64   // non-crashed modules. If an out-of-process module crashes, it may
65   // continue as long as there are WebKit references to it, but it will not
66   // appear in this list.
67   typedef std::map<base::FilePath, PluginModule*> NonOwningModuleMap;
68   NonOwningModuleMap live_modules_;
69
70   DISALLOW_COPY_AND_ASSIGN(PepperPluginRegistry);
71 };
72
73 }  // namespace content
74
75 #endif  // CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_REGISTRY_H_