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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
#import
<WebKit/npapi.h>#import
<WebKit/npfunctions.h>#import
<WebKit/npruntime.h>//
Browser function table,可以通过它来得到浏览器提供的功能staticNPNetscapeFuncs *browser ;staticconstchar*plugin_method_name_open ="open";/////////////////////////////////////*******各种接口的声明*********///在NPAPI编程的接口中你会发现有NP_打头的,有NPP_打头的,有NPN_打头的//NP是npapi的插件库提供给浏览器的最上层的接口//NPP即NP
Plugin是插件本身提供给浏览器调用的接口,主要被用来填充NPPluginFuncs的结构体//NPN即NP
Netscape ,是浏览器提供给插件使用的接口,这些接口一般都在NPNetscapeFuncs结构体中//Mach-o
entry points,浏览器和创建交流的最上层的接口
NPError NP_Initialize (NPNetscapeFuncs *browserFuncs );
NPError NP_GetEntryPoints (NPPluginFuncs *pluginFuncs );voidNP_Shutdown (void);//NPP
Functions
NPError NPP_New (NPMIMEType
pluginType ,NPP
instance ,uint16_tmode ,int16_targc ,char*argn [],char*argv [],NPSavedData *saved );
NPError NPP_Destroy (NPP
instance ,NPSavedData **save );
NPError NPP_SetWindow (NPP
instance ,NPWindow *window );
NPError NPP_NewStream (NPP
instance ,NPMIMEType
type ,NPStream *stream ,NPBool
seekable ,uint16_t*stype );
NPError NPP_DestroyStream (NPP
instance ,NPStream *stream ,NPReason
reason );int32NPP_WriteReady (NPP
instance ,NPStream *stream );int32NPP_Write (NPP
instance ,NPStream *stream ,int32offset ,int32len ,void*buffer );voidNPP_StreamAsFile (NPP
instance ,NPStream *stream ,constchar*fname );voidNPP_Print (NPP
instance ,NPPrint *platformPrint );int16_tNPP_HandleEvent (NPP
instance ,void*event );voidNPP_URLNotify (NPP
instance ,constchar*URL ,NPReason
reason ,void*notifyData );
NPError NPP_GetValue (NPP
instance ,NPPVariable
variable ,void*value );
NPError NPP_SetValue (NPP
instance ,NPNVariable
variable ,void*value );//Functions
for scriptablePluginClass
bool plugin_has_method (NPObject *obj ,NPIdentifier
methodName );
bool plugin_invoke (NPObject *obj ,NPIdentifier
methodName ,constNPVariant *args ,uint32_targCount ,NPVariant *result );
bool hasProperty (NPObject *obj ,NPIdentifier
propertyName );
bool getProperty (NPObject *obj ,NPIdentifier
propertyName ,NPVariant *result );////////////////////////////////////staticstructNPClass
scriptablePluginClass ={
NP_CLASS_STRUCT_VERSION ,
NULL ,
NULL ,
NULL ,
plugin_has_method ,
plugin_invoke ,
NULL ,
hasProperty ,
getProperty ,
NULL ,
NULL ,};//接口的实现
NPError NP_Initialize (NPNetscapeFuncs *browserFuncs ){
browser =browserFuncs ;returnNPERR_NO_ERROR ;}
NPError NP_GetEntryPoints (NPPluginFuncs *pluginFuncs ){
pluginFuncs ->version =11;
pluginFuncs ->size =sizeof(pluginFuncs );
pluginFuncs ->newp =NPP_New ;
pluginFuncs ->destroy =NPP_Destroy ;
pluginFuncs ->setwindow =NPP_SetWindow ;
pluginFuncs ->newstream =NPP_NewStream ;
pluginFuncs ->destroystream =NPP_DestroyStream ;
pluginFuncs ->asfile =NPP_StreamAsFile ;
pluginFuncs ->writeready =NPP_WriteReady ;
pluginFuncs ->write =(NPP_WriteProcPtr )NPP_Write ;
pluginFuncs ->print =NPP_Print ;
pluginFuncs ->event =NPP_HandleEvent ;
pluginFuncs ->urlnotify =NPP_URLNotify ;
pluginFuncs ->getvalue =NPP_GetValue ;
pluginFuncs ->setvalue =NPP_SetValue ;returnNPERR_NO_ERROR ;}voidNP_Shutdown (void){}
bool plugin_has_method (NPObject *obj ,NPIdentifier
methodName ){//
This function will be called when we invoke method on this plugin elements.
NPUTF8 *name =browser ->utf8fromidentifier (methodName );
bool result =strcmp(name ,plugin_method_name_open )==0;
browser ->memfree (name );returnresult ;}
bool plugin_invoke (NPObject *obj ,NPIdentifier
methodName ,constNPVariant *args ,uint32_targCount ,NPVariant *result ){//
Make sure the method called is "open".
NPUTF8 *name =browser ->utf8fromidentifier (methodName );if(strcmp(name ,plugin_method_name_open )==0){
browser ->memfree (name );
BOOLEAN_TO_NPVARIANT (false,*result );//
Meke sure the arugment has at least one String parameter.if(argCount >0&&NPVARIANT_IS_STRING (args [0])){//
Build CFURL object from the arugment.
NPString str =NPVARIANT_TO_STRING (args [0]);
CFURLRef url =CFURLCreateWithBytes (NULL ,(constUInt8 *)str. UTF8Characters,str. UTF8Length,kCFStringEncodingUTF8 ,NULL );if(url ){//
Open URL with the default application by Launch Service.
OSStatus res =LSOpenCFURLRef (url ,NULL );
CFRelease (url );
BOOLEAN_TO_NPVARIANT (res ==noErr ,*result );}}returntrue;}
browser ->memfree (name );returnfalse;}
bool hasProperty (NPObject *obj ,NPIdentifier
propertyName ){returnfalse;}
bool getProperty (NPObject *obj ,NPIdentifier
propertyName ,NPVariant *result ){returnfalse;}//NPP
Functions Implements
NPError NPP_New (NPMIMEType
pluginType ,NPP
instance ,uint16_tmode ,int16_targc ,char*argn [],char*argv [],NPSavedData *saved ){//
Create per-instance storage//obj
= (PluginObject *)malloc(sizeof(PluginObject));//bzero(obj,
sizeof(PluginObject));//obj->npp
= instance;//instance->pdata
= obj;if(!instance ->pdata ){
instance ->pdata =browser ->createobject (instance ,&scriptablePluginClass );}//
Ask the browser if it supports the CoreGraphics drawing model
NPBool supportsCoreGraphics ;if(browser ->getvalue (instance ,NPNVsupportsCoreGraphicsBool ,&supportsCoreGraphics )!=NPERR_NO_ERROR )
supportsCoreGraphics =FALSE ;if(!supportsCoreGraphics )returnNPERR_INCOMPATIBLE_VERSION_ERROR ;//
If the browser supports the CoreGraphics drawing model, enable it.
browser ->setvalue (instance ,NPPVpluginDrawingModel ,(void*)NPDrawingModelCoreGraphics );returnNPERR_NO_ERROR ;}
NPError NPP_Destroy (NPP
instance ,NPSavedData **save ){//
If we created a plugin instance, we'll destroy and clean it up.
NPObject *pluginInstance =instance ->pdata ;if(!pluginInstance ){
browser ->releaseobject (pluginInstance );
pluginInstance =NULL ;}returnNPERR_NO_ERROR ;}
NPError NPP_SetWindow (NPP
instance ,NPWindow *window ){returnNPERR_NO_ERROR ;}
NPError NPP_NewStream (NPP
instance ,NPMIMEType
type ,NPStream *stream ,NPBool
seekable ,uint16_t*stype ){*stype =NP_ASFILEONLY ;returnNPERR_NO_ERROR ;}
NPError NPP_DestroyStream (NPP
instance ,NPStream *stream ,NPReason
reason ){returnNPERR_NO_ERROR ;}int32NPP_WriteReady (NPP
instance ,NPStream *stream ){return0;}int32NPP_Write (NPP
instance ,NPStream *stream ,int32offset ,int32len ,void*buffer ){return0;}voidNPP_StreamAsFile (NPP
instance ,NPStream *stream ,constchar*fname ){}voidNPP_Print (NPP
instance ,NPPrint *platformPrint ){}int16_tNPP_HandleEvent (NPP
instance ,void*event ){return0;}voidNPP_URLNotify (NPP
instance ,constchar*url ,NPReason
reason ,void*notifyData ){}
NPError NPP_GetValue (NPP
instance ,NPPVariable
variable ,void*value ){
NPObject *pluginInstance =NULL ;switch(variable ){caseNPPVpluginScriptableNPObject ://
If we didn't create any plugin instance, we create it.
pluginInstance =instance ->pdata ;if(pluginInstance ){
browser ->retainobject (pluginInstance );}*(NPObject **)value =pluginInstance ;break;default:returnNPERR_GENERIC_ERROR ;}returnNPERR_NO_ERROR ;}
NPError NPP_SetValue (NPP
instance ,NPNVariable
variable ,void*value ){returnNPERR_GENERIC_ERROR ;}
|
相关推荐
npapi插件中插件主动调网页js函数的例子程序 插件中添加一个按钮,点击按钮调用js函数
JS调用NPAPI插件内的函数 新手的DEMO 希望对大家有用
这是一个简单的npapi插件实现的代码和npapi插件实现的sdk
npapi 插件 js页面调用插件函数Demo
最简单的NPAPI插件代码及整个VS工程。博文中相关代码。欢迎下载,研究学习!
让ActiveX在FireFox和Chrome等NPAPI插件接口的浏览器中上运行 这样firefox浏览器就可以正常浏览有ActiveX插件的网页,比如flash 的ActiveX控件: id="Control" TYPE="application/x-itst-activex" WIDTH="300" ...
基于webkit框架的NPAPI插件开发,遵守NPAPI开发准则,实现Browser+plugin+NPAPI完美调用。
具有类封装的最简NPAPI插件代码及相应VS项目,欢迎下载研究学习
用于自动生成NPAPI插件开发过程中的一些必要文件,相关使用方式请参考本人CSDN博客!欢迎下载使用!
附带NPAPI插件的Chrome扩展及代码
虽然火狐新版已经不支持npapi技术了,有兴趣研究的同学可以下载参考一下。 其中npruntie实例已经在ff36~ff50版本测试通过
具有脚本化接口的简单NPAPI插件,包含代码及相应VS项目,欢迎下载研究。
最简单的NPAPI插件的实现框架, 结构稳定而简单可大规模使用,适合初学者学习
用于自动生成NPAPI插件开发过程中的一些必要文件,相关使用方式请参考本人CSDN博客!欢迎下载使用!这个是最新版本,前面两个有问题,请下载本文件
Delphi开发npapi插件的一个小例子,简单明白。 目前用的虽然少了,但是学习很有用 ~!!!!
google chrome扩展和插件开发,使用 NPAPI 插件获取浏览器地址栏URL
一步一步教你怎么开发支持多浏览器的插件,是一套最全的说明文档
使用Qt5+msvc2015编写的npapi浏览器插件 支持firefox52以下浏览器版本 有详细说明文档 有源码和bin文件以及需要的动态库
360浏览器(带NPAPI插件) 支持ARM架构架构主机 Deb安装文件
一份代码(用VS2008创建的)、一个Word文档(NPAPI插件创建步骤)、一个测试html,npruntime