Bug 741246: Simplify plugin instance creation and initialization (further). r=jst

This commit is contained in:
Josh Aas 2012-04-02 15:17:34 -04:00
parent e1aae0e872
commit eaea6992fd
3 changed files with 23 additions and 55 deletions

View File

@ -78,7 +78,7 @@ static NS_DEFINE_IID(kIPluginStreamListenerIID, NS_IPLUGINSTREAMLISTENER_IID);
NS_IMPL_THREADSAFE_ISUPPORTS0(nsNPAPIPluginInstance)
nsNPAPIPluginInstance::nsNPAPIPluginInstance(nsNPAPIPlugin* plugin)
nsNPAPIPluginInstance::nsNPAPIPluginInstance()
:
mDrawingModel(kDefaultDrawingModel),
#ifdef MOZ_WIDGET_ANDROID
@ -92,7 +92,7 @@ nsNPAPIPluginInstance::nsNPAPIPluginInstance(nsNPAPIPlugin* plugin)
mCached(false),
mUsesDOMForCursor(false),
mInPluginInitCall(false),
mPlugin(plugin),
mPlugin(nsnull),
mMIMEType(nsnull),
mOwner(nsnull),
mCurrentPluginEvent(nsnull),
@ -102,10 +102,6 @@ nsNPAPIPluginInstance::nsNPAPIPluginInstance(nsNPAPIPlugin* plugin)
mUsePluginLayersPref(false)
#endif
{
NS_ASSERTION(mPlugin != NULL, "Plugin is required when creating an instance.");
// Initialize the NPP structure.
mNPP.pdata = NULL;
mNPP.ndata = this;
@ -143,30 +139,24 @@ nsNPAPIPluginInstance::StopTime()
return mStopTime;
}
nsresult nsNPAPIPluginInstance::Initialize(nsIPluginInstanceOwner* aOwner, const char* aMIMEType)
nsresult nsNPAPIPluginInstance::Initialize(nsNPAPIPlugin *aPlugin, nsIPluginInstanceOwner* aOwner, const char* aMIMEType)
{
PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("nsNPAPIPluginInstance::Initialize this=%p\n",this));
NS_ENSURE_ARG_POINTER(aPlugin);
NS_ENSURE_ARG_POINTER(aOwner);
mPlugin = aPlugin;
mOwner = aOwner;
if (aMIMEType) {
mMIMEType = (char*)PR_Malloc(PL_strlen(aMIMEType) + 1);
if (mMIMEType)
if (mMIMEType) {
PL_strcpy(mMIMEType, aMIMEType);
}
}
return InitializePlugin();
}
nsresult nsNPAPIPluginInstance::Start()
{
PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("nsNPAPIPluginInstance::Start this=%p\n",this));
if (RUNNING == mRunning)
return NS_OK;
return InitializePlugin();
return Start();
}
nsresult nsNPAPIPluginInstance::Stop()
@ -316,8 +306,12 @@ nsNPAPIPluginInstance::FileCachedStreamListeners()
}
nsresult
nsNPAPIPluginInstance::InitializePlugin()
nsNPAPIPluginInstance::Start()
{
if (mRunning == RUNNING) {
return NS_OK;
}
PluginDestructionGuard guard(this);
PRUint16 count = 0;

View File

@ -94,7 +94,7 @@ private:
public:
NS_DECL_ISUPPORTS
nsresult Initialize(nsIPluginInstanceOwner* aOwner, const char* aMIMEType);
nsresult Initialize(nsNPAPIPlugin *aPlugin, nsIPluginInstanceOwner* aOwner, const char* aMIMEType);
nsresult Start();
nsresult Stop();
nsresult SetWindow(NPWindow* window);
@ -176,7 +176,7 @@ public:
nsresult NewStreamListener(const char* aURL, void* notifyData,
nsIPluginStreamListener** listener);
nsNPAPIPluginInstance(nsNPAPIPlugin* plugin);
nsNPAPIPluginInstance();
virtual ~nsNPAPIPluginInstance();
// To be called when an instance becomes orphaned, when
@ -233,7 +233,6 @@ public:
void CarbonNPAPIFailure();
protected:
nsresult InitializePlugin();
nsresult GetTagType(nsPluginTagType *result);
nsresult GetAttributes(PRUint16& n, const char*const*& names,

View File

@ -1294,42 +1294,17 @@ nsPluginHost::TrySetUpPluginInstance(const char *aMimeType,
return NS_ERROR_FAILURE;
}
#if defined(XP_WIN)
static BOOL firstJavaPlugin = FALSE;
BOOL restoreOrigDir = FALSE;
WCHAR origDir[_MAX_PATH];
if (pluginTag->mIsJavaPlugin && !firstJavaPlugin) {
DWORD dw = GetCurrentDirectoryW(_MAX_PATH, origDir);
NS_ASSERTION(dw <= _MAX_PATH, "Failed to obtain the current directory, which may lead to incorrect class loading");
nsCOMPtr<nsIFile> binDirectory;
nsresult rv = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR,
getter_AddRefs(binDirectory));
nsRefPtr<nsNPAPIPluginInstance> instance = new nsNPAPIPluginInstance();
if (NS_SUCCEEDED(rv)) {
nsAutoString path;
binDirectory->GetPath(path);
restoreOrigDir = SetCurrentDirectoryW(path.get());
}
}
#endif
nsRefPtr<nsNPAPIPluginInstance> instance = new nsNPAPIPluginInstance(plugin.get());
#if defined(XP_WIN)
if (!firstJavaPlugin && restoreOrigDir) {
BOOL bCheck = SetCurrentDirectoryW(origDir);
NS_ASSERTION(bCheck, "Error restoring directory");
firstJavaPlugin = TRUE;
}
#endif
// it is adreffed here
// This will create the owning reference. The connection must be made between the
// instance and the instance owner before initialization. Plugins can call into
// the browser during initialization.
aOwner->SetInstance(instance.get());
// this should not addref the instance or owner
// except in some cases not Java, see bug 140931
// our COM pointer will free the peer
nsresult rv = instance->Initialize(aOwner, mimetype);
nsresult rv = instance->Initialize(plugin.get(), aOwner, mimetype);
if (NS_FAILED(rv)) {
aOwner->SetInstance(nsnull);
return rv;