From 088fe2bf42ad46089188ece9d5852004f7518b52 Mon Sep 17 00:00:00 2001 From: Trevor Saunders Date: Fri, 15 Nov 2013 02:12:43 -0500 Subject: [PATCH 01/92] bug 939049 - staticly type nsIDocument::mDocumentContainer and nsDocumentViewerContainer::mContainer r=smaug --- content/base/public/nsIDocument.h | 15 ++-- content/base/src/moz.build | 1 + content/base/src/nsDocument.cpp | 79 +++++++++++-------- content/html/document/src/ImageDocument.cpp | 5 +- content/html/document/src/moz.build | 1 + content/html/document/src/nsHTMLDocument.cpp | 4 +- content/xul/document/src/XULDocument.cpp | 4 +- content/xul/document/src/moz.build | 1 + docshell/base/nsDocShell.cpp | 10 +-- docshell/base/nsDocShell.h | 4 +- docshell/base/nsIContentViewer.idl | 3 +- docshell/base/nsIDocumentLoaderFactory.idl | 5 +- docshell/shistory/src/nsSHEntryShared.cpp | 3 +- layout/base/moz.build | 3 + layout/base/nsDocumentViewer.cpp | 77 +++++++++--------- layout/build/moz.build | 3 + layout/build/nsContentDLF.cpp | 11 +-- layout/build/nsContentDLF.h | 4 +- layout/printing/nsPrintEngine.cpp | 4 +- layout/printing/nsPrintEngine.h | 2 +- .../prefetch/nsOfflineCacheUpdateService.cpp | 4 +- .../directory/nsDirectoryViewer.cpp | 3 +- 22 files changed, 138 insertions(+), 108 deletions(-) diff --git a/content/base/public/nsIDocument.h b/content/base/public/nsIDocument.h index 1e94bb1fea7..4ac7ced9144 100644 --- a/content/base/public/nsIDocument.h +++ b/content/base/public/nsIDocument.h @@ -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" @@ -28,6 +29,8 @@ class imgIRequest; class nsAString; class nsBindingManager; class nsCSSStyleSheet; +class nsIDocShell; +class nsDocShell; class nsDOMNavigationTiming; class nsDOMTouchList; class nsEventStates; @@ -1150,16 +1153,12 @@ public: * 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 GetContainer() const - { - nsCOMPtr container = do_QueryReferent(mDocumentContainer); - return container.forget(); - } + nsISupports* GetContainer() const; /** * Get the container's load context for this document. @@ -1696,7 +1695,7 @@ public: * @param aCloneContainer The container for the clone document. */ virtual already_AddRefed - CreateStaticClone(nsISupports* aCloneContainer); + CreateStaticClone(nsIDocShell* aCloneContainer); /** * If this document is a static clone, this returns the original @@ -2227,7 +2226,7 @@ protected: nsWeakPtr mDocumentLoadGroup; - nsWeakPtr mDocumentContainer; + mozilla::WeakPtr mDocumentContainer; nsCString mCharacterSet; int32_t mCharacterSetSource; diff --git a/content/base/src/moz.build b/content/base/src/moz.build index 8b46268ee07..a882fb892e3 100644 --- a/content/base/src/moz.build +++ b/content/base/src/moz.build @@ -193,6 +193,7 @@ LOCAL_INCLUDES += [ '/content/xslt/src/xpath', '/content/xul/content/src', '/content/xul/document/src', + '/docshell/base', '/dom/base', '/dom/ipc', '/dom/workers', diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index 6b5feb2e73f..b08e2f42409 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -33,7 +33,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" @@ -2203,7 +2203,7 @@ nsDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup, nsIScriptSecurityManager *securityManager = nsContentUtils::GetSecurityManager(); if (securityManager) { - nsCOMPtr docShell = do_QueryReferent(mDocumentContainer); + nsCOMPtr docShell(mDocumentContainer); if (!docShell && aLoadGroup) { nsCOMPtr cbs; @@ -2699,7 +2699,7 @@ nsDocument::InitCSP(nsIChannel* aChannel) } // ----- Enforce frame-ancestor policy on any applied policies - nsCOMPtr docShell = do_QueryReferent(mDocumentContainer); + nsCOMPtr docShell(mDocumentContainer); if (docShell) { bool safeAncestry = false; @@ -2930,7 +2930,7 @@ nsresult nsDocument::GetAllowPlugins(bool * aAllowPlugins) { // First, we ask our docshell if it allows plugins. - nsCOMPtr docShell = do_QueryReferent(mDocumentContainer); + nsCOMPtr docShell(mDocumentContainer); if (docShell) { docShell->GetAllowPlugins(aAllowPlugins); @@ -3398,7 +3398,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 refresher = do_QueryReferent(mDocumentContainer); + nsCOMPtr 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 @@ -3479,7 +3479,7 @@ nsDocument::doCreateShell(nsPresContext* aContext, mPresShell = shell; // Make sure to never paint if we belong to an invisible DocShell. - nsCOMPtr docShell = do_QueryReferent(mDocumentContainer); + nsCOMPtr docShell(mDocumentContainer); if (docShell && docShell->IsInvisible()) shell->SetNeverPainting(true); @@ -4192,29 +4192,41 @@ NotifyActivityChanged(nsIContent *aContent, void *aUnused) } void -nsIDocument::SetContainer(nsISupports* aContainer) +nsIDocument::SetContainer(nsDocShell* aContainer) { - mDocumentContainer = do_GetWeakReference(aContainer); - EnumerateFreezableElements(NotifyActivityChanged, nullptr); - // Get the Docshell - nsCOMPtr docShell = do_QueryInterface(aContainer); - if (docShell) { - int32_t itemType; - docShell->GetItemType(&itemType); - // check itemtype - if (itemType == nsIDocShellTreeItem::typeContent) { - // check if same type root - nsCOMPtr sameTypeRoot; - docShell->GetSameTypeRootTreeItem(getter_AddRefs(sameTypeRoot)); - NS_ASSERTION(sameTypeRoot, "No document shell root tree item from document shell tree item!"); + if (aContainer) { + mDocumentContainer = aContainer->asWeakPtr(); + } else { + mDocumentContainer = WeakPtr(); + } - if (sameTypeRoot == docShell) { - static_cast(this)->SetIsTopLevelContentDocument(true); - } + EnumerateFreezableElements(NotifyActivityChanged, nullptr); + if (!aContainer) { + return; + } + + // Get the Docshell + int32_t itemType; + aContainer->GetItemType(&itemType); + // check itemtype + if (itemType == nsIDocShellTreeItem::typeContent) { + // check if same type root + nsCOMPtr 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(this)->SetIsTopLevelContentDocument(true); } } } +nsISupports* +nsIDocument::GetContainer() const +{ + return static_cast(mDocumentContainer); +} + void nsDocument::SetScriptGlobalObject(nsIScriptGlobalObject *aScriptGlobalObject) { @@ -4272,7 +4284,7 @@ nsDocument::SetScriptGlobalObject(nsIScriptGlobalObject *aScriptGlobalObject) #endif if (mAllowDNSPrefetch) { - nsCOMPtr docShell = do_QueryReferent(mDocumentContainer); + nsCOMPtr docShell(mDocumentContainer); if (docShell) { #ifdef DEBUG nsCOMPtr webNav = @@ -4371,8 +4383,7 @@ nsDocument::GetWindowInternal() const // the docshell, the outer window might be still obtainable from the it. nsCOMPtr win; if (mRemovedFromDocShell) { - nsCOMPtr requestor = - do_QueryReferent(mDocumentContainer); + nsCOMPtr requestor(mDocumentContainer); if (requestor) { // The docshell returns the outer window we are done. win = do_GetInterface(requestor); @@ -7799,7 +7810,7 @@ nsDocument::GetLayoutHistoryState() const if (!mScriptGlobalObject) { state = mLayoutHistoryState; } else { - nsCOMPtr docShell(do_QueryReferent(mDocumentContainer)); + nsCOMPtr docShell(mDocumentContainer); if (docShell) { docShell->GetLayoutHistoryState(getter_AddRefs(state)); } @@ -8320,7 +8331,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 docLoader = do_QueryReferent(mDocumentContainer); + nsCOMPtr docLoader(mDocumentContainer); if (docLoader) { docLoader->GetLoadGroup(getter_AddRefs(loadGroup)); } @@ -8333,8 +8344,7 @@ nsDocument::CloneDocHelper(nsDocument* clone) const clone->ResetToURI(uri, loadGroup, NodePrincipal()); } } - nsCOMPtr container = GetContainer(); - clone->SetContainer(container); + clone->SetContainer(mDocumentContainer); } // Set scripting object @@ -8845,7 +8855,7 @@ nsIDocument::FlushPendingLinkUpdates() } already_AddRefed -nsIDocument::CreateStaticClone(nsISupports* aCloneContainer) +nsIDocument::CreateStaticClone(nsIDocShell* aCloneContainer) { nsCOMPtr domDoc = do_QueryInterface(this); NS_ENSURE_TRUE(domDoc, nullptr); @@ -8853,10 +8863,11 @@ nsIDocument::CreateStaticClone(nsISupports* aCloneContainer) // Make document use different container during cloning. nsCOMPtr originalContainer = GetContainer(); - SetContainer(aCloneContainer); + nsCOMPtr originalShell = do_QueryInterface(originalContainer); + SetContainer(static_cast(aCloneContainer)); nsCOMPtr clonedNode; nsresult rv = domDoc->CloneNode(true, 1, getter_AddRefs(clonedNode)); - SetContainer(originalContainer); + SetContainer(static_cast(originalShell.get())); nsCOMPtr clonedDoc; if (NS_SUCCEEDED(rv)) { @@ -10524,7 +10535,7 @@ nsDocument::IsFullScreenEnabled(bool aCallerIsChrome, bool aLogFailure) // Ensure that all ancestor