From ee659229d7e08be3918ae00980bc123c63d1b174 Mon Sep 17 00:00:00 2001 From: Kartikaya Gupta Date: Mon, 4 Jun 2012 12:26:03 -0400 Subject: [PATCH] Bug 758361 - Move the before-first-paint event so it doesn't get improperly triggered on a plugin codepath. r=bz --- layout/base/nsDocumentViewer.cpp | 30 ------------------------------ layout/base/nsPresContext.cpp | 6 ++++-- layout/base/nsPresShell.cpp | 31 ++++++++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 33 deletions(-) diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 7a885c577df..6991065233e 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -471,18 +471,6 @@ public: nsCOMPtr mTop; }; -class nsBeforeFirstPaintDispatcher : public nsRunnable -{ -public: - nsBeforeFirstPaintDispatcher(nsIDocument* aDocument) - : mDocument(aDocument) {} - - NS_IMETHOD Run(); - -private: - nsCOMPtr mDocument; -}; - class nsDocumentShownDispatcher : public nsRunnable { public: @@ -2025,11 +2013,6 @@ DocumentViewerImpl::Show(void) } } - // Notify observers that a new page is about to be drawn. Execute this - // as soon as it is safe to run JS, which is guaranteed to be before we - // go back to the event loop and actually draw the page. - nsContentUtils::AddScriptRunner(new nsBeforeFirstPaintDispatcher(mDocument)); - // Notify observers that a new page has been shown. This will get run // from the event loop after we actually draw the page. NS_DispatchToMainThread(new nsDocumentShownDispatcher(mDocument)); @@ -4376,19 +4359,6 @@ DocumentViewerImpl::SetPrintPreviewPresentation(nsIViewManager* aViewManager, mPresShell = aPresShell; } -// Fires the "before-first-paint" event so that interested parties (right now, the -// mobile browser) are aware of it. -NS_IMETHODIMP -nsBeforeFirstPaintDispatcher::Run() -{ - nsCOMPtr observerService = - mozilla::services::GetObserverService(); - if (observerService) { - observerService->NotifyObservers(mDocument, "before-first-paint", NULL); - } - return NS_OK; -} - // Fires the "document-shown" event so that interested parties are aware of it. NS_IMETHODIMP nsDocumentShownDispatcher::Run() diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 61594d4f56d..7b7b1b4ebb5 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -1822,8 +1822,10 @@ nsPresContext::EnsureVisible() cv->GetPresContext(getter_AddRefs(currentPresContext)); if (currentPresContext == this) { // OK, this is us. We want to call Show() on the content viewer. - cv->Show(); - return true; + nsresult result = cv->Show(); + if (NS_SUCCEEDED(result)) { + return true; + } } } } diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 79970ff6658..d157c6d239b 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -483,6 +483,28 @@ public: nsRefPtr mPresShell; }; +class nsBeforeFirstPaintDispatcher : public nsRunnable +{ +public: + nsBeforeFirstPaintDispatcher(nsIDocument* aDocument) + : mDocument(aDocument) {} + + // Fires the "before-first-paint" event so that interested parties (right now, the + // mobile browser) are aware of it. + NS_IMETHOD Run() + { + nsCOMPtr observerService = + mozilla::services::GetObserverService(); + if (observerService) { + observerService->NotifyObservers(mDocument, "before-first-paint", NULL); + } + return NS_OK; + } + +private: + nsCOMPtr mDocument; +}; + bool PresShell::sDisableNonTestMouseEvents = false; #ifdef PR_LOGGING @@ -3509,7 +3531,14 @@ PresShell::UnsuppressAndInvalidate() // No point; we're about to be torn down anyway. return; } - + + if (!mDocument->IsResourceDoc()) { + // Notify observers that a new page is about to be drawn. Execute this + // as soon as it is safe to run JS, which is guaranteed to be before we + // go back to the event loop and actually draw the page. + nsContentUtils::AddScriptRunner(new nsBeforeFirstPaintDispatcher(mDocument)); + } + mPaintingSuppressed = false; nsIFrame* rootFrame = mFrameConstructor->GetRootFrame(); if (rootFrame) {