Don't throw NS_ERROR_INVALID_ARG if listeners are added before window creation

-- it's a perfectly valid thing to do.  Bug 309232, r+sr=darin
This commit is contained in:
bzbarsky%mit.edu 2006-01-09 22:20:30 +00:00
Родитель 5953e5d327
Коммит 829e20c2b9
1 изменённых файлов: 12 добавлений и 5 удалений

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

@ -239,13 +239,13 @@ NS_IMETHODIMP nsWebBrowser::GetInterface(const nsIID& aIID, void** aSink)
// - nsIWebProgressListener
NS_IMETHODIMP nsWebBrowser::AddWebBrowserListener(nsIWeakReference *aListener, const nsIID& aIID)
{
nsresult rv = NS_ERROR_INVALID_ARG;
NS_ENSURE_ARG_POINTER(aListener);
nsresult rv = NS_OK;
if (!mWebProgress) {
// The window hasn't been created yet, so queue up the listener. They'll be
// registered when the window gets created.
nsWebBrowserListenerState *state = nsnull;
nsAutoPtr<nsWebBrowserListenerState> state;
NS_NEWXPCOM(state, nsWebBrowserListenerState);
if (!state) return NS_ERROR_OUT_OF_MEMORY;
@ -254,10 +254,17 @@ NS_IMETHODIMP nsWebBrowser::AddWebBrowserListener(nsIWeakReference *aListener, c
if (!mListenerArray) {
NS_NEWXPCOM(mListenerArray, nsVoidArray);
if (!mListenerArray) return NS_ERROR_OUT_OF_MEMORY;
if (!mListenerArray) {
return NS_ERROR_OUT_OF_MEMORY;
}
}
if (!mListenerArray->AppendElement(state)) return NS_ERROR_OUT_OF_MEMORY;
if (!mListenerArray->AppendElement(state)) {
return NS_ERROR_OUT_OF_MEMORY;
}
// We're all set now; don't delete |state| after this point
state.forget();
} else {
nsCOMPtr<nsISupports> supports(do_QueryReferent(aListener));
if (!supports) return NS_ERROR_INVALID_ARG;
@ -290,9 +297,9 @@ NS_IMETHODIMP nsWebBrowser::BindListener(nsISupports *aListener, const nsIID& aI
NS_IMETHODIMP nsWebBrowser::RemoveWebBrowserListener(nsIWeakReference *aListener, const nsIID& aIID)
{
nsresult rv = NS_ERROR_INVALID_ARG;
NS_ENSURE_ARG_POINTER(aListener);
nsresult rv = NS_OK;
if (!mWebProgress) {
// if there's no-one to register the listener w/, and we don't have a queue going,
// the the called is calling Remove before an Add which doesn't make sense.