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 ***** */
42 #include "epmanager.h"
45 // we need to keep track of different plugins and different instances
46 // of the same plugin when we call NPP functions, so that we always
47 // call the right ones. Entry point manager will take care of it.
48 NPPEntryPointManager * epManager = NULL;
50 Logger * logger = NULL;
52 NPNetscapeFuncs NPNFuncs;
54 NPError WINAPI NP_GetEntryPoints(NPPluginFuncs* pFuncs)
62 logger->platformInit();
68 logger->logNS_NP_GetEntryPoints();
71 return NPERR_INVALID_FUNCTABLE_ERROR;
73 if(pFuncs->size < sizeof(NPPluginFuncs))
74 return NPERR_INVALID_FUNCTABLE_ERROR;
76 pFuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
77 pFuncs->newp = NPP_New;
78 pFuncs->destroy = NPP_Destroy;
79 pFuncs->setwindow = NPP_SetWindow;
80 pFuncs->newstream = NPP_NewStream;
81 pFuncs->destroystream = NPP_DestroyStream;
82 pFuncs->asfile = NPP_StreamAsFile;
83 pFuncs->writeready = NPP_WriteReady;
84 pFuncs->write = NPP_Write;
85 pFuncs->print = NPP_Print;
86 pFuncs->event = NPP_HandleEvent;
87 pFuncs->urlnotify = NPP_URLNotify;
88 pFuncs->getvalue = NPP_GetValue;
89 pFuncs->setvalue = NPP_SetValue;
90 pFuncs->javaClass = NULL;
92 return NPERR_NO_ERROR;
95 NPError WINAPI NP_Initialize(NPNetscapeFuncs* pFuncs)
102 logger = NewLogger();
105 logger->platformInit();
111 logger->logNS_NP_Initialize();
114 logger->logMessage("NP_Initialize: NULL functable!\r\n");
115 return NPERR_INVALID_FUNCTABLE_ERROR;
118 if(HIBYTE(pFuncs->version) > NP_VERSION_MAJOR) {
119 logger->logMessage("NP_Initialize: incompatible version!\r\n");
120 return NPERR_INCOMPATIBLE_VERSION_ERROR;
125 * Removing this check so that we can work with older versions
126 * of servers (which may provide fewer functions)
128 if(pFuncs->size < sizeof NPNetscapeFuncs) {
129 logger->logReturn(NPERR_INVALID_FUNCTABLE_ERROR);
131 sprintf(msg, "functable is %d, expected %d", pFuncs->size, sizeof(NPNetscapeFuncs));
132 logger->logMessage(msg);
133 return NPERR_INVALID_FUNCTABLE_ERROR;
138 NPNFuncs.size = pFuncs->size;
139 NPNFuncs.version = pFuncs->version;
140 NPNFuncs.geturlnotify = pFuncs->geturlnotify;
141 NPNFuncs.geturl = pFuncs->geturl;
142 NPNFuncs.posturlnotify = pFuncs->posturlnotify;
143 NPNFuncs.posturl = pFuncs->posturl;
144 NPNFuncs.requestread = pFuncs->requestread;
145 NPNFuncs.newstream = pFuncs->newstream;
146 NPNFuncs.write = pFuncs->write;
147 NPNFuncs.destroystream = pFuncs->destroystream;
148 NPNFuncs.status = pFuncs->status;
149 NPNFuncs.uagent = pFuncs->uagent;
150 NPNFuncs.memalloc = pFuncs->memalloc;
151 NPNFuncs.memfree = pFuncs->memfree;
152 NPNFuncs.memflush = pFuncs->memflush;
153 NPNFuncs.reloadplugins = pFuncs->reloadplugins;
154 NPNFuncs.getJavaEnv = pFuncs->getJavaEnv;
155 NPNFuncs.getJavaPeer = pFuncs->getJavaPeer;
156 NPNFuncs.getvalue = pFuncs->getvalue;
157 NPNFuncs.setvalue = pFuncs->setvalue;
158 NPNFuncs.invalidaterect = pFuncs->invalidaterect;
159 NPNFuncs.invalidateregion = pFuncs->invalidateregion;
160 NPNFuncs.forceredraw = pFuncs->forceredraw;
161 NPNFuncs.getstringidentifier = pFuncs->getstringidentifier;
162 NPNFuncs.getstringidentifiers = pFuncs->getstringidentifiers;
163 NPNFuncs.identifierisstring = pFuncs->identifierisstring;
164 NPNFuncs.utf8fromidentifier = pFuncs->utf8fromidentifier;
165 NPNFuncs.intfromidentifier = pFuncs->intfromidentifier;
166 NPNFuncs.createobject = pFuncs->createobject;
167 NPNFuncs.retainobject = pFuncs->retainobject;
168 NPNFuncs.releaseobject = pFuncs->releaseobject;
169 NPNFuncs.invoke = pFuncs->invoke;
170 NPNFuncs.invokeDefault = pFuncs->invokeDefault;
171 NPNFuncs.evaluate = pFuncs->evaluate;
172 NPNFuncs.getproperty = pFuncs->getproperty;
173 NPNFuncs.setproperty = pFuncs->setproperty;
174 NPNFuncs.removeproperty = pFuncs->removeproperty;
175 NPNFuncs.hasproperty = pFuncs->hasproperty;
176 NPNFuncs.hasmethod = pFuncs->hasmethod;
177 NPNFuncs.releasevariantvalue = pFuncs->releasevariantvalue;
178 NPNFuncs.setexception = pFuncs->setexception;
179 NPNFuncs.pushpopupsenabledstate = pFuncs->pushpopupsenabledstate;
180 NPNFuncs.poppopupsenabledstate = pFuncs->poppopupsenabledstate;
181 NPNFuncs.enumerate = pFuncs->enumerate;
183 // create entry point manager for real plugins
184 epManager = new NPPEntryPointManager();
186 logger->logMessage("NP_Initialize: could not create EntryPointManager\r\n");
187 return NPERR_GENERIC_ERROR;
190 logger->logMessage("NP_Initialize: success\r\n");
191 return NPERR_NO_ERROR;
194 NPError WINAPI NP_Shutdown()
196 // should be safe because if they've already been called shutdown procs must be NULL
198 epManager->callNP_ShutdownAll(); // this will log the action
203 logger->platformShut();
204 DeleteLogger(logger);
210 return NPERR_NO_ERROR;