From d1e465e30bae2744c5b26b2f67af860a23c036d3 Mon Sep 17 00:00:00 2001 From: Josh Aas Date: Sun, 1 Apr 2012 06:13:10 -0400 Subject: [PATCH] Bug 741126: Require plugin for instance creation. r=jst --- dom/plugins/base/nsPluginHost.cpp | 63 +++++++++++++++---------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/dom/plugins/base/nsPluginHost.cpp b/dom/plugins/base/nsPluginHost.cpp index 66c9a76d768..ebcd7d78d3b 100644 --- a/dom/plugins/base/nsPluginHost.cpp +++ b/dom/plugins/base/nsPluginHost.cpp @@ -1290,40 +1290,39 @@ nsPluginHost::TrySetUpPluginInstance(const char *aMimeType, nsRefPtr plugin; GetPlugin(mimetype, getter_AddRefs(plugin)); - - nsRefPtr instance; - - if (plugin) { -#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 binDirectory; - nsresult rv = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR, - getter_AddRefs(binDirectory)); - - if (NS_SUCCEEDED(rv)) { - nsAutoString path; - binDirectory->GetPath(path); - restoreOrigDir = SetCurrentDirectoryW(path.get()); - } - } -#endif - - 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 + if (!plugin) { + 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 binDirectory; + nsresult rv = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR, + getter_AddRefs(binDirectory)); + + if (NS_SUCCEEDED(rv)) { + nsAutoString path; + binDirectory->GetPath(path); + restoreOrigDir = SetCurrentDirectoryW(path.get()); + } + } +#endif + + nsRefPtr 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 aOwner->SetInstance(instance.get());