Bug 709492 - Part 1: Add an observer that allows us to determine when a new page is shown. r=bz

This commit is contained in:
Patrick Walton 2011-12-29 15:10:26 -08:00
parent b583d4c969
commit 22f3a217cb

View File

@ -194,6 +194,8 @@ static const char sPrintOptionsContractID[] = "@mozilla.org/gfx/printset
//switch to page layout
#include "nsGfxCIID.h"
#include "nsObserverService.h"
#include "mozilla/dom/Element.h"
using namespace mozilla;
@ -509,6 +511,18 @@ public:
nsCOMPtr<nsIDocument> mTop;
};
class nsDocumentShownDispatcher : public nsRunnable
{
public:
nsDocumentShownDispatcher(nsIDocument *aDocument)
: mDocument(aDocument) {}
NS_IMETHOD Run();
private:
nsCOMPtr<nsIDocument> mDocument;
};
//------------------------------------------------------------------
// DocumentViewerImpl
@ -2039,6 +2053,10 @@ DocumentViewerImpl::Show(void)
}
}
// Notify observers that a new page has been shown. (But not right now;
// running JS at this time is not safe.)
NS_DispatchToMainThread(new nsDocumentShownDispatcher(mDocument));
return NS_OK;
}
@ -4371,3 +4389,17 @@ DocumentViewerImpl::SetPrintPreviewPresentation(nsIViewManager* aViewManager,
mPresContext = aPresContext;
mPresShell = aPresShell;
}
// Fires the "document-shown" event so that interested parties (right now, the
// mobile browser) are aware of it.
NS_IMETHODIMP
nsDocumentShownDispatcher::Run()
{
nsCOMPtr<nsIObserverService> observerService =
mozilla::services::GetObserverService();
if (observerService) {
observerService->NotifyObservers(mDocument, "document-shown", NULL);
}
return NS_OK;
}