1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
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 MPL, 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 MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 // Implementation of plugin entry points (NPP_*)
40 #include "pluginbase.h"
42 // here the plugin creates a plugin instance object which
43 // will be associated with this newly created NPP instance and
44 // will do all the necessary job
45 NPError
NPP_New(NPMIMEType pluginType
, NPP instance
, uint16_t mode
, int16_t argc
, char* argn
[], char* argv
[], NPSavedData
* saved
)
48 return NPERR_INVALID_INSTANCE_ERROR
;
50 // create a new plugin instance object
51 // initialization will be done when the associated window is ready
52 nsPluginCreateData ds
;
54 ds
.instance
= instance
;
62 nsPluginInstanceBase
* plugin
= NS_NewPluginInstance(&ds
);
64 return NPERR_OUT_OF_MEMORY_ERROR
;
66 // associate the plugin instance object with NPP instance
67 instance
->pdata
= (void *)plugin
;
68 return NPERR_NO_ERROR
;
71 // here is the place to clean up and destroy the nsPluginInstance object
72 NPError
NPP_Destroy (NPP instance
, NPSavedData
** save
)
75 return NPERR_INVALID_INSTANCE_ERROR
;
77 nsPluginInstanceBase
* plugin
= (nsPluginInstanceBase
*)instance
->pdata
;
80 NS_DestroyPluginInstance(plugin
);
82 return NPERR_NO_ERROR
;
85 // during this call we know when the plugin window is ready or
86 // is about to be destroyed so we can do some gui specific
87 // initialization and shutdown
88 NPError
NPP_SetWindow (NPP instance
, NPWindow
* pNPWindow
)
91 return NPERR_INVALID_INSTANCE_ERROR
;
94 return NPERR_GENERIC_ERROR
;
96 nsPluginInstanceBase
* plugin
= (nsPluginInstanceBase
*)instance
->pdata
;
99 return NPERR_GENERIC_ERROR
;
101 // window just created
102 if (!plugin
->isInitialized() && pNPWindow
->window
) {
103 if (!plugin
->init(pNPWindow
)) {
104 NS_DestroyPluginInstance(plugin
);
105 return NPERR_MODULE_LOAD_FAILED_ERROR
;
110 if (!pNPWindow
->window
&& plugin
->isInitialized())
111 return plugin
->SetWindow(pNPWindow
);
114 if (plugin
->isInitialized() && pNPWindow
->window
)
115 return plugin
->SetWindow(pNPWindow
);
117 // this should not happen, nothing to do
118 if (!pNPWindow
->window
&& !plugin
->isInitialized())
119 return plugin
->SetWindow(pNPWindow
);
121 return NPERR_NO_ERROR
;
124 NPError
NPP_NewStream(NPP instance
, NPMIMEType type
, NPStream
* stream
, NPBool seekable
, uint16_t* stype
)
127 return NPERR_INVALID_INSTANCE_ERROR
;
129 nsPluginInstanceBase
* plugin
= (nsPluginInstanceBase
*)instance
->pdata
;
131 return NPERR_GENERIC_ERROR
;
133 return plugin
->NewStream(type
, stream
, seekable
, stype
);
136 int32_t NPP_WriteReady (NPP instance
, NPStream
*stream
)
141 nsPluginInstanceBase
* plugin
= (nsPluginInstanceBase
*)instance
->pdata
;
145 return plugin
->WriteReady(stream
);
148 int32_t NPP_Write (NPP instance
, NPStream
*stream
, int32_t offset
, int32_t len
, void *buffer
)
153 nsPluginInstanceBase
* plugin
= (nsPluginInstanceBase
*)instance
->pdata
;
157 return plugin
->Write(stream
, offset
, len
, buffer
);
160 NPError
NPP_DestroyStream (NPP instance
, NPStream
*stream
, NPError reason
)
163 return NPERR_INVALID_INSTANCE_ERROR
;
165 nsPluginInstanceBase
* plugin
= (nsPluginInstanceBase
*)instance
->pdata
;
167 return NPERR_GENERIC_ERROR
;
169 return plugin
->DestroyStream(stream
, reason
);
172 void NPP_StreamAsFile (NPP instance
, NPStream
* stream
, const char* fname
)
177 nsPluginInstanceBase
* plugin
= (nsPluginInstanceBase
*)instance
->pdata
;
181 plugin
->StreamAsFile(stream
, fname
);
184 void NPP_Print (NPP instance
, NPPrint
* printInfo
)
189 nsPluginInstanceBase
* plugin
= (nsPluginInstanceBase
*)instance
->pdata
;
193 plugin
->Print(printInfo
);
196 void NPP_URLNotify(NPP instance
, const char* url
, NPReason reason
, void* notifyData
)
201 nsPluginInstanceBase
* plugin
= (nsPluginInstanceBase
*)instance
->pdata
;
205 plugin
->URLNotify(url
, reason
, notifyData
);
208 NPError
NPP_GetValue(NPP instance
, NPPVariable variable
, void *value
)
211 return NPERR_INVALID_INSTANCE_ERROR
;
213 nsPluginInstanceBase
* plugin
= (nsPluginInstanceBase
*)instance
->pdata
;
215 return NPERR_GENERIC_ERROR
;
217 return plugin
->GetValue(variable
, value
);
220 NPError
NPP_SetValue(NPP instance
, NPNVariable variable
, void *value
)
223 return NPERR_INVALID_INSTANCE_ERROR
;
225 nsPluginInstanceBase
* plugin
= (nsPluginInstanceBase
*)instance
->pdata
;
227 return NPERR_GENERIC_ERROR
;
229 return plugin
->SetValue(variable
, value
);
232 int16_t NPP_HandleEvent(NPP instance
, void* event
)
237 nsPluginInstanceBase
* plugin
= (nsPluginInstanceBase
*)instance
->pdata
;
241 return plugin
->HandleEvent(event
);