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 // Main plugin entry point implementation - exports from the plugin library
41 #include "pluginbase.h"
43 NPNetscapeFuncs NPNFuncs
;
45 NPError OSCALL
NP_Shutdown()
48 return NPERR_NO_ERROR
;
51 static NPError
fillPluginFunctionTable(NPPluginFuncs
* aNPPFuncs
)
54 return NPERR_INVALID_FUNCTABLE_ERROR
;
56 // Set up the plugin function table that Netscape will use to call us.
57 aNPPFuncs
->version
= (NP_VERSION_MAJOR
<< 8) | NP_VERSION_MINOR
;
58 aNPPFuncs
->newp
= NPP_New
;
59 aNPPFuncs
->destroy
= NPP_Destroy
;
60 aNPPFuncs
->setwindow
= NPP_SetWindow
;
61 aNPPFuncs
->newstream
= NPP_NewStream
;
62 aNPPFuncs
->destroystream
= NPP_DestroyStream
;
63 aNPPFuncs
->asfile
= NPP_StreamAsFile
;
64 aNPPFuncs
->writeready
= NPP_WriteReady
;
65 aNPPFuncs
->write
= NPP_Write
;
66 aNPPFuncs
->print
= NPP_Print
;
67 aNPPFuncs
->event
= NPP_HandleEvent
;
68 aNPPFuncs
->urlnotify
= NPP_URLNotify
;
69 aNPPFuncs
->getvalue
= NPP_GetValue
;
70 aNPPFuncs
->setvalue
= NPP_SetValue
;
72 return NPERR_NO_ERROR
;
75 static NPError
fillNetscapeFunctionTable(NPNetscapeFuncs
* aNPNFuncs
)
78 return NPERR_INVALID_FUNCTABLE_ERROR
;
80 if (HIBYTE(aNPNFuncs
->version
) > NP_VERSION_MAJOR
)
81 return NPERR_INCOMPATIBLE_VERSION_ERROR
;
83 if (aNPNFuncs
->size
< sizeof(NPNetscapeFuncs
))
84 return NPERR_INVALID_FUNCTABLE_ERROR
;
86 NPNFuncs
.size
= aNPNFuncs
->size
;
87 NPNFuncs
.version
= aNPNFuncs
->version
;
88 NPNFuncs
.geturlnotify
= aNPNFuncs
->geturlnotify
;
89 NPNFuncs
.geturl
= aNPNFuncs
->geturl
;
90 NPNFuncs
.posturlnotify
= aNPNFuncs
->posturlnotify
;
91 NPNFuncs
.posturl
= aNPNFuncs
->posturl
;
92 NPNFuncs
.requestread
= aNPNFuncs
->requestread
;
93 NPNFuncs
.newstream
= aNPNFuncs
->newstream
;
94 NPNFuncs
.write
= aNPNFuncs
->write
;
95 NPNFuncs
.destroystream
= aNPNFuncs
->destroystream
;
96 NPNFuncs
.status
= aNPNFuncs
->status
;
97 NPNFuncs
.uagent
= aNPNFuncs
->uagent
;
98 NPNFuncs
.memalloc
= aNPNFuncs
->memalloc
;
99 NPNFuncs
.memfree
= aNPNFuncs
->memfree
;
100 NPNFuncs
.memflush
= aNPNFuncs
->memflush
;
101 NPNFuncs
.reloadplugins
= aNPNFuncs
->reloadplugins
;
102 NPNFuncs
.getvalue
= aNPNFuncs
->getvalue
;
103 NPNFuncs
.setvalue
= aNPNFuncs
->setvalue
;
104 NPNFuncs
.invalidaterect
= aNPNFuncs
->invalidaterect
;
105 NPNFuncs
.invalidateregion
= aNPNFuncs
->invalidateregion
;
106 NPNFuncs
.forceredraw
= aNPNFuncs
->forceredraw
;
108 return NPERR_NO_ERROR
;
112 // Some exports are different on different platforms
116 NPError OSCALL
NP_Initialize(NPNetscapeFuncs
* aNPNFuncs
)
118 NPError rv
= fillNetscapeFunctionTable(aNPNFuncs
);
119 if (rv
!= NPERR_NO_ERROR
)
122 return NS_PluginInitialize();
125 NPError OSCALL
NP_GetEntryPoints(NPPluginFuncs
* aNPPFuncs
)
127 return fillPluginFunctionTable(aNPPFuncs
);
132 NPError
NP_Initialize(NPNetscapeFuncs
* aNPNFuncs
, NPPluginFuncs
* aNPPFuncs
)
134 NPError rv
= fillNetscapeFunctionTable(aNPNFuncs
);
135 if (rv
!= NPERR_NO_ERROR
)
138 rv
= fillPluginFunctionTable(aNPPFuncs
);
139 if (rv
!= NPERR_NO_ERROR
)
142 return NS_PluginInitialize();
145 char * NP_GetMIMEDescription(void)
147 return NPP_GetMIMEDescription();
150 NPError
NP_GetValue(void *future
, NPPVariable aVariable
, void *aValue
)
152 return NS_PluginGetValue(aVariable
, aValue
);
157 short gResFile
; // Refnum of the plugin's resource file
159 NPError
Private_Initialize(void)
161 NPError rv
= NS_PluginInitialize();
165 void Private_Shutdown(void)
168 __destroy_global_chain();
171 NPError
main(NPNetscapeFuncs
* aNPNFuncs
, NPPluginFuncs
* aNPPFuncs
, NPP_ShutdownUPP
* aUnloadUpp
)
173 NPError rv
= NPERR_NO_ERROR
;
176 rv
= NPERR_INVALID_FUNCTABLE_ERROR
;
178 if (rv
== NPERR_NO_ERROR
)
179 rv
= fillNetscapeFunctionTable(aNPNFuncs
);
181 if (rv
== NPERR_NO_ERROR
) {
182 // defer static constructors until the global functions are initialized.
184 rv
= fillPluginFunctionTable(aNPPFuncs
);
187 *aUnloadUpp
= NewNPP_ShutdownProc(Private_Shutdown
);
188 gResFile
= CurResFile();
189 rv
= Private_Initialize();