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" |
15 | 16 |
16 namespace pepper { | 17 namespace pepper { |
17 | 18 |
18 class PluginDelegate; | 19 class PluginDelegate; |
19 class PluginInstance; | 20 class PluginInstance; |
20 | 21 |
21 class PluginModule : public base::RefCounted<PluginModule> { | 22 class PluginModule : public base::RefCounted<PluginModule> { |
22 public: | 23 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 |
23 ~PluginModule(); | 40 ~PluginModule(); |
24 | 41 |
25 static scoped_refptr<PluginModule> CreateModule(const FilePath& filename); | 42 static scoped_refptr<PluginModule> CreateModule(const FilePath& path); |
| 43 static scoped_refptr<PluginModule> CreateInternalModule( |
| 44 EntryPoints entry_points); |
26 | 45 |
27 // Converts the given module ID to an actual module object. Will return NULL | 46 // Converts the given module ID to an actual module object. Will return NULL |
28 // if the module is invalid. | 47 // if the module is invalid. |
29 static PluginModule* FromPPModule(PP_Module module); | 48 static PluginModule* FromPPModule(PP_Module module); |
30 | 49 |
31 PP_Module GetPPModule() const; | 50 PP_Module GetPPModule() const; |
32 | 51 |
33 PluginInstance* CreateInstance(PluginDelegate* delegate); | 52 PluginInstance* CreateInstance(PluginDelegate* delegate); |
34 | 53 |
35 // Returns "some" plugin instance associated with this module. This is not | 54 // Returns "some" plugin instance associated with this module. This is not |
36 // guaranteed to be any one in particular. This is normally used to execute | 55 // guaranteed to be any one in particular. This is normally used to execute |
37 // callbacks up to the browser layer that are not inherently per-instance, | 56 // callbacks up to the browser layer that are not inherently per-instance, |
38 // but the delegate lives only on the plugin instance so we need one of them. | 57 // but the delegate lives only on the plugin instance so we need one of them. |
39 PluginInstance* GetSomeInstance() const; | 58 PluginInstance* GetSomeInstance() const; |
40 | 59 |
41 const void* GetPluginInterface(const char* name) const; | 60 const void* GetPluginInterface(const char* name) const; |
42 | 61 |
43 // This module is associated with a set of instances. The PluginInstance | 62 // This module is associated with a set of instances. The PluginInstance |
44 // object declares its association with this module in its destructor and | 63 // object declares its association with this module in its destructor and |
45 // releases us in its destructor. | 64 // releases us in its destructor. |
46 void InstanceCreated(PluginInstance* instance); | 65 void InstanceCreated(PluginInstance* instance); |
47 void InstanceDeleted(PluginInstance* instance); | 66 void InstanceDeleted(PluginInstance* instance); |
48 | 67 |
49 private: | 68 private: |
50 typedef const void* (*PPP_GetInterfaceFunc)(const char*); | 69 PluginModule(); |
51 | 70 |
52 explicit PluginModule(const FilePath& filename); | 71 bool InitFromEntryPoints(const EntryPoints& entry_points); |
53 | 72 bool InitFromFile(const FilePath& path); |
54 bool Load(); | 73 static bool LoadEntryPoints(const base::NativeLibrary& library, |
55 | 74 EntryPoints* entry_points); |
56 FilePath filename_; | |
57 | 75 |
58 bool initialized_; | 76 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. |
59 base::NativeLibrary library_; | 82 base::NativeLibrary library_; |
60 | 83 |
61 PPP_GetInterfaceFunc ppp_get_interface_; | 84 // Contains pointers to the entry points of the actual plugin |
| 85 // implementation. |
| 86 EntryPoints entry_points_; |
62 | 87 |
63 // Non-owning pointers to all instances associated with this module. When | 88 // Non-owning pointers to all instances associated with this module. When |
64 // there are no more instances, this object should be deleted. | 89 // there are no more instances, this object should be deleted. |
65 typedef std::set<PluginInstance*> PluginInstanceSet; | 90 typedef std::set<PluginInstance*> PluginInstanceSet; |
66 PluginInstanceSet instances_; | 91 PluginInstanceSet instances_; |
67 | 92 |
68 DISALLOW_COPY_AND_ASSIGN(PluginModule); | 93 DISALLOW_COPY_AND_ASSIGN(PluginModule); |
69 }; | 94 }; |
70 | 95 |
71 } // namespace pepper | 96 } // namespace pepper |
72 | 97 |
73 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_PLUGIN_MODULE_H_ | 98 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_PLUGIN_MODULE_H_ |
OLD | NEW |