Bug 1544215 - Make nsIContentVewer::GetPresShell() return mozilla::PresShell instead of nsIPresShell r=bzbarsky

Additionally, this patch makes `nsDocumentViewer` which is the only
implementation of `nsIContentViewer` use `mozilla::PresShell` directly
rather than via `nsIPresShell`.

Differential Revision: https://phabricator.services.mozilla.com/D27470

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2019-04-16 02:47:26 +00:00
parent 7001c282bf
commit 60e014c55e
13 changed files with 80 additions and 92 deletions

View File

@ -8286,11 +8286,9 @@ nsresult nsDocShell::SetupNewViewer(nsIContentViewer* aNewViewer) {
// Try to extract the canvas background color from the old
// presentation shell, so we can use it for the next document.
nsCOMPtr<nsIPresShell> shell = contentViewer->GetPresShell();
if (shell) {
bgcolor = shell->GetCanvasBackground();
isActive = shell->IsActive();
if (PresShell* presShell = contentViewer->GetPresShell()) {
bgcolor = presShell->GetCanvasBackground();
isActive = presShell->IsActive();
}
contentViewer->Close(mSavingOldViewer ? mOSHE.get() : nullptr);
@ -8339,12 +8337,10 @@ nsresult nsDocShell::SetupNewViewer(nsIContentViewer* aNewViewer) {
// Stuff the bgcolor from the old pres shell into the new
// pres shell. This improves page load continuity.
nsCOMPtr<nsIPresShell> shell = mContentViewer->GetPresShell();
if (shell) {
shell->SetCanvasBackground(bgcolor);
if (RefPtr<PresShell> presShell = mContentViewer->GetPresShell()) {
presShell->SetCanvasBackground(bgcolor);
if (isActive) {
shell->SetIsActive(isActive);
presShell->SetIsActive(isActive);
}
}

View File

@ -15,23 +15,23 @@ webidl Node;
#include "nsRect.h"
class nsIWidget;
class nsIPresShell;
class nsPresContext;
class nsView;
class nsDOMNavigationTiming;
namespace mozilla {
class Encoding;
class PresShell;
}
%}
[ptr] native nsIWidgetPtr(nsIWidget);
[ref] native nsIntRectRef(nsIntRect);
[ptr] native nsIPresShellPtr(nsIPresShell);
[ptr] native nsPresContextPtr(nsPresContext);
[ptr] native nsViewPtr(nsView);
[ptr] native nsDOMNavigationTimingPtr(nsDOMNavigationTiming);
[ref] native nsIContentViewerTArray(nsTArray<nsCOMPtr<nsIContentViewer> >);
[ptr] native Encoding(const mozilla::Encoding);
[ptr] native PresShellPtr(mozilla::PresShell);
[scriptable, builtinclass, uuid(2da17016-7851-4a45-a7a8-00b360e01595)]
interface nsIContentViewer : nsISupports
@ -215,7 +215,7 @@ interface nsIContentViewer : nsISupports
attribute boolean isHidden;
// presShell can be null.
[notxpcom,nostdcall] readonly attribute nsIPresShellPtr presShell;
[notxpcom,nostdcall] readonly attribute PresShellPtr presShell;
// presContext can be null.
[notxpcom,nostdcall] readonly attribute nsPresContextPtr presContext;
// aDocument must not be null.

View File

@ -4,34 +4,34 @@
#include "gfxSVGGlyphs.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/LoadInfo.h"
#include "mozilla/NullPrincipal.h"
#include "mozilla/PresShell.h"
#include "mozilla/SMILAnimationController.h"
#include "mozilla/SVGContextPaint.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/FontTableURIProtocolHandler.h"
#include "mozilla/dom/ImageTracker.h"
#include "mozilla/dom/SVGDocument.h"
#include "nsError.h"
#include "nsString.h"
#include "mozilla/dom/Document.h"
#include "nsICategoryManager.h"
#include "nsIDocumentLoaderFactory.h"
#include "nsIContentViewer.h"
#include "nsIStreamListener.h"
#include "nsServiceManagerUtils.h"
#include "nsIPresShell.h"
#include "nsNetUtil.h"
#include "nsIInputStream.h"
#include "nsStringStream.h"
#include "nsStreamUtils.h"
#include "nsIPrincipal.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/FontTableURIProtocolHandler.h"
#include "mozilla/dom/SVGDocument.h"
#include "mozilla/LoadInfo.h"
#include "mozilla/NullPrincipal.h"
#include "mozilla/SMILAnimationController.h"
#include "nsSVGUtils.h"
#include "nsContentUtils.h"
#include "gfxFont.h"
#include "gfxContext.h"
#include "harfbuzz/hb.h"
#include "mozilla/dom/ImageTracker.h"
#define SVG_CONTENT_TYPE NS_LITERAL_CSTRING("image/svg+xml")
#define UTF8_CHARSET NS_LITERAL_CSTRING("utf-8")
@ -148,7 +148,7 @@ nsresult gfxSVGGlyphsDocument::SetupPresentation() {
NS_ENSURE_SUCCESS(rv, rv);
}
nsCOMPtr<nsIPresShell> presShell = viewer->GetPresShell();
RefPtr<PresShell> presShell = viewer->GetPresShell();
if (!presShell->DidInitialize()) {
rv = presShell->Initialize();
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -64,7 +64,7 @@ class gfxSVGGlyphsDocument final : public nsAPostRefreshObserver {
gfxSVGGlyphs *mOwner;
RefPtr<mozilla::dom::Document> mDocument;
nsCOMPtr<nsIContentViewer> mViewer;
nsCOMPtr<nsIPresShell> mPresShell;
RefPtr<mozilla::PresShell> mPresShell;
nsBaseHashtable<nsUint32HashKey, Element *, Element *> mGlyphIdMap;

View File

@ -5,9 +5,14 @@
#include "SVGDocumentWrapper.h"
#include "mozilla/PresShell.h"
#include "mozilla/SMILAnimationController.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/DocumentTimeline.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/ImageTracker.h"
#include "mozilla/dom/SVGDocument.h"
#include "mozilla/dom/SVGSVGElement.h"
#include "nsICategoryManager.h"
#include "nsIChannel.h"
#include "nsIContentViewer.h"
@ -15,19 +20,14 @@
#include "nsIHttpChannel.h"
#include "nsIObserverService.h"
#include "nsIParser.h"
#include "nsIPresShell.h"
#include "nsIRequest.h"
#include "nsIStreamListener.h"
#include "nsIXMLContentSink.h"
#include "nsNetCID.h"
#include "nsComponentManagerUtils.h"
#include "mozilla/SMILAnimationController.h"
#include "nsServiceManagerUtils.h"
#include "mozilla/dom/SVGSVGElement.h"
#include "SVGObserverUtils.h"
#include "nsMimeTypes.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/ImageTracker.h"
namespace mozilla {
@ -174,10 +174,8 @@ void SVGDocumentWrapper::SetCurrentTime(float aTime) {
}
void SVGDocumentWrapper::TickRefreshDriver() {
nsCOMPtr<nsIPresShell> presShell = mViewer->GetPresShell();
if (presShell) {
nsPresContext* presContext = presShell->GetPresContext();
if (presContext) {
if (RefPtr<PresShell> presShell = mViewer->GetPresShell()) {
if (RefPtr<nsPresContext> presContext = presShell->GetPresContext()) {
presContext->RefreshDriver()->DoTick();
}
}

View File

@ -17,7 +17,6 @@
#include "nsWeakReference.h"
#include "nsSize.h"
class nsIPresShell;
class nsIRequest;
class nsILoadGroup;
class nsIFrame;
@ -25,6 +24,7 @@ class nsIFrame;
#define OBSERVER_SVC_CID "@mozilla.org/observer-service;1"
namespace mozilla {
class PresShell;
namespace dom {
class SVGSVGElement;
class SVGDocument;
@ -64,9 +64,9 @@ class SVGDocumentWrapper final : public nsIStreamListener,
nsIFrame* GetRootLayoutFrame();
/**
* Returns the nsIPresShell for the wrapped document.
* Returns the mozilla::PresShell for the wrapped document.
*/
inline nsIPresShell* GetPresShell() { return mViewer->GetPresShell(); }
inline mozilla::PresShell* GetPresShell() { return mViewer->GetPresShell(); }
/**
* Modifier to update the viewport dimensions of the wrapped document. This

View File

@ -262,7 +262,7 @@ bool SVGDrawingCallback::operator()(gfxContext* aContext,
MOZ_ASSERT(mSVGDocumentWrapper, "need an SVGDocumentWrapper");
// Get (& sanity-check) the helper-doc's presShell
nsCOMPtr<nsIPresShell> presShell = mSVGDocumentWrapper->GetPresShell();
RefPtr<PresShell> presShell = mSVGDocumentWrapper->GetPresShell();
MOZ_ASSERT(presShell, "GetPresShell returned null for an SVG image?");
#ifdef MOZ_GECKO_PROFILER

View File

@ -186,6 +186,9 @@ class PresShell final : public nsIPresShell,
Document* GetPrimaryContentDocument() override;
void PausePainting() override;
void ResumePainting() override;
// nsIViewObserver interface
void Paint(nsView* aViewToPaint, const nsRegion& aDirtyRegion,
@ -1316,9 +1319,6 @@ class PresShell final : public nsIPresShell,
// The callback for the mPaintSuppressionTimer timer.
static void sPaintSuppressionCallback(nsITimer* aTimer, void* aPresShell);
void PausePainting() override;
void ResumePainting() override;
//////////////////////////////////////////////////////////////////////////////
// Approximate frame visibility tracking implementation.
//////////////////////////////////////////////////////////////////////////////

View File

@ -1483,8 +1483,7 @@ static void AttachContainerRecurse(nsIDocShell* aShell) {
nsCOMPtr<nsILinkHandler> handler = do_QueryInterface(aShell);
pc->SetLinkHandler(handler);
}
nsCOMPtr<nsIPresShell> presShell = viewer->GetPresShell();
if (presShell) {
if (PresShell* presShell = viewer->GetPresShell()) {
presShell->SetForwardingContainer(WeakPtr<nsDocShell>());
}
}
@ -1644,8 +1643,7 @@ static void DetachContainerRecurse(nsIDocShell* aShell) {
if (pc) {
pc->Detach();
}
nsCOMPtr<nsIPresShell> presShell = viewer->GetPresShell();
if (presShell) {
if (PresShell* presShell = viewer->GetPresShell()) {
auto weakShell = static_cast<nsDocShell*>(aShell);
presShell->SetForwardingContainer(weakShell);
}
@ -1974,7 +1972,7 @@ nsDocumentViewer::SetDocumentInternal(Document* aDocument,
return rv;
}
nsIPresShell* nsDocumentViewer::GetPresShell() { return mPresShell; }
PresShell* nsDocumentViewer::GetPresShell() { return mPresShell; }
nsPresContext* nsDocumentViewer::GetPresContext() { return mPresContext; }
@ -3088,8 +3086,7 @@ nsDocumentViewer::PausePainting() {
bool enablePaint = false;
CallChildren(ChangeChildPaintingEnabled, &enablePaint);
nsIPresShell* presShell = GetPresShell();
if (presShell) {
if (PresShell* presShell = GetPresShell()) {
presShell->PausePainting();
}
@ -3101,8 +3098,7 @@ nsDocumentViewer::ResumePainting() {
bool enablePaint = true;
CallChildren(ChangeChildPaintingEnabled, &enablePaint);
nsIPresShell* presShell = GetPresShell();
if (presShell) {
if (PresShell* presShell = GetPresShell()) {
presShell->ResumePainting();
}
@ -3115,7 +3111,7 @@ nsresult nsDocumentViewer::GetContentSizeInternal(int32_t* aWidth,
nscoord aMaxHeight) {
NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
nsCOMPtr<nsIPresShell> presShell = GetPresShell();
RefPtr<PresShell> presShell = GetPresShell();
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
// Flush out all content and style updates. We can't use a resize reflow
@ -3374,12 +3370,11 @@ nsDocViewerFocusListener::~nsDocViewerFocusListener() {}
nsresult nsDocViewerFocusListener::HandleEvent(Event* aEvent) {
NS_ENSURE_STATE(mDocViewer);
nsCOMPtr<nsIPresShell> shell = mDocViewer->GetPresShell();
NS_ENSURE_TRUE(shell, NS_ERROR_FAILURE);
RefPtr<PresShell> presShell = mDocViewer->GetPresShell();
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
nsCOMPtr<nsISelectionController> selCon = do_QueryInterface(shell);
int16_t selectionStatus;
selCon->GetDisplaySelection(&selectionStatus);
presShell->GetDisplaySelection(&selectionStatus);
nsAutoString eventType;
aEvent->GetType(eventType);
@ -3387,16 +3382,17 @@ nsresult nsDocViewerFocusListener::HandleEvent(Event* aEvent) {
// If selection was disabled, re-enable it.
if (selectionStatus == nsISelectionController::SELECTION_DISABLED ||
selectionStatus == nsISelectionController::SELECTION_HIDDEN) {
selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON);
selCon->RepaintSelection(nsISelectionController::SELECTION_NORMAL);
presShell->SetDisplaySelection(nsISelectionController::SELECTION_ON);
presShell->RepaintSelection(nsISelectionController::SELECTION_NORMAL);
}
} else {
MOZ_ASSERT(eventType.EqualsLiteral("blur"), "Unexpected event type");
// If selection was on, disable it.
if (selectionStatus == nsISelectionController::SELECTION_ON ||
selectionStatus == nsISelectionController::SELECTION_ATTENTION) {
selCon->SetDisplaySelection(nsISelectionController::SELECTION_DISABLED);
selCon->RepaintSelection(nsISelectionController::SELECTION_NORMAL);
presShell->SetDisplaySelection(
nsISelectionController::SELECTION_DISABLED);
presShell->RepaintSelection(nsISelectionController::SELECTION_NORMAL);
}
}
@ -4181,7 +4177,7 @@ void nsDocumentViewer::InitializeForPrintPreview() {
void nsDocumentViewer::SetPrintPreviewPresentation(nsViewManager* aViewManager,
nsPresContext* aPresContext,
nsIPresShell* aPresShell) {
PresShell* aPresShell) {
// Protect against pres shell destruction running scripts and re-entrantly
// creating a new presentation.
nsAutoScriptBlocker scriptBlocker;
@ -4193,7 +4189,7 @@ void nsDocumentViewer::SetPrintPreviewPresentation(nsViewManager* aViewManager,
mWindow = nullptr;
mViewManager = aViewManager;
mPresContext = aPresContext;
mPresShell = static_cast<PresShell*>(aPresShell);
mPresShell = aPresShell;
if (ShouldAttachToTopLevel()) {
DetachFromTopLevelWidget();

View File

@ -11,9 +11,9 @@
#include "mozilla/UniquePtr.h"
namespace mozilla {
class PresShell;
class ServoStyleSet;
} // namespace mozilla
class nsIPresShell;
class nsPresContext;
class nsViewManager;
@ -64,7 +64,7 @@ class nsIDocumentViewerPrint : public nsISupports {
*/
virtual void SetPrintPreviewPresentation(nsViewManager* aViewManager,
nsPresContext* aPresContext,
nsIPresShell* aPresShell) = 0;
mozilla::PresShell* aPresShell) = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumentViewerPrint,
@ -83,6 +83,6 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumentViewerPrint,
void InitializeForPrintPreview() override; \
void SetPrintPreviewPresentation(nsViewManager* aViewManager, \
nsPresContext* aPresContext, \
nsIPresShell* aPresShell) override;
mozilla::PresShell* aPresShell) override;
#endif /* nsIDocumentViewerPrint_h___ */

View File

@ -8808,12 +8808,11 @@ static void MaybeReflowForInflationScreenSizeChange(
cv->AppendSubtree(array);
for (uint32_t i = 0, iEnd = array.Length(); i < iEnd; ++i) {
nsCOMPtr<nsIContentViewer> cv = array[i];
nsCOMPtr<nsIPresShell> shell = cv->GetPresShell();
if (shell) {
nsIFrame* rootFrame = shell->GetRootFrame();
if (RefPtr<PresShell> descendantPresShell = cv->GetPresShell()) {
nsIFrame* rootFrame = descendantPresShell->GetRootFrame();
if (rootFrame) {
shell->FrameNeedsReflow(rootFrame, nsIPresShell::eStyleChange,
NS_FRAME_IS_DIRTY);
descendantPresShell->FrameNeedsReflow(
rootFrame, nsIPresShell::eStyleChange, NS_FRAME_IS_DIRTY);
}
}
}

View File

@ -2282,7 +2282,8 @@ nsresult nsPrintJob::ReflowPrintObject(const UniquePtr<nsPrintObject>& aPO) {
if (mIsCreatingPrintPreview && documentIsTopLevel) {
mDocViewerPrint->SetPrintPreviewPresentation(
aPO->mViewManager, aPO->mPresContext, aPO->mPresShell);
aPO->mViewManager, aPO->mPresContext,
static_cast<PresShell*>(aPO->mPresShell.get()));
}
rv = aPO->mPresShell->Initialize();

View File

@ -15,9 +15,7 @@
#include "nsQuickSort.h"
#include "nsIContent.h"
#include "mozilla/dom/Document.h"
#include "nsIPresShell.h"
#include "nsViewManager.h"
#include "nsIFrame.h"
@ -26,8 +24,10 @@
static NS_DEFINE_CID(kLayoutDebuggerCID, NS_LAYOUT_DEBUGGER_CID);
#include "nsISelectionController.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/Element.h"
#include "mozilla/Preferences.h"
#include "mozilla/PresShell.h"
using namespace mozilla;
using mozilla::dom::Document;
@ -39,16 +39,18 @@ static already_AddRefed<nsIContentViewer> doc_viewer(nsIDocShell* aDocShell) {
return result.forget();
}
static nsIPresShell* pres_shell(nsIDocShell* aDocShell) {
static PresShell* GetPresShell(nsIDocShell* aDocShell) {
nsCOMPtr<nsIContentViewer> cv = doc_viewer(aDocShell);
if (!cv) return nullptr;
return cv->GetPresShell();
}
static nsViewManager* view_manager(nsIDocShell* aDocShell) {
nsCOMPtr<nsIPresShell> shell(pres_shell(aDocShell));
if (!shell) return nullptr;
return shell->GetViewManager();
PresShell* presShell = GetPresShell(aDocShell);
if (!presShell) {
return nullptr;
}
return presShell->GetViewManager();
}
#ifdef DEBUG
@ -246,10 +248,9 @@ nsLayoutDebuggingTools::GetReflowCounts(bool* aShow) {
NS_IMETHODIMP
nsLayoutDebuggingTools::SetReflowCounts(bool aShow) {
NS_ENSURE_TRUE(mDocShell, NS_ERROR_NOT_INITIALIZED);
nsCOMPtr<nsIPresShell> shell(pres_shell(mDocShell));
if (shell) {
if (PresShell* presShell = GetPresShell(mDocShell)) {
#ifdef MOZ_REFLOW_PERF
shell->SetPaintFrameCount(aShow);
presShell->SetPaintFrameCount(aShow);
SetBoolPrefAndRefresh("layout.reflow.showframecounts", aShow);
mReflowCounts = aShow;
#else
@ -334,9 +335,8 @@ nsLayoutDebuggingTools::DumpContent() {
static void DumpFramesRecur(nsIDocShell* aDocShell, FILE* out) {
#ifdef DEBUG_FRAME_DUMP
fprintf(out, "webshell=%p \n", static_cast<void*>(aDocShell));
nsCOMPtr<nsIPresShell> shell(pres_shell(aDocShell));
if (shell) {
nsIFrame* root = shell->GetRootFrame();
if (PresShell* presShell = GetPresShell(aDocShell)) {
nsIFrame* root = presShell->GetRootFrame();
if (root) {
root->List(out);
}
@ -404,11 +404,11 @@ nsLayoutDebuggingTools::DumpStyleSheets() {
NS_ENSURE_TRUE(mDocShell, NS_ERROR_NOT_INITIALIZED);
#ifdef DEBUG
FILE* out = stdout;
nsCOMPtr<nsIPresShell> shell(pres_shell(mDocShell));
if (shell)
shell->ListStyleSheets(out);
else
if (PresShell* presShell = GetPresShell(mDocShell)) {
presShell->ListStyleSheets(out);
} else {
fputs("null pres shell\n", out);
}
#endif
return NS_OK;
}
@ -418,9 +418,8 @@ nsLayoutDebuggingTools::DumpComputedStyles() {
NS_ENSURE_TRUE(mDocShell, NS_ERROR_NOT_INITIALIZED);
#ifdef DEBUG
FILE* out = stdout;
nsCOMPtr<nsIPresShell> shell(pres_shell(mDocShell));
if (shell) {
shell->ListComputedStyles(out);
if (PresShell* presShell = GetPresShell(mDocShell)) {
presShell->ListComputedStyles(out);
} else {
fputs("null pres shell\n", out);
}
@ -432,10 +431,9 @@ NS_IMETHODIMP
nsLayoutDebuggingTools::DumpReflowStats() {
NS_ENSURE_TRUE(mDocShell, NS_ERROR_NOT_INITIALIZED);
#ifdef DEBUG
nsCOMPtr<nsIPresShell> shell(pres_shell(mDocShell));
if (shell) {
if (RefPtr<PresShell> presShell = GetPresShell(mDocShell)) {
# ifdef MOZ_REFLOW_PERF
shell->DumpReflows();
presShell->DumpReflows();
# else
printf("************************************************\n");
printf("Sorry, you have not built with MOZ_REFLOW_PERF=1\n");