Send out notifications when docshells are created or destroyed. Bug 308438,

r=biesi, sr=darin


git-svn-id: svn://10.0.0.236/trunk@180400 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
bzbarsky%mit.edu
2005-09-16 15:51:14 +00:00
parent b8e0480ec5
commit 6e99396530
4 changed files with 74 additions and 7 deletions

View File

@@ -86,6 +86,7 @@
#include "nsAutoPtr.h"
#include "nsIPrefService.h"
#include "nsIWritablePropertyBag2.h"
#include "nsObserverService.h"
// we want to explore making the document own the load group
// so we can associate the document URI with the load group.
@@ -3360,6 +3361,9 @@ nsDocShell::InitWindow(nativeWindow parentNativeWindow,
NS_IMETHODIMP
nsDocShell::Create()
{
NS_ASSERTION(mItemType == typeContent || mItemType == typeChrome,
"Unexpected item type in docshell");
nsresult rv = NS_ERROR_FAILURE;
mPrefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
@@ -3385,12 +3389,32 @@ nsDocShell::Create()
if (NS_SUCCEEDED(rv))
mUseErrorPages = tmpbool;
nsCOMPtr<nsIObserverService> serv = do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
if (serv) {
const char* msg = mItemType == typeContent ?
NS_WEBNAVIGATION_CREATE : NS_CHROME_WEBNAVIGATION_CREATE;
serv->NotifyObservers(GetAsSupports(this), msg, nsnull);
}
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::Destroy()
{
NS_ASSERTION(mItemType == typeContent || mItemType == typeChrome,
"Unexpected item type in docshell");
if (!mIsBeingDestroyed) {
nsCOMPtr<nsIObserverService> serv =
do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
if (serv) {
const char* msg = mItemType == typeContent ?
NS_WEBNAVIGATION_DESTROY : NS_CHROME_WEBNAVIGATION_DESTROY;
serv->NotifyObservers(GetAsSupports(this), msg, nsnull);
}
}
mIsBeingDestroyed = PR_TRUE;
//Fire unload event before we blow anything away.