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
46 NPP_GetMIMEDescription(void)
48 return "application/mozilla-npruntime-scriptable-plugin:.foo:Scriptability Demo Plugin";
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
,
74 return NPERR_INVALID_INSTANCE_ERROR
;
76 NPError rv
= NPERR_NO_ERROR
;
78 CPlugin
* pPlugin
= new CPlugin(instance
);
80 return NPERR_OUT_OF_MEMORY_ERROR
;
82 instance
->pdata
= (void *)pPlugin
;
86 // here is the place to clean up and destroy the CPlugin object
87 NPError
NPP_Destroy (NPP instance
, NPSavedData
** save
)
90 return NPERR_INVALID_INSTANCE_ERROR
;
92 NPError rv
= NPERR_NO_ERROR
;
94 CPlugin
* pPlugin
= (CPlugin
*)instance
->pdata
;
102 // during this call we know when the plugin window is ready or
103 // is about to be destroyed so we can do some gui specific
104 // initialization and shutdown
105 NPError
NPP_SetWindow (NPP instance
, NPWindow
* pNPWindow
)
108 return NPERR_INVALID_INSTANCE_ERROR
;
110 NPError rv
= NPERR_NO_ERROR
;
112 if(pNPWindow
== NULL
)
113 return NPERR_GENERIC_ERROR
;
115 CPlugin
* pPlugin
= (CPlugin
*)instance
->pdata
;
118 return NPERR_GENERIC_ERROR
;
120 // window just created
121 if(!pPlugin
->isInitialized() && (pNPWindow
->window
!= NULL
)) {
122 if(!pPlugin
->init(pNPWindow
)) {
125 return NPERR_MODULE_LOAD_FAILED_ERROR
;
130 if((pNPWindow
->window
== NULL
) && pPlugin
->isInitialized())
131 return NPERR_NO_ERROR
;
134 if(pPlugin
->isInitialized() && (pNPWindow
->window
!= NULL
))
135 return NPERR_NO_ERROR
;
137 // this should not happen, nothing to do
138 if((pNPWindow
->window
== NULL
) && !pPlugin
->isInitialized())
139 return NPERR_NO_ERROR
;
144 // ==============================
145 // ! Scriptability related code !
146 // ==============================
148 // here the plugin is asked by Mozilla to tell if it is scriptable
149 // we should return a valid interface id and a pointer to
150 // nsScriptablePeer interface which we should have implemented
151 // and which should be defined in the corressponding *.xpt file
152 // in the bin/components folder
153 NPError
NPP_GetValue(NPP instance
, NPPVariable variable
, void *value
)
156 return NPERR_INVALID_INSTANCE_ERROR
;
158 NPError rv
= NPERR_NO_ERROR
;
161 return NPERR_GENERIC_ERROR
;
163 CPlugin
* plugin
= (CPlugin
*)instance
->pdata
;
165 return NPERR_GENERIC_ERROR
;
168 case NPPVpluginNameString
:
169 *((char **)value
) = "NPRuntimeTest";
171 case NPPVpluginDescriptionString
:
172 *((char **)value
) = "NPRuntime scriptability API test plugin";
174 case NPPVpluginScriptableNPObject
:
175 *(NPObject
**)value
= plugin
->GetScriptableObject();
178 rv
= NPERR_GENERIC_ERROR
;
184 NPError
NPP_NewStream(NPP instance
,
191 return NPERR_INVALID_INSTANCE_ERROR
;
193 NPError rv
= NPERR_NO_ERROR
;
197 int32_t NPP_WriteReady (NPP instance
, NPStream
*stream
)
200 return NPERR_INVALID_INSTANCE_ERROR
;
202 int32_t rv
= 0x0fffffff;
206 int32_t NPP_Write (NPP instance
, NPStream
*stream
, int32_t offset
, int32_t len
, void *buffer
)
209 return NPERR_INVALID_INSTANCE_ERROR
;
215 NPError
NPP_DestroyStream (NPP instance
, NPStream
*stream
, NPError reason
)
218 return NPERR_INVALID_INSTANCE_ERROR
;
220 NPError rv
= NPERR_NO_ERROR
;
224 void NPP_StreamAsFile (NPP instance
, NPStream
* stream
, const char* fname
)
230 void NPP_Print (NPP instance
, NPPrint
* printInfo
)
236 void NPP_URLNotify(NPP instance
, const char* url
, NPReason reason
, void* notifyData
)
242 NPError
NPP_SetValue(NPP instance
, NPNVariable variable
, void *value
)
245 return NPERR_INVALID_INSTANCE_ERROR
;
247 NPError rv
= NPERR_NO_ERROR
;
251 int16_t NPP_HandleEvent(NPP instance
, void* event
)
257 CPlugin
* pPlugin
= (CPlugin
*)instance
->pdata
;
259 rv
= pPlugin
->handleEvent(event
);
264 NPObject
*NPP_GetScriptableInstance(NPP instance
)
270 CPlugin
* pPlugin
= (CPlugin
*)instance
->pdata
;
272 npobj
= pPlugin
->GetScriptableObject();