blob: cd3db9736da58d60ca958b1a1e5065ee4525bc24 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WEBKIT_GLUE_PLUGIN_PLUGIN_LIB_H__
#define WEBKIT_GLUE_PLUGIN_PLUGIN_LIB_H__
#include "build/build_config.h"
#include <string>
#include "base/basictypes.h"
#include "base/file_path.h"
#include "base/hash_tables.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 external 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 FilePath& filename);
// Unloads all the loaded plugin libraries 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);
#if defined(OS_WIN)
// Helper function to load a plugin.
// Returns the module handle on success.
static HMODULE LoadPluginHelper(const FilePath plugin_file);
#endif
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 a library.
PluginLib(WebPluginInfo* info,
const InternalPluginInfo* internal_plugin_info);
// Attempts to load the plugin from the library.
// Returns true if it is a legitimate plugin, false otherwise
bool Load();
// Unloads the plugin library.
void Unload();
// Shutdown the plugin library.
void Shutdown();
// Returns a WebPluginInfo structure given a plugin's path. Returns NULL if
// the library couldn't be found, or if it's not a plugin.
static WebPluginInfo* ReadWebPluginInfo(const FilePath &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
#if defined(OS_WIN)
HMODULE module_; // the opened DLL handle
#endif
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 instantiated plugins.
typedef base::hash_map<FilePath, 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__
|