Patch to fix crash with sample plugin and OS X plugins bug 85334 r=av sr=attinasi

This commit is contained in:
peterlubczynski%netscape.com 2001-07-03 01:56:28 +00:00
Родитель 430832298b
Коммит 52512c32b6
2 изменённых файлов: 108 добавлений и 54 удалений

Просмотреть файл

@ -120,10 +120,7 @@ ns4xPlugin::ns4xPlugin(NPPluginFuncs* callbacks, PRLibrary* aLibrary, NP_PLUGINS
(NP_GETENTRYPOINTS)PR_FindSymbol(aLibrary, "NP_GetEntryPoints");
if (!pfnGetEntryPoints)
{
NS_ASSERTION(pfnGetEntryPoints, "failed to get entry points");
return;
}
fCallbacks.size = sizeof(fCallbacks);
@ -134,32 +131,24 @@ ns4xPlugin::ns4xPlugin(NPPluginFuncs* callbacks, PRLibrary* aLibrary, NP_PLUGINS
"callback version is less than NP version");
fShutdownEntry = (NP_PLUGINSHUTDOWN)PR_FindSymbol(aLibrary, "NP_Shutdown");
#elif defined(XP_MAC)
#elif defined(XP_MAC) && !defined(TARGET_CARBON)
// get the main entry point
#if TARGET_CARBON
NP_MAIN pfnMain = (NP_MAIN) PR_FindSymbol(aLibrary, "main");
#else
NP_MAIN pfnMain = (NP_MAIN) PR_FindSymbol(aLibrary, "mainRD");
if(pfnMain == NULL)
{
NS_ASSERTION(pfnMain, "failed to get entry points");
return;
}
// call into the entry point
NPError error;
NS_TRY_SAFE_CALL_RETURN(error, CallNPP_MainEntryProc(pfnMain,
&(ns4xPlugin::CALLBACKS),
&fCallbacks,
(NP_PLUGINSHUTDOWN)&fShutdownEntry), aLibrary);
&fShutdownEntry), aLibrary);
if(error != NPERR_NO_ERROR || ((fCallbacks.version >> 8) < NP_VERSION_MAJOR))
{
return;
}
#endif // !TARGET_CARBON
#else // for everyone else
memcpy((void*) &fCallbacks, (void*) callbacks, sizeof(fCallbacks));
fShutdownEntry = aShutdown;
@ -344,7 +333,11 @@ ns4xPlugin::CreatePlugin(nsIServiceManager* aServiceMgr,
// we must init here because the plugin may call NPN functions
// when we call into the NP_Initialize entry point - NPN functions
// require that mBrowserManager be set up
(*aResult)->Initialize();
if (NS_FAILED((*aResult)->Initialize()))
{
NS_RELEASE(*aResult);
return NS_ERROR_FAILURE;
}
// the NP_Initialize entry point was misnamed as NP_PluginInit,
// early in plugin project development. Its correct name is
@ -414,19 +407,51 @@ ns4xPlugin::CreatePlugin(nsIServiceManager* aServiceMgr,
}
}
#if TARGET_CARBON
// call into the entry point
NP_MAIN pfnMain = (NP_MAIN) PR_FindSymbol(aLibrary, "main");
ns4xPlugin* plugin = new ns4xPlugin(nsnull, aLibrary, nsnull, aServiceMgr);
if(plugin == NULL)
return NS_ERROR_OUT_OF_MEMORY;
if(pfnMain == NULL)
return NS_ERROR_FAILURE;
NPP_ShutdownUPP pfnShutdown;
NPPluginFuncs callbacks;
memset((void*) &callbacks, 0, sizeof(callbacks));
callbacks.size = sizeof(callbacks);
NPError error;
NS_TRY_SAFE_CALL_RETURN(error, CallNPP_MainEntryProc(pfnMain,
&(ns4xPlugin::CALLBACKS),
&callbacks,
&pfnShutdown), fLibrary);
if(error != NPERR_NO_ERROR)
return NS_ERROR_FAILURE;
::UseResFile(appRefNum);
plugin->SetPluginRefNum(pluginRefNum);
if ((callbacks.version >> 8) < NP_VERSION_MAJOR)
return NS_ERROR_FAILURE;
// create the new plugin handler
ns4xPlugin* plugin = new ns4xPlugin(&callbacks, aLibrary, (NP_PLUGINSHUTDOWN)pfnShutdown, aServiceMgr);
#else // not carbon
::UseResFile(appRefNum);
ns4xPlugin* plugin = new ns4xPlugin(nsnull, aLibrary, nsnull, aServiceMgr);
#endif
if(plugin == NULL)
return NS_ERROR_OUT_OF_MEMORY;
*aResult = plugin;
NS_ADDREF(*aResult);
#endif
if (NS_FAILED((*aResult)->Initialize()))
{
NS_RELEASE(*aResult);
return NS_ERROR_FAILURE;
}
plugin->SetPluginRefNum(pluginRefNum);
#endif // XP_MAC
#ifdef XP_BEOS
// I just copied UNIX version.
@ -520,6 +545,8 @@ NS_METHOD ns4xPlugin :: CreatePluginInstance(nsISupports *aOuter, REFNSIID aIID,
nsresult
ns4xPlugin::Initialize(void)
{
if (nsnull == fLibrary)
return NS_ERROR_FAILURE;
return NS_OK;
}

Просмотреть файл

@ -120,10 +120,7 @@ ns4xPlugin::ns4xPlugin(NPPluginFuncs* callbacks, PRLibrary* aLibrary, NP_PLUGINS
(NP_GETENTRYPOINTS)PR_FindSymbol(aLibrary, "NP_GetEntryPoints");
if (!pfnGetEntryPoints)
{
NS_ASSERTION(pfnGetEntryPoints, "failed to get entry points");
return;
}
fCallbacks.size = sizeof(fCallbacks);
@ -134,32 +131,24 @@ ns4xPlugin::ns4xPlugin(NPPluginFuncs* callbacks, PRLibrary* aLibrary, NP_PLUGINS
"callback version is less than NP version");
fShutdownEntry = (NP_PLUGINSHUTDOWN)PR_FindSymbol(aLibrary, "NP_Shutdown");
#elif defined(XP_MAC)
#elif defined(XP_MAC) && !defined(TARGET_CARBON)
// get the main entry point
#if TARGET_CARBON
NP_MAIN pfnMain = (NP_MAIN) PR_FindSymbol(aLibrary, "main");
#else
NP_MAIN pfnMain = (NP_MAIN) PR_FindSymbol(aLibrary, "mainRD");
if(pfnMain == NULL)
{
NS_ASSERTION(pfnMain, "failed to get entry points");
return;
}
// call into the entry point
NPError error;
NS_TRY_SAFE_CALL_RETURN(error, CallNPP_MainEntryProc(pfnMain,
&(ns4xPlugin::CALLBACKS),
&fCallbacks,
(NP_PLUGINSHUTDOWN)&fShutdownEntry), aLibrary);
&fShutdownEntry), aLibrary);
if(error != NPERR_NO_ERROR || ((fCallbacks.version >> 8) < NP_VERSION_MAJOR))
{
return;
}
#endif // !TARGET_CARBON
#else // for everyone else
memcpy((void*) &fCallbacks, (void*) callbacks, sizeof(fCallbacks));
fShutdownEntry = aShutdown;
@ -344,7 +333,11 @@ ns4xPlugin::CreatePlugin(nsIServiceManager* aServiceMgr,
// we must init here because the plugin may call NPN functions
// when we call into the NP_Initialize entry point - NPN functions
// require that mBrowserManager be set up
(*aResult)->Initialize();
if (NS_FAILED((*aResult)->Initialize()))
{
NS_RELEASE(*aResult);
return NS_ERROR_FAILURE;
}
// the NP_Initialize entry point was misnamed as NP_PluginInit,
// early in plugin project development. Its correct name is
@ -414,19 +407,51 @@ ns4xPlugin::CreatePlugin(nsIServiceManager* aServiceMgr,
}
}
#if TARGET_CARBON
// call into the entry point
NP_MAIN pfnMain = (NP_MAIN) PR_FindSymbol(aLibrary, "main");
ns4xPlugin* plugin = new ns4xPlugin(nsnull, aLibrary, nsnull, aServiceMgr);
if(plugin == NULL)
return NS_ERROR_OUT_OF_MEMORY;
if(pfnMain == NULL)
return NS_ERROR_FAILURE;
NPP_ShutdownUPP pfnShutdown;
NPPluginFuncs callbacks;
memset((void*) &callbacks, 0, sizeof(callbacks));
callbacks.size = sizeof(callbacks);
NPError error;
NS_TRY_SAFE_CALL_RETURN(error, CallNPP_MainEntryProc(pfnMain,
&(ns4xPlugin::CALLBACKS),
&callbacks,
&pfnShutdown), fLibrary);
if(error != NPERR_NO_ERROR)
return NS_ERROR_FAILURE;
::UseResFile(appRefNum);
plugin->SetPluginRefNum(pluginRefNum);
if ((callbacks.version >> 8) < NP_VERSION_MAJOR)
return NS_ERROR_FAILURE;
// create the new plugin handler
ns4xPlugin* plugin = new ns4xPlugin(&callbacks, aLibrary, (NP_PLUGINSHUTDOWN)pfnShutdown, aServiceMgr);
#else // not carbon
::UseResFile(appRefNum);
ns4xPlugin* plugin = new ns4xPlugin(nsnull, aLibrary, nsnull, aServiceMgr);
#endif
if(plugin == NULL)
return NS_ERROR_OUT_OF_MEMORY;
*aResult = plugin;
NS_ADDREF(*aResult);
#endif
if (NS_FAILED((*aResult)->Initialize()))
{
NS_RELEASE(*aResult);
return NS_ERROR_FAILURE;
}
plugin->SetPluginRefNum(pluginRefNum);
#endif // XP_MAC
#ifdef XP_BEOS
// I just copied UNIX version.
@ -520,6 +545,8 @@ NS_METHOD ns4xPlugin :: CreatePluginInstance(nsISupports *aOuter, REFNSIID aIID,
nsresult
ns4xPlugin::Initialize(void)
{
if (nsnull == fLibrary)
return NS_ERROR_FAILURE;
return NS_OK;
}