Skip to content

Commit

Permalink
bug 939049 - staticly type nsIDocument::mDocumentContainer and nsDocu…
Browse files Browse the repository at this point in the history
…mentViewerContainer::mContainer r=smaug
  • Loading branch information
Trevor Saunders committed Nov 15, 2013
1 parent e56ba10 commit 830c054
Show file tree
Hide file tree
Showing 22 changed files with 137 additions and 107 deletions.
15 changes: 7 additions & 8 deletions content/base/public/nsIDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "nsPropertyTable.h" // for member
#include "nsTHashtable.h" // for member
#include "mozilla/dom/DocumentBinding.h"
#include "mozilla/WeakPtr.h"
#include "Units.h"
#include "nsExpirationTracker.h"
#include "nsClassHashtable.h"
Expand All @@ -28,6 +29,8 @@ class imgIRequest;
class nsAString;
class nsBindingManager;
class nsCSSStyleSheet;
class nsIDocShell;
class nsDocShell;
class nsDOMNavigationTiming;
class nsDOMTouchList;
class nsEventStates;
Expand Down Expand Up @@ -1150,16 +1153,12 @@ class nsIDocument : public nsINode
* Set the container (docshell) for this document. Virtual so that
* docshell can call it.
*/
virtual void SetContainer(nsISupports *aContainer);
virtual void SetContainer(nsDocShell* aContainer);

/**
* Get the container (docshell) for this document.
*/
already_AddRefed<nsISupports> GetContainer() const
{
nsCOMPtr<nsISupports> container = do_QueryReferent(mDocumentContainer);
return container.forget();
}
virtual nsISupports* GetContainer() const;

/**
* Get the container's load context for this document.
Expand Down Expand Up @@ -1696,7 +1695,7 @@ class nsIDocument : public nsINode
* @param aCloneContainer The container for the clone document.
*/
virtual already_AddRefed<nsIDocument>
CreateStaticClone(nsISupports* aCloneContainer);
CreateStaticClone(nsIDocShell* aCloneContainer);

/**
* If this document is a static clone, this returns the original
Expand Down Expand Up @@ -2227,7 +2226,7 @@ class nsIDocument : public nsINode

nsWeakPtr mDocumentLoadGroup;

nsWeakPtr mDocumentContainer;
mozilla::WeakPtr<nsDocShell> mDocumentContainer;

nsCString mCharacterSet;
int32_t mCharacterSetSource;
Expand Down
1 change: 1 addition & 0 deletions content/base/src/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ LOCAL_INCLUDES += [
'/content/xslt/src/xpath',
'/content/xul/content/src',
'/content/xul/document/src',
'/docshell/base',
'/dom/base',
'/dom/ipc',
'/dom/workers',
Expand Down
77 changes: 44 additions & 33 deletions content/base/src/nsDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "nsIBaseWindow.h"
#include "mozilla/css/Loader.h"
#include "mozilla/css/ImageLoader.h"
#include "nsIDocShell.h"
#include "nsDocShell.h"
#include "nsIDocShellTreeItem.h"
#include "nsCOMArray.h"
#include "nsDOMClassInfo.h"
Expand Down Expand Up @@ -2204,7 +2204,7 @@ nsDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup,
nsIScriptSecurityManager *securityManager =
nsContentUtils::GetSecurityManager();
if (securityManager) {
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocumentContainer);
nsCOMPtr<nsIDocShell> docShell(mDocumentContainer);

if (!docShell && aLoadGroup) {
nsCOMPtr<nsIInterfaceRequestor> cbs;
Expand Down Expand Up @@ -2700,7 +2700,7 @@ nsDocument::InitCSP(nsIChannel* aChannel)
}

// ----- Enforce frame-ancestor policy on any applied policies
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocumentContainer);
nsCOMPtr<nsIDocShell> docShell(mDocumentContainer);
if (docShell) {
bool safeAncestry = false;

Expand Down Expand Up @@ -2931,7 +2931,7 @@ nsresult
nsDocument::GetAllowPlugins(bool * aAllowPlugins)
{
// First, we ask our docshell if it allows plugins.
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocumentContainer);
nsCOMPtr<nsIDocShell> docShell(mDocumentContainer);

if (docShell) {
docShell->GetAllowPlugins(aAllowPlugins);
Expand Down Expand Up @@ -3399,7 +3399,7 @@ nsDocument::SetHeaderData(nsIAtom* aHeaderField, const nsAString& aData)
if (aHeaderField == nsGkAtoms::refresh) {
// We get into this code before we have a script global yet, so get to
// our container via mDocumentContainer.
nsCOMPtr<nsIRefreshURI> refresher = do_QueryReferent(mDocumentContainer);
nsCOMPtr<nsIRefreshURI> refresher(mDocumentContainer);
if (refresher) {
// Note: using mDocumentURI instead of mBaseURI here, for consistency
// (used to just use the current URI of our webnavigation, but that
Expand Down Expand Up @@ -3480,7 +3480,7 @@ nsDocument::doCreateShell(nsPresContext* aContext,
mPresShell = shell;

// Make sure to never paint if we belong to an invisible DocShell.
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocumentContainer);
nsCOMPtr<nsIDocShell> docShell(mDocumentContainer);
if (docShell && docShell->IsInvisible())
shell->SetNeverPainting(true);

Expand Down Expand Up @@ -4193,29 +4193,41 @@ NotifyActivityChanged(nsIContent *aContent, void *aUnused)
}

void
nsIDocument::SetContainer(nsISupports* aContainer)
nsIDocument::SetContainer(nsDocShell* aContainer)
{
mDocumentContainer = do_GetWeakReference(aContainer);
if (aContainer) {
mDocumentContainer = aContainer->asWeakPtr();
} else {
mDocumentContainer = WeakPtr<nsDocShell>();
}

EnumerateFreezableElements(NotifyActivityChanged, nullptr);
if (!aContainer) {
return;
}

// Get the Docshell
nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(aContainer);
if (docShell) {
int32_t itemType;
docShell->GetItemType(&itemType);
// check itemtype
if (itemType == nsIDocShellTreeItem::typeContent) {
// check if same type root
nsCOMPtr<nsIDocShellTreeItem> sameTypeRoot;
docShell->GetSameTypeRootTreeItem(getter_AddRefs(sameTypeRoot));
NS_ASSERTION(sameTypeRoot, "No document shell root tree item from document shell tree item!");

if (sameTypeRoot == docShell) {
static_cast<nsDocument*>(this)->SetIsTopLevelContentDocument(true);
}
int32_t itemType;
aContainer->GetItemType(&itemType);
// check itemtype
if (itemType == nsIDocShellTreeItem::typeContent) {
// check if same type root
nsCOMPtr<nsIDocShellTreeItem> sameTypeRoot;
aContainer->GetSameTypeRootTreeItem(getter_AddRefs(sameTypeRoot));
NS_ASSERTION(sameTypeRoot, "No document shell root tree item from document shell tree item!");

if (sameTypeRoot == aContainer) {
static_cast<nsDocument*>(this)->SetIsTopLevelContentDocument(true);
}
}
}

nsISupports*
nsIDocument::GetContainer() const
{
return static_cast<nsIDocShell*>(mDocumentContainer);
}

void
nsDocument::SetScriptGlobalObject(nsIScriptGlobalObject *aScriptGlobalObject)
{
Expand Down Expand Up @@ -4273,7 +4285,7 @@ nsDocument::SetScriptGlobalObject(nsIScriptGlobalObject *aScriptGlobalObject)
#endif

if (mAllowDNSPrefetch) {
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocumentContainer);
nsCOMPtr<nsIDocShell> docShell(mDocumentContainer);
if (docShell) {
#ifdef DEBUG
nsCOMPtr<nsIWebNavigation> webNav =
Expand Down Expand Up @@ -4372,8 +4384,7 @@ nsDocument::GetWindowInternal() const
// the docshell, the outer window might be still obtainable from the it.
nsCOMPtr<nsPIDOMWindow> win;
if (mRemovedFromDocShell) {
nsCOMPtr<nsIInterfaceRequestor> requestor =
do_QueryReferent(mDocumentContainer);
nsCOMPtr<nsIInterfaceRequestor> requestor(mDocumentContainer);
if (requestor) {
// The docshell returns the outer window we are done.
win = do_GetInterface(requestor);
Expand Down Expand Up @@ -7800,7 +7811,7 @@ nsDocument::GetLayoutHistoryState() const
if (!mScriptGlobalObject) {
state = mLayoutHistoryState;
} else {
nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocumentContainer));
nsCOMPtr<nsIDocShell> docShell(mDocumentContainer);
if (docShell) {
docShell->GetLayoutHistoryState(getter_AddRefs(state));
}
Expand Down Expand Up @@ -8321,7 +8332,7 @@ nsDocument::CloneDocHelper(nsDocument* clone) const

// |mDocumentContainer| is the container of the document that is being
// created and not the original container. See CreateStaticClone function().
nsCOMPtr<nsIDocumentLoader> docLoader = do_QueryReferent(mDocumentContainer);
nsCOMPtr<nsIDocumentLoader> docLoader(mDocumentContainer);
if (docLoader) {
docLoader->GetLoadGroup(getter_AddRefs(loadGroup));
}
Expand All @@ -8334,8 +8345,7 @@ nsDocument::CloneDocHelper(nsDocument* clone) const
clone->ResetToURI(uri, loadGroup, NodePrincipal());
}
}
nsCOMPtr<nsISupports> container = GetContainer();
clone->SetContainer(container);
clone->SetContainer(mDocumentContainer);
}

// Set scripting object
Expand Down Expand Up @@ -8852,18 +8862,19 @@ nsIDocument::FlushPendingLinkUpdates()
}

already_AddRefed<nsIDocument>
nsIDocument::CreateStaticClone(nsISupports* aCloneContainer)
nsIDocument::CreateStaticClone(nsIDocShell* aCloneContainer)
{
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(this);
NS_ENSURE_TRUE(domDoc, nullptr);
mCreatingStaticClone = true;

// Make document use different container during cloning.
nsCOMPtr<nsISupports> originalContainer = GetContainer();
SetContainer(aCloneContainer);
nsCOMPtr<nsIDocShell> originalShell = do_QueryInterface(originalContainer);
SetContainer(static_cast<nsDocShell*>(aCloneContainer));
nsCOMPtr<nsIDOMNode> clonedNode;
nsresult rv = domDoc->CloneNode(true, 1, getter_AddRefs(clonedNode));
SetContainer(originalContainer);
SetContainer(static_cast<nsDocShell*>(originalShell.get()));

nsCOMPtr<nsIDocument> clonedDoc;
if (NS_SUCCEEDED(rv)) {
Expand Down Expand Up @@ -10531,7 +10542,7 @@ nsDocument::IsFullScreenEnabled(bool aCallerIsChrome, bool aLogFailure)

// Ensure that all ancestor <iframe> elements have the allowfullscreen
// boolean attribute set.
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocumentContainer);
nsCOMPtr<nsIDocShell> docShell(mDocumentContainer);
bool allowed = false;
if (docShell) {
docShell->GetFullscreenAllowed(&allowed);
Expand Down
5 changes: 3 additions & 2 deletions content/html/document/src/ImageDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "nsRect.h"
#include "nsIImageLoadingContent.h"
#include "nsGenericHTMLElement.h"
#include "nsDocShell.h"
#include "nsIDocumentInlines.h"
#include "nsDOMTokenList.h"
#include "nsIDOMHTMLImageElement.h"
Expand Down Expand Up @@ -763,7 +764,7 @@ ImageDocument::UpdateTitleAndCharset()
void
ImageDocument::ResetZoomLevel()
{
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocumentContainer);
nsCOMPtr<nsIDocShell> docShell(mDocumentContainer);
if (docShell) {
if (nsContentUtils::IsChildOfSameType(this)) {
return;
Expand All @@ -782,7 +783,7 @@ float
ImageDocument::GetZoomLevel()
{
float zoomLevel = mOriginalZoomLevel;
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocumentContainer);
nsCOMPtr<nsIDocShell> docShell(mDocumentContainer);
if (docShell) {
nsCOMPtr<nsIContentViewer> cv;
docShell->GetContentViewer(getter_AddRefs(cv));
Expand Down
1 change: 1 addition & 0 deletions content/html/document/src/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ LOCAL_INCLUDES += [
'/caps/include',
'/content/base/src',
'/content/events/src',
'/docshell/base',
'/dom/base',
'/layout/style',
'/xpcom/ds',
Expand Down
4 changes: 2 additions & 2 deletions content/html/document/src/nsHTMLDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "nsIContentViewerContainer.h"
#include "nsIContentViewer.h"
#include "nsIMarkupDocumentViewer.h"
#include "nsIDocShell.h"
#include "nsDocShell.h"
#include "nsDocShellLoadTypes.h"
#include "nsIWebNavigation.h"
#include "nsIBaseWindow.h"
Expand Down Expand Up @@ -1362,7 +1362,7 @@ nsHTMLDocument::Open(JSContext* cx,
}

// check whether we're in the middle of unload. If so, ignore this call.
nsCOMPtr<nsIDocShell> shell = do_QueryReferent(mDocumentContainer);
nsCOMPtr<nsIDocShell> shell(mDocumentContainer);
if (!shell) {
// We won't be able to create a parser anyway.
nsCOMPtr<nsIDocument> ret = this;
Expand Down
4 changes: 2 additions & 2 deletions content/xul/document/src/XULDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include "nsIRDFService.h"
#include "nsIStreamListener.h"
#include "nsITimer.h"
#include "nsIDocShell.h"
#include "nsDocShell.h"
#include "nsGkAtoms.h"
#include "nsXMLContentSink.h"
#include "nsXULContentSink.h"
Expand Down Expand Up @@ -4660,7 +4660,7 @@ XULDocument::ParserObserver::OnStopRequest(nsIRequest *request,
already_AddRefed<nsPIWindowRoot>
XULDocument::GetWindowRoot()
{
nsCOMPtr<nsIInterfaceRequestor> ir = do_QueryReferent(mDocumentContainer);
nsCOMPtr<nsIInterfaceRequestor> ir(mDocumentContainer);
nsCOMPtr<nsIDOMWindow> window(do_GetInterface(ir));
nsCOMPtr<nsPIDOMWindow> piWin(do_QueryInterface(window));
return piWin ? piWin->GetTopWindowRoot() : nullptr;
Expand Down
1 change: 1 addition & 0 deletions content/xul/document/src/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ LOCAL_INCLUDES += [
'/content/xml/document/src',
'/content/xul/content/src',
'/content/xul/templates/src',
'/docshell/base',
'/dom/base',
'/layout/base',
'/layout/generic',
Expand Down
10 changes: 5 additions & 5 deletions docshell/base/nsDocShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7259,7 +7259,7 @@ nsDocShell::CreateAboutBlankContentViewer(nsIPrincipal* aPrincipal,
// got Reset() with a channel.
blankDoc->SetBaseURI(aBaseURI);

blankDoc->SetContainer(static_cast<nsIDocShell *>(this));
blankDoc->SetContainer(this);

// Copy our sandbox flags to the document. These are immutable
// after being set here.
Expand All @@ -7271,7 +7271,7 @@ nsDocShell::CreateAboutBlankContentViewer(nsIPrincipal* aPrincipal,

// hook 'em up
if (viewer) {
viewer->SetContainer(static_cast<nsIContentViewerContainer *>(this));
viewer->SetContainer(this);
Embed(viewer, "", 0);

SetCurrentURI(blankDoc->GetDocumentURI(), nullptr, true, 0);
Expand Down Expand Up @@ -7607,7 +7607,7 @@ nsDocShell::RestorePresentation(nsISHEntry *aSHEntry, bool *aRestoring)
// different one. We don't currently support restoring the presentation
// in that case.

nsCOMPtr<nsISupports> container;
nsCOMPtr<nsIDocShell> container;
viewer->GetContainer(getter_AddRefs(container));
if (!::SameCOMIdentity(container, GetAsSupports(this))) {
#ifdef DEBUG_PAGE_CACHE
Expand Down Expand Up @@ -8333,13 +8333,13 @@ nsDocShell::NewContentViewerObj(const char *aContentType,
nsresult rv = docLoaderFactory->CreateInstance("view",
aOpenedChannel,
aLoadGroup, aContentType,
static_cast<nsIContentViewerContainer*>(this),
this,
nullptr,
aContentHandler,
aViewer);
NS_ENSURE_SUCCESS(rv, rv);

(*aViewer)->SetContainer(static_cast<nsIContentViewerContainer *>(this));
(*aViewer)->SetContainer(this);
return NS_OK;
}

Expand Down
4 changes: 3 additions & 1 deletion docshell/base/nsDocShell.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "nsIContentViewerContainer.h"
#include "nsIDOMStorageManager.h"
#include "nsDocLoader.h"
#include "mozilla/WeakPtr.h"

// Helper Classes
#include "nsCOMPtr.h"
Expand Down Expand Up @@ -137,7 +138,8 @@ class nsDocShell : public nsDocLoader,
public nsIWebShellServices,
public nsILinkHandler,
public nsIClipboardCommands,
public nsIDOMStorageManager
public nsIDOMStorageManager,
public mozilla::SupportsWeakPtr<nsDocShell>
{
friend class nsDSURIContentListener;

Expand Down
Loading

0 comments on commit 830c054

Please sign in to comment.