| OLD | NEW |
| (Empty) |
| 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | |
| 2 /* ***** BEGIN LICENSE BLOCK ***** | |
| 3 * Version: NPL 1.1/GPL 2.0/LGPL 2.1 | |
| 4 * | |
| 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/ | |
| 9 * | |
| 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. | |
| 14 * | |
| 15 * The Original Code is mozilla.org code. | |
| 16 * | |
| 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. | |
| 21 * | |
| 22 * Contributor(s): | |
| 23 * | |
| 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. | |
| 35 * | |
| 36 * ***** END LICENSE BLOCK ***** */ | |
| 37 | |
| 38 ////////////////////////////////////////////////////////////// | |
| 39 // | |
| 40 // Main plugin entry point implementation -- exports from the | |
| 41 // plugin library | |
| 42 // | |
| 43 | |
| 44 #include <algorithm> | |
| 45 #include "omaha/plugins/base/npplat.h" | |
| 46 #include "omaha/plugins/base/pluginbase.h" | |
| 47 | |
| 48 #ifdef _WINDOWS | |
| 49 #define OSCALL WINAPI | |
| 50 #else | |
| 51 #define OSCALL | |
| 52 #endif | |
| 53 | |
| 54 NPNetscapeFuncs NPNFuncs = {sizeof(NPNFuncs)}; | |
| 55 | |
| 56 NPError OSCALL NP_Shutdown() | |
| 57 { | |
| 58 NS_PluginShutdown(); | |
| 59 return NPERR_NO_ERROR; | |
| 60 } | |
| 61 | |
| 62 static NPError fillPluginFunctionTable(NPPluginFuncs* aNPPFuncs) | |
| 63 { | |
| 64 if (aNPPFuncs == NULL || aNPPFuncs->size < sizeof(NPPluginFuncs)) { | |
| 65 return NPERR_INVALID_FUNCTABLE_ERROR; | |
| 66 } | |
| 67 | |
| 68 // Set up the plugin function table that Netscape will use to | |
| 69 // call us. Netscape needs to know about our version and size | |
| 70 // and have a UniversalProcPointer for every function we implement. | |
| 71 | |
| 72 aNPPFuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR; | |
| 73 #ifdef XP_MAC | |
| 74 aNPPFuncs->newp = NewNPP_NewProc(Private_New); | |
| 75 aNPPFuncs->destroy = NewNPP_DestroyProc(Private_Destroy); | |
| 76 aNPPFuncs->setwindow = NewNPP_SetWindowProc(Private_SetWindow); | |
| 77 aNPPFuncs->newstream = NewNPP_NewStreamProc(Private_NewStream); | |
| 78 aNPPFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream); | |
| 79 aNPPFuncs->asfile = NewNPP_StreamAsFileProc(Private_StreamAsFile); | |
| 80 aNPPFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady); | |
| 81 aNPPFuncs->write = NewNPP_WriteProc(Private_Write); | |
| 82 aNPPFuncs->print = NewNPP_PrintProc(Private_Print); | |
| 83 aNPPFuncs->event = NewNPP_HandleEventProc(Private_HandleEvent); | |
| 84 aNPPFuncs->urlnotify = NewNPP_URLNotifyProc(Private_URLNotify); | |
| 85 aNPPFuncs->getvalue = NewNPP_GetValueProc(Private_GetValue); | |
| 86 aNPPFuncs->setvalue = NewNPP_SetValueProc(Private_SetValue); | |
| 87 #else | |
| 88 aNPPFuncs->newp = NPP_New; | |
| 89 aNPPFuncs->destroy = NPP_Destroy; | |
| 90 aNPPFuncs->setwindow = NPP_SetWindow; | |
| 91 aNPPFuncs->newstream = NPP_NewStream; | |
| 92 aNPPFuncs->destroystream = NPP_DestroyStream; | |
| 93 aNPPFuncs->asfile = NPP_StreamAsFile; | |
| 94 aNPPFuncs->writeready = NPP_WriteReady; | |
| 95 aNPPFuncs->write = NPP_Write; | |
| 96 aNPPFuncs->print = NPP_Print; | |
| 97 aNPPFuncs->event = NPP_HandleEvent; | |
| 98 aNPPFuncs->urlnotify = NPP_URLNotify; | |
| 99 aNPPFuncs->getvalue = NPP_GetValue; | |
| 100 aNPPFuncs->setvalue = NPP_SetValue; | |
| 101 #endif | |
| 102 #ifdef OJI | |
| 103 aNPPFuncs->javaClass = NULL; | |
| 104 #endif | |
| 105 | |
| 106 return NPERR_NO_ERROR; | |
| 107 } | |
| 108 | |
| 109 static NPError fillNetscapeFunctionTable(NPNetscapeFuncs* aNPNFuncs) | |
| 110 { | |
| 111 if (aNPNFuncs == NULL) { | |
| 112 return NPERR_INVALID_FUNCTABLE_ERROR; | |
| 113 } | |
| 114 | |
| 115 if (HIBYTE(aNPNFuncs->version) > NP_VERSION_MAJOR) { | |
| 116 return NPERR_INCOMPATIBLE_VERSION_ERROR; | |
| 117 } | |
| 118 | |
| 119 memcpy(&NPNFuncs, aNPNFuncs, std::min(static_cast<size_t>(aNPNFuncs->size), | |
| 120 sizeof(NPNFuncs))); | |
| 121 | |
| 122 if (!NPNFuncs.memalloc || | |
| 123 !NPNFuncs.memfree || | |
| 124 !NPNFuncs.createobject || | |
| 125 !NPNFuncs.retainobject || | |
| 126 !NPNFuncs.releaseobject || | |
| 127 !NPNFuncs.utf8fromidentifier || | |
| 128 !NPNFuncs.releasevariantvalue || | |
| 129 !NPNFuncs.getstringidentifier || | |
| 130 !NPNFuncs.getvalue || | |
| 131 !NPNFuncs.setexception || | |
| 132 !NPNFuncs.getproperty || | |
| 133 // Used only by oneclick plugin. | |
| 134 !NPNFuncs.invokeDefault) { | |
| 135 return NPERR_INVALID_FUNCTABLE_ERROR; | |
| 136 } | |
| 137 | |
| 138 return NPERR_NO_ERROR; | |
| 139 } | |
| 140 | |
| 141 // | |
| 142 // Some exports are different on different platforms | |
| 143 // | |
| 144 | |
| 145 /**************************************************/ | |
| 146 /* */ | |
| 147 /* Windows */ | |
| 148 /* */ | |
| 149 /**************************************************/ | |
| 150 #ifdef XP_WIN | |
| 151 | |
| 152 NPError OSCALL NP_Initialize(NPNetscapeFuncs* aNPNFuncs) | |
| 153 { | |
| 154 NPError rv = fillNetscapeFunctionTable(aNPNFuncs); | |
| 155 if(rv != NPERR_NO_ERROR) | |
| 156 return rv; | |
| 157 | |
| 158 return NS_PluginInitialize(); | |
| 159 } | |
| 160 | |
| 161 NPError OSCALL NP_GetEntryPoints(NPPluginFuncs* aNPPFuncs) | |
| 162 { | |
| 163 return fillPluginFunctionTable(aNPPFuncs); | |
| 164 } | |
| 165 | |
| 166 #endif //XP_WIN | |
| 167 | |
| 168 /**************************************************/ | |
| 169 /* */ | |
| 170 /* Unix */ | |
| 171 /* */ | |
| 172 /**************************************************/ | |
| 173 #ifdef XP_UNIX | |
| 174 | |
| 175 NPError NP_Initialize(NPNetscapeFuncs* aNPNFuncs, NPPluginFuncs* aNPPFuncs) | |
| 176 { | |
| 177 NPError rv = fillNetscapeFunctionTable(aNPNFuncs); | |
| 178 if(rv != NPERR_NO_ERROR) | |
| 179 return rv; | |
| 180 | |
| 181 rv = fillPluginFunctionTable(aNPPFuncs); | |
| 182 if(rv != NPERR_NO_ERROR) | |
| 183 return rv; | |
| 184 | |
| 185 return NS_PluginInitialize(); | |
| 186 } | |
| 187 | |
| 188 char * NP_GetMIMEDescription(void) | |
| 189 { | |
| 190 return NPP_GetMIMEDescription(); | |
| 191 } | |
| 192 | |
| 193 NPError NP_GetValue(void *future, NPPVariable aVariable, void *aValue) | |
| 194 { | |
| 195 return NS_PluginGetValue(aVariable, aValue); | |
| 196 } | |
| 197 | |
| 198 #endif //XP_UNIX | |
| 199 | |
| 200 /**************************************************/ | |
| 201 /* */ | |
| 202 /* Mac */ | |
| 203 /* */ | |
| 204 /**************************************************/ | |
| 205 #ifdef XP_MAC | |
| 206 | |
| 207 #if !TARGET_API_MAC_CARBON | |
| 208 QDGlobals* gQDPtr; // Pointer to Netscape's QuickDraw globals | |
| 209 #endif | |
| 210 | |
| 211 short gResFile; // Refnum of the plugin's resource file | |
| 212 | |
| 213 NPError Private_Initialize(void) | |
| 214 { | |
| 215 NPError rv = NS_PluginInitialize(); | |
| 216 return rv; | |
| 217 } | |
| 218 | |
| 219 void Private_Shutdown(void) | |
| 220 { | |
| 221 NS_PluginShutdown(); | |
| 222 __destroy_global_chain(); | |
| 223 } | |
| 224 | |
| 225 void SetUpQD(void); | |
| 226 | |
| 227 void SetUpQD(void) | |
| 228 { | |
| 229 ProcessSerialNumber PSN; | |
| 230 FSSpec myFSSpec; | |
| 231 Str63 name; | |
| 232 ProcessInfoRec infoRec; | |
| 233 OSErr result = noErr; | |
| 234 CFragConnectionID connID; | |
| 235 Str255 errName; | |
| 236 | |
| 237 // Memorize the plugin¹s resource file refnum for later use. | |
| 238 gResFile = CurResFile(); | |
| 239 | |
| 240 #if !TARGET_API_MAC_CARBON | |
| 241 // Ask the system if CFM is available. | |
| 242 long response; | |
| 243 OSErr err = Gestalt(gestaltCFMAttr, &response); | |
| 244 Boolean hasCFM = BitTst(&response, 31-gestaltCFMPresent); | |
| 245 | |
| 246 if (hasCFM) { | |
| 247 // GetProcessInformation takes a process serial number and | |
| 248 // will give us back the name and FSSpec of the application. | |
| 249 // See the Process Manager in IM. | |
| 250 infoRec.processInfoLength = sizeof(ProcessInfoRec); | |
| 251 infoRec.processName = name; | |
| 252 infoRec.processAppSpec = &myFSSpec; | |
| 253 | |
| 254 PSN.highLongOfPSN = 0; | |
| 255 PSN.lowLongOfPSN = kCurrentProcess; | |
| 256 | |
| 257 result = GetProcessInformation(&PSN, &infoRec); | |
| 258 } | |
| 259 else | |
| 260 // If no CFM installed, assume it must be a 68K app. | |
| 261 result = -1; | |
| 262 | |
| 263 if (result == noErr) { | |
| 264 // Now that we know the app name and FSSpec, we can call GetDiskFragment | |
| 265 // to get a connID to use in a subsequent call to FindSymbol (it will also | |
| 266 // return the address of ³main² in app, which we ignore). If GetDiskFragmen
t | |
| 267 // returns an error, we assume the app must be 68K. | |
| 268 Ptr mainAddr; | |
| 269 result = GetDiskFragment(infoRec.processAppSpec, 0L, 0L, infoRec.processNam
e, | |
| 270 kReferenceCFrag, &connID, (Ptr*)&mainAddr, errName
); | |
| 271 } | |
| 272 | |
| 273 if (result == noErr) { | |
| 274 // The app is a PPC code fragment, so call FindSymbol | |
| 275 // to get the exported ³qd² symbol so we can access its | |
| 276 // QuickDraw globals. | |
| 277 CFragSymbolClass symClass; | |
| 278 result = FindSymbol(connID, "\pqd", (Ptr*)&gQDPtr, &symClass); | |
| 279 } | |
| 280 else { | |
| 281 // The app is 68K, so use its A5 to compute the address | |
| 282 // of its QuickDraw globals. | |
| 283 gQDPtr = (QDGlobals*)(*((long*)SetCurrentA5()) - (sizeof(QDGlobals) - sizeof
(GrafPtr))); | |
| 284 } | |
| 285 #endif /* !TARGET_API_MAC_CARBON */ | |
| 286 } | |
| 287 | |
| 288 NPError main(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs, NPP_ShutdownU
PP* unloadUpp); | |
| 289 | |
| 290 #if !TARGET_API_MAC_CARBON | |
| 291 #pragma export on | |
| 292 #if GENERATINGCFM | |
| 293 RoutineDescriptor mainRD = BUILD_ROUTINE_DESCRIPTOR(uppNPP_MainEntryProcInfo, ma
in); | |
| 294 #endif | |
| 295 #pragma export off | |
| 296 #endif /* !TARGET_API_MAC_CARBON */ | |
| 297 | |
| 298 | |
| 299 NPError main(NPNetscapeFuncs* aNPNFuncs, NPPluginFuncs* aNPPFuncs, NPP_ShutdownU
PP* aUnloadUpp) | |
| 300 { | |
| 301 NPError rv = NPERR_NO_ERROR; | |
| 302 | |
| 303 if (aUnloadUpp == NULL) | |
| 304 rv = NPERR_INVALID_FUNCTABLE_ERROR; | |
| 305 | |
| 306 if (rv == NPERR_NO_ERROR) | |
| 307 rv = fillNetscapeFunctionTable(aNPNFuncs); | |
| 308 | |
| 309 if (rv == NPERR_NO_ERROR) { | |
| 310 // defer static constructors until the global functions are initialized. | |
| 311 __InitCode__(); | |
| 312 rv = fillPluginFunctionTable(aNPPFuncs); | |
| 313 } | |
| 314 | |
| 315 *aUnloadUpp = NewNPP_ShutdownProc(Private_Shutdown); | |
| 316 SetUpQD(); | |
| 317 rv = Private_Initialize(); | |
| 318 | |
| 319 return rv; | |
| 320 } | |
| 321 #endif //XP_MAC | |
| OLD | NEW |