summaryrefslogtreecommitdiffstats
path: root/webkit/glue/plugins/plugin_lib.h
diff options
context:
space:
mode:
authorinitial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98>2008-07-27 00:20:51 +0000
committerinitial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98>2008-07-27 00:20:51 +0000
commitf5b16fed647e941aa66933178da85db2860d639b (patch)
treef00e9856c04aad3b558a140955e7674add33f051 /webkit/glue/plugins/plugin_lib.h
parent920c091ac3ee15079194c82ae8a7a18215f3f23c (diff)
downloadchromium_src-f5b16fed647e941aa66933178da85db2860d639b.zip
chromium_src-f5b16fed647e941aa66933178da85db2860d639b.tar.gz
chromium_src-f5b16fed647e941aa66933178da85db2860d639b.tar.bz2
Add webkit to the repository.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/plugins/plugin_lib.h')
-rw-r--r--webkit/glue/plugins/plugin_lib.h163
1 files changed, 163 insertions, 0 deletions
diff --git a/webkit/glue/plugins/plugin_lib.h b/webkit/glue/plugins/plugin_lib.h
new file mode 100644
index 0000000..798b2ea
--- /dev/null
+++ b/webkit/glue/plugins/plugin_lib.h
@@ -0,0 +1,163 @@
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef WEBKIT_GLUE_PLUGIN_PLUGIN_LIB_H__
+#define WEBKIT_GLUE_PLUGIN_PLUGIN_LIB_H__
+
+#include <hash_map>
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/ref_counted.h"
+#include "base/scoped_ptr.h"
+#include "webkit/glue/plugins/nphostapi.h"
+#include "third_party/npapi/bindings/npapi.h"
+
+struct WebPluginInfo;
+
+namespace NPAPI
+{
+
+class PluginInstance;
+
+// This struct fully describes a plugin. For dll plugins, it's read in from
+// the version info of the dll; For internal plugins, it's predefined.
+struct PluginVersionInfo {
+ std::wstring file_name;
+ std::wstring product_name;
+ std::wstring file_description;
+ std::wstring file_version;
+ std::wstring mime_types;
+ std::wstring file_extents;
+ std::wstring file_open_names;
+};
+
+// This struct contains information of an internal plugin and addresses of
+// entry functions.
+struct InternalPluginInfo {
+ PluginVersionInfo version_info;
+ NP_GetEntryPointsFunc np_getentrypoints;
+ NP_InitializeFunc np_initialize;
+ NP_ShutdownFunc np_shutdown;
+};
+
+// A PluginLib is a single NPAPI Plugin Library, and is the lifecycle
+// manager for new PluginInstances.
+class PluginLib : public base::RefCounted<PluginLib> {
+ public:
+ virtual ~PluginLib();
+ static PluginLib* CreatePluginLib(const std::wstring& filename);
+
+ // Unloads all the loaded plugin dlls and cleans up the plugin map.
+ static void UnloadAllPlugins();
+
+ // Shuts down all loaded plugin instances.
+ static void ShutdownAllPlugins();
+
+ // Get the Plugin's function pointer table.
+ NPPluginFuncs *functions();
+
+ // Returns true if this Plugin supports a given mime-type.
+ // mime_type should be all lower case.
+ bool SupportsType(const std::string &mime_type, bool allow_wildcard);
+
+ // Creates a new instance of this plugin.
+ PluginInstance *CreateInstance(const std::string &mime_type);
+
+ // Called by the instance when the instance is tearing down.
+ void CloseInstance();
+
+ // Gets information about this plugin and the mime types that it
+ // supports.
+ const WebPluginInfo& plugin_info() { return *web_plugin_info_; }
+
+ //
+ // NPAPI functions
+ //
+
+ // NPAPI method to initialize a Plugin.
+ // Initialize can be safely called multiple times
+ NPError NP_Initialize();
+
+ // NPAPI method to shutdown a Plugin.
+ void NP_Shutdown(void);
+
+ // Helper function to load a plugin.
+ // Returns the module handle on success.
+ static HMODULE LoadPluginHelper(const std::wstring plugin_file);
+
+ int instance_count() const { return instance_count_; }
+
+ private:
+ // Creates a new PluginLib. The WebPluginInfo object is owned by this
+ // object. If internal_plugin_info is not NULL, this Lib is an internal
+ // plugin thus doesn't need to load dll.
+ PluginLib(WebPluginInfo* info,
+ const InternalPluginInfo* internal_plugin_info);
+
+ // Attempts to load the plugin from the DLL.
+ // Returns true if it is a legitimate plugin, false otherwise
+ bool Load();
+
+ // Unloading the plugin DLL.
+ void Unload();
+
+ // Shutdown the plugin DLL.
+ void Shutdown();
+
+ // Returns a WebPluginInfo structure given a plugin's path. Returns NULL if
+ // the dll couldn't be found, or if it's not a plugin.
+ static WebPluginInfo* ReadWebPluginInfo(const std::wstring &filename);
+ // Creates WebPluginInfo structure based on read in or built in
+ // PluginVersionInfo.
+ static WebPluginInfo* CreateWebPluginInfo(const PluginVersionInfo& info);
+
+ bool internal_; // Whether this an internal plugin.
+ scoped_ptr<WebPluginInfo> web_plugin_info_; // supported mime types, description
+ HMODULE module_; // the opened DLL handle
+ NPPluginFuncs plugin_funcs_; // the struct of plugin side functions
+ bool initialized_; // is the plugin initialized
+ NPSavedData *saved_data_; // persisted plugin info for NPAPI
+ int instance_count_; // count of plugins in use
+
+ // A map of all the insantiated plugins.
+ typedef stdext::hash_map<std::wstring, scoped_refptr<PluginLib> > PluginMap;
+ static PluginMap* loaded_libs_;
+
+ // C-style function pointers
+ NP_InitializeFunc NP_Initialize_;
+ NP_GetEntryPointsFunc NP_GetEntryPoints_;
+ NP_ShutdownFunc NP_Shutdown_;
+
+ DISALLOW_EVIL_CONSTRUCTORS(PluginLib);
+};
+
+} // namespace NPAPI
+
+#endif // WEBKIT_GLUE_PLUGIN_PLUGIN_LIB_H__