Bug 709492 - Part 1: Add an observer that allows us to determine when a new page is shown. r=bz
authorPatrick Walton <pwalton@mozilla.com>
Thu, 29 Dec 2011 15:10:26 -0800
changeset 84771 20d649e04ccf18f0807c0fc7c1d018b726a50e18
parent 84770 ca5ebc597cdc5a23c70f74dd8081a9b5e95d87ae
child 84772 22e0c14b7fc85ff2d91c754cacebe195d667b705
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
bugs709492
milestone12.0a1
Bug 709492 - 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(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;
+}
+