| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CONTENT_CHILD_NPAPI_PLUGIN_LIB_H_ | |
| 6 #define CONTENT_CHILD_NPAPI_PLUGIN_LIB_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <string> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/macros.h" | |
| 14 #include "base/memory/ref_counted.h" | |
| 15 #include "base/native_library.h" | |
| 16 #include "build/build_config.h" | |
| 17 #include "content/child/npapi/webplugin.h" | |
| 18 #include "content/common/content_export.h" | |
| 19 #include "content/public/common/webplugininfo.h" | |
| 20 #include "third_party/npapi/bindings/nphostapi.h" | |
| 21 | |
| 22 namespace base { | |
| 23 class FilePath; | |
| 24 } | |
| 25 | |
| 26 namespace content { | |
| 27 | |
| 28 class PluginInstance; | |
| 29 | |
| 30 // This struct holds entry points into a plugin. The entry points are | |
| 31 // slightly different between Win/Mac and Unixes. Note that the interface for | |
| 32 // querying plugins is synchronous and it is preferable to use a higher-level | |
| 33 // asynchronous information to query information. | |
| 34 struct PluginEntryPoints { | |
| 35 #if !defined(OS_POSIX) || defined(OS_MACOSX) | |
| 36 NP_GetEntryPointsFunc np_getentrypoints; | |
| 37 #endif | |
| 38 NP_InitializeFunc np_initialize; | |
| 39 NP_ShutdownFunc np_shutdown; | |
| 40 }; | |
| 41 | |
| 42 // A PluginLib is a single NPAPI Plugin Library, and is the lifecycle | |
| 43 // manager for new PluginInstances. | |
| 44 class CONTENT_EXPORT PluginLib : public base::RefCounted<PluginLib> { | |
| 45 public: | |
| 46 static PluginLib* CreatePluginLib(const base::FilePath& filename); | |
| 47 | |
| 48 // Unloads all the loaded plugin libraries and cleans up the plugin map. | |
| 49 static void UnloadAllPlugins(); | |
| 50 | |
| 51 // Shuts down all loaded plugin instances. | |
| 52 static void ShutdownAllPlugins(); | |
| 53 | |
| 54 // Get the Plugin's function pointer table. | |
| 55 NPPluginFuncs* functions(); | |
| 56 | |
| 57 // Creates a new instance of this plugin. | |
| 58 PluginInstance* CreateInstance(const std::string& mime_type); | |
| 59 | |
| 60 // Called by the instance when the instance is tearing down. | |
| 61 void CloseInstance(); | |
| 62 | |
| 63 // Gets information about this plugin and the mime types that it | |
| 64 // supports. | |
| 65 const WebPluginInfo& plugin_info() { return web_plugin_info_; } | |
| 66 | |
| 67 // | |
| 68 // NPAPI functions | |
| 69 // | |
| 70 | |
| 71 // NPAPI method to initialize a Plugin. | |
| 72 // Initialize can be safely called multiple times | |
| 73 NPError NP_Initialize(); | |
| 74 | |
| 75 // NPAPI method to shutdown a Plugin. | |
| 76 void NP_Shutdown(void); | |
| 77 | |
| 78 // NPAPI method to clear locally stored data (LSO's or "Flash cookies"). | |
| 79 NPError NP_ClearSiteData(const char* site, uint64_t flags, uint64_t max_age); | |
| 80 | |
| 81 // NPAPI method to get a NULL-terminated list of all sites under which data | |
| 82 // is stored. | |
| 83 char** NP_GetSitesWithData(); | |
| 84 | |
| 85 int instance_count() const { return instance_count_; } | |
| 86 | |
| 87 // Prevents the library code from being unload when Unload() is called (since | |
| 88 // some plugins crash if unloaded). | |
| 89 void PreventLibraryUnload(); | |
| 90 | |
| 91 // Indicates whether plugin unload can be deferred. | |
| 92 void set_defer_unload(bool defer_unload) { | |
| 93 defer_unload_ = defer_unload; | |
| 94 } | |
| 95 | |
| 96 // protected for testability. | |
| 97 protected: | |
| 98 friend class base::RefCounted<PluginLib>; | |
| 99 | |
| 100 // Creates a new PluginLib. | |
| 101 explicit PluginLib(const WebPluginInfo& info); | |
| 102 | |
| 103 virtual ~PluginLib(); | |
| 104 | |
| 105 // Attempts to load the plugin from the library. | |
| 106 // Returns true if it is a legitimate plugin, false otherwise | |
| 107 bool Load(); | |
| 108 | |
| 109 // Unloads the plugin library. | |
| 110 void Unload(); | |
| 111 | |
| 112 // Shutdown the plugin library. | |
| 113 void Shutdown(); | |
| 114 | |
| 115 private: | |
| 116 WebPluginInfo web_plugin_info_; // Supported mime types, description | |
| 117 base::NativeLibrary library_; // The opened library reference. | |
| 118 NPPluginFuncs plugin_funcs_; // The struct of plugin side functions. | |
| 119 bool initialized_; // Is the plugin initialized? | |
| 120 NPSavedData *saved_data_; // Persisted plugin info for NPAPI. | |
| 121 int instance_count_; // Count of plugins in use. | |
| 122 bool skip_unload_; // True if library_ should not be unloaded. | |
| 123 | |
| 124 // Function pointers to entry points into the plugin. | |
| 125 PluginEntryPoints entry_points_; | |
| 126 | |
| 127 // Set to true if unloading of the plugin dll is to be deferred. | |
| 128 bool defer_unload_; | |
| 129 | |
| 130 DISALLOW_COPY_AND_ASSIGN(PluginLib); | |
| 131 }; | |
| 132 | |
| 133 } // namespace content | |
| 134 | |
| 135 #endif // CONTENT_CHILD_NPAPI_PLUGIN_LIB_H_ | |
| OLD | NEW |