Bug 758361 - Move the before-first-paint event so it doesn't get improperly triggered on a plugin codepath. r=bz

This commit is contained in:
Kartikaya Gupta 2012-06-04 12:26:03 -04:00
parent 402c53d371
commit ee659229d7
3 changed files with 34 additions and 33 deletions

View File

@ -471,18 +471,6 @@ public:
nsCOMPtr<nsIDocument> mTop;
};
class nsBeforeFirstPaintDispatcher : public nsRunnable
{
public:
nsBeforeFirstPaintDispatcher(nsIDocument* aDocument)
: mDocument(aDocument) {}
NS_IMETHOD Run();
private:
nsCOMPtr<nsIDocument> 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<nsIObserverService> 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()

View File

@ -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;
}
}
}
}

View File

@ -483,6 +483,28 @@ public:
nsRefPtr<PresShell> 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<nsIObserverService> observerService =
mozilla::services::GetObserverService();
if (observerService) {
observerService->NotifyObservers(mDocument, "before-first-paint", NULL);
}
return NS_OK;
}
private:
nsCOMPtr<nsIDocument> 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) {