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
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/
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
15
* The Original Code is mozilla.org code.
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.
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.
36
* ***** END LICENSE BLOCK ***** */
38
////////////////////////////////////////////////////////////
40
// Implementation of plugin entry points (NPP_*)
41
// most are just empty stubs for this particular plugin
44
#include "plugin_types.h"
45
#include "plugin_setup.h"
47
char *NPP_GetMIMEDescription(void)
49
return GetMIMEDescription();
53
NPError NPP_Initialize(void)
55
return NPERR_NO_ERROR;
58
void NPP_Shutdown(void)
62
// here the plugin creates an instance of our CPlugin object which
63
// will be associated with this newly created plugin instance and
64
// will do all the neccessary job
65
NPError NPP_New(NPMIMEType pluginType,
67
uint16_t mode, int16_t argc, char *argn[], char *argv[], NPSavedData * saved)
70
return NPERR_INVALID_INSTANCE_ERROR;
72
NPError rv = NPERR_NO_ERROR;
74
CPlugin *pPlugin = new CPlugin(instance);
76
return NPERR_OUT_OF_MEMORY_ERROR;
78
instance->pdata = (void *) pPlugin;
80
pPlugin->mimetype = g_strdup(pluginType);
81
pPlugin->mInstance = instance;
82
new_instance(pPlugin, argc, argn, argv);
84
g_debug ("NEW INSTANCE mode=%d NP_FULL=%d NP_EMBED=%d", mode, NP_FULL, NP_EMBED);
88
// here is the place to clean up and destroy the CPlugin object
89
NPError NPP_Destroy(NPP instance, NPSavedData ** save)
92
return NPERR_INVALID_INSTANCE_ERROR;
94
NPError rv = NPERR_NO_ERROR;
96
CPlugin *pPlugin = (CPlugin *) instance->pdata;
97
if (pPlugin != NULL) {
104
// during this call we know when the plugin window is ready or
105
// is about to be destroyed so we can do some gui specific
106
// initialization and shutdown
107
NPError NPP_SetWindow(NPP instance, NPWindow * pNPWindow)
109
if (instance == NULL)
110
return NPERR_INVALID_INSTANCE_ERROR;
112
NPError rv = NPERR_NO_ERROR;
114
if (pNPWindow == NULL)
115
return NPERR_GENERIC_ERROR;
117
CPlugin *pPlugin = (CPlugin *) instance->pdata;
120
return NPERR_GENERIC_ERROR;
122
// window just created
123
if (!pPlugin->isInitialized() && (pNPWindow->window != NULL)) {
124
if (!pPlugin->init(pNPWindow)) {
127
return NPERR_MODULE_LOAD_FAILED_ERROR;
131
if ((pNPWindow->window == NULL) && pPlugin->isInitialized())
132
return NPERR_NO_ERROR;
135
if (pPlugin->isInitialized() && (pNPWindow->window != NULL)) {
136
pPlugin->SetWindow(pNPWindow);
137
return NPERR_NO_ERROR;
139
// this should not happen, nothing to do
140
if ((pNPWindow->window == NULL) && !pPlugin->isInitialized())
141
return NPERR_NO_ERROR;
146
// ==============================
147
// ! Scriptability related code !
148
// ==============================
150
// here the plugin is asked by Mozilla to tell if it is scriptable
151
// we should return a valid interface id and a pointer to
152
// nsScriptablePeer interface which we should have implemented
153
// and which should be defined in the corressponding *.xpt file
154
// in the bin/components folder
155
NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value)
157
NPError rv = NPERR_NO_ERROR;
159
if (variable == NPPVpluginScriptableNPObject) {
160
if (instance == NULL)
161
return NPERR_INVALID_INSTANCE_ERROR;
162
CPlugin *plugin = (CPlugin *) instance->pdata;
164
return NPERR_GENERIC_ERROR;
165
//*(NPObject **) value = plugin->GetScriptableObject();
167
rv = PluginGetValue(variable, value);
173
NPError NPP_NewStream(NPP instance,
174
NPMIMEType type, NPStream * stream, NPBool seekable, uint16_t * stype)
176
if (instance == NULL)
177
return NPERR_INVALID_INSTANCE_ERROR;
179
NPError rv = NPERR_NO_ERROR;
181
CPlugin *pPlugin = (CPlugin *) instance->pdata;
184
return NPERR_GENERIC_ERROR;
186
pPlugin->NewStream(type, stream, seekable, stype);
191
int32_t NPP_WriteReady(NPP instance, NPStream * stream)
193
if (instance == NULL)
194
return NPERR_INVALID_INSTANCE_ERROR;
196
int32_t rv = 0x0fffffff;
197
CPlugin *pPlugin = (CPlugin *) instance->pdata;
200
return NPERR_GENERIC_ERROR;
202
rv = pPlugin->WriteReady(stream);
203
// printf("rv = %i\n",rv);
208
int32_t NPP_Write(NPP instance, NPStream * stream, int32_t offset, int32_t len, void *buffer)
210
if (instance == NULL)
211
return NPERR_INVALID_INSTANCE_ERROR;
214
CPlugin *pPlugin = (CPlugin *) instance->pdata;
217
return NPERR_GENERIC_ERROR;
219
rv = pPlugin->Write(stream, offset, len, buffer);
220
// printf("rv = %i\n", rv);
224
NPError NPP_DestroyStream(NPP instance, NPStream * stream, NPError reason)
226
if (instance == NULL)
227
return NPERR_INVALID_INSTANCE_ERROR;
229
NPError rv = NPERR_NO_ERROR;
230
CPlugin *pPlugin = (CPlugin *) instance->pdata;
233
return NPERR_GENERIC_ERROR;
235
pPlugin->DestroyStream(stream, reason);
239
void NPP_StreamAsFile(NPP instance, NPStream * stream, const char *fname)
241
if (instance == NULL)
245
void NPP_Print(NPP instance, NPPrint * printInfo)
247
if (instance == NULL)
251
void NPP_URLNotify(NPP instance, const char *url, NPReason reason, void *notifyData)
253
if (instance == NULL)
256
CPlugin *pPlugin = (CPlugin *) instance->pdata;
261
pPlugin->URLNotify(url, reason, notifyData);
265
NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value)
267
if (instance == NULL)
268
return NPERR_INVALID_INSTANCE_ERROR;
270
NPError rv = NPERR_NO_ERROR;
274
int16_t NPP_HandleEvent(NPP instance, void *event)
276
if (instance == NULL)
280
CPlugin *pPlugin = (CPlugin *) instance->pdata;
282
rv = pPlugin->handleEvent(event);
288
jref NPP_GetJavaClass (void)
294
NPObject *NPP_GetScriptableInstance(NPP instance)
300
CPlugin *pPlugin = (CPlugin *) instance->pdata;
302
npobj = pPlugin->GetScriptableObject();