From 7badcbb935c0eeeea35318e56ff4fd7b0d620dbe Mon Sep 17 00:00:00 2001 From: "saari%netscape.com" Date: Tue, 21 Mar 2000 00:47:19 +0000 Subject: [PATCH] Null checking for saftey in some of the focus code. r=hyatt --- content/events/src/nsEventStateManager.cpp | 44 ++++++++++++---------- layout/events/src/nsEventStateManager.cpp | 44 ++++++++++++---------- 2 files changed, 48 insertions(+), 40 deletions(-) diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index 2f3e2eccdf41..eb5682ebf514 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -461,20 +461,24 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext, // de-activation. This will cause it to remember the last // focused sub-window and sub-element for this top-level // window. + nsCOMPtr commandDispatcher; nsCOMPtr rootWindow; nsCOMPtr ourWindow = do_QueryInterface(ourGlobal); - ourWindow->GetPrivateRoot(getter_AddRefs(rootWindow)); - nsCOMPtr rootDocument; - rootWindow->GetDocument(getter_AddRefs(rootDocument)); + if(ourWindow) { + ourWindow->GetPrivateRoot(getter_AddRefs(rootWindow)); + if(rootWindow) { + nsCOMPtr rootDocument; + rootWindow->GetDocument(getter_AddRefs(rootDocument)); - nsCOMPtr commandDispatcher; - nsCOMPtr xulDoc = do_QueryInterface(rootDocument); - if (xulDoc) { - // See if we have a command dispatcher attached. - xulDoc->GetCommandDispatcher(getter_AddRefs(commandDispatcher)); - if (commandDispatcher) { - // Suppress the command dispatcher. - commandDispatcher->SetSuppressFocus(PR_TRUE); + nsCOMPtr xulDoc = do_QueryInterface(rootDocument); + if (xulDoc) { + // See if we have a command dispatcher attached. + xulDoc->GetCommandDispatcher(getter_AddRefs(commandDispatcher)); + if (commandDispatcher) { + // Suppress the command dispatcher. + commandDispatcher->SetSuppressFocus(PR_TRUE); + } + } } } @@ -501,7 +505,7 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext, esm->SetFocusedContent(gLastFocusedContent); gLastFocusedContent->HandleDOMEvent(oldPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); esm->SetFocusedContent(nsnull); - NS_RELEASE(gLastFocusedContent); + NS_IF_RELEASE(gLastFocusedContent); } } @@ -512,15 +516,15 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext, // fire blur on document and window nsCOMPtr globalObject; - gLastFocusedDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); - gLastFocusedDocument->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); - if(!globalObject) break; - - globalObject->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); - mCurrentTarget = nsnull; - + if(gLastFocusedDocument) { + gLastFocusedDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); + gLastFocusedDocument->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); + if(globalObject) + globalObject->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); + } // Now clear our our global variables - NS_RELEASE(gLastFocusedDocument); + mCurrentTarget = nsnull; + NS_IF_RELEASE(gLastFocusedDocument); gLastFocusedPresContext = nsnull; } diff --git a/layout/events/src/nsEventStateManager.cpp b/layout/events/src/nsEventStateManager.cpp index 2f3e2eccdf41..eb5682ebf514 100644 --- a/layout/events/src/nsEventStateManager.cpp +++ b/layout/events/src/nsEventStateManager.cpp @@ -461,20 +461,24 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext, // de-activation. This will cause it to remember the last // focused sub-window and sub-element for this top-level // window. + nsCOMPtr commandDispatcher; nsCOMPtr rootWindow; nsCOMPtr ourWindow = do_QueryInterface(ourGlobal); - ourWindow->GetPrivateRoot(getter_AddRefs(rootWindow)); - nsCOMPtr rootDocument; - rootWindow->GetDocument(getter_AddRefs(rootDocument)); + if(ourWindow) { + ourWindow->GetPrivateRoot(getter_AddRefs(rootWindow)); + if(rootWindow) { + nsCOMPtr rootDocument; + rootWindow->GetDocument(getter_AddRefs(rootDocument)); - nsCOMPtr commandDispatcher; - nsCOMPtr xulDoc = do_QueryInterface(rootDocument); - if (xulDoc) { - // See if we have a command dispatcher attached. - xulDoc->GetCommandDispatcher(getter_AddRefs(commandDispatcher)); - if (commandDispatcher) { - // Suppress the command dispatcher. - commandDispatcher->SetSuppressFocus(PR_TRUE); + nsCOMPtr xulDoc = do_QueryInterface(rootDocument); + if (xulDoc) { + // See if we have a command dispatcher attached. + xulDoc->GetCommandDispatcher(getter_AddRefs(commandDispatcher)); + if (commandDispatcher) { + // Suppress the command dispatcher. + commandDispatcher->SetSuppressFocus(PR_TRUE); + } + } } } @@ -501,7 +505,7 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext, esm->SetFocusedContent(gLastFocusedContent); gLastFocusedContent->HandleDOMEvent(oldPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); esm->SetFocusedContent(nsnull); - NS_RELEASE(gLastFocusedContent); + NS_IF_RELEASE(gLastFocusedContent); } } @@ -512,15 +516,15 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext, // fire blur on document and window nsCOMPtr globalObject; - gLastFocusedDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); - gLastFocusedDocument->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); - if(!globalObject) break; - - globalObject->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); - mCurrentTarget = nsnull; - + if(gLastFocusedDocument) { + gLastFocusedDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); + gLastFocusedDocument->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); + if(globalObject) + globalObject->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); + } // Now clear our our global variables - NS_RELEASE(gLastFocusedDocument); + mCurrentTarget = nsnull; + NS_IF_RELEASE(gLastFocusedDocument); gLastFocusedPresContext = nsnull; }