FreeWRL / FreeX3D 4.3.0
npp_gate.cpp
1/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Netscape Public License
6 * Version 1.1 (the "License"); you may not use this file except in
7 * compliance with the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/NPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is mozilla.org code.
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the NPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the NPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
39//
40// Implementation of plugin entry points (NPP_*)
41// most are just empty stubs for this particular plugin
42//
43#include "plugin.h"
44#include "windows.h"
45
46char*
47NPP_GetMIMEDescription(void)
48{
49 static char mime_types[] =
50 "x-world/x-vrml:wrl:FreeWRL VRML Browser;"
51 "model/vrml:wrl:FreeWRL VRML Browser;"
52 "model/x3d:x3d:FreeWRL X3D Browser;"
53 "model/x3d+xml:x3d:FreeWRL X3D Browser;"
54 "model/x3d+vrml:x3dv:FreeWRL X3D Browser;"
55 "model/x3d+binary:x3db:FreeWRL X3D Browser"
56 ;
57 return mime_types;
58}
59
60
61
62NPError NPP_Initialize(void)
63{
64 return NPERR_NO_ERROR;
65}
66
67void NPP_Shutdown(void)
68{
69}
70
71// here the plugin creates an instance of our CPlugin object which
72// will be associated with this newly created plugin instance and
73// will do all the neccessary job
74NPError NPP_New(NPMIMEType pluginType,
75 NPP instance,
76 uint16_t mode,
77 int16_t argc,
78 char* argn[],
79 char* argv[],
80 NPSavedData* saved)
81{
82 if(instance == NULL)
83 return NPERR_INVALID_INSTANCE_ERROR;
84
85 NPError rv = NPERR_NO_ERROR;
86
87#ifdef _DEBUG
88 ::MessageBoxA(NULL,"You may now attach a debugger.\n Press OK when you want to proceed.","np_freeWRL plugin process(1)",MB_OK);
89#endif
90
91 CPlugin * pPlugin = new CPlugin(instance);
92 if(pPlugin == NULL)
93 return NPERR_OUT_OF_MEMORY_ERROR;
94
95 instance->pdata = (void *)pPlugin;
96
97 int i = 0;
98
99 for(i = 0; i < argc ; i++)
100 {
101 char* argni;
102 char* argvi;
103 argni = argn[i];
104 argvi = argv[i];
105 if(!_stricmp(argn[i],"target") || !_stricmp(argn[i],"src"))
106 {
107 pPlugin->setSceneUrl(argv[i]);
108 }
109
110 if(!_stricmp(argn[i],"eai"))
111 {
112 pPlugin->setEAIFlag();
113 }
114 }
115 return rv;
116}
117
118// here is the place to clean up and destroy the CPlugin object
119NPError NPP_Destroy (NPP instance, NPSavedData** save)
120{
121 if(instance == NULL)
122 return NPERR_INVALID_INSTANCE_ERROR;
123
124 NPError rv = NPERR_NO_ERROR;
125
126 CPlugin * pPlugin = (CPlugin *)instance->pdata;
127 if(pPlugin != NULL) {
128 pPlugin->shut();
129 delete pPlugin;
130 }
131 return rv;
132}
133
134// during this call we know when the plugin window is ready or
135// is about to be destroyed so we can do some gui specific
136// initialization and shutdown
137NPError NPP_SetWindow (NPP instance, NPWindow* pNPWindow)
138{
139 if(instance == NULL)
140 return NPERR_INVALID_INSTANCE_ERROR;
141
142 NPError rv = NPERR_NO_ERROR;
143
144 if(pNPWindow == NULL)
145 return NPERR_GENERIC_ERROR;
146
147 CPlugin * pPlugin = (CPlugin *)instance->pdata;
148
149 if(pPlugin == NULL)
150 return NPERR_GENERIC_ERROR;
151
152 // window just created
153 if(!pPlugin->isInitialized() && (pNPWindow->window != NULL)) {
154 if(!pPlugin->init(pNPWindow)) {
155 delete pPlugin;
156 pPlugin = NULL;
157 return NPERR_MODULE_LOAD_FAILED_ERROR;
158 }
159 }
160
161 // window goes away
162 if((pNPWindow->window == NULL) && pPlugin->isInitialized())
163 return NPERR_NO_ERROR;
164
165 // window resized
166 if(pPlugin->isInitialized() && (pNPWindow->window != NULL))
167 return NPERR_NO_ERROR;
168
169 // this should not happen, nothing to do
170 if((pNPWindow->window == NULL) && !pPlugin->isInitialized())
171 return NPERR_NO_ERROR;
172
173 return rv;
174}
175
176// ==============================
177// ! Scriptability related code !
178// ==============================
179//
180// here the plugin is asked by Mozilla to tell if it is scriptable
181// we should return a valid interface id and a pointer to
182// nsScriptablePeer interface which we should have implemented
183NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value)
184{
185 if(instance == NULL)
186 return NPERR_INVALID_INSTANCE_ERROR;
187
188 NPError rv = NPERR_NO_ERROR;
189
190 if(instance == NULL)
191 return NPERR_GENERIC_ERROR;
192
193 CPlugin * plugin = (CPlugin *)instance->pdata;
194 if(plugin == NULL)
195 return NPERR_GENERIC_ERROR;
196
197 switch (variable) {
198 case NPPVpluginNameString:
199 *((char **)value) = "NPRuntimeTest";
200 break;
201 case NPPVpluginDescriptionString:
202 *((char **)value) = "NPRuntime scriptability API test plugin";
203 break;
204 case NPPVpluginScriptableNPObject:
205 *(NPObject **)value = plugin->GetScriptableObject();
206 break;
207 default:
208 rv = NPERR_GENERIC_ERROR;
209 }
210
211 return rv;
212}
213
214NPError NPP_NewStream(NPP instance,
215 NPMIMEType type,
216 NPStream* stream,
217 NPBool seekable,
218 uint16_t* stype)
219{
220//#ifdef _DEBUG
221// ::MessageBoxA(NULL,"You may now attach a debugger.\n Press OK when you want to proceed.","np_freeX3D plugin process(2)",MB_OK);
222//#endif
223
224 if(instance == NULL)
225 return NPERR_INVALID_INSTANCE_ERROR;
226 //Ian's suggestion based on linux (but on windows it comes in NPP_New() first, so handle it there)
227 //CPlugin * pPlugin = (CPlugin *)(instance->pdata);
228 //pPlugin->setSceneUrl(_strdup(stream->url));
229 NPError rv = NPERR_NO_ERROR;
230 return rv;
231}
232
233int32_t NPP_WriteReady (NPP instance, NPStream *stream)
234{
235 if(instance == NULL)
236 return NPERR_INVALID_INSTANCE_ERROR;
237
238 int32_t rv = 0x0fffffff;
239 return rv;
240}
241
242int32_t NPP_Write (NPP instance, NPStream *stream, int32_t offset, int32_t len, void *buffer)
243{
244 if(instance == NULL)
245 return NPERR_INVALID_INSTANCE_ERROR;
246
247 int32_t rv = len;
248 return rv;
249}
250
251NPError NPP_DestroyStream (NPP instance, NPStream *stream, NPError reason)
252{
253 if(instance == NULL)
254 return NPERR_INVALID_INSTANCE_ERROR;
255
256 NPError rv = NPERR_NO_ERROR;
257 return rv;
258}
259
260void NPP_StreamAsFile (NPP instance, NPStream* stream, const char* fname)
261{
262 if(instance == NULL)
263 return;
264}
265
266void NPP_Print (NPP instance, NPPrint* printInfo)
267{
268 if(instance == NULL)
269 return;
270}
271
272void NPP_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData)
273{
274 if(instance == NULL)
275 return;
276}
277
278NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value)
279{
280 if(instance == NULL)
281 return NPERR_INVALID_INSTANCE_ERROR;
282
283 NPError rv = NPERR_NO_ERROR;
284 return rv;
285}
286
287int16_t NPP_HandleEvent(NPP instance, void* event)
288{
289 if(instance == NULL)
290 return 0;
291
292 int16_t rv = 0;
293 CPlugin * pPlugin = (CPlugin *)instance->pdata;
294 if (pPlugin)
295 rv = pPlugin->handleEvent(event);
296
297 return rv;
298}
299
300NPObject *NPP_GetScriptableInstance(NPP instance)
301{
302 if(!instance)
303 return 0;
304
305 NPObject *npobj = 0;
306 CPlugin * pPlugin = (CPlugin *)instance->pdata;
307 if (!pPlugin)
308 npobj = pPlugin->GetScriptableObject();
309
310 return npobj;
311}
Definition npapi.h:149