Bug 708746 - Part 1: Add an observer that allows us to determine when a new page is shown. r=bz
authorPatrick Walton <pwalton@mozilla.com>
Fri, 06 Jan 2012 16:42:42 -0800
changeset 85203 ed2a79ca496fa83166452e03f4be9d2cdb86f4f6
parent 85202 48928463f9785a3518a2936c313de4546857c980
child 85204 ef5ab1377d94943fd3dc7c76ab275c1cb05caf44
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs708746
milestone12.0a1
Bug 708746 - Part 1: Add an observer that allows us to determine when a new page is shown. r=bz
layout/base/nsDocumentViewer.cpp
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -189,16 +189,18 @@ static const char sPrintOptionsContractI
 
 //paint forcing
 #include "prenv.h"
 #include <stdio.h>
 
 //switch to page layout
 #include "nsGfxCIID.h"
 
+#include "nsObserverService.h"
+
 #include "mozilla/dom/Element.h"
 
 using namespace mozilla;
 
 #ifdef NS_DEBUG
 
 #undef NOISY_VIEWER
 #else
@@ -504,16 +506,28 @@ public:
   ~nsPrintEventDispatcher()
   {
     DocumentViewerImpl::DispatchAfterPrint(mTop);
   }
 
   nsCOMPtr<nsIDocument> mTop;
 };
 
+class nsDocumentShownDispatcher : public nsRunnable
+{
+public:
+  nsDocumentShownDispatcher(nsCOMPtr<nsIDocument> aDocument)
+  : mDocument(aDocument) {}
+
+  NS_IMETHOD Run();
+
+private:
+  nsCOMPtr<nsIDocument> mDocument;
+};
+
 
 //------------------------------------------------------------------
 // DocumentViewerImpl
 //------------------------------------------------------------------
 // Class IDs
 static NS_DEFINE_CID(kViewManagerCID,       NS_VIEW_MANAGER_CID);
 
 //------------------------------------------------------------------
@@ -2034,16 +2048,20 @@ DocumentViewerImpl::Show(void)
     // shown...
 
     if (mPresShell) {
       nsCOMPtr<nsIPresShell> shellDeathGrip(mPresShell); // bug 378682
       mPresShell->UnsuppressPainting();
     }
   }
 
+  // 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;
 }
 
 NS_IMETHODIMP
 DocumentViewerImpl::Hide(void)
 {
   if (!mAttachedToParent && mWindow) {
     mWindow->Show(false);
@@ -4366,8 +4384,22 @@ DocumentViewerImpl::SetPrintPreviewPrese
     DestroyPresShell();
   }
 
   mWindow = nsnull;
   mViewManager = 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;
+}
+