OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef WEBKIT_GLUE_PLUGINS_PEPPER_PLUGIN_MODULE_H_ | 5 #ifndef WEBKIT_GLUE_PLUGINS_PEPPER_PLUGIN_MODULE_H_ |
6 #define WEBKIT_GLUE_PLUGINS_PEPPER_PLUGIN_MODULE_H_ | 6 #define WEBKIT_GLUE_PLUGINS_PEPPER_PLUGIN_MODULE_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/native_library.h" | 12 #include "base/native_library.h" |
13 #include "base/ref_counted.h" | 13 #include "base/ref_counted.h" |
14 #include "third_party/ppapi/c/pp_module.h" | 14 #include "third_party/ppapi/c/pp_module.h" |
15 #include "third_party/ppapi/c/ppb.h" | |
16 | 15 |
17 namespace pepper { | 16 namespace pepper { |
18 | 17 |
19 class PluginDelegate; | 18 class PluginDelegate; |
20 class PluginInstance; | 19 class PluginInstance; |
21 | 20 |
22 class PluginModule : public base::RefCounted<PluginModule> { | 21 class PluginModule : public base::RefCounted<PluginModule> { |
23 public: | 22 public: |
24 typedef const void* (*PPP_GetInterfaceFunc)(const char*); | |
25 typedef int (*PPP_InitializeModuleFunc)(PP_Module, PPB_GetInterface); | |
26 typedef void (*PPP_ShutdownModuleFunc)(); | |
27 | |
28 struct EntryPoints { | |
29 EntryPoints() | |
30 : get_interface(NULL), | |
31 initialize_module(NULL), | |
32 shutdown_module(NULL) { | |
33 } | |
34 | |
35 PPP_GetInterfaceFunc get_interface; | |
36 PPP_InitializeModuleFunc initialize_module; | |
37 PPP_ShutdownModuleFunc shutdown_module; | |
38 }; | |
39 | |
40 ~PluginModule(); | 23 ~PluginModule(); |
41 | 24 |
42 static scoped_refptr<PluginModule> CreateModule(const FilePath& path); | 25 static scoped_refptr<PluginModule> CreateModule(const FilePath& filename); |
43 static scoped_refptr<PluginModule> CreateInternalModule( | |
44 EntryPoints entry_points); | |
45 | 26 |
46 // Converts the given module ID to an actual module object. Will return NULL | 27 // Converts the given module ID to an actual module object. Will return NULL |
47 // if the module is invalid. | 28 // if the module is invalid. |
48 static PluginModule* FromPPModule(PP_Module module); | 29 static PluginModule* FromPPModule(PP_Module module); |
49 | 30 |
50 PP_Module GetPPModule() const; | 31 PP_Module GetPPModule() const; |
51 | 32 |
52 PluginInstance* CreateInstance(PluginDelegate* delegate); | 33 PluginInstance* CreateInstance(PluginDelegate* delegate); |
53 | 34 |
54 // Returns "some" plugin instance associated with this module. This is not | 35 // Returns "some" plugin instance associated with this module. This is not |
55 // guaranteed to be any one in particular. This is normally used to execute | 36 // guaranteed to be any one in particular. This is normally used to execute |
56 // callbacks up to the browser layer that are not inherently per-instance, | 37 // callbacks up to the browser layer that are not inherently per-instance, |
57 // but the delegate lives only on the plugin instance so we need one of them. | 38 // but the delegate lives only on the plugin instance so we need one of them. |
58 PluginInstance* GetSomeInstance() const; | 39 PluginInstance* GetSomeInstance() const; |
59 | 40 |
60 const void* GetPluginInterface(const char* name) const; | 41 const void* GetPluginInterface(const char* name) const; |
61 | 42 |
62 // This module is associated with a set of instances. The PluginInstance | 43 // This module is associated with a set of instances. The PluginInstance |
63 // object declares its association with this module in its destructor and | 44 // object declares its association with this module in its destructor and |
64 // releases us in its destructor. | 45 // releases us in its destructor. |
65 void InstanceCreated(PluginInstance* instance); | 46 void InstanceCreated(PluginInstance* instance); |
66 void InstanceDeleted(PluginInstance* instance); | 47 void InstanceDeleted(PluginInstance* instance); |
67 | 48 |
68 private: | 49 private: |
69 PluginModule(); | 50 typedef const void* (*PPP_GetInterfaceFunc)(const char*); |
70 | 51 |
71 bool InitFromEntryPoints(const EntryPoints& entry_points); | 52 explicit PluginModule(const FilePath& filename); |
72 bool InitFromFile(const FilePath& path); | 53 |
73 static bool LoadEntryPoints(const base::NativeLibrary& library, | 54 bool Load(); |
74 EntryPoints* entry_points); | 55 |
| 56 FilePath filename_; |
75 | 57 |
76 bool initialized_; | 58 bool initialized_; |
77 | |
78 // Holds a reference to the base::NativeLibrary handle if this PluginModule | |
79 // instance wraps functions loaded from a library. Can be NULL. If | |
80 // |library_| is non-NULL, PluginModule will attempt to unload the library | |
81 // during destruction. | |
82 base::NativeLibrary library_; | 59 base::NativeLibrary library_; |
83 | 60 |
84 // Contains pointers to the entry points of the actual plugin | 61 PPP_GetInterfaceFunc ppp_get_interface_; |
85 // implementation. | |
86 EntryPoints entry_points_; | |
87 | 62 |
88 // Non-owning pointers to all instances associated with this module. When | 63 // Non-owning pointers to all instances associated with this module. When |
89 // there are no more instances, this object should be deleted. | 64 // there are no more instances, this object should be deleted. |
90 typedef std::set<PluginInstance*> PluginInstanceSet; | 65 typedef std::set<PluginInstance*> PluginInstanceSet; |
91 PluginInstanceSet instances_; | 66 PluginInstanceSet instances_; |
92 | 67 |
93 DISALLOW_COPY_AND_ASSIGN(PluginModule); | 68 DISALLOW_COPY_AND_ASSIGN(PluginModule); |
94 }; | 69 }; |
95 | 70 |
96 } // namespace pepper | 71 } // namespace pepper |
97 | 72 |
98 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_PLUGIN_MODULE_H_ | 73 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_PLUGIN_MODULE_H_ |
OLD | NEW |