Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / modules / plugin / sdk / samples / npruntime / npp_gate.cpp
blob51c52da94e6706e669bf63cd09f131fc0d411cab
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
13 * License.
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.
22 * Contributor(s):
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
43 #include "plugin.h"
45 char*
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,
66 NPP instance,
67 uint16_t mode,
68 int16_t argc,
69 char* argn[],
70 char* argv[],
71 NPSavedData* saved)
73 if(instance == NULL)
74 return NPERR_INVALID_INSTANCE_ERROR;
76 NPError rv = NPERR_NO_ERROR;
78 CPlugin * pPlugin = new CPlugin(instance);
79 if(pPlugin == NULL)
80 return NPERR_OUT_OF_MEMORY_ERROR;
82 instance->pdata = (void *)pPlugin;
83 return rv;
86 // here is the place to clean up and destroy the CPlugin object
87 NPError NPP_Destroy (NPP instance, NPSavedData** save)
89 if(instance == NULL)
90 return NPERR_INVALID_INSTANCE_ERROR;
92 NPError rv = NPERR_NO_ERROR;
94 CPlugin * pPlugin = (CPlugin *)instance->pdata;
95 if(pPlugin != NULL) {
96 pPlugin->shut();
97 delete pPlugin;
99 return rv;
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)
107 if(instance == NULL)
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;
117 if(pPlugin == NULL)
118 return NPERR_GENERIC_ERROR;
120 // window just created
121 if(!pPlugin->isInitialized() && (pNPWindow->window != NULL)) {
122 if(!pPlugin->init(pNPWindow)) {
123 delete pPlugin;
124 pPlugin = NULL;
125 return NPERR_MODULE_LOAD_FAILED_ERROR;
129 // window goes away
130 if((pNPWindow->window == NULL) && pPlugin->isInitialized())
131 return NPERR_NO_ERROR;
133 // window resized
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;
141 return rv;
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)
155 if(instance == NULL)
156 return NPERR_INVALID_INSTANCE_ERROR;
158 NPError rv = NPERR_NO_ERROR;
160 if(instance == NULL)
161 return NPERR_GENERIC_ERROR;
163 CPlugin * plugin = (CPlugin *)instance->pdata;
164 if(plugin == NULL)
165 return NPERR_GENERIC_ERROR;
167 switch (variable) {
168 case NPPVpluginNameString:
169 *((char **)value) = "NPRuntimeTest";
170 break;
171 case NPPVpluginDescriptionString:
172 *((char **)value) = "NPRuntime scriptability API test plugin";
173 break;
174 case NPPVpluginScriptableNPObject:
175 *(NPObject **)value = plugin->GetScriptableObject();
176 break;
177 default:
178 rv = NPERR_GENERIC_ERROR;
181 return rv;
184 NPError NPP_NewStream(NPP instance,
185 NPMIMEType type,
186 NPStream* stream,
187 NPBool seekable,
188 uint16_t* stype)
190 if(instance == NULL)
191 return NPERR_INVALID_INSTANCE_ERROR;
193 NPError rv = NPERR_NO_ERROR;
194 return rv;
197 int32_t NPP_WriteReady (NPP instance, NPStream *stream)
199 if(instance == NULL)
200 return NPERR_INVALID_INSTANCE_ERROR;
202 int32_t rv = 0x0fffffff;
203 return rv;
206 int32_t NPP_Write (NPP instance, NPStream *stream, int32_t offset, int32_t len, void *buffer)
208 if(instance == NULL)
209 return NPERR_INVALID_INSTANCE_ERROR;
211 int32_t rv = len;
212 return rv;
215 NPError NPP_DestroyStream (NPP instance, NPStream *stream, NPError reason)
217 if(instance == NULL)
218 return NPERR_INVALID_INSTANCE_ERROR;
220 NPError rv = NPERR_NO_ERROR;
221 return rv;
224 void NPP_StreamAsFile (NPP instance, NPStream* stream, const char* fname)
226 if(instance == NULL)
227 return;
230 void NPP_Print (NPP instance, NPPrint* printInfo)
232 if(instance == NULL)
233 return;
236 void NPP_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData)
238 if(instance == NULL)
239 return;
242 NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value)
244 if(instance == NULL)
245 return NPERR_INVALID_INSTANCE_ERROR;
247 NPError rv = NPERR_NO_ERROR;
248 return rv;
251 int16_t NPP_HandleEvent(NPP instance, void* event)
253 if(instance == NULL)
254 return 0;
256 int16_t rv = 0;
257 CPlugin * pPlugin = (CPlugin *)instance->pdata;
258 if (pPlugin)
259 rv = pPlugin->handleEvent(event);
261 return rv;
264 NPObject *NPP_GetScriptableInstance(NPP instance)
266 if(!instance)
267 return 0;
269 NPObject *npobj = 0;
270 CPlugin * pPlugin = (CPlugin *)instance->pdata;
271 if (!pPlugin)
272 npobj = pPlugin->GetScriptableObject();
274 return npobj;