diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index ff96474c76ac..2b14a2e1d8fc 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -11066,14 +11066,7 @@ nsDocShell::AddState(JS::Handle aData, const nsAString& aTitle, } } else { // It's a file:// URI - nsCOMPtr docScriptObj = - do_QueryInterface(document); - - if (!docScriptObj) { - return NS_ERROR_DOM_SECURITY_ERR; - } - - nsCOMPtr principal = docScriptObj->GetPrincipal(); + nsCOMPtr principal = document->GetPrincipal(); if (!principal || NS_FAILED(principal->CheckMayLoad(newURI, true, false))) { diff --git a/dom/animation/AnimationEffect.h b/dom/animation/AnimationEffect.h index 8a1ecbf0bc94..9f888fac6818 100644 --- a/dom/animation/AnimationEffect.h +++ b/dom/animation/AnimationEffect.h @@ -41,7 +41,7 @@ class AnimationEffect : public nsISupports, public nsWrapperCache { return nullptr; } - nsISupports* GetParentObject() const { return mDocument; } + nsISupports* GetParentObject() const { return ToSupports(mDocument); } bool IsCurrent() const; bool IsInEffect() const; diff --git a/dom/animation/AnimationTimeline.cpp b/dom/animation/AnimationTimeline.cpp index 0181d4f3d0c4..950c10057957 100644 --- a/dom/animation/AnimationTimeline.cpp +++ b/dom/animation/AnimationTimeline.cpp @@ -11,6 +11,8 @@ namespace mozilla { namespace dom { +AnimationTimeline::~AnimationTimeline() { mAnimationOrder.clear(); } + NS_IMPL_CYCLE_COLLECTION_CLASS(AnimationTimeline) NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(AnimationTimeline) diff --git a/dom/animation/AnimationTimeline.h b/dom/animation/AnimationTimeline.h index 391c616eab0e..dc58096f345c 100644 --- a/dom/animation/AnimationTimeline.h +++ b/dom/animation/AnimationTimeline.h @@ -31,7 +31,7 @@ class AnimationTimeline : public nsISupports, public nsWrapperCache { } protected: - virtual ~AnimationTimeline() { mAnimationOrder.clear(); } + virtual ~AnimationTimeline(); public: NS_DECL_CYCLE_COLLECTING_ISUPPORTS diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index dc763513db3f..ff3b92147a19 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -19,6 +19,7 @@ #include "mozilla/dom/Attr.h" #include "mozilla/dom/Flex.h" #include "mozilla/dom/Grid.h" +#include "mozilla/dom/ScriptLoader.h" #include "mozilla/dom/Text.h" #include "mozilla/gfx/Matrix.h" #include "nsAtom.h" diff --git a/dom/base/FragmentOrElement.cpp b/dom/base/FragmentOrElement.cpp index ff6e959576a6..53dbe3b22d50 100644 --- a/dom/base/FragmentOrElement.cpp +++ b/dom/base/FragmentOrElement.cpp @@ -31,6 +31,7 @@ #include "nsAtom.h" #include "mozilla/dom/NodeInfo.h" #include "mozilla/dom/Event.h" +#include "mozilla/dom/ScriptLoader.h" #include "mozilla/dom/TouchEvent.h" #include "nsIDocumentInlines.h" #include "nsIDocumentEncoder.h" diff --git a/dom/base/nsContentSink.cpp b/dom/base/nsContentSink.cpp index 1e39dfa9c878..07cc38695ab1 100644 --- a/dom/base/nsContentSink.cpp +++ b/dom/base/nsContentSink.cpp @@ -911,11 +911,6 @@ nsresult nsContentSink::SelectDocAppCache( *aAction = CACHE_SELECTION_NONE; - nsCOMPtr applicationCacheDocument = - do_QueryInterface(mDocument); - NS_ASSERTION(applicationCacheDocument, - "mDocument must implement nsIApplicationCacheContainer."); - if (aLoadApplicationCache) { nsCOMPtr groupURI; rv = aLoadApplicationCache->GetManifestURI(getter_AddRefs(groupURI)); @@ -944,7 +939,7 @@ nsresult nsContentSink::SelectDocAppCache( clientID.get(), docURISpec.get())); #endif - rv = applicationCacheDocument->SetApplicationCache(aLoadApplicationCache); + rv = mDocument->SetApplicationCache(aLoadApplicationCache); NS_ENSURE_SUCCESS(rv, rv); // Document will be added as implicit entry to the cache as part of @@ -981,11 +976,6 @@ nsresult nsContentSink::SelectDocAppCacheNoManifest( if (aLoadApplicationCache) { // The document was loaded from an application cache, use that // application cache as the document's application cache. - nsCOMPtr applicationCacheDocument = - do_QueryInterface(mDocument); - NS_ASSERTION(applicationCacheDocument, - "mDocument must implement nsIApplicationCacheContainer."); - #ifdef DEBUG nsAutoCString docURISpec, clientID; mDocumentURI->GetAsciiSpec(docURISpec); @@ -996,7 +986,7 @@ nsresult nsContentSink::SelectDocAppCacheNoManifest( clientID.get(), docURISpec.get())); #endif - rv = applicationCacheDocument->SetApplicationCache(aLoadApplicationCache); + rv = mDocument->SetApplicationCache(aLoadApplicationCache); NS_ENSURE_SUCCESS(rv, rv); // Return the uri and invoke the update process for the selected @@ -1563,13 +1553,13 @@ void nsContentSink::NotifyDocElementCreated(nsIDocument* aDoc) { nsCOMPtr observerService = mozilla::services::GetObserverService(); if (observerService) { - observerService->NotifyObservers(aDoc, "document-element-inserted", - EmptyString().get()); + observerService->NotifyObservers( + ToSupports(aDoc), "document-element-inserted", EmptyString().get()); } nsContentUtils::DispatchChromeEvent( - aDoc, aDoc, NS_LITERAL_STRING("DOMDocElementInserted"), CanBubble::eYes, - Cancelable::eNo); + aDoc, ToSupports(aDoc), NS_LITERAL_STRING("DOMDocElementInserted"), + CanBubble::eYes, Cancelable::eNo); } NS_IMETHODIMP diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index d6413bc45641..e402f7c75d70 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -9,6 +9,7 @@ #include "mozilla/layers/CompositorBridgeChild.h" #include "mozilla/layers/LayerTransactionChild.h" #include "nsPresContext.h" +#include "nsContentList.h" #include "nsError.h" #include "nsQueryContentEventResult.h" #include "nsGlobalWindow.h" diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 80a720503aae..daf8044c1fd6 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -43,6 +43,7 @@ #include "nsCSSPseudoElements.h" #include "nsIObserver.h" #include "nsIBaseWindow.h" +#include "nsILayoutHistoryState.h" #include "mozilla/css/Loader.h" #include "mozilla/css/ImageLoader.h" #include "nsDocShell.h" @@ -59,6 +60,7 @@ #include "mozilla/EventListenerManager.h" #include "mozilla/EventStateManager.h" #include "mozilla/FullscreenChange.h" +#include "mozilla/PendingAnimationTracker.h" #include "mozilla/dom/Attr.h" #include "mozilla/dom/BindingDeclarations.h" @@ -69,7 +71,10 @@ #include "mozilla/dom/FramingChecker.h" #include "mozilla/dom/HTMLSharedElement.h" #include "mozilla/dom/Navigator.h" +#include "mozilla/dom/Performance.h" #include "mozilla/dom/ServiceWorkerContainer.h" +#include "mozilla/dom/ScriptLoader.h" +#include "mozilla/dom/StyleSheetList.h" #include "mozilla/dom/SVGUseElement.h" #include "nsGenericHTMLElement.h" #include "mozilla/dom/CDATASection.h" @@ -673,7 +678,17 @@ class SubDocMapEntry : public PLDHashEntryHdr { nsIDocument* mSubDocument; }; -// nsOnloadBlocker implementation +class nsOnloadBlocker final : public nsIRequest { + public: + nsOnloadBlocker() {} + + NS_DECL_ISUPPORTS + NS_DECL_NSIREQUEST + + private: + ~nsOnloadBlocker() {} +}; + NS_IMPL_ISUPPORTS(nsOnloadBlocker, nsIRequest) NS_IMETHODIMP @@ -792,7 +807,7 @@ void nsExternalResourceMap::Traverse( NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*aCallback, "mExternalResourceMap.mMap entry" "->mDocument"); - aCallback->NoteXPCOMChild(resource->mDocument); + aCallback->NoteXPCOMChild(ToSupports(resource->mDocument)); NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*aCallback, "mExternalResourceMap.mMap entry" @@ -899,7 +914,8 @@ nsresult nsExternalResourceMap::AddExternalResource( const nsTArray>& obs = load->Observers(); for (uint32_t i = 0; i < obs.Length(); ++i) { - obs[i]->Observe(doc, "external-resource-document-created", nullptr); + obs[i]->Observe(ToSupports(doc), "external-resource-document-created", + nullptr); } return rv; @@ -1624,31 +1640,31 @@ nsDocument::~nsDocument() { mPlugins.Clear(); } -NS_INTERFACE_TABLE_HEAD(nsDocument) +NS_INTERFACE_TABLE_HEAD(nsIDocument) NS_WRAPPERCACHE_INTERFACE_TABLE_ENTRY NS_INTERFACE_TABLE_BEGIN - NS_INTERFACE_TABLE_ENTRY_AMBIGUOUS(nsDocument, nsISupports, nsINode) - NS_INTERFACE_TABLE_ENTRY(nsDocument, nsINode) - NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIDocument) - NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIScriptObjectPrincipal) - NS_INTERFACE_TABLE_ENTRY(nsDocument, mozilla::dom::EventTarget) - NS_INTERFACE_TABLE_ENTRY(nsDocument, nsISupportsWeakReference) - NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIRadioGroupContainer) - NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIMutationObserver) - NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIApplicationCacheContainer) + NS_INTERFACE_TABLE_ENTRY_AMBIGUOUS(nsIDocument, nsISupports, nsINode) + NS_INTERFACE_TABLE_ENTRY(nsIDocument, nsINode) + NS_INTERFACE_TABLE_ENTRY(nsIDocument, nsIDocument) + NS_INTERFACE_TABLE_ENTRY(nsIDocument, nsIScriptObjectPrincipal) + NS_INTERFACE_TABLE_ENTRY(nsIDocument, mozilla::dom::EventTarget) + NS_INTERFACE_TABLE_ENTRY(nsIDocument, nsISupportsWeakReference) + NS_INTERFACE_TABLE_ENTRY(nsIDocument, nsIRadioGroupContainer) + NS_INTERFACE_TABLE_ENTRY(nsIDocument, nsIMutationObserver) + NS_INTERFACE_TABLE_ENTRY(nsIDocument, nsIApplicationCacheContainer) NS_INTERFACE_TABLE_END - NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(nsDocument) + NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(nsIDocument) NS_INTERFACE_MAP_END -NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDocument) +NS_IMPL_CYCLE_COLLECTING_ADDREF(nsIDocument) NS_IMETHODIMP_(MozExternalRefCountType) -nsDocument::Release() { +nsIDocument::Release() { MOZ_ASSERT(0 != mRefCnt, "dup release"); - NS_ASSERT_OWNINGTHREAD(nsDocument); - nsISupports* base = NS_CYCLE_COLLECTION_CLASSNAME(nsDocument)::Upcast(this); + NS_ASSERT_OWNINGTHREAD(nsIDocument); + nsISupports* base = NS_CYCLE_COLLECTION_CLASSNAME(nsIDocument)::Upcast(this); bool shouldDelete = false; nsrefcnt count = mRefCnt.decr(base, &shouldDelete); - NS_LOG_RELEASE(this, count, "nsDocument"); + NS_LOG_RELEASE(this, count, "nsIDocument"); if (count == 0) { if (mStackRefCnt && !mNeedsReleaseAfterStackRefCntRelease) { mNeedsReleaseAfterStackRefCntRelease = true; @@ -1667,9 +1683,9 @@ nsDocument::Release() { } NS_IMETHODIMP_(void) -nsDocument::DeleteCycleCollectable() { delete this; } +nsIDocument::DeleteCycleCollectable() { delete this; } -NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsDocument) +NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsIDocument) if (Element::CanSkip(tmp, aRemovingAllowed)) { EventListenerManager* elm = tmp->GetExistingListenerManager(); if (elm) { @@ -1679,11 +1695,11 @@ NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsDocument) } NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END -NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(nsDocument) +NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(nsIDocument) return Element::CanSkipInCC(tmp); NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_END -NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_BEGIN(nsDocument) +NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_BEGIN(nsIDocument) return Element::CanSkipThis(tmp); NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_END @@ -1691,7 +1707,7 @@ static const char* kNSURIs[] = {"([none])", "(xmlns)", "(xml)", "(xhtml)", "(XLink)", "(XSLT)", "(XBL)", "(MathML)", "(RDF)", "(XUL)"}; -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsDocument) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsIDocument) if (MOZ_UNLIKELY(cb.WantDebugInfo())) { char name[512]; nsAutoCString loadedAsData; @@ -1704,14 +1720,14 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsDocument) nsAutoCString uri; if (tmp->mDocumentURI) uri = tmp->mDocumentURI->GetSpecOrDefault(); if (nsid < ArrayLength(kNSURIs)) { - SprintfLiteral(name, "nsDocument %s %s %s", loadedAsData.get(), + SprintfLiteral(name, "nsIDocument %s %s %s", loadedAsData.get(), kNSURIs[nsid], uri.get()); } else { - SprintfLiteral(name, "nsDocument %s %s", loadedAsData.get(), uri.get()); + SprintfLiteral(name, "nsIDocument %s %s", loadedAsData.get(), uri.get()); } cb.DescribeRefCountedNode(tmp->mRefCnt.get(), name); } else { - NS_IMPL_CYCLE_COLLECTION_DESCRIBE(nsDocument, tmp->mRefCnt.get()) + NS_IMPL_CYCLE_COLLECTION_DESCRIBE(nsIDocument, tmp->mRefCnt.get()) } if (!nsINode::Traverse(tmp, cb)) { @@ -1760,7 +1776,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsDocument) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChannel) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLayoutHistoryState) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOnloadBlocker) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFirstBaseNodeWithHref) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDOMImplementation) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mImageMaps) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOrientationPendingPromise) @@ -1804,7 +1819,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsDocument) cb.NoteXPCOMChild(entry->mKey); NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSubDocuments entry->mSubDocument"); - cb.NoteXPCOMChild(entry->mSubDocument); + cb.NoteXPCOMChild(ToSupports(entry->mSubDocument)); } } @@ -1823,11 +1838,11 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsDocument) } NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END -NS_IMPL_CYCLE_COLLECTION_CLASS(nsDocument) +NS_IMPL_CYCLE_COLLECTION_CLASS(nsIDocument) -NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(nsDocument) +NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(nsIDocument) -NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDocument) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsIDocument) tmp->mInUnlinkOrDeletion = true; // Clear out our external resources @@ -1840,7 +1855,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDocument) while (tmp->HasChildren()) { // Hold a strong ref to the node when we remove it, because we may be // the last reference to it. - // If this code changes, change the corresponding code in nsDocument's + // If this code changes, change the corresponding code in nsIDocument's // unlink impl and ContentUnbinder::UnbindSubtree. nsCOMPtr child = tmp->GetLastChild(); tmp->DisconnectChild(child); @@ -1851,7 +1866,6 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDocument) tmp->mCachedRootElement = nullptr; // Avoid a dangling pointer NS_IMPL_CYCLE_COLLECTION_UNLINK(mDisplayDocument) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mFirstBaseNodeWithHref) NS_IMPL_CYCLE_COLLECTION_UNLINK(mMaybeEndOutermostXBLUpdateRunner) NS_IMPL_CYCLE_COLLECTION_UNLINK(mDOMImplementation) NS_IMPL_CYCLE_COLLECTION_UNLINK(mImageMaps) @@ -1905,7 +1919,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDocument) DocumentOrShadowRoot::Unlink(tmp); - // nsDocument has a pretty complex destructor, so we're going to + // nsIDocument has a pretty complex destructor, so we're going to // assume that *most* cycles you actually want to break somewhere // else, and not unlink an awful lot here. @@ -1936,7 +1950,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDocument) tmp->mInUnlinkOrDeletion = false; NS_IMPL_CYCLE_COLLECTION_UNLINK_END -nsresult nsDocument::Init() { +nsresult nsIDocument::Init() { if (mCSSLoader || mStyleImageLoader || mNodeInfoManager || mScriptLoader) { return NS_ERROR_ALREADY_INITIALIZED; } @@ -2461,18 +2475,18 @@ bool nsIDocument::IsSynthesized() { } // static -bool nsDocument::IsCallerChromeOrAddon(JSContext* aCx, JSObject* aObject) { +bool nsIDocument::IsCallerChromeOrAddon(JSContext* aCx, JSObject* aObject) { nsIPrincipal* principal = nsContentUtils::SubjectPrincipal(aCx); return principal && (nsContentUtils::IsSystemPrincipal(principal) || principal->GetIsAddonOrExpandedAddonPrincipal()); } -nsresult nsDocument::StartDocumentLoad(const char* aCommand, - nsIChannel* aChannel, - nsILoadGroup* aLoadGroup, - nsISupports* aContainer, - nsIStreamListener** aDocListener, - bool aReset, nsIContentSink* aSink) { +nsresult nsIDocument::StartDocumentLoad(const char* aCommand, + nsIChannel* aChannel, + nsILoadGroup* aLoadGroup, + nsISupports* aContainer, + nsIStreamListener** aDocListener, + bool aReset, nsIContentSink* aSink) { if (MOZ_LOG_TEST(gDocumentLeakPRLog, LogLevel::Debug)) { nsCOMPtr uri; aChannel->GetURI(getter_AddRefs(uri)); @@ -2870,7 +2884,7 @@ nsresult nsIDocument::InitFeaturePolicy(nsIChannel* aChannel) { return NS_OK; } -void nsDocument::StopDocumentLoad() { +void nsIDocument::StopDocumentLoad() { if (mParser) { mParserAborted = true; mParser->Terminate(); @@ -2936,7 +2950,7 @@ void nsIDocument::GetLastModified(nsAString& aLastModified) const { } static void IncrementExpandoGeneration(nsIDocument& aDoc) { - ++static_cast(aDoc).mExpandoAndGeneration.generation; + ++aDoc.mExpandoAndGeneration.generation; } void nsIDocument::AddToNameTable(Element* aElement, nsAtom* aName) { @@ -3008,8 +3022,6 @@ void nsIDocument::RemoveFromIdTable(Element* aElement, nsAtom* aId) { } } -nsIPrincipal* nsDocument::GetPrincipal() { return NodePrincipal(); } - extern bool sDisablePrefetchHTTPSPref; void nsIDocument::SetPrincipal(nsIPrincipal* aNewPrincipal) { @@ -3096,16 +3108,14 @@ bool nsIDocument::IsScriptTracking(const nsACString& aURL) const { } NS_IMETHODIMP -nsDocument::GetApplicationCache(nsIApplicationCache** aApplicationCache) { +nsIDocument::GetApplicationCache(nsIApplicationCache** aApplicationCache) { NS_IF_ADDREF(*aApplicationCache = mApplicationCache); - return NS_OK; } NS_IMETHODIMP -nsDocument::SetApplicationCache(nsIApplicationCache* aApplicationCache) { +nsIDocument::SetApplicationCache(nsIApplicationCache* aApplicationCache) { mApplicationCache = aApplicationCache; - return NS_OK; } @@ -3153,7 +3163,7 @@ void nsIDocument::InitializeLocalization(nsTArray& aResourceIds) { DocumentL10n* nsIDocument::GetL10n() { return mDocumentL10n; } -bool nsDocument::DocumentSupportsL10n(JSContext* aCx, JSObject* aObject) { +bool nsIDocument::DocumentSupportsL10n(JSContext* aCx, JSObject* aObject) { nsCOMPtr callerPrincipal = nsContentUtils::SubjectPrincipal(aCx); return PrincipalAllowsL10n(callerPrincipal); @@ -3232,22 +3242,22 @@ void nsIDocument::TriggerInitialDocumentTranslation() { } } -bool nsDocument::IsWebAnimationsEnabled(JSContext* aCx, JSObject* /*unused*/) { +bool nsIDocument::IsWebAnimationsEnabled(JSContext* aCx, JSObject* /*unused*/) { MOZ_ASSERT(NS_IsMainThread()); return nsContentUtils::IsSystemCaller(aCx) || nsContentUtils::AnimationsAPICoreEnabled(); } -bool nsDocument::IsWebAnimationsEnabled(CallerType aCallerType) { +bool nsIDocument::IsWebAnimationsEnabled(CallerType aCallerType) { MOZ_ASSERT(NS_IsMainThread()); return aCallerType == dom::CallerType::System || nsContentUtils::AnimationsAPICoreEnabled(); } -bool nsDocument::IsWebAnimationsGetAnimationsEnabled(JSContext* aCx, - JSObject* /*unused*/ +bool nsIDocument::IsWebAnimationsGetAnimationsEnabled(JSContext* aCx, + JSObject* /*unused*/ ) { MOZ_ASSERT(NS_IsMainThread()); @@ -3255,8 +3265,8 @@ bool nsDocument::IsWebAnimationsGetAnimationsEnabled(JSContext* aCx, StaticPrefs::dom_animations_api_getAnimations_enabled(); } -bool nsDocument::AreWebAnimationsImplicitKeyframesEnabled(JSContext* aCx, - JSObject* /*unused*/ +bool nsIDocument::AreWebAnimationsImplicitKeyframesEnabled(JSContext* aCx, + JSObject* /*unused*/ ) { MOZ_ASSERT(NS_IsMainThread()); @@ -3264,8 +3274,8 @@ bool nsDocument::AreWebAnimationsImplicitKeyframesEnabled(JSContext* aCx, StaticPrefs::dom_animations_api_implicit_keyframes_enabled(); } -bool nsDocument::AreWebAnimationsTimelinesEnabled(JSContext* aCx, - JSObject* /*unused*/ +bool nsIDocument::AreWebAnimationsTimelinesEnabled(JSContext* aCx, + JSObject* /*unused*/ ) { MOZ_ASSERT(NS_IsMainThread()); @@ -3580,10 +3590,10 @@ void nsIDocument::SetHeaderData(nsAtom* aHeaderField, const nsAString& aData) { } } } -void nsDocument::TryChannelCharset(nsIChannel* aChannel, - int32_t& aCharsetSource, - NotNull& aEncoding, - nsHtml5TreeOpExecutor* aExecutor) { +void nsIDocument::TryChannelCharset(nsIChannel* aChannel, + int32_t& aCharsetSource, + NotNull& aEncoding, + nsHtml5TreeOpExecutor* aExecutor) { if (aChannel) { nsAutoCString charsetVal; nsresult rv = aChannel->GetContentCharset(charsetVal); @@ -4094,7 +4104,7 @@ void nsIDocument::NotifyStyleSheetApplicableStateChanged() { mozilla::services::GetObserverService(); if (observerService) { observerService->NotifyObservers( - this, "style-sheet-applicable-state-changed", nullptr); + ToSupports(this), "style-sheet-applicable-state-changed", nullptr); } } @@ -4345,10 +4355,10 @@ void nsIDocument::SetContainer(nsDocShell* aContainer) { "No document shell root tree item from document shell tree item!"); if (sameTypeRoot == aContainer) { - static_cast(this)->SetIsTopLevelContentDocument(true); + SetIsTopLevelContentDocument(true); } - static_cast(this)->SetIsContentDocument(true); + SetIsContentDocument(true); } mAncestorPrincipals = aContainer->AncestorPrincipals(); @@ -4636,7 +4646,7 @@ void nsIDocument::BeginUpdate() { NS_DOCUMENT_NOTIFY_OBSERVERS(BeginUpdate, (this)); } -void nsDocument::EndUpdate() { +void nsIDocument::EndUpdate() { NS_DOCUMENT_NOTIFY_OBSERVERS(EndUpdate, (this)); nsContentUtils::RemoveScriptBlocker(); @@ -4653,7 +4663,7 @@ void nsDocument::EndUpdate() { } } -void nsDocument::BeginLoad() { +void nsIDocument::BeginLoad() { MOZ_ASSERT(!mDidCallBeginLoad); mDidCallBeginLoad = true; @@ -4706,7 +4716,7 @@ void nsIDocument::DispatchContentLoadedEvents() { nsCOMPtr os = mozilla::services::GetObserverService(); if (os) { nsIPrincipal* principal = NodePrincipal(); - os->NotifyObservers(this, + os->NotifyObservers(ToSupports(this), nsContentUtils::IsSystemPrincipal(principal) ? "chrome-document-interactive" : "content-document-interactive", @@ -4716,7 +4726,7 @@ void nsIDocument::DispatchContentLoadedEvents() { // Fire a DOM event notifying listeners that this document has been // loaded (excluding images and other loads initiated by this // document). - nsContentUtils::DispatchTrustedEvent(this, this, + nsContentUtils::DispatchTrustedEvent(this, ToSupports(this), NS_LITERAL_STRING("DOMContentLoaded"), CanBubble::eYes, Cancelable::eNo); @@ -4787,11 +4797,9 @@ void nsIDocument::DispatchContentLoadedEvents() { if (innerEvent) { nsEventStatus status = nsEventStatus_eIgnore; - RefPtr context = parent->GetPresContext(); - - if (context) { - EventDispatcher::Dispatch(parent, context, innerEvent, event, - &status); + if (RefPtr context = parent->GetPresContext()) { + EventDispatcher::Dispatch(ToSupports(parent), context, innerEvent, + event, &status); } } } @@ -4805,7 +4813,7 @@ void nsIDocument::DispatchContentLoadedEvents() { Element* root = GetRootElement(); if (root && root->HasAttr(kNameSpaceID_None, nsGkAtoms::manifest)) { nsContentUtils::DispatchChromeEvent( - this, this, NS_LITERAL_STRING("MozApplicationManifest"), + this, ToSupports(this), NS_LITERAL_STRING("MozApplicationManifest"), CanBubble::eYes, Cancelable::eYes); } @@ -4904,7 +4912,7 @@ static void AssertAboutPageHasCSP(nsIURI* aDocumentURI, } #endif -void nsDocument::EndLoad() { +void nsIDocument::EndLoad() { #if defined(DEBUG) && !defined(ANDROID) // only assert if nothing stopped the load on purpose if (!mParserAborted) { @@ -5920,7 +5928,7 @@ void nsIDocument::DoNotifyPossibleTitleChange() { } // Fire a DOM event for the title change. - nsContentUtils::DispatchChromeEvent(this, static_cast(this), + nsContentUtils::DispatchChromeEvent(this, ToSupports(this), NS_LITERAL_STRING("DOMTitleChanged"), CanBubble::eYes, Cancelable::eYes); } @@ -6491,7 +6499,7 @@ nsINode* nsIDocument::AdoptNode(nsINode& aAdoptedNode, ErrorResult& rv) { // canonical scope. But we try to pass something sane anyway. JSAutoRealm ar(cx, GetScopeObject()->GetGlobalJSObject()); JS::Rooted v(cx); - rv = nsContentUtils::WrapNative(cx, this, this, &v, + rv = nsContentUtils::WrapNative(cx, ToSupports(this), this, &v, /* aAllowWrapping = */ false); if (rv.Failed()) return nullptr; newScope = &v.toObject(); @@ -6975,7 +6983,7 @@ void nsIDocument::UpdateViewportOverflowType(nscoord aScrolledWidth, } } -EventListenerManager* nsDocument::GetOrCreateListenerManager() { +EventListenerManager* nsIDocument::GetOrCreateListenerManager() { if (!mListenerManager) { mListenerManager = new EventListenerManager(static_cast(this)); @@ -6985,11 +6993,11 @@ EventListenerManager* nsDocument::GetOrCreateListenerManager() { return mListenerManager; } -EventListenerManager* nsDocument::GetExistingListenerManager() const { +EventListenerManager* nsIDocument::GetExistingListenerManager() const { return mListenerManager; } -void nsDocument::GetEventTargetParent(EventChainPreVisitor& aVisitor) { +void nsIDocument::GetEventTargetParent(EventChainPreVisitor& aVisitor) { if (mDocGroup && aVisitor.mEvent->mMessage != eVoidEvent && !mIgnoreDocGroupMismatches) { mDocGroup->ValidateAccess(); @@ -7032,6 +7040,17 @@ void nsIDocument::FlushPendingNotifications(FlushType aType) { FlushPendingNotifications(flush); } +class nsDocumentOnStack { + public: + explicit nsDocumentOnStack(nsIDocument* aDoc) : mDoc(aDoc) { + mDoc->IncreaseStackRefCnt(); + } + ~nsDocumentOnStack() { mDoc->DecreaseStackRefCnt(); } + + private: + nsIDocument* mDoc; +}; + void nsIDocument::FlushPendingNotifications(mozilla::ChangesToFlush aFlush) { FlushType flushType = aFlush.mFlushType; @@ -7179,7 +7198,7 @@ bool nsIDocument::IsScriptEnabled() { return xpc::Scriptability::Get(globalObject->GetGlobalJSObject()).Allowed(); } -void nsDocument::RetrieveRelevantHeaders(nsIChannel* aChannel) { +void nsIDocument::RetrieveRelevantHeaders(nsIChannel* aChannel) { PRTime modDate = 0; nsresult rv; @@ -7512,7 +7531,7 @@ bool nsIDocument::CanSavePresentation(nsIRequest* aNewRequest) { return true; } -void nsDocument::Destroy() { +void nsIDocument::Destroy() { // The ContentViewer wants to release the document now. So, tell our content // to drop any references to the document so that it can be destroyed. if (mIsGoingAway) return; @@ -7547,7 +7566,7 @@ void nsDocument::Destroy() { mExternalResourceMap.Shutdown(); } -void nsDocument::RemovedFromDocShell() { +void nsIDocument::RemovedFromDocShell() { if (mRemovedFromDocShell) return; mRemovedFromDocShell = true; @@ -7600,14 +7619,14 @@ void nsIDocument::EnsureOnloadBlocker() { } } -void nsDocument::AsyncBlockOnload() { +void nsIDocument::AsyncBlockOnload() { while (mAsyncOnloadBlockCount) { --mAsyncOnloadBlockCount; BlockOnload(); } } -void nsDocument::BlockOnload() { +void nsIDocument::BlockOnload() { if (mDisplayDocument) { mDisplayDocument->BlockOnload(); return; @@ -7622,8 +7641,8 @@ void nsDocument::BlockOnload() { ++mAsyncOnloadBlockCount; if (mAsyncOnloadBlockCount == 1) { nsContentUtils::AddScriptRunner( - NewRunnableMethod("nsDocument::AsyncBlockOnload", this, - &nsDocument::AsyncBlockOnload)); + NewRunnableMethod("nsIDocument::AsyncBlockOnload", this, + &nsIDocument::AsyncBlockOnload)); } return; } @@ -7635,7 +7654,7 @@ void nsDocument::BlockOnload() { ++mOnloadBlockCount; } -void nsDocument::UnblockOnload(bool aFireSync) { +void nsIDocument::UnblockOnload(bool aFireSync) { if (mDisplayDocument) { mDisplayDocument->UnblockOnload(aFireSync); return; @@ -7823,7 +7842,7 @@ void nsIDocument::OnPageShow(bool aPersisted, EventTarget* aDispatchStartTarget, nsCOMPtr os = mozilla::services::GetObserverService(); if (os) { nsIPrincipal* principal = NodePrincipal(); - os->NotifyObservers(this, + os->NotifyObservers(ToSupports(this), nsContentUtils::IsSystemPrincipal(principal) ? "chrome-page-shown" : "content-page-shown", @@ -7920,7 +7939,7 @@ void nsIDocument::OnPageHide(bool aPersisted, EventTarget* aDispatchStartTarget, nsCOMPtr os = mozilla::services::GetObserverService(); if (os) { nsIPrincipal* principal = NodePrincipal(); - os->NotifyObservers(this, + os->NotifyObservers(ToSupports(this), nsContentUtils::IsSystemPrincipal(principal) ? "chrome-page-hidden" : "content-page-hidden", @@ -8066,7 +8085,7 @@ void nsIDocument::RefreshLinkHrefs() { } } -nsresult nsDocument::CloneDocHelper(nsDocument* clone) const { +nsresult nsIDocument::CloneDocHelper(nsIDocument* clone) const { clone->mIsStaticDocument = mCreatingStaticClone; // Init document @@ -8103,7 +8122,7 @@ nsresult nsDocument::CloneDocHelper(nsDocument* clone) const { // information came from the channel. So we override explicitly, and do it // for all these properties, in case ResetToURI messes with any of the rest of // them. - clone->nsDocument::SetDocumentURI(nsIDocument::GetDocumentURI()); + clone->SetDocumentURI(nsIDocument::GetDocumentURI()); clone->SetChromeXHRDocURI(mChromeXHRDocURI); clone->SetPrincipal(NodePrincipal()); clone->mDocumentBaseURI = mDocumentBaseURI; @@ -10887,7 +10906,7 @@ void nsIDocument::UpdateVisibilityState() { dom::VisibilityState oldState = mVisibilityState; mVisibilityState = ComputeVisibilityState(); if (oldState != mVisibilityState) { - nsContentUtils::DispatchTrustedEvent(this, static_cast(this), + nsContentUtils::DispatchTrustedEvent(this, ToSupports(this), NS_LITERAL_STRING("visibilitychange"), CanBubble::eYes, Cancelable::eNo); EnumerateActivityObservers(NotifyActivityChanged, nullptr); @@ -10929,32 +10948,63 @@ void nsIDocument::MaybeActiveMediaComponents() { GetWindow()->MaybeActiveMediaComponents(); } -/* virtual */ void nsIDocument::DocAddSizeOfExcludingThis( - nsWindowSizes& aSizes) const { - if (mPresShell) { - mPresShell->AddSizeOfIncludingThis(aSizes); +void nsIDocument::DocAddSizeOfExcludingThis(nsWindowSizes& aWindowSizes) const { + nsINode::AddSizeOfExcludingThis(aWindowSizes, &aWindowSizes.mDOMOtherSize); + + for (nsIContent* kid = GetFirstChild(); kid; kid = kid->GetNextSibling()) { + AddSizeOfNodeTree(*kid, aWindowSizes); } - aSizes.mPropertyTablesSize += - mPropertyTable.SizeOfExcludingThis(aSizes.mState.mMallocSizeOf); + // IMPORTANT: for our ComputedValues measurements, we want to measure + // ComputedValues accessible from DOM elements before ComputedValues not + // accessible from DOM elements (i.e. accessible only from the frame tree). + // + // Therefore, the measurement of the nsIDocument superclass must happen after + // the measurement of DOM nodes (above), because nsIDocument contains the + // PresShell, which contains the frame tree. + if (mPresShell) { + mPresShell->AddSizeOfIncludingThis(aWindowSizes); + } + + aWindowSizes.mPropertyTablesSize += + mPropertyTable.SizeOfExcludingThis(aWindowSizes.mState.mMallocSizeOf); if (EventListenerManager* elm = GetExistingListenerManager()) { - aSizes.mDOMEventListenersCount += elm->ListenerCount(); + aWindowSizes.mDOMEventListenersCount += elm->ListenerCount(); } if (mNodeInfoManager) { - mNodeInfoManager->AddSizeOfIncludingThis(aSizes); + mNodeInfoManager->AddSizeOfIncludingThis(aWindowSizes); } - aSizes.mDOMMediaQueryLists += - mDOMMediaQueryLists.sizeOfExcludingThis(aSizes.mState.mMallocSizeOf); + aWindowSizes.mDOMMediaQueryLists += mDOMMediaQueryLists.sizeOfExcludingThis( + aWindowSizes.mState.mMallocSizeOf); for (const MediaQueryList* mql : mDOMMediaQueryLists) { - aSizes.mDOMMediaQueryLists += - mql->SizeOfExcludingThis(aSizes.mState.mMallocSizeOf); + aWindowSizes.mDOMMediaQueryLists += + mql->SizeOfExcludingThis(aWindowSizes.mState.mMallocSizeOf); } - mContentBlockingLog.AddSizeOfExcludingThis(aSizes); + mContentBlockingLog.AddSizeOfExcludingThis(aWindowSizes); + + DocumentOrShadowRoot::AddSizeOfExcludingThis(aWindowSizes); + + for (auto& sheetArray : mAdditionalSheets) { + AddSizeOfOwnedSheetArrayExcludingThis(aWindowSizes, sheetArray); + } + // Lumping in the loader with the style-sheets size is not ideal, + // but most of the things in there are in fact stylesheets, so it + // doesn't seem worthwhile to separate it out. + aWindowSizes.mLayoutStyleSheetsSize += + CSSLoader()->SizeOfIncludingThis(aWindowSizes.mState.mMallocSizeOf); + + aWindowSizes.mDOMOtherSize += mAttrStyleSheet + ? mAttrStyleSheet->DOMSizeOfIncludingThis( + aWindowSizes.mState.mMallocSizeOf) + : 0; + + aWindowSizes.mDOMOtherSize += mStyledLinks.ShallowSizeOfExcludingThis( + aWindowSizes.mState.mMallocSizeOf); // Measurement of the following members may be added later if DMD finds it // is worthwhile: @@ -10966,8 +11016,8 @@ void nsIDocument::DocAddSizeOfIncludingThis(nsWindowSizes& aWindowSizes) const { DocAddSizeOfExcludingThis(aWindowSizes); } -void nsDocument::AddSizeOfExcludingThis(nsWindowSizes& aSizes, - size_t* aNodeSize) const { +void nsIDocument::AddSizeOfExcludingThis(nsWindowSizes& aSizes, + size_t* aNodeSize) const { // This AddSizeOfExcludingThis() overrides the one from nsINode. But // nsDocuments can only appear at the top of the DOM tree, and we use the // specialized DocAddSizeOfExcludingThis() in that case. So this should never @@ -11036,45 +11086,6 @@ void nsDocument::AddSizeOfExcludingThis(nsWindowSizes& aSizes, } } -void nsDocument::DocAddSizeOfExcludingThis(nsWindowSizes& aWindowSizes) const { - nsINode::AddSizeOfExcludingThis(aWindowSizes, &aWindowSizes.mDOMOtherSize); - - for (nsIContent* kid = GetFirstChild(); kid; kid = kid->GetNextSibling()) { - AddSizeOfNodeTree(*kid, aWindowSizes); - } - - // IMPORTANT: for our ComputedValues measurements, we want to measure - // ComputedValues accessible from DOM elements before ComputedValues not - // accessible from DOM elements (i.e. accessible only from the frame tree). - // - // Therefore, the measurement of the nsIDocument superclass must happen after - // the measurement of DOM nodes (above), because nsIDocument contains the - // PresShell, which contains the frame tree. - nsIDocument::DocAddSizeOfExcludingThis(aWindowSizes); - - DocumentOrShadowRoot::AddSizeOfExcludingThis(aWindowSizes); - for (auto& sheetArray : mAdditionalSheets) { - AddSizeOfOwnedSheetArrayExcludingThis(aWindowSizes, sheetArray); - } - // Lumping in the loader with the style-sheets size is not ideal, - // but most of the things in there are in fact stylesheets, so it - // doesn't seem worthwhile to separate it out. - aWindowSizes.mLayoutStyleSheetsSize += - CSSLoader()->SizeOfIncludingThis(aWindowSizes.mState.mMallocSizeOf); - - aWindowSizes.mDOMOtherSize += mAttrStyleSheet - ? mAttrStyleSheet->DOMSizeOfIncludingThis( - aWindowSizes.mState.mMallocSizeOf) - : 0; - - aWindowSizes.mDOMOtherSize += mStyledLinks.ShallowSizeOfExcludingThis( - aWindowSizes.mState.mMallocSizeOf); - - // Measurement of the following members may be added later if DMD finds it - // is worthwhile: - // - many! -} - already_AddRefed nsIDocument::Constructor( const GlobalObject& aGlobal, ErrorResult& rv) { nsCOMPtr global = @@ -11567,14 +11578,13 @@ already_AddRefed nsIDocument::CreateHTMLElement(nsAtom* aTag) { } bool MarkDocumentTreeToBeInSyncOperation(nsIDocument* aDoc, void* aData) { - nsCOMArray* documents = - static_cast*>(aData); + auto* documents = static_cast>*>(aData); if (aDoc) { aDoc->SetIsInSyncOperation(true); if (nsCOMPtr window = aDoc->GetInnerWindow()) { window->TimeoutManager().BeginSyncOperation(); } - documents->AppendObject(aDoc); + documents->AppendElement(aDoc); aDoc->EnumerateSubDocuments(MarkDocumentTreeToBeInSyncOperation, aData); } return true; @@ -11598,11 +11608,11 @@ nsAutoSyncOperation::nsAutoSyncOperation(nsIDocument* aDoc) { } nsAutoSyncOperation::~nsAutoSyncOperation() { - for (int32_t i = 0; i < mDocuments.Count(); ++i) { - if (nsCOMPtr window = mDocuments[i]->GetInnerWindow()) { + for (nsCOMPtr& doc : mDocuments) { + if (nsCOMPtr window = doc->GetInnerWindow()) { window->TimeoutManager().EndSyncOperation(); } - mDocuments[i]->SetIsInSyncOperation(false); + doc->SetIsInSyncOperation(false); } CycleCollectedJSContext* ccjs = CycleCollectedJSContext::Get(); if (ccjs) { @@ -12533,14 +12543,7 @@ bool nsIDocument::IsThirdParty() { } nsCOMPtr principal = NodePrincipal(); - nsCOMPtr sop = - do_QueryInterface(parentDocument, &rv); - if (NS_WARN_IF(NS_FAILED(rv) || !sop)) { - // Failure - mIsThirdParty.emplace(true); - return mIsThirdParty.value(); - } - nsCOMPtr parentPrincipal = sop->GetPrincipal(); + nsCOMPtr parentPrincipal = parentDocument->GetPrincipal(); bool principalsMatch = false; rv = principal->Equals(parentPrincipal, &principalsMatch); diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h index fef9d64d4c6c..5aef98593d1e 100644 --- a/dom/base/nsDocument.h +++ b/dom/base/nsDocument.h @@ -13,284 +13,23 @@ #include "nsIDocument.h" -#include "jsfriendapi.h" -#include "nsCOMPtr.h" -#include "nsAutoPtr.h" -#include "nsCRT.h" -#include "nsIWeakReferenceUtils.h" -#include "nsTArray.h" -#include "nsIdentifierMapEntry.h" -#include "nsStubDocumentObserver.h" -#include "nsIScriptGlobalObject.h" -#include "nsIContent.h" -#include "nsIPrincipal.h" -#include "nsIParser.h" -#include "nsBindingManager.h" -#include "nsRefPtrHashtable.h" -#include "nsJSThingHashtable.h" -#include "nsIScriptObjectPrincipal.h" -#include "nsIRadioGroupContainer.h" -#include "nsILayoutHistoryState.h" -#include "nsIRequest.h" -#include "nsILoadGroup.h" -#include "nsTObserverArray.h" -#include "nsStubMutationObserver.h" -#include "nsIChannel.h" -#include "nsCycleCollectionParticipant.h" -#include "nsContentList.h" -#include "nsGkAtoms.h" -#include "PLDHashTable.h" -#include "nsDOMAttributeMap.h" -#include "imgIRequest.h" -#include "mozilla/EventStates.h" -#include "mozilla/MemoryReporting.h" -#include "mozilla/PendingAnimationTracker.h" -#include "mozilla/dom/BoxObject.h" -#include "mozilla/dom/DOMImplementation.h" -#include "mozilla/dom/ScriptLoader.h" -#include "mozilla/dom/StyleSheetList.h" -#include "nsDataHashtable.h" -#include "mozilla/TimeStamp.h" -#include "mozilla/Attributes.h" -#include "CustomElementRegistry.h" -#include "mozilla/dom/Performance.h" -#include "mozilla/Maybe.h" -#include "nsIURIClassifier.h" - #define XML_DECLARATION_BITS_DECLARATION_EXISTS (1 << 0) #define XML_DECLARATION_BITS_ENCODING_EXISTS (1 << 1) #define XML_DECLARATION_BITS_STANDALONE_EXISTS (1 << 2) #define XML_DECLARATION_BITS_STANDALONE_YES (1 << 3) -class nsDOMStyleSheetSetList; -class nsDocument; -class nsIFormControl; -class nsOnloadBlocker; -class nsDOMNavigationTiming; -class nsWindowSizes; -class nsHtml5TreeOpExecutor; -class nsDocumentOnStack; -class nsISecurityConsoleMessage; - -namespace mozilla { -class EventChainPreVisitor; -namespace dom { -class ImageTracker; -struct LifecycleCallbacks; -class CallbackFunction; -class DOMIntersectionObserver; -class Performance; -} // namespace dom -} // namespace mozilla - -class nsOnloadBlocker final : public nsIRequest { - public: - nsOnloadBlocker() {} - - NS_DECL_ISUPPORTS - NS_DECL_NSIREQUEST - - private: - ~nsOnloadBlocker() {} -}; - // Base class for our document implementations. -class nsDocument : public nsIDocument, - public nsSupportsWeakReference, - public nsIScriptObjectPrincipal, - public nsIRadioGroupContainer, - public nsIApplicationCacheContainer, - public nsStubMutationObserver { - friend class nsIDocument; - - public: - typedef mozilla::dom::Element Element; - typedef mozilla::net::ReferrerPolicy ReferrerPolicy; - - NS_DECL_CYCLE_COLLECTING_ISUPPORTS - - NS_DECL_ADDSIZEOFEXCLUDINGTHIS - - // StartDocumentLoad is pure virtual so that subclasses must override it. - // The nsDocument StartDocumentLoad does some setup, but does NOT set - // *aDocListener; this is the job of subclasses. - virtual nsresult StartDocumentLoad( - const char* aCommand, nsIChannel* aChannel, nsILoadGroup* aLoadGroup, - nsISupports* aContainer, nsIStreamListener** aDocListener, - bool aReset = true, nsIContentSink* aContentSink = nullptr) override = 0; - - virtual void StopDocumentLoad() override; - - static bool DocumentSupportsL10n(JSContext* aCx, JSObject* aObject); - static bool IsWebAnimationsEnabled(JSContext* aCx, JSObject* aObject); - static bool IsWebAnimationsEnabled(mozilla::dom::CallerType aCallerType); - static bool IsWebAnimationsGetAnimationsEnabled(JSContext* aCx, - JSObject* aObject); - static bool AreWebAnimationsImplicitKeyframesEnabled(JSContext* aCx, - JSObject* aObject); - static bool AreWebAnimationsTimelinesEnabled(JSContext* aCx, - JSObject* aObject); - - virtual void EndUpdate() override; - virtual void BeginLoad() override; - virtual void EndLoad() override; - - // nsIRadioGroupContainer - NS_IMETHOD WalkRadioGroup(const nsAString& aName, nsIRadioVisitor* aVisitor, - bool aFlushContent) override { - return DocumentOrShadowRoot::WalkRadioGroup(aName, aVisitor, aFlushContent); - } - virtual void SetCurrentRadioButton( - const nsAString& aName, mozilla::dom::HTMLInputElement* aRadio) override { - DocumentOrShadowRoot::SetCurrentRadioButton(aName, aRadio); - } - virtual mozilla::dom::HTMLInputElement* GetCurrentRadioButton( - const nsAString& aName) override { - return DocumentOrShadowRoot::GetCurrentRadioButton(aName); - } - NS_IMETHOD - GetNextRadioButton(const nsAString& aName, const bool aPrevious, - mozilla::dom::HTMLInputElement* aFocusedRadio, - mozilla::dom::HTMLInputElement** aRadioOut) override { - return DocumentOrShadowRoot::GetNextRadioButton(aName, aPrevious, - aFocusedRadio, aRadioOut); - } - virtual void AddToRadioGroup( - const nsAString& aName, mozilla::dom::HTMLInputElement* aRadio) override { - DocumentOrShadowRoot::AddToRadioGroup(aName, aRadio); - } - virtual void RemoveFromRadioGroup( - const nsAString& aName, mozilla::dom::HTMLInputElement* aRadio) override { - DocumentOrShadowRoot::RemoveFromRadioGroup(aName, aRadio); - } - virtual uint32_t GetRequiredRadioCount( - const nsAString& aName) const override { - return DocumentOrShadowRoot::GetRequiredRadioCount(aName); - } - virtual void RadioRequiredWillChange(const nsAString& aName, - bool aRequiredAdded) override { - DocumentOrShadowRoot::RadioRequiredWillChange(aName, aRequiredAdded); - } - virtual bool GetValueMissingState(const nsAString& aName) const override { - return DocumentOrShadowRoot::GetValueMissingState(aName); - } - virtual void SetValueMissingState(const nsAString& aName, - bool aValue) override { - return DocumentOrShadowRoot::SetValueMissingState(aName, aValue); - } - - // Check whether shadow DOM is enabled for the document this node belongs to. - // Same as above, but also checks that the caller is either chrome or some - // addon. - static bool IsCallerChromeOrAddon(JSContext* aCx, JSObject* aObject); - - public: - using mozilla::dom::DocumentOrShadowRoot::GetElementById; - using mozilla::dom::DocumentOrShadowRoot::GetElementsByClassName; - using mozilla::dom::DocumentOrShadowRoot::GetElementsByTagName; - using mozilla::dom::DocumentOrShadowRoot::GetElementsByTagNameNS; - - // EventTarget - void GetEventTargetParent(mozilla::EventChainPreVisitor& aVisitor) override; - virtual mozilla::EventListenerManager* GetOrCreateListenerManager() override; - virtual mozilla::EventListenerManager* GetExistingListenerManager() - const override; - - // nsIScriptObjectPrincipal - virtual nsIPrincipal* GetPrincipal() override; - - // nsIApplicationCacheContainer - NS_DECL_NSIAPPLICATIONCACHECONTAINER - - virtual nsresult Init(); - - virtual void Destroy() override; - virtual void RemovedFromDocShell() override; - - virtual void BlockOnload() override; - virtual void UnblockOnload(bool aFireSync) override; - - NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsDocument, - nsIDocument) - - void SetLoadedAsData(bool aLoadedAsData) { mLoadedAsData = aLoadedAsData; } - void SetLoadedAsInteractiveData(bool aLoadedAsInteractiveData) { - mLoadedAsInteractiveData = aLoadedAsInteractiveData; - } - - nsresult CloneDocHelper(nsDocument* clone) const; - - // Only BlockOnload should call this! - void AsyncBlockOnload(); - - virtual void DocAddSizeOfExcludingThis( - nsWindowSizes& aWindowSizes) const override; - // DocAddSizeOfIncludingThis is inherited from nsIDocument. - +class nsDocument : public nsIDocument { protected: - friend class nsNodeUtils; - - void RetrieveRelevantHeaders(nsIChannel* aChannel); - - void TryChannelCharset(nsIChannel* aChannel, int32_t& aCharsetSource, - NotNull& aEncoding, - nsHtml5TreeOpExecutor* aExecutor); - - nsIContent* GetFirstBaseNodeWithHref(); - nsresult SetFirstBaseNodeWithHref(nsIContent* node); - -#define NS_DOCUMENT_NOTIFY_OBSERVERS(func_, params_) \ - do { \ - NS_OBSERVER_ARRAY_NOTIFY_XPCOM_OBSERVERS(mObservers, nsIDocumentObserver, \ - func_, params_); \ - /* FIXME(emilio): Apparently we can keep observing from the BFCache? That \ - looks bogus. */ \ - if (nsIPresShell* shell = GetObservingShell()) { \ - shell->func_ params_; \ - } \ - } while (0) - -#ifdef DEBUG - void VerifyRootContentState(); -#endif explicit nsDocument(const char* aContentType); virtual ~nsDocument(); - public: - // FIXME(emilio): This needs to be here instead of in nsIDocument because Rust - // can't represent alignas(8) values on 32-bit architectures, which would - // cause nsIDocument's layout to be wrong in the Rust side. - // - // This can be fixed after updating to rust 1.25 and updating bindgen to - // include https://github.com/rust-lang-nursery/rust-bindgen/pull/1271. - js::ExpandoAndGeneration mExpandoAndGeneration; - - friend class nsCallRequestFullscreen; - - // The application cache that this document is associated with, if - // any. This can change during the lifetime of the document. - nsCOMPtr mApplicationCache; - - nsCOMPtr mFirstBaseNodeWithHref; + // Don't add stuff here, add to nsIDocument instead. private: - friend class nsUnblockOnloadEvent; - - // These are not implemented and not supported. - nsDocument(const nsDocument& aOther); - nsDocument& operator=(const nsDocument& aOther); -}; - -class nsDocumentOnStack { - public: - explicit nsDocumentOnStack(nsIDocument* aDoc) : mDoc(aDoc) { - mDoc->IncreaseStackRefCnt(); - } - ~nsDocumentOnStack() { mDoc->DecreaseStackRefCnt(); } - - private: - nsIDocument* mDoc; + nsDocument(const nsDocument& aOther) = delete; + nsDocument& operator=(const nsDocument& aOther) = delete; }; #endif /* nsDocument_h___ */ diff --git a/dom/base/nsFocusManager.cpp b/dom/base/nsFocusManager.cpp index 9958720859ed..b2e5e9195b20 100644 --- a/dom/base/nsFocusManager.cpp +++ b/dom/base/nsFocusManager.cpp @@ -1687,7 +1687,8 @@ bool nsFocusManager::Blur(nsPIDOMWindowOuter* aWindowToClear, // that the check is made for suppressed documents. Check to ensure that // the document isn't null in case someone closed it during the blur above nsIDocument* doc = window->GetExtantDoc(); - if (doc) SendFocusOrBlurEvent(eBlur, presShell, doc, doc, 1, false); + if (doc) + SendFocusOrBlurEvent(eBlur, presShell, doc, ToSupports(doc), 1, false); if (mFocusedWindow == nullptr) SendFocusOrBlurEvent(eBlur, presShell, doc, window->GetCurrentInnerWindow(), 1, false); @@ -1804,7 +1805,7 @@ void nsFocusManager::Focus(nsPIDOMWindowOuter* aWindow, Element* aElement, GetFocusMoveActionCause(aFlags)); } if (doc) { - SendFocusOrBlurEvent(eFocus, presShell, doc, doc, + SendFocusOrBlurEvent(eFocus, presShell, doc, ToSupports(doc), aFlags & FOCUSMETHOD_MASK, aWindowRaised); } if (mFocusedWindow == aWindow && mFocusedElement == nullptr) { diff --git a/dom/base/nsGlobalWindowOuter.cpp b/dom/base/nsGlobalWindowOuter.cpp index 1248a20fc5e0..458de55cb0b6 100644 --- a/dom/base/nsGlobalWindowOuter.cpp +++ b/dom/base/nsGlobalWindowOuter.cpp @@ -2059,7 +2059,7 @@ void nsGlobalWindowOuter::DispatchDOMWindowCreated() { } // Fire DOMWindowCreated at chrome event listeners - nsContentUtils::DispatchChromeEvent(mDoc, mDoc, + nsContentUtils::DispatchChromeEvent(mDoc, ToSupports(mDoc), NS_LITERAL_STRING("DOMWindowCreated"), CanBubble::eYes, Cancelable::eNo); diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index 29c4ecc9666b..91313fd094d7 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -25,6 +25,8 @@ #include "nsIPresShell.h" #include "nsIChannelEventSink.h" #include "nsIProgressEventSink.h" +#include "nsIRadioGroupContainer.h" +#include "nsIScriptObjectPrincipal.h" #include "nsISecurityEventSink.h" #include "nsIScriptGlobalObject.h" // for member (in nsCOMPtr) #include "nsIServiceManager.h" @@ -35,6 +37,7 @@ #include "nsPIDOMWindow.h" // for use in inline functions #include "nsPropertyTable.h" // for member #include "nsStringFwd.h" +#include "nsStubMutationObserver.h" #include "nsTHashtable.h" // for member #include "nsURIHashKey.h" #include "mozilla/net/ReferrerPolicy.h" // for member @@ -82,6 +85,7 @@ class nsDOMNavigationTiming; class nsDOMStyleSheetSetList; class nsFrameLoader; class nsGlobalWindowInner; +class nsHtml5TreeOpExecutor; class nsHTMLCSSStyleSheet; class nsHTMLDocument; class nsHTMLStyleSheet; @@ -434,6 +438,11 @@ class PrincipalFlashClassifier; // Gecko. class nsIDocument : public nsINode, public mozilla::dom::DocumentOrShadowRoot, + public nsSupportsWeakReference, + public nsIRadioGroupContainer, + public nsIScriptObjectPrincipal, + public nsIApplicationCacheContainer, + public nsStubMutationObserver, public mozilla::dom::DispatcherTrait { typedef mozilla::dom::GlobalObject GlobalObject; @@ -451,10 +460,84 @@ class nsIDocument : public nsINode, NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_IID) + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + + NS_DECL_ADDSIZEOFEXCLUDINGTHIS + + NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsIDocument, + nsINode) + +#define NS_DOCUMENT_NOTIFY_OBSERVERS(func_, params_) \ + do { \ + NS_OBSERVER_ARRAY_NOTIFY_XPCOM_OBSERVERS(mObservers, nsIDocumentObserver, \ + func_, params_); \ + /* FIXME(emilio): Apparently we can keep observing from the BFCache? That \ + looks bogus. */ \ + if (nsIPresShell* shell = GetObservingShell()) { \ + shell->func_ params_; \ + } \ + } while (0) + #ifdef MOZILLA_INTERNAL_API nsIDocument(); #endif + // nsIApplicationCacheContainer + NS_DECL_NSIAPPLICATIONCACHECONTAINER + + // nsIRadioGroupContainer + NS_IMETHOD WalkRadioGroup(const nsAString& aName, nsIRadioVisitor* aVisitor, + bool aFlushContent) final { + return DocumentOrShadowRoot::WalkRadioGroup(aName, aVisitor, aFlushContent); + } + + void SetCurrentRadioButton(const nsAString& aName, + mozilla::dom::HTMLInputElement* aRadio) final { + DocumentOrShadowRoot::SetCurrentRadioButton(aName, aRadio); + } + + mozilla::dom::HTMLInputElement* GetCurrentRadioButton( + const nsAString& aName) final { + return DocumentOrShadowRoot::GetCurrentRadioButton(aName); + } + + NS_IMETHOD + GetNextRadioButton(const nsAString& aName, const bool aPrevious, + mozilla::dom::HTMLInputElement* aFocusedRadio, + mozilla::dom::HTMLInputElement** aRadioOut) final { + return DocumentOrShadowRoot::GetNextRadioButton(aName, aPrevious, + aFocusedRadio, aRadioOut); + } + void AddToRadioGroup(const nsAString& aName, + mozilla::dom::HTMLInputElement* aRadio) final { + DocumentOrShadowRoot::AddToRadioGroup(aName, aRadio); + } + void RemoveFromRadioGroup(const nsAString& aName, + mozilla::dom::HTMLInputElement* aRadio) final { + DocumentOrShadowRoot::RemoveFromRadioGroup(aName, aRadio); + } + uint32_t GetRequiredRadioCount(const nsAString& aName) const final { + return DocumentOrShadowRoot::GetRequiredRadioCount(aName); + } + void RadioRequiredWillChange(const nsAString& aName, + bool aRequiredAdded) final { + DocumentOrShadowRoot::RadioRequiredWillChange(aName, aRequiredAdded); + } + bool GetValueMissingState(const nsAString& aName) const final { + return DocumentOrShadowRoot::GetValueMissingState(aName); + } + void SetValueMissingState(const nsAString& aName, bool aValue) final { + return DocumentOrShadowRoot::SetValueMissingState(aName, aValue); + } + + // nsIScriptObjectPrincipal + nsIPrincipal* GetPrincipal() final { return NodePrincipal(); } + + // EventTarget + void GetEventTargetParent(mozilla::EventChainPreVisitor& aVisitor) override; + mozilla::EventListenerManager* GetOrCreateListenerManager() override; + mozilla::EventListenerManager* GetExistingListenerManager() const override; + // This helper class must be set when we dispatch beforeunload and unload // events in order to avoid unterminate sync XHRs. class MOZ_RAII PageUnloadingEventTimeStamp { @@ -510,6 +593,9 @@ class nsIDocument : public nsINode, * MayStartLayout() until SetMayStartLayout(true) is called on it. Making * sure this happens is the responsibility of the caller of * StartDocumentLoad(). + * + * This function has an implementation, and does some setup, but does NOT set + * *aDocListener; this is the job of subclasses. */ virtual nsresult StartDocumentLoad(const char* aCommand, nsIChannel* aChannel, nsILoadGroup* aLoadGroup, @@ -517,7 +603,7 @@ class nsIDocument : public nsINode, nsIStreamListener** aDocListener, bool aReset, nsIContentSink* aSink = nullptr) = 0; - virtual void StopDocumentLoad() = 0; + virtual void StopDocumentLoad(); virtual void SetSuppressParserErrorElement(bool aSuppress) {} virtual bool SuppressParserErrorElement() { return false; } @@ -534,6 +620,7 @@ class nsIDocument : public nsINode, nsINode** aResult) const override { return NS_ERROR_NOT_IMPLEMENTED; } + nsresult CloneDocHelper(nsIDocument* clone) const; /** * Signal that the document title may have changed @@ -788,6 +875,11 @@ class nsIDocument : public nsINode, mIsInitialDocumentInWindow = aIsInitialDocument; } + void SetLoadedAsData(bool aLoadedAsData) { mLoadedAsData = aLoadedAsData; } + void SetLoadedAsInteractiveData(bool aLoadedAsInteractiveData) { + mLoadedAsInteractiveData = aLoadedAsInteractiveData; + } + /** * Normally we assert if a runnable labeled with one DocGroup touches data * from another DocGroup. Calling IgnoreDocGroupMismatches() on a document @@ -1318,6 +1410,12 @@ class nsIDocument : public nsINode, void MaybeEndOutermostXBLUpdate(); + void RetrieveRelevantHeaders(nsIChannel* aChannel); + + void TryChannelCharset(nsIChannel* aChannel, int32_t& aCharsetSource, + NotNull& aEncoding, + nsHtml5TreeOpExecutor* aExecutor); + void DispatchContentLoadedEvents(); void DispatchPageTransition(mozilla::dom::EventTarget* aDispatchTarget, @@ -1782,11 +1880,11 @@ class nsIDocument : public nsINode, // content model or of style data, EndUpdate must be called afterward. // To make this easy and painless, use the mozAutoDocUpdate helper class. void BeginUpdate(); - virtual void EndUpdate() = 0; + virtual void EndUpdate(); uint32_t UpdateNestingLevel() { return mUpdateNestLevel; } - virtual void BeginLoad() = 0; - virtual void EndLoad() = 0; + virtual void BeginLoad(); + virtual void EndLoad(); enum ReadyState { READYSTATE_UNINITIALIZED = 0, @@ -2036,12 +2134,14 @@ class nsIDocument : public nsINode, */ virtual bool CanSavePresentation(nsIRequest* aNewRequest); + virtual nsresult Init(); + /** * Notify the document that its associated ContentViewer is being destroyed. * This releases circular references so that the document can go away. * Destroy() is only called on documents that have a content viewer. */ - virtual void Destroy() = 0; + virtual void Destroy(); /** * Notify the document that its associated ContentViewer is no longer @@ -2049,7 +2149,7 @@ class nsIDocument : public nsINode, * be rendered in "zombie state" until the next document is ready. * The document should save form control state. */ - virtual void RemovedFromDocShell() = 0; + virtual void RemovedFromDocShell(); /** * Get the layout history state that should be used to save and restore state @@ -2065,14 +2165,17 @@ class nsIDocument : public nsINode, * UnblockOnload() or the load has been stopped altogether (by the user * pressing the Stop button, say). */ - virtual void BlockOnload() = 0; + void BlockOnload(); /** * @param aFireSync whether to fire onload synchronously. If false, * onload will fire asynchronously after all onload blocks have been * removed. It will NOT fire from inside UnblockOnload. If true, * onload may fire from inside UnblockOnload. */ - virtual void UnblockOnload(bool aFireSync) = 0; + void UnblockOnload(bool aFireSync); + + // Only BlockOnload should call this! + void AsyncBlockOnload(); void BlockDOMContentLoaded() { ++mBlockDOMContentLoaded; } @@ -2995,6 +3098,17 @@ class nsIDocument : public nsINode, void ExitPointerLock() { UnlockPointer(this); } static bool IsUnprefixedFullscreenEnabled(JSContext* aCx, JSObject* aObject); + static bool DocumentSupportsL10n(JSContext* aCx, JSObject* aObject); + static bool IsWebAnimationsEnabled(JSContext* aCx, JSObject* aObject); + static bool IsWebAnimationsEnabled(mozilla::dom::CallerType aCallerType); + static bool IsWebAnimationsGetAnimationsEnabled(JSContext* aCx, + JSObject* aObject); + static bool AreWebAnimationsImplicitKeyframesEnabled(JSContext* aCx, + JSObject* aObject); + static bool AreWebAnimationsTimelinesEnabled(JSContext* aCx, + JSObject* aObject); + // Checks that the caller is either chrome or some addon. + static bool IsCallerChromeOrAddon(JSContext* aCx, JSObject* aObject); #ifdef MOZILLA_INTERNAL_API bool Hidden() const { @@ -3323,6 +3437,10 @@ class nsIDocument : public nsINode, nsTArray mL10nResources; + // The application cache that this document is associated with, if + // any. This can change during the lifetime of the document. + nsCOMPtr mApplicationCache; + public: bool IsThirdParty(); @@ -4338,6 +4456,10 @@ class nsIDocument : public nsINode, // Pres shell resolution saved before entering fullscreen mode. float mSavedResolution; + + public: + // Needs to be public because the bindings code pokes at it. + js::ExpandoAndGeneration mExpandoAndGeneration; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocument, NS_IDOCUMENT_IID) @@ -4384,7 +4506,7 @@ class MOZ_STACK_CLASS nsAutoSyncOperation { ~nsAutoSyncOperation(); private: - nsCOMArray mDocuments; + nsTArray> mDocuments; uint32_t mMicroTaskLevel; }; @@ -4497,4 +4619,8 @@ inline const nsIDocument* nsINode::AsDocument() const { return static_cast(this); } +inline nsISupports* ToSupports(nsIDocument* aDoc) { + return static_cast(aDoc); +} + #endif /* nsIDocument_h___ */ diff --git a/dom/base/nsImageLoadingContent.cpp b/dom/base/nsImageLoadingContent.cpp index 58ac7cd8f49e..714c10f838cc 100644 --- a/dom/base/nsImageLoadingContent.cpp +++ b/dom/base/nsImageLoadingContent.cpp @@ -788,8 +788,8 @@ nsImageLoadingContent::LoadImageWithChannel(nsIChannel* aChannel, // Do the load. RefPtr& req = PrepareNextRequest(eImageLoadType_Normal); - nsresult rv = loader->LoadImageWithChannel(aChannel, this, doc, aListener, - getter_AddRefs(req)); + nsresult rv = loader->LoadImageWithChannel(aChannel, this, ToSupports(doc), + aListener, getter_AddRefs(req)); if (NS_SUCCEEDED(rv)) { CloneScriptedRequests(req); TrackImage(req); diff --git a/dom/base/nsNodeUtils.cpp b/dom/base/nsNodeUtils.cpp index 2a4eaf26642b..84660e17c16a 100644 --- a/dom/base/nsNodeUtils.cpp +++ b/dom/base/nsNodeUtils.cpp @@ -35,6 +35,7 @@ #include "nsObjectLoadingContent.h" #include "nsDOMMutationObserver.h" #include "mozilla/dom/BindingUtils.h" +#include "mozilla/dom/CustomElementRegistry.h" #include "mozilla/dom/HTMLTemplateElement.h" #include "mozilla/dom/ShadowRoot.h" diff --git a/dom/base/nsObjectLoadingContent.cpp b/dom/base/nsObjectLoadingContent.cpp index 55b20a00886e..c880b6e41ae8 100644 --- a/dom/base/nsObjectLoadingContent.cpp +++ b/dom/base/nsObjectLoadingContent.cpp @@ -262,7 +262,7 @@ class nsSimplePluginEvent : public Runnable { nsSimplePluginEvent(nsIDocument* aTarget, const nsAString& aEvent) : mozilla::Runnable("nsSimplePluginEvent"), - mTarget(aTarget), + mTarget(ToSupports(aTarget)), mDocument(aTarget), mEvent(aEvent) { MOZ_ASSERT(aTarget); diff --git a/dom/bindings/BindingDeclarations.h b/dom/bindings/BindingDeclarations.h index e6bcd2903598..0a719e661771 100644 --- a/dom/bindings/BindingDeclarations.h +++ b/dom/bindings/BindingDeclarations.h @@ -425,7 +425,7 @@ enum class ReflectionScope { Content, XBL, UAWidget }; struct MOZ_STACK_CLASS ParentObject { template MOZ_IMPLICIT ParentObject(T* aObject) - : mObject(aObject), + : mObject(ToSupports(aObject)), mWrapperCache(GetWrapperCache(aObject)), mReflectionScope(ReflectionScope::Content) {} diff --git a/dom/console/Console.cpp b/dom/console/Console.cpp index 318f2e4a101b..1caa8b1ab80a 100644 --- a/dom/console/Console.cpp +++ b/dom/console/Console.cpp @@ -15,6 +15,7 @@ #include "mozilla/dom/File.h" #include "mozilla/dom/FunctionBinding.h" #include "mozilla/dom/Performance.h" +#include "mozilla/dom/PromiseBinding.h" #include "mozilla/dom/ScriptSettings.h" #include "mozilla/dom/StructuredCloneHolder.h" #include "mozilla/dom/ToJSValue.h" diff --git a/dom/events/EventStateManager.cpp b/dom/events/EventStateManager.cpp index 12b3ebef5eb2..6f7cef0d7710 100644 --- a/dom/events/EventStateManager.cpp +++ b/dom/events/EventStateManager.cpp @@ -2102,7 +2102,7 @@ void EventStateManager::DoScrollZoom(nsIFrame* aTargetFrame, ChangeTextSize(change); } nsContentUtils::DispatchChromeEvent( - mDocument, static_cast(mDocument), + mDocument, ToSupports(mDocument), NS_LITERAL_STRING("ZoomChangeUsingMouseWheel"), CanBubble::eYes, Cancelable::eYes); } diff --git a/dom/html/ImageDocument.cpp b/dom/html/ImageDocument.cpp index 768763de7213..6e4eb0275bd3 100644 --- a/dom/html/ImageDocument.cpp +++ b/dom/html/ImageDocument.cpp @@ -131,7 +131,7 @@ NS_IMETHODIMP ImageListener::OnStopRequest(nsIRequest* aRequest, nsISupports* aCtxt, nsresult aStatus) { ImageDocument* imgDoc = static_cast(mDocument.get()); - nsContentUtils::DispatchChromeEvent(imgDoc, static_cast(imgDoc), + nsContentUtils::DispatchChromeEvent(imgDoc, ToSupports(imgDoc), NS_LITERAL_STRING("ImageContentLoaded"), CanBubble::eYes, Cancelable::eYes); return MediaDocumentStreamListener::OnStopRequest(aRequest, aCtxt, aStatus); diff --git a/dom/html/nsHTMLContentSink.cpp b/dom/html/nsHTMLContentSink.cpp index 6abbb5d2c12e..30b3308cd436 100644 --- a/dom/html/nsHTMLContentSink.cpp +++ b/dom/html/nsHTMLContentSink.cpp @@ -950,7 +950,7 @@ void HTMLContentSink::SetDocumentCharset(NotNull aEncoding) { MOZ_ASSERT_UNREACHABLE(" case doesn't occur with about:blank"); } -nsISupports* HTMLContentSink::GetTarget() { return mDocument; } +nsISupports* HTMLContentSink::GetTarget() { return ToSupports(mDocument); } bool HTMLContentSink::IsScriptExecuting() { return IsScriptExecutingImpl(); } diff --git a/dom/html/nsHTMLDocument.h b/dom/html/nsHTMLDocument.h index b624c4c04c3c..f65ed0037b91 100644 --- a/dom/html/nsHTMLDocument.h +++ b/dom/html/nsHTMLDocument.h @@ -7,6 +7,7 @@ #define nsHTMLDocument_h___ #include "mozilla/Attributes.h" +#include "nsContentList.h" #include "nsDocument.h" #include "nsIHTMLDocument.h" #include "nsIHTMLCollection.h" @@ -33,6 +34,8 @@ class HTMLAllCollection; } // namespace mozilla class nsHTMLDocument : public nsDocument, public nsIHTMLDocument { + typedef mozilla::net::ReferrerPolicy ReferrerPolicy; + public: using nsDocument::GetPlugins; using nsDocument::SetDocumentURI; diff --git a/dom/ipc/TabChild.cpp b/dom/ipc/TabChild.cpp index 5aaf96211cca..a2a4b73475b3 100644 --- a/dom/ipc/TabChild.cpp +++ b/dom/ipc/TabChild.cpp @@ -444,7 +444,7 @@ TabChild::Observe(nsISupports* aSubject, const char* aTopic, nsCOMPtr subject(do_QueryInterface(aSubject)); nsCOMPtr doc(GetDocument()); - if (SameCOMIdentity(subject, doc)) { + if (subject == doc) { nsCOMPtr shell(doc->GetShell()); if (shell) { shell->SetIsFirstPaint(true); diff --git a/dom/svg/SVGAngle.cpp b/dom/svg/SVGAngle.cpp index f5314af09804..9bb3e84eb950 100644 --- a/dom/svg/SVGAngle.cpp +++ b/dom/svg/SVGAngle.cpp @@ -16,6 +16,12 @@ NS_SVG_VAL_IMPL_CYCLE_COLLECTION_WRAPPERCACHED(SVGAngle, mSVGElement) NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(SVGAngle, AddRef) NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(SVGAngle, Release) +SVGAngle::SVGAngle(SVGElement* aSVGElement) + : mSVGElement(aSVGElement), mType(SVGAngle::CreatedValue) { + mVal = new nsSVGAngle(); + mVal->Init(); +} + JSObject* SVGAngle::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { return SVGAngle_Binding::Wrap(aCx, this, aGivenProto); diff --git a/dom/svg/SVGAngle.h b/dom/svg/SVGAngle.h index 55fcde8db917..f3ef4502a6fd 100644 --- a/dom/svg/SVGAngle.h +++ b/dom/svg/SVGAngle.h @@ -23,9 +23,18 @@ class SVGAngle final : public nsWrapperCache { NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(SVGAngle) NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(SVGAngle) + /** + * Generic ctor for SVGAngle objects that are created for an attribute. + */ SVGAngle(nsSVGAngle* aVal, SVGElement* aSVGElement, AngleType aType) : mVal(aVal), mSVGElement(aSVGElement), mType(aType) {} + /** + * Ctor for creating the objects returned by SVGSVGElement.createSVGAngle(), + * which do not initially belong to an attribute. + */ + explicit SVGAngle(SVGElement* aSVGElement); + // WebIDL SVGElement* GetParentObject() { return mSVGElement; } virtual JSObject* WrapObject(JSContext* aCx, diff --git a/dom/svg/SVGSVGElement.cpp b/dom/svg/SVGSVGElement.cpp index 3bf655d969cb..9232e95828c0 100644 --- a/dom/svg/SVGSVGElement.cpp +++ b/dom/svg/SVGSVGElement.cpp @@ -22,7 +22,6 @@ #include "nsIFrame.h" #include "nsISVGSVGFrame.h" #include "nsSMILTimeContainer.h" -#include "nsSVGAngle.h" #include "SVGAngle.h" #include "nsSVGDisplayableFrame.h" #include "nsSVGUtils.h" @@ -263,10 +262,7 @@ already_AddRefed SVGSVGElement::CreateSVGLength() { } already_AddRefed SVGSVGElement::CreateSVGAngle() { - nsSVGAngle* angle = new nsSVGAngle(); - angle->Init(); - RefPtr svgangle = new SVGAngle(angle, this, SVGAngle::CreatedValue); - return svgangle.forget(); + return do_AddRef(new SVGAngle(this)); } already_AddRefed SVGSVGElement::CreateSVGPoint() { diff --git a/dom/xbl/nsXBLProtoImplField.cpp b/dom/xbl/nsXBLProtoImplField.cpp index d2f5ee49407d..4fe17ed602d8 100644 --- a/dom/xbl/nsXBLProtoImplField.cpp +++ b/dom/xbl/nsXBLProtoImplField.cpp @@ -17,6 +17,7 @@ #include "nsIURI.h" #include "nsXBLSerialize.h" #include "nsXBLPrototypeBinding.h" +#include "mozilla/CycleCollectedJSContext.h" #include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/ElementBinding.h" #include "mozilla/dom/ScriptSettings.h" diff --git a/dom/xbl/nsXBLProtoImplMethod.cpp b/dom/xbl/nsXBLProtoImplMethod.cpp index 0d18b92dc994..2820f3254b76 100644 --- a/dom/xbl/nsXBLProtoImplMethod.cpp +++ b/dom/xbl/nsXBLProtoImplMethod.cpp @@ -19,6 +19,7 @@ #include "nsIXPConnect.h" #include "xpcpublic.h" #include "nsXBLPrototypeBinding.h" +#include "mozilla/CycleCollectedJSContext.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/ScriptSettings.h" diff --git a/dom/xhr/XMLHttpRequestMainThread.cpp b/dom/xhr/XMLHttpRequestMainThread.cpp index 5ffc4a2420a2..f6a70fd85f69 100644 --- a/dom/xhr/XMLHttpRequestMainThread.cpp +++ b/dom/xhr/XMLHttpRequestMainThread.cpp @@ -24,6 +24,7 @@ #include "mozilla/dom/MutableBlobStorage.h" #include "mozilla/dom/XMLDocument.h" #include "mozilla/dom/URLSearchParams.h" +#include "mozilla/dom/Promise.h" #include "mozilla/dom/PromiseNativeHandler.h" #include "mozilla/Encoding.h" #include "mozilla/EventDispatcher.h" @@ -709,7 +710,8 @@ void XMLHttpRequestMainThread::GetResponse( return; } - aRv = nsContentUtils::WrapNative(aCx, mResponseXML, aResponse); + aRv = + nsContentUtils::WrapNative(aCx, ToSupports(mResponseXML), aResponse); return; } case XMLHttpRequestResponseType::Json: { diff --git a/dom/xml/XMLDocument.cpp b/dom/xml/XMLDocument.cpp index 5a4c9ba58c41..c5fe4bf622fa 100644 --- a/dom/xml/XMLDocument.cpp +++ b/dom/xml/XMLDocument.cpp @@ -545,7 +545,7 @@ void XMLDocument::EndLoad() { // document was loaded as pure data without any presentation // attached to it. WidgetEvent event(true, eLoad); - EventDispatcher::Dispatch(static_cast(this), nullptr, &event); + EventDispatcher::Dispatch(ToSupports(this), nullptr, &event); } } diff --git a/dom/xml/nsXMLContentSink.cpp b/dom/xml/nsXMLContentSink.cpp index 966ff75fe1c4..2e9cbd18a3db 100644 --- a/dom/xml/nsXMLContentSink.cpp +++ b/dom/xml/nsXMLContentSink.cpp @@ -737,7 +737,7 @@ void nsXMLContentSink::SetDocumentCharset(NotNull aEncoding) { } } -nsISupports* nsXMLContentSink::GetTarget() { return mDocument; } +nsISupports* nsXMLContentSink::GetTarget() { return ToSupports(mDocument); } bool nsXMLContentSink::IsScriptExecuting() { return IsScriptExecutingImpl(); } diff --git a/dom/xml/nsXMLFragmentContentSink.cpp b/dom/xml/nsXMLFragmentContentSink.cpp index d2048837c95f..71e04be17a61 100644 --- a/dom/xml/nsXMLFragmentContentSink.cpp +++ b/dom/xml/nsXMLFragmentContentSink.cpp @@ -168,7 +168,9 @@ void nsXMLFragmentContentSink::SetDocumentCharset( MOZ_ASSERT_UNREACHABLE("fragments shouldn't set charset"); } -nsISupports* nsXMLFragmentContentSink::GetTarget() { return mTargetDocument; } +nsISupports* nsXMLFragmentContentSink::GetTarget() { + return ToSupports(mTargetDocument); +} //////////////////////////////////////////////////////////////////////// diff --git a/dom/xul/XULDocument.cpp b/dom/xul/XULDocument.cpp index 3a7fef0a2390..005fc13f252f 100644 --- a/dom/xul/XULDocument.cpp +++ b/dom/xul/XULDocument.cpp @@ -78,6 +78,7 @@ #include "nsCCUncollectableMarker.h" #include "nsURILoader.h" #include "mozilla/BasicEvents.h" +#include "mozilla/CycleCollectedJSContext.h" #include "mozilla/dom/DocumentL10n.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/NodeInfoInlines.h" @@ -989,9 +990,8 @@ nsresult XULDocument::DoneWalking() { mDocumentL10n, true, false); nsContentUtils::DispatchTrustedEvent( - this, static_cast(this), - NS_LITERAL_STRING("MozBeforeInitialXULLayout"), CanBubble::eYes, - Cancelable::eNo); + this, ToSupports(this), NS_LITERAL_STRING("MozBeforeInitialXULLayout"), + CanBubble::eYes, Cancelable::eNo); RemoveEventListener(NS_LITERAL_STRING("MozBeforeInitialXULLayout"), mDocumentL10n, true); diff --git a/dom/xul/nsXULContentSink.cpp b/dom/xul/nsXULContentSink.cpp index a4b5cd571f98..0b25fb931179 100644 --- a/dom/xul/nsXULContentSink.cpp +++ b/dom/xul/nsXULContentSink.cpp @@ -232,7 +232,7 @@ void XULContentSinkImpl::SetDocumentCharset( nsISupports* XULContentSinkImpl::GetTarget() { nsCOMPtr doc = do_QueryReferent(mDocument); - return doc; + return ToSupports(doc); } //---------------------------------------------------------------------- diff --git a/gfx/layers/wr/WebRenderBridgeParent.cpp b/gfx/layers/wr/WebRenderBridgeParent.cpp index 59f21901bc49..fe7fdef9d88b 100644 --- a/gfx/layers/wr/WebRenderBridgeParent.cpp +++ b/gfx/layers/wr/WebRenderBridgeParent.cpp @@ -735,6 +735,7 @@ mozilla::ipc::IPCResult WebRenderBridgeParent::RecvValidateFontDescriptor( << family << "\" has " << (attribs == INVALID_FILE_ATTRIBUTES ? "INVALID" : "valid") + << "(" << hexa(attribs) << ")" << " file \"" << files << "\""; } remaining -= fileLength + 1; diff --git a/image/VectorImage.cpp b/image/VectorImage.cpp index c48b43618c74..cfe24202113e 100644 --- a/image/VectorImage.cpp +++ b/image/VectorImage.cpp @@ -17,6 +17,7 @@ #include "mozilla/dom/SVGSVGElement.h" #include "mozilla/dom/SVGDocument.h" #include "mozilla/gfx/2D.h" +#include "mozilla/PendingAnimationTracker.h" #include "mozilla/RefPtr.h" #include "mozilla/Tuple.h" #include "nsIPresShell.h" @@ -36,7 +37,7 @@ #include "SVGDrawingParameters.h" #include "nsIDOMEventListener.h" #include "SurfaceCache.h" -#include "nsDocument.h" +#include "nsIDocument.h" namespace mozilla { @@ -1479,9 +1480,8 @@ void VectorImage::PropagateUseCounters(nsIDocument* aParentDocument) { } void VectorImage::ReportUseCounters() { - nsIDocument* doc = mSVGDocumentWrapper->GetDocument(); - if (doc) { - static_cast(doc)->ReportUseCounters(); + if (nsIDocument* doc = mSVGDocumentWrapper->GetDocument()) { + doc->ReportUseCounters(); } } diff --git a/image/imgLoader.cpp b/image/imgLoader.cpp index a1550adf2dbc..0c38265534c3 100644 --- a/image/imgLoader.cpp +++ b/image/imgLoader.cpp @@ -2155,11 +2155,11 @@ nsresult imgLoader::LoadImage( if (cache.Get(key, getter_AddRefs(entry)) && entry) { bool newChannelCreated = false; - if (ValidateEntry(entry, aURI, aInitialDocumentURI, aReferrerURI, - aReferrerPolicy, aLoadGroup, aObserver, aLoadingDocument, - aLoadingDocument, requestFlags, aContentPolicyType, true, - &newChannelCreated, _retval, aTriggeringPrincipal, - corsmode)) { + if (ValidateEntry( + entry, aURI, aInitialDocumentURI, aReferrerURI, aReferrerPolicy, + aLoadGroup, aObserver, ToSupports(aLoadingDocument), + aLoadingDocument, requestFlags, aContentPolicyType, true, + &newChannelCreated, _retval, aTriggeringPrincipal, corsmode)) { request = entry->GetRequest(); // If this entry has no proxies, its request has no reference to the @@ -2185,9 +2185,10 @@ nsresult imgLoader::LoadImage( // - we don't have cache. We are not in this if() stmt. A new channel is // created and that triggers the CSP checks. // - We have a cache entry and this is blocked by CSP directives. - DebugOnly shouldLoad = ShouldLoadCachedImage( - request, aLoadingDocument, aTriggeringPrincipal, aContentPolicyType, - /* aSendCSPViolationReports */ true); + DebugOnly shouldLoad = + ShouldLoadCachedImage(request, ToSupports(aLoadingDocument), + aTriggeringPrincipal, aContentPolicyType, + /* aSendCSPViolationReports */ true); MOZ_ASSERT(shouldLoad); } } else { @@ -2244,8 +2245,9 @@ nsresult imgLoader::LoadImage( nsCOMPtr channelLoadGroup; newChannel->GetLoadGroup(getter_AddRefs(channelLoadGroup)); rv = request->Init(aURI, aURI, /* aHadInsecureRedirect = */ false, - channelLoadGroup, newChannel, entry, aLoadingDocument, - aTriggeringPrincipal, corsmode, aReferrerPolicy); + channelLoadGroup, newChannel, entry, + ToSupports(aLoadingDocument), aTriggeringPrincipal, + corsmode, aReferrerPolicy); if (NS_FAILED(rv)) { return NS_ERROR_FAILURE; } diff --git a/layout/base/GeometryUtils.cpp b/layout/base/GeometryUtils.cpp index 251480e62d7f..d8555dd0a6c9 100644 --- a/layout/base/GeometryUtils.cpp +++ b/layout/base/GeometryUtils.cpp @@ -157,12 +157,12 @@ static nsRect GetBoxRectForFrame(nsIFrame** aFrame, CSSBoxType aType) { class AccumulateQuadCallback : public nsLayoutUtils::BoxCallback { public: - AccumulateQuadCallback(nsISupports* aParentObject, + AccumulateQuadCallback(nsIDocument* aParentObject, nsTArray >& aResult, nsIFrame* aRelativeToFrame, const nsPoint& aRelativeToBoxTopLeft, CSSBoxType aBoxType) - : mParentObject(aParentObject), + : mParentObject(ToSupports(aParentObject)), mResult(aResult), mRelativeToFrame(aRelativeToFrame), mRelativeToBoxTopLeft(aRelativeToBoxTopLeft), diff --git a/layout/base/MobileViewportManager.cpp b/layout/base/MobileViewportManager.cpp index df929fdec637..7e08cba7072a 100644 --- a/layout/base/MobileViewportManager.cpp +++ b/layout/base/MobileViewportManager.cpp @@ -159,7 +159,7 @@ MobileViewportManager::HandleEvent(dom::Event* event) { NS_IMETHODIMP MobileViewportManager::Observe(nsISupports* aSubject, const char* aTopic, const char16_t* aData) { - if (SameCOMIdentity(aSubject, mDocument) && + if (SameCOMIdentity(aSubject, ToSupports(mDocument)) && BEFORE_FIRST_PAINT.EqualsASCII(aTopic)) { MVM_LOG("%p: got a before-first-paint event\n", this); if (!mPainted) { diff --git a/layout/base/PresShell.cpp b/layout/base/PresShell.cpp index 583310ef6d1f..8fc50f28d61c 100644 --- a/layout/base/PresShell.cpp +++ b/layout/base/PresShell.cpp @@ -520,8 +520,8 @@ class nsBeforeFirstPaintDispatcher : public Runnable { nsCOMPtr observerService = mozilla::services::GetObserverService(); if (observerService) { - observerService->NotifyObservers(mDocument, "before-first-paint", - nullptr); + observerService->NotifyObservers(ToSupports(mDocument), + "before-first-paint", nullptr); } return NS_OK; } @@ -1444,7 +1444,7 @@ void nsIPresShell::SetAuthorStyleDisabled(bool aStyleDisabled) { mozilla::services::GetObserverService(); if (observerService) { observerService->NotifyObservers( - mDocument, "author-style-disabled-changed", nullptr); + ToSupports(mDocument), "author-style-disabled-changed", nullptr); } } } diff --git a/layout/base/ZoomConstraintsClient.cpp b/layout/base/ZoomConstraintsClient.cpp index a6b1f5c86e12..1da811cd002c 100644 --- a/layout/base/ZoomConstraintsClient.cpp +++ b/layout/base/ZoomConstraintsClient.cpp @@ -144,7 +144,7 @@ ZoomConstraintsClient::HandleEvent(dom::Event* event) { NS_IMETHODIMP ZoomConstraintsClient::Observe(nsISupports* aSubject, const char* aTopic, const char16_t* aData) { - if (SameCOMIdentity(aSubject, mDocument) && + if (SameCOMIdentity(aSubject, ToSupports(mDocument)) && BEFORE_FIRST_PAINT.EqualsASCII(aTopic)) { ZCC_LOG("Got a before-first-paint event in %p\n", this); RefreshZoomConstraints(); diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index c18aaa2239dc..5e21f430aa85 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -488,18 +488,19 @@ class AutoPrintEventDispatcher { private: void DispatchEventToWindowTree(const nsAString& aEvent) { - nsCOMArray targets; + nsTArray> targets; CollectDocuments(mTop, &targets); - for (int32_t i = 0; i < targets.Count(); ++i) { - nsIDocument* d = targets[i]; - nsContentUtils::DispatchTrustedEvent( - d, d->GetWindow(), aEvent, CanBubble::eNo, Cancelable::eNo, nullptr); + for (nsCOMPtr& doc : targets) { + nsContentUtils::DispatchTrustedEvent(doc, doc->GetWindow(), aEvent, + CanBubble::eNo, Cancelable::eNo, + nullptr); } } static bool CollectDocuments(nsIDocument* aDocument, void* aData) { if (aDocument) { - static_cast*>(aData)->AppendObject(aDocument); + static_cast>*>(aData)->AppendElement( + aDocument); aDocument->EnumerateSubDocuments(CollectDocuments, aData); } return true; @@ -1085,7 +1086,7 @@ nsDocumentViewer::LoadComplete(nsresult aStatus) { nsCOMPtr os = mozilla::services::GetObserverService(); if (os) { nsIPrincipal* principal = d->NodePrincipal(); - os->NotifyObservers(d, + os->NotifyObservers(ToSupports(d), nsContentUtils::IsSystemPrincipal(principal) ? "chrome-document-loaded" : "content-document-loaded", @@ -2851,9 +2852,9 @@ nsDocumentViewer::SetTextZoom(float aTextZoom) { // Dispatch TextZoomChange event only if text zoom value has changed. if (textZoomChange) { - nsContentUtils::DispatchChromeEvent( - mDocument, static_cast(mDocument), - NS_LITERAL_STRING("TextZoomChange"), CanBubble::eYes, Cancelable::eYes); + nsContentUtils::DispatchChromeEvent(mDocument, ToSupports(mDocument), + NS_LITERAL_STRING("TextZoomChange"), + CanBubble::eYes, Cancelable::eYes); } return NS_OK; @@ -2968,9 +2969,9 @@ nsDocumentViewer::SetFullZoom(float aFullZoom) { // Dispatch FullZoomChange event only if fullzoom value really was been // changed if (fullZoomChange) { - nsContentUtils::DispatchChromeEvent( - mDocument, static_cast(mDocument), - NS_LITERAL_STRING("FullZoomChange"), CanBubble::eYes, Cancelable::eYes); + nsContentUtils::DispatchChromeEvent(mDocument, ToSupports(mDocument), + NS_LITERAL_STRING("FullZoomChange"), + CanBubble::eYes, Cancelable::eYes); } return NS_OK; @@ -4381,7 +4382,8 @@ nsDocumentShownDispatcher::Run() { nsCOMPtr observerService = mozilla::services::GetObserverService(); if (observerService) { - observerService->NotifyObservers(mDocument, "document-shown", nullptr); + observerService->NotifyObservers(ToSupports(mDocument), "document-shown", + nullptr); } return NS_OK; } diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index fcea7f01bff2..5150c3762852 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -8572,8 +8572,8 @@ void MaybeSetupTransactionIdAllocator(layers::LayerManager* aManager, if (nsIDocument* doc = aShell->GetDocument()) { WidgetEvent event(true, eVoidEvent); nsTArray targets; - nsresult rv = EventDispatcher::Dispatch(doc, nullptr, &event, nullptr, - nullptr, nullptr, &targets); + nsresult rv = EventDispatcher::Dispatch( + ToSupports(doc), nullptr, &event, nullptr, nullptr, nullptr, &targets); NS_ENSURE_SUCCESS(rv, false); for (size_t i = 0; i < targets.Length(); i++) { if (targets[i]->IsApzAware()) { diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp index 08ae9522ad4d..3ddfd511801d 100644 --- a/layout/generic/nsGfxScrollFrame.cpp +++ b/layout/generic/nsGfxScrollFrame.cpp @@ -4914,9 +4914,9 @@ void ScrollFrameHelper::FireScrollEvent() { mozilla::layers::ScrollLinkedEffectDetector detector( content->GetComposedDoc()); if (mIsRoot) { - nsIDocument* doc = content->GetUncomposedDoc(); - if (doc) { - EventDispatcher::Dispatch(doc, prescontext, &event, nullptr, &status); + if (nsIDocument* doc = content->GetUncomposedDoc()) { + EventDispatcher::Dispatch(ToSupports(doc), prescontext, &event, nullptr, + &status); } } else { // scroll events fired at elements don't bubble (although scroll events @@ -6193,10 +6193,8 @@ void ScrollFrameHelper::FireScrolledAreaEvent() { nsIContent* content = mOuter->GetContent(); event.mArea = mScrolledFrame->GetScrollableOverflowRectRelativeToParent(); - - nsIDocument* doc = content->GetUncomposedDoc(); - if (doc) { - EventDispatcher::Dispatch(doc, prescontext, &event, nullptr); + if (nsIDocument* doc = content->GetUncomposedDoc()) { + EventDispatcher::Dispatch(ToSupports(doc), prescontext, &event, nullptr); } } diff --git a/layout/style/MediaQueryList.cpp b/layout/style/MediaQueryList.cpp index b01d8743131f..4568d1d611e9 100644 --- a/layout/style/MediaQueryList.cpp +++ b/layout/style/MediaQueryList.cpp @@ -143,7 +143,9 @@ void MediaQueryList::RecomputeMatches() { mMatchesValid = true; } -nsISupports* MediaQueryList::GetParentObject() const { return mDocument; } +nsISupports* MediaQueryList::GetParentObject() const { + return ToSupports(mDocument); +} JSObject* MediaQueryList::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { diff --git a/layout/style/ServoBindings.toml b/layout/style/ServoBindings.toml index e32a92a792c7..25371c9934d8 100644 --- a/layout/style/ServoBindings.toml +++ b/layout/style/ServoBindings.toml @@ -49,11 +49,6 @@ hide-types = [ "nsString", ".*char_traits", ".*incompatible_char_type", - # JS::Value uses alignas(8) which bindgen can't represent correctly on Linux - # 32-bit. See https://github.com/rust-lang-nursery/rust-bindgen/issues/917. - # It's also not used by Stylo. The following types are also hidden for - # making use of it and being similarly unused by Stylo. - "JS::Value", "mozilla::binding_danger::TErrorResult.*", "mozilla::ErrorResult.*", # Causes JSWhyMagic to be included & handled incorrectly. "mozilla::dom::CallbackFunction", diff --git a/parser/html/nsHtml5TreeOpExecutor.cpp b/parser/html/nsHtml5TreeOpExecutor.cpp index 36924d285c3c..a779734d130c 100644 --- a/parser/html/nsHtml5TreeOpExecutor.cpp +++ b/parser/html/nsHtml5TreeOpExecutor.cpp @@ -234,7 +234,9 @@ void nsHtml5TreeOpExecutor::FlushPendingNotifications(FlushType aType) { } } -nsISupports* nsHtml5TreeOpExecutor::GetTarget() { return mDocument; } +nsISupports* nsHtml5TreeOpExecutor::GetTarget() { + return ToSupports(mDocument); +} nsresult nsHtml5TreeOpExecutor::MarkAsBroken(nsresult aReason) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); diff --git a/toolkit/components/browser/nsWebBrowser.cpp b/toolkit/components/browser/nsWebBrowser.cpp index 3f9cc7c5a53f..c36ad5ddc00f 100644 --- a/toolkit/components/browser/nsWebBrowser.cpp +++ b/toolkit/components/browser/nsWebBrowser.cpp @@ -887,7 +887,7 @@ nsWebBrowser::SaveDocument(nsISupports* aDocumentish, nsISupports* aFile, } else { nsCOMPtr domDoc; GetDocument(getter_AddRefs(domDoc)); - doc = domDoc.forget(); + doc = already_AddRefed(ToSupports(domDoc.forget().take())); } if (!doc) { return NS_ERROR_FAILURE; diff --git a/toolkit/content/tests/widgets/xbl/mochitest.ini b/toolkit/content/tests/widgets/xbl/mochitest.ini index b4fc5c8c9c02..ec2d4f1e8ca4 100644 --- a/toolkit/content/tests/widgets/xbl/mochitest.ini +++ b/toolkit/content/tests/widgets/xbl/mochitest.ini @@ -26,7 +26,7 @@ support-files = [test_audiocontrols_dimensions.html] [test_videocontrols.html] tags = fullscreen -skip-if = toolkit == 'android' || (verify && debug && (os == 'linux')) #TIMED_OUT +skip-if = toolkit == 'android' || (verify && debug && (os == 'linux')) || (os == 'linux') #TIMED_OUT, Bug 1511256 [test_videocontrols_keyhandler.html] skip-if = (toolkit == 'android') || (os == 'linux') #Bug 1366957 [test_videocontrols_vtt.html] diff --git a/uriloader/prefetch/OfflineCacheUpdateChild.cpp b/uriloader/prefetch/OfflineCacheUpdateChild.cpp index 30c16eb1893f..8270accf505a 100644 --- a/uriloader/prefetch/OfflineCacheUpdateChild.cpp +++ b/uriloader/prefetch/OfflineCacheUpdateChild.cpp @@ -134,12 +134,8 @@ nsresult OfflineCacheUpdateChild::AssociateDocument( // Check that the document that requested this update was // previously associated with an application cache. If not, it // should be associated with the new one. - nsCOMPtr container = - do_QueryInterface(aDocument); - if (!container) return NS_OK; - nsCOMPtr existingCache; - nsresult rv = container->GetApplicationCache(getter_AddRefs(existingCache)); + nsresult rv = aDocument->GetApplicationCache(getter_AddRefs(existingCache)); NS_ENSURE_SUCCESS(rv, rv); if (!existingCache) { @@ -152,7 +148,7 @@ nsresult OfflineCacheUpdateChild::AssociateDocument( clientID.get(), aDocument)); } - rv = container->SetApplicationCache(aApplicationCache); + rv = aDocument->SetApplicationCache(aApplicationCache); NS_ENSURE_SUCCESS(rv, rv); } diff --git a/uriloader/prefetch/OfflineCacheUpdateGlue.cpp b/uriloader/prefetch/OfflineCacheUpdateGlue.cpp index 5d034269b363..20ada6f6a2e9 100644 --- a/uriloader/prefetch/OfflineCacheUpdateGlue.cpp +++ b/uriloader/prefetch/OfflineCacheUpdateGlue.cpp @@ -183,12 +183,12 @@ OfflineCacheUpdateGlue::ApplicationCacheAvailable( // Check that the document that requested this update was // previously associated with an application cache. If not, it // should be associated with the new one. - nsCOMPtr container = - do_QueryInterface(mDocument); - if (!container) return NS_OK; + if (!mDocument) { + return NS_OK; + } nsCOMPtr existingCache; - nsresult rv = container->GetApplicationCache(getter_AddRefs(existingCache)); + nsresult rv = mDocument->GetApplicationCache(getter_AddRefs(existingCache)); NS_ENSURE_SUCCESS(rv, rv); if (!existingCache) { @@ -201,7 +201,7 @@ OfflineCacheUpdateGlue::ApplicationCacheAvailable( clientID.get(), mDocument.get())); } - rv = container->SetApplicationCache(aApplicationCache); + rv = mDocument->SetApplicationCache(aApplicationCache); NS_ENSURE_SUCCESS(rv, rv); } diff --git a/uriloader/prefetch/nsOfflineCacheUpdateService.cpp b/uriloader/prefetch/nsOfflineCacheUpdateService.cpp index 341f0ecb6daf..4716d6fef88f 100644 --- a/uriloader/prefetch/nsOfflineCacheUpdateService.cpp +++ b/uriloader/prefetch/nsOfflineCacheUpdateService.cpp @@ -166,9 +166,7 @@ nsOfflineCachePendingUpdate::OnStateChange(nsIWebProgress *aWebProgress, nsPIDOMWindowInner *innerWindow = outerWindow->GetCurrentInnerWindow(); nsCOMPtr progressDoc = outerWindow->GetDoc(); - if (!progressDoc) return NS_OK; - - if (!SameCOMIdentity(progressDoc, updateDoc)) { + if (!progressDoc || progressDoc != updateDoc) { return NS_OK; } diff --git a/xpcom/base/nsCOMPtr.h b/xpcom/base/nsCOMPtr.h index 85f14a83ac63..8afb29f512b1 100644 --- a/xpcom/base/nsCOMPtr.h +++ b/xpcom/base/nsCOMPtr.h @@ -164,7 +164,8 @@ template class MOZ_STACK_CLASS nsQueryInterface final : public nsQueryInterfaceISupports { public: - explicit nsQueryInterface(T* aRawPtr) : nsQueryInterfaceISupports(aRawPtr) {} + explicit nsQueryInterface(T* aRawPtr) + : nsQueryInterfaceISupports(ToSupports(aRawPtr)) {} nsresult NS_FASTCALL operator()(const nsIID& aIID, void** aAnswer) const { return nsQueryInterfaceISupports::operator()(aIID, aAnswer); @@ -190,7 +191,7 @@ class MOZ_STACK_CLASS nsQueryInterfaceWithError final : public nsQueryInterfaceISupportsWithError { public: explicit nsQueryInterfaceWithError(T* aRawPtr, nsresult* aError) - : nsQueryInterfaceISupportsWithError(aRawPtr, aError) {} + : nsQueryInterfaceISupportsWithError(ToSupports(aRawPtr), aError) {} nsresult NS_FASTCALL operator()(const nsIID& aIID, void** aAnswer) const { return nsQueryInterfaceISupportsWithError::operator()(aIID, aAnswer); @@ -198,19 +199,6 @@ class MOZ_STACK_CLASS nsQueryInterfaceWithError final }; #endif // #ifndef NSCAP_FEATURE_USE_BASE -#ifdef NSCAP_FEATURE_USE_BASE - -inline nsQueryInterfaceISupports do_QueryInterface(nsISupports* aRawPtr) { - return nsQueryInterfaceISupports(aRawPtr); -} - -inline nsQueryInterfaceISupportsWithError do_QueryInterface( - nsISupports* aRawPtr, nsresult* aError) { - return nsQueryInterfaceISupportsWithError(aRawPtr, aError); -} - -#else - namespace mozilla { // PointedToType<> is needed so that do_QueryInterface() will work with a // variety of smart pointer types in addition to raw pointers. These types @@ -220,6 +208,20 @@ using PointedToType = typename mozilla::RemovePointer())>::Type; } // namespace mozilla +#ifdef NSCAP_FEATURE_USE_BASE +template +inline nsQueryInterfaceISupports do_QueryInterface(T aPtr) { + return nsQueryInterfaceISupports( + ToSupports(static_cast*>(aPtr))); +} + +template +inline nsQueryInterfaceISupportsWithError do_QueryInterface(T aPtr, + nsresult* aError) { + return nsQueryInterfaceISupportsWithError( + ToSupports(static_cast*>(aPtr)), aError); +} +#else template inline nsQueryInterface > do_QueryInterface(T aPtr) { return nsQueryInterface >(aPtr); @@ -230,6 +232,7 @@ inline nsQueryInterfaceWithError > do_QueryInterface( T aRawPtr, nsresult* aError) { return nsQueryInterfaceWithError >(aRawPtr, aError); } + #endif // ! #ifdef NSCAP_FEATURE_USE_BASE template @@ -380,13 +383,15 @@ class MOZ_IS_REFPTR nsCOMPtr final : private nsCOMPtr_base #endif { - + private: #ifdef NSCAP_FEATURE_USE_BASE -#define NSCAP_CTOR_BASE(x) nsCOMPtr_base(x) +#define NSCAP_CTOR_BASE(x) nsCOMPtr_base(ToSupports(x)) + void assign_assuming_AddRef(T* aNewPtr) { + nsCOMPtr_base::assign_assuming_AddRef(ToSupports(aNewPtr)); + } #else #define NSCAP_CTOR_BASE(x) mRawPtr(x) - private: void assign_with_AddRef(nsISupports*); template void assign_from_qi(const nsQueryInterface, const nsIID&); @@ -635,7 +640,7 @@ class MOZ_IS_REFPTR nsCOMPtr final // Assignment operators nsCOMPtr& operator=(const nsCOMPtr& aRhs) { - assign_with_AddRef(aRhs.mRawPtr); + assign_with_AddRef(ToSupports(aRhs.mRawPtr)); return *this; } @@ -644,7 +649,7 @@ class MOZ_IS_REFPTR nsCOMPtr final // Make sure that U actually inherits from T static_assert(mozilla::IsBaseOf::value, "U should be a subclass of T"); - assign_with_AddRef(static_cast(aRhs.get())); + assign_with_AddRef(ToSupports(static_cast(aRhs.get()))); return *this; } @@ -664,7 +669,7 @@ class MOZ_IS_REFPTR nsCOMPtr final } nsCOMPtr& operator=(T* aRhs) { - assign_with_AddRef(aRhs); + assign_with_AddRef(ToSupports(aRhs)); NSCAP_ASSERT_NO_QUERY_NEEDED(); return *this; } @@ -780,7 +785,7 @@ class MOZ_IS_REFPTR nsCOMPtr final // Exchange ownership with |aRhs|; can save a pair of refcount operations. void swap(T*& aRhs) { #ifdef NSCAP_FEATURE_USE_BASE - nsISupports* temp = aRhs; + nsISupports* temp = ToSupports(aRhs); #else T* temp = aRhs; #endif diff --git a/xpcom/base/nsISupportsImpl.h b/xpcom/base/nsISupportsImpl.h index 6eb9535217d7..f717ad936322 100644 --- a/xpcom/base/nsISupportsImpl.h +++ b/xpcom/base/nsISupportsImpl.h @@ -34,6 +34,8 @@ " should not have a public destructor. " \ "Make this class's destructor non-public"); +inline nsISupports* ToSupports(decltype(nullptr)) { return nullptr; } + inline nsISupports* ToSupports(nsISupports* aSupports) { return aSupports; } //////////////////////////////////////////////////////////////////////////////// @@ -147,10 +149,10 @@ class nsAutoOwningThread { * Note: The explicit comparison to nullptr is needed to avoid warnings * when _p is a nullptr itself. */ #define NSCAP_LOG_ASSIGNMENT(_c, _p) \ - if (_p != nullptr) NS_LogCOMPtrAddRef((_c), static_cast(_p)) + if (_p != nullptr) NS_LogCOMPtrAddRef((_c), ToSupports(_p)) #define NSCAP_LOG_RELEASE(_c, _p) \ - if (_p) NS_LogCOMPtrRelease((_c), static_cast(_p)) + if (_p) NS_LogCOMPtrRelease((_c), ToSupports(_p)) #else /* !NS_BUILD_REFCNT_LOGGING */ diff --git a/xpfe/appshell/nsContentTreeOwner.cpp b/xpfe/appshell/nsContentTreeOwner.cpp index ecec1d11dfdd..6b71be9d0f67 100644 --- a/xpfe/appshell/nsContentTreeOwner.cpp +++ b/xpfe/appshell/nsContentTreeOwner.cpp @@ -649,8 +649,7 @@ NS_IMETHODIMP nsContentTreeOwner::SetTitle(const nsAString& aTitle) { // nsCOMPtr dsitem; GetPrimaryContentShell(getter_AddRefs(dsitem)); - nsCOMPtr doc = - do_QueryInterface(dsitem ? dsitem->GetDocument() : nullptr); + nsCOMPtr doc = dsitem ? dsitem->GetDocument() : nullptr; if (doc) { nsCOMPtr uri; nsIPrincipal* principal = doc->GetPrincipal(); diff --git a/xpfe/appshell/nsWebShellWindow.cpp b/xpfe/appshell/nsWebShellWindow.cpp index 58093b3a8548..d7888f20fb29 100644 --- a/xpfe/appshell/nsWebShellWindow.cpp +++ b/xpfe/appshell/nsWebShellWindow.cpp @@ -7,6 +7,7 @@ #include "nsLayoutCID.h" #include "nsContentCID.h" +#include "nsContentList.h" #include "nsIWeakReference.h" #include "nsIContentViewer.h" #include "nsIComponentManager.h"