From 5b41db1b0d3ff06a8d44bc0ea96bd9d770744eb4 Mon Sep 17 00:00:00 2001 From: "timeless%mozdev.org" Date: Mon, 17 Jan 2005 07:57:04 +0000 Subject: [PATCH] Bug 273056 PluginArrayImpl::GetLength should not throw if there's no plugin host, and PluginArrayImpl::GetPlugins should handle no plugin host and failure from mPluginHost->GetPlugins r=bz sr=jst git-svn-id: svn://10.0.0.236/trunk@167875 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/dom/src/base/nsPluginArray.cpp | 40 ++++++++++++------- .../plugin/base/public/nsIPluginHost.idl | 6 +-- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/mozilla/dom/src/base/nsPluginArray.cpp b/mozilla/dom/src/base/nsPluginArray.cpp index 2d7c54d2a5f..7ba1dd434ec 100644 --- a/mozilla/dom/src/base/nsPluginArray.cpp +++ b/mozilla/dom/src/base/nsPluginArray.cpp @@ -88,9 +88,11 @@ NS_IMPL_RELEASE(nsPluginArray) NS_IMETHODIMP nsPluginArray::GetLength(PRUint32* aLength) { - if (mPluginHost && NS_SUCCEEDED(mPluginHost->GetPluginCount(aLength))) - return NS_OK; - return NS_ERROR_FAILURE; + if (mPluginHost) + return mPluginHost->GetPluginCount(aLength); + + *aLength = 0; + return NS_OK; } NS_IMETHODIMP @@ -261,21 +263,29 @@ nsresult nsPluginArray::GetPlugins() { nsresult rv = GetLength(&mPluginCount); - if (rv == NS_OK) { + if (NS_SUCCEEDED(rv)) { mPluginArray = new nsIDOMPlugin*[mPluginCount]; - if (mPluginArray != nsnull) { - rv = mPluginHost->GetPlugins(mPluginCount, mPluginArray); - if (rv == NS_OK) { - // need to wrap each of these with a nsPluginElement, which - // is scriptable. - for (PRUint32 i = 0; i < mPluginCount; i++) { - nsIDOMPlugin* wrapper = new nsPluginElement(mPluginArray[i]); - NS_IF_ADDREF(wrapper); - mPluginArray[i] = wrapper; - } + if (!mPluginArray) + return NS_ERROR_OUT_OF_MEMORY; + + if (!mPluginCount) + return NS_OK; + + rv = mPluginHost->GetPlugins(mPluginCount, mPluginArray); + if (NS_SUCCEEDED(rv)) { + // need to wrap each of these with a nsPluginElement, which + // is scriptable. + for (PRUint32 i = 0; i < mPluginCount; i++) { + nsIDOMPlugin* wrapper = new PluginElement(mPluginArray[i]); + NS_IF_ADDREF(wrapper); + mPluginArray[i] = wrapper; } } else { - rv = NS_ERROR_OUT_OF_MEMORY; + /* XXX this code is all broken. If GetPlugins fails, there's no contract + * explaining what should happen. Instead of deleting elements in an + * array of random pointers, we mark the array as 0 length. + */ + mPluginCount = 0; } } return rv; diff --git a/mozilla/modules/plugin/base/public/nsIPluginHost.idl b/mozilla/modules/plugin/base/public/nsIPluginHost.idl index 31571a029ea..ba7a870ae25 100644 --- a/mozilla/modules/plugin/base/public/nsIPluginHost.idl +++ b/mozilla/modules/plugin/base/public/nsIPluginHost.idl @@ -77,11 +77,9 @@ interface nsIPluginHost : nsIFactory void isPluginEnabledForExtension(in string aExtension, in constCharStarRef aMimeType); - void getPluginCount(out unsigned long aPluginCount); + readonly attribute unsigned long pluginCount; -%{C++ - NS_IMETHOD GetPlugins(PRUint32 aPluginCount, nsIDOMPlugin* aPluginArray[]) = 0; -%} + [noscript] void getPlugins(in unsigned long aPluginCount, out /*array*/ nsIDOMPlugin aPluginArray); void stopPluginInstance(in nsIPluginInstance aInstance);