OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef WEBKIT_GLUE_PLUGINS_PLUGIN_LIB_H_ | |
6 #define WEBKIT_GLUE_PLUGINS_PLUGIN_LIB_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/native_library.h" | |
13 #include "base/ref_counted.h" | |
14 #include "build/build_config.h" | |
15 #include "webkit/glue/plugins/plugin_list.h" | |
16 #include "webkit/glue/plugins/webplugin.h" | |
17 | |
18 class FilePath; | |
19 struct WebPluginInfo; | |
20 | |
21 namespace NPAPI { | |
22 | |
23 class PluginInstance; | |
24 | |
25 // A PluginLib is a single NPAPI Plugin Library, and is the lifecycle | |
26 // manager for new PluginInstances. | |
27 class PluginLib : public base::RefCounted<PluginLib> { | |
28 public: | |
29 static PluginLib* CreatePluginLib(const FilePath& filename); | |
30 | |
31 // Creates a WebPluginInfo structure given a plugin's path. On success | |
32 // returns true, with the information being put into "info". | |
33 // Returns false if the library couldn't be found, or if it's not a plugin. | |
34 static bool ReadWebPluginInfo(const FilePath& filename, WebPluginInfo* info); | |
35 | |
36 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
37 // Parse the result of an NP_GetMIMEDescription() call. | |
38 // This API is only used on Unixes, and is exposed here for testing. | |
39 static void ParseMIMEDescription(const std::string& description, | |
40 std::vector<WebPluginMimeType>* mime_types); | |
41 #endif | |
42 | |
43 // Unloads all the loaded plugin libraries and cleans up the plugin map. | |
44 static void UnloadAllPlugins(); | |
45 | |
46 // Shuts down all loaded plugin instances. | |
47 static void ShutdownAllPlugins(); | |
48 | |
49 // Get the Plugin's function pointer table. | |
50 NPPluginFuncs* functions(); | |
51 | |
52 // Creates a new instance of this plugin. | |
53 PluginInstance* CreateInstance(const std::string& mime_type); | |
54 | |
55 // Called by the instance when the instance is tearing down. | |
56 void CloseInstance(); | |
57 | |
58 // Gets information about this plugin and the mime types that it | |
59 // supports. | |
60 const WebPluginInfo& plugin_info() { return web_plugin_info_; } | |
61 | |
62 bool internal() { return internal_; } | |
63 | |
64 // | |
65 // NPAPI functions | |
66 // | |
67 | |
68 // NPAPI method to initialize a Plugin. | |
69 // Initialize can be safely called multiple times | |
70 NPError NP_Initialize(); | |
71 | |
72 // NPAPI method to shutdown a Plugin. | |
73 void NP_Shutdown(void); | |
74 | |
75 int instance_count() const { return instance_count_; } | |
76 | |
77 // Prevents the library code from being unload when Unload() is called (since | |
78 // some plugins crash if unloaded). | |
79 void PreventLibraryUnload(); | |
80 | |
81 // protected for testability. | |
82 protected: | |
83 friend class base::RefCounted<PluginLib>; | |
84 | |
85 // Creates a new PluginLib. | |
86 // |entry_points| is non-NULL for internal plugins. | |
87 PluginLib(const WebPluginInfo& info, | |
88 const PluginEntryPoints* entry_points); | |
89 | |
90 virtual ~PluginLib(); | |
91 | |
92 // Attempts to load the plugin from the library. | |
93 // Returns true if it is a legitimate plugin, false otherwise | |
94 bool Load(); | |
95 | |
96 // Unloads the plugin library. | |
97 void Unload(); | |
98 | |
99 // Shutdown the plugin library. | |
100 void Shutdown(); | |
101 | |
102 private: | |
103 bool internal_; // True for plugins that are built-in into chrome binaries. | |
104 WebPluginInfo web_plugin_info_; // Supported mime types, description | |
105 base::NativeLibrary library_; // The opened library reference. | |
106 NPPluginFuncs plugin_funcs_; // The struct of plugin side functions. | |
107 bool initialized_; // Is the plugin initialized? | |
108 NPSavedData *saved_data_; // Persisted plugin info for NPAPI. | |
109 int instance_count_; // Count of plugins in use. | |
110 bool skip_unload_; // True if library_ should not be unloaded. | |
111 | |
112 // Function pointers to entry points into the plugin. | |
113 PluginEntryPoints entry_points_; | |
114 | |
115 DISALLOW_COPY_AND_ASSIGN(PluginLib); | |
116 }; | |
117 | |
118 } // namespace NPAPI | |
119 | |
120 #endif // WEBKIT_GLUE_PLUGINS_PLUGIN_LIB_H_ | |
OLD | NEW |