From 4fd57b7de3750050d84fcb7a0f5cd8c5e0d1abaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 26 Dec 2018 03:32:26 +0100 Subject: [PATCH 01/22] Bug 1516366 - Sprinkle some ToSupports around xpcom. r=froydnj This will be needed for the next patches since the cast from nsIDocument* to nsISupports* will become ambiguous, and I don't really want to replace all users of nsCOMPtr with RefPtr. We have ToSupports to handle this, so use it. Differential Revision: https://phabricator.services.mozilla.com/D15350 --- xpcom/base/nsCOMPtr.h | 49 ++++++++++++++++++++---------------- xpcom/base/nsISupportsImpl.h | 6 +++-- 2 files changed, 31 insertions(+), 24 deletions(-) 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 */ From ecc88f298e5ea0a21233770f2b683575965a6918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 26 Dec 2018 03:32:38 +0100 Subject: [PATCH 02/22] Bug 1516366 - Remove uses of nsCOMArray. r=bzbarsky,smaug Just use nsTArray. They're used to keep an array of strong references to documents, and never use nsISupports-specific methods. Plus they're are allocated on the stack so it should be safe to access them via ranged for, so do that. This is needed because nsCOMArray depends on the cast from T to nsISupports not to be ambiguous. I could fix that if needed, but it seems easier to just not use it in these two cases. Differential Revision: https://phabricator.services.mozilla.com/D15351 --- dom/base/nsDocument.cpp | 11 +++++------ dom/base/nsIDocument.h | 2 +- layout/base/nsDocumentViewer.cpp | 13 +++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 9b0da7c0e9f4..4effce47b034 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -11566,14 +11566,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; @@ -11597,11 +11596,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) { diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index 29c4ecc9666b..50a65f1f4ee2 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -4384,7 +4384,7 @@ class MOZ_STACK_CLASS nsAutoSyncOperation { ~nsAutoSyncOperation(); private: - nsCOMArray mDocuments; + nsTArray> mDocuments; uint32_t mMicroTaskLevel; }; diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index c18aaa2239dc..194acc69a010 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; From f131713362934f6e91fc0a0a70b8f1893f03a695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 26 Dec 2018 03:32:55 +0100 Subject: [PATCH 03/22] Bug 1516366 - Move base classes from nsDocument to nsIDocument. r=smaug This is a big step in order to merge both. Also allows to remove some very silly casts, though it causes us to add some ToSupports around to deal with ambiguity of casts from nsIDocument to nsISupports, and add a dummy nsISupports implementation that will go away later in the series. Differential Revision: https://phabricator.services.mozilla.com/D15352 --- docshell/base/nsDocShell.cpp | 9 +-- dom/animation/AnimationEffect.h | 2 +- dom/base/nsContentSink.cpp | 22 ++---- dom/base/nsDocument.cpp | 64 +++++++++-------- dom/base/nsDocument.h | 70 +------------------ dom/base/nsFocusManager.cpp | 5 +- dom/base/nsGlobalWindowOuter.cpp | 2 +- dom/base/nsIDocument.h | 68 ++++++++++++++++++ dom/base/nsImageLoadingContent.cpp | 4 +- dom/base/nsObjectLoadingContent.cpp | 2 +- dom/bindings/BindingDeclarations.h | 2 +- dom/events/EventStateManager.cpp | 2 +- dom/html/ImageDocument.cpp | 2 +- dom/html/nsHTMLContentSink.cpp | 2 +- dom/ipc/TabChild.cpp | 2 +- dom/xhr/XMLHttpRequestMainThread.cpp | 3 +- dom/xml/XMLDocument.cpp | 2 +- dom/xml/nsXMLContentSink.cpp | 2 +- dom/xml/nsXMLFragmentContentSink.cpp | 4 +- dom/xul/XULDocument.cpp | 5 +- dom/xul/nsXULContentSink.cpp | 2 +- image/imgLoader.cpp | 22 +++--- layout/base/GeometryUtils.cpp | 4 +- layout/base/MobileViewportManager.cpp | 2 +- layout/base/PresShell.cpp | 6 +- layout/base/ZoomConstraintsClient.cpp | 2 +- layout/base/nsDocumentViewer.cpp | 17 ++--- layout/base/nsLayoutUtils.cpp | 4 +- layout/generic/nsGfxScrollFrame.cpp | 12 ++-- layout/style/MediaQueryList.cpp | 4 +- parser/html/nsHtml5TreeOpExecutor.cpp | 4 +- toolkit/components/browser/nsWebBrowser.cpp | 2 +- .../prefetch/OfflineCacheUpdateChild.cpp | 8 +-- uriloader/prefetch/OfflineCacheUpdateGlue.cpp | 10 +-- .../prefetch/nsOfflineCacheUpdateService.cpp | 4 +- xpfe/appshell/nsContentTreeOwner.cpp | 3 +- 36 files changed, 185 insertions(+), 195 deletions(-) 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/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/nsDocument.cpp b/dom/base/nsDocument.cpp index 4effce47b034..e2c35fb56382 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -792,7 +792,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 +899,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,6 +1625,20 @@ nsDocument::~nsDocument() { mPlugins.Clear(); } +// In practice these three are always overriden by the nsDocument version, we +// just need them to avoid making nsIDocument::AddRef / Release ambiguous. +// +// We can get rid of these once we merge nsIDocument and nsDocument. +NS_IMETHODIMP_(MozExternalRefCountType) nsIDocument::Release() { + MOZ_CRASH("Should never be reachable"); +} +NS_IMETHODIMP_(MozExternalRefCountType) nsIDocument::AddRef() { + MOZ_CRASH("Should never be reachable"); +} +NS_IMETHODIMP nsIDocument::QueryInterface(REFNSIID aIID, void** aInstancePtr) { + MOZ_CRASH("Should never be reachable"); +} + NS_INTERFACE_TABLE_HEAD(nsDocument) NS_WRAPPERCACHE_INTERFACE_TABLE_ENTRY NS_INTERFACE_TABLE_BEGIN @@ -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)); } } @@ -3008,8 +3023,6 @@ void nsIDocument::RemoveFromIdTable(Element* aElement, nsAtom* aId) { } } -nsIPrincipal* nsDocument::GetPrincipal() { return NodePrincipal(); } - extern bool sDisablePrefetchHTTPSPref; void nsIDocument::SetPrincipal(nsIPrincipal* aNewPrincipal) { @@ -3096,16 +3109,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; } @@ -4094,7 +4105,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); } } @@ -4706,7 +4717,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 +4727,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 +4798,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 +4814,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); } @@ -5920,7 +5929,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 +6500,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(); @@ -7823,7 +7832,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 +7929,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", @@ -10886,7 +10895,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); @@ -12531,14 +12540,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..3de89a382e72 100644 --- a/dom/base/nsDocument.h +++ b/dom/base/nsDocument.h @@ -17,7 +17,6 @@ #include "nsCOMPtr.h" #include "nsAutoPtr.h" #include "nsCRT.h" -#include "nsIWeakReferenceUtils.h" #include "nsTArray.h" #include "nsIdentifierMapEntry.h" #include "nsStubDocumentObserver.h" @@ -28,8 +27,6 @@ #include "nsBindingManager.h" #include "nsRefPtrHashtable.h" #include "nsJSThingHashtable.h" -#include "nsIScriptObjectPrincipal.h" -#include "nsIRadioGroupContainer.h" #include "nsILayoutHistoryState.h" #include "nsIRequest.h" #include "nsILoadGroup.h" @@ -95,12 +92,7 @@ class nsOnloadBlocker final : public nsIRequest { }; // Base class for our document implementations. -class nsDocument : public nsIDocument, - public nsSupportsWeakReference, - public nsIScriptObjectPrincipal, - public nsIRadioGroupContainer, - public nsIApplicationCacheContainer, - public nsStubMutationObserver { +class nsDocument : public nsIDocument { friend class nsIDocument; public: @@ -135,53 +127,7 @@ class nsDocument : public nsIDocument, 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. + // Checks that the caller is either chrome or some addon. static bool IsCallerChromeOrAddon(JSContext* aCx, JSObject* aObject); public: @@ -196,12 +142,6 @@ class nsDocument : public nsIDocument, virtual mozilla::EventListenerManager* GetExistingListenerManager() const override; - // nsIScriptObjectPrincipal - virtual nsIPrincipal* GetPrincipal() override; - - // nsIApplicationCacheContainer - NS_DECL_NSIAPPLICATIONCACHECONTAINER - virtual nsresult Init(); virtual void Destroy() override; @@ -211,7 +151,7 @@ class nsDocument : public nsIDocument, virtual void UnblockOnload(bool aFireSync) override; NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsDocument, - nsIDocument) + nsINode) void SetLoadedAsData(bool aLoadedAsData) { mLoadedAsData = aLoadedAsData; } void SetLoadedAsInteractiveData(bool aLoadedAsInteractiveData) { @@ -268,10 +208,6 @@ class nsDocument : public nsIDocument, 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; private: 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 50a65f1f4ee2..260909a6a2c8 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 @@ -434,6 +437,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; @@ -450,11 +458,63 @@ class nsIDocument : public nsINode, typedef mozilla::dom::SVGElement SVGElement; NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_IID) + NS_DECL_ISUPPORTS_INHERITED #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(); } + // This helper class must be set when we dispatch beforeunload and unload // events in order to avoid unterminate sync XHRs. class MOZ_RAII PageUnloadingEventTimeStamp { @@ -3323,6 +3383,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(); @@ -4497,4 +4561,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/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/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/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/xhr/XMLHttpRequestMainThread.cpp b/dom/xhr/XMLHttpRequestMainThread.cpp index 5ffc4a2420a2..d74b2698880b 100644 --- a/dom/xhr/XMLHttpRequestMainThread.cpp +++ b/dom/xhr/XMLHttpRequestMainThread.cpp @@ -709,7 +709,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..4e17ff3a2242 100644 --- a/dom/xul/XULDocument.cpp +++ b/dom/xul/XULDocument.cpp @@ -989,9 +989,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/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 435e7c5991b8..ce517e32848e 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 721cc8a5f06f..8c5a61a52bf1 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 194acc69a010..5e21f430aa85 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -1086,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", @@ -2852,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; @@ -2969,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; @@ -4382,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 5a3218b97bf5..0b8c8bae4f47 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 @@ -6195,10 +6195,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/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/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/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(); From 595209705950a132dc0446d8a30316fff0340797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 26 Dec 2018 03:33:06 +0100 Subject: [PATCH 04/22] Bug 1516366 - Remove unused mFirstBaseNodeWithHref member. r=smaug This is done via SetBaseURIUsingFirstBaseWithHref now. Differential Revision: https://phabricator.services.mozilla.com/D15353 --- dom/base/nsDocument.cpp | 2 -- dom/base/nsDocument.h | 5 ----- 2 files changed, 7 deletions(-) diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index e2c35fb56382..34db04d429bd 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -1775,7 +1775,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) @@ -1866,7 +1865,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) diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h index 3de89a382e72..2d4a2c5351e7 100644 --- a/dom/base/nsDocument.h +++ b/dom/base/nsDocument.h @@ -176,9 +176,6 @@ class nsDocument : public nsIDocument { 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, \ @@ -208,8 +205,6 @@ class nsDocument : public nsIDocument { friend class nsCallRequestFullscreen; - nsCOMPtr mFirstBaseNodeWithHref; - private: friend class nsUnblockOnloadEvent; From dce45c2cad0ea9442c961f98840aa8e75116f98c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 26 Dec 2018 03:33:15 +0100 Subject: [PATCH 05/22] Bug 1516366 - Remove unused declaration. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D15354 --- dom/base/nsDocument.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h index 2d4a2c5351e7..d0dbaa4f2283 100644 --- a/dom/base/nsDocument.h +++ b/dom/base/nsDocument.h @@ -187,10 +187,6 @@ class nsDocument : public nsIDocument { } \ } while (0) -#ifdef DEBUG - void VerifyRootContentState(); -#endif - explicit nsDocument(const char* aContentType); virtual ~nsDocument(); From 8dae1360c2d6b4cee7e59194485d55f6841cc885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 26 Dec 2018 03:33:29 +0100 Subject: [PATCH 06/22] Bug 1516366 - Move some static functions from nsDocument to nsIDocument. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D15355 --- dom/base/nsDocument.cpp | 20 ++++++++++---------- dom/base/nsDocument.h | 13 ------------- dom/base/nsIDocument.h | 11 +++++++++++ 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 34db04d429bd..f948c8878f6f 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -2474,7 +2474,7 @@ 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()); @@ -3162,7 +3162,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); @@ -3241,22 +3241,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()); @@ -3264,8 +3264,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()); @@ -3273,8 +3273,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()); diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h index d0dbaa4f2283..f7bd2e20bec1 100644 --- a/dom/base/nsDocument.h +++ b/dom/base/nsDocument.h @@ -113,23 +113,10 @@ class nsDocument : public nsIDocument { 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; - // 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; diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index 260909a6a2c8..8876bc793ea9 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -3055,6 +3055,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 { From 97ceb59666423eebc35676ff05650ea398d6f9b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 26 Dec 2018 03:33:39 +0100 Subject: [PATCH 07/22] Bug 1516366 - Move some setters from nsDocument to nsIDocument. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D15356 --- dom/base/nsDocument.h | 5 ----- dom/base/nsIDocument.h | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h index f7bd2e20bec1..44d4b5ac17cf 100644 --- a/dom/base/nsDocument.h +++ b/dom/base/nsDocument.h @@ -140,11 +140,6 @@ class nsDocument : public nsIDocument { NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsDocument, nsINode) - void SetLoadedAsData(bool aLoadedAsData) { mLoadedAsData = aLoadedAsData; } - void SetLoadedAsInteractiveData(bool aLoadedAsInteractiveData) { - mLoadedAsInteractiveData = aLoadedAsInteractiveData; - } - nsresult CloneDocHelper(nsDocument* clone) const; // Only BlockOnload should call this! diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index 8876bc793ea9..d7d9e8cdb11f 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -848,6 +848,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 From e2c716a29d0f4818aca92a9248f75bcc7340fbd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 26 Dec 2018 03:33:49 +0100 Subject: [PATCH 08/22] Bug 1516366 - Move mExpandoAndGeneration from nsDocument to nsIDocument. r=smaug Now that bindgen can represent it properly (bug 1516365) we can do this. Differential Revision: https://phabricator.services.mozilla.com/D15357 --- dom/base/nsDocument.h | 7 ------- dom/base/nsIDocument.h | 4 ++++ layout/style/ServoBindings.toml | 5 ----- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h index 44d4b5ac17cf..10bb4af1a32f 100644 --- a/dom/base/nsDocument.h +++ b/dom/base/nsDocument.h @@ -173,13 +173,6 @@ class nsDocument : public nsIDocument { 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; diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index d7d9e8cdb11f..fb00ae482894 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -4418,6 +4418,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) 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", From aab2c27c3e186e785906974a8604ad0fad9e9bb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 26 Dec 2018 03:34:00 +0100 Subject: [PATCH 09/22] Bug 1516366 - Merge nsIDocument::DocAddSizeOfExcludingThis and nsDocument::DocAddSizeOfExcludingThis. r=smaug No point in having both really. Differential Revision: https://phabricator.services.mozilla.com/D15358 --- dom/base/nsDocument.cpp | 100 ++++++++++++++++++---------------------- dom/base/nsDocument.h | 6 --- dom/base/nsIDocument.h | 2 + 3 files changed, 48 insertions(+), 60 deletions(-) diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index f948c8878f6f..e07d8da4e8ec 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -10935,32 +10935,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: @@ -10972,8 +11003,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 @@ -11042,45 +11073,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 = diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h index 10bb4af1a32f..8112101ff3a9 100644 --- a/dom/base/nsDocument.h +++ b/dom/base/nsDocument.h @@ -101,8 +101,6 @@ class nsDocument : public nsIDocument { 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. @@ -145,10 +143,6 @@ class nsDocument : public nsIDocument { // Only BlockOnload should call this! void AsyncBlockOnload(); - virtual void DocAddSizeOfExcludingThis( - nsWindowSizes& aWindowSizes) const override; - // DocAddSizeOfIncludingThis is inherited from nsIDocument. - protected: friend class nsNodeUtils; diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index fb00ae482894..827f4e4165b6 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -460,6 +460,8 @@ class nsIDocument : public nsINode, NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_IID) NS_DECL_ISUPPORTS_INHERITED + NS_DECL_ADDSIZEOFEXCLUDINGTHIS + #ifdef MOZILLA_INTERNAL_API nsIDocument(); #endif From d66facd45a2921a5ee72fef3fd4fb33de624e856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 26 Dec 2018 03:34:10 +0100 Subject: [PATCH 10/22] Bug 1516366 - Move various miscellaneous methods from nsDocument to nsIDocument. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D15359 --- dom/base/nsDocument.cpp | 30 +++++++++++++++--------------- dom/base/nsDocument.h | 20 -------------------- dom/base/nsIDocument.h | 18 ++++++++++++++---- 3 files changed, 29 insertions(+), 39 deletions(-) diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index e07d8da4e8ec..6c72edb3e461 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -2480,12 +2480,12 @@ bool nsIDocument::IsCallerChromeOrAddon(JSContext* aCx, JSObject* aObject) { 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)); @@ -2883,7 +2883,7 @@ nsresult nsIDocument::InitFeaturePolicy(nsIChannel* aChannel) { return NS_OK; } -void nsDocument::StopDocumentLoad() { +void nsIDocument::StopDocumentLoad() { if (mParser) { mParserAborted = true; mParser->Terminate(); @@ -3589,10 +3589,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); @@ -4645,7 +4645,7 @@ void nsIDocument::BeginUpdate() { NS_DOCUMENT_NOTIFY_OBSERVERS(BeginUpdate, (this)); } -void nsDocument::EndUpdate() { +void nsIDocument::EndUpdate() { NS_DOCUMENT_NOTIFY_OBSERVERS(EndUpdate, (this)); nsContentUtils::RemoveScriptBlocker(); @@ -4662,7 +4662,7 @@ void nsDocument::EndUpdate() { } } -void nsDocument::BeginLoad() { +void nsIDocument::BeginLoad() { MOZ_ASSERT(!mDidCallBeginLoad); mDidCallBeginLoad = true; @@ -4911,7 +4911,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) { @@ -7186,7 +7186,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; diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h index 8112101ff3a9..b3d20dfdd41a 100644 --- a/dom/base/nsDocument.h +++ b/dom/base/nsDocument.h @@ -101,20 +101,6 @@ class nsDocument : public nsIDocument { NS_DECL_CYCLE_COLLECTING_ISUPPORTS - // 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; - - virtual void EndUpdate() override; - virtual void BeginLoad() override; - virtual void EndLoad() override; - public: using mozilla::dom::DocumentOrShadowRoot::GetElementById; using mozilla::dom::DocumentOrShadowRoot::GetElementsByClassName; @@ -146,12 +132,6 @@ class nsDocument : public nsIDocument { protected: friend class nsNodeUtils; - void RetrieveRelevantHeaders(nsIChannel* aChannel); - - void TryChannelCharset(nsIChannel* aChannel, int32_t& aCharsetSource, - NotNull& aEncoding, - nsHtml5TreeOpExecutor* aExecutor); - #define NS_DOCUMENT_NOTIFY_OBSERVERS(func_, params_) \ do { \ NS_OBSERVER_ARRAY_NOTIFY_XPCOM_OBSERVERS(mObservers, nsIDocumentObserver, \ diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index 827f4e4165b6..23ed75c9947d 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -85,6 +85,7 @@ class nsDOMNavigationTiming; class nsDOMStyleSheetSetList; class nsFrameLoader; class nsGlobalWindowInner; +class nsHtml5TreeOpExecutor; class nsHTMLCSSStyleSheet; class nsHTMLDocument; class nsHTMLStyleSheet; @@ -572,6 +573,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, @@ -579,7 +583,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; } @@ -1385,6 +1389,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, @@ -1849,11 +1859,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, From a9e10105d5889d05fc117e4eeba3fe11390b05e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 26 Dec 2018 03:34:20 +0100 Subject: [PATCH 11/22] Bug 1516366 - Move EventTarget methods to nsIDocument. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D15360 --- dom/base/nsDocument.cpp | 6 +++--- dom/base/nsDocument.h | 6 ------ dom/base/nsIDocument.h | 5 +++++ 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 6c72edb3e461..4784ab9837ff 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -6982,7 +6982,7 @@ void nsIDocument::UpdateViewportOverflowType(nscoord aScrolledWidth, } } -EventListenerManager* nsDocument::GetOrCreateListenerManager() { +EventListenerManager* nsIDocument::GetOrCreateListenerManager() { if (!mListenerManager) { mListenerManager = new EventListenerManager(static_cast(this)); @@ -6992,11 +6992,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(); diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h index b3d20dfdd41a..5c25f8533de9 100644 --- a/dom/base/nsDocument.h +++ b/dom/base/nsDocument.h @@ -107,12 +107,6 @@ class nsDocument : public nsIDocument { 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; - virtual nsresult Init(); virtual void Destroy() override; diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index 23ed75c9947d..636a688b62fe 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -518,6 +518,11 @@ class nsIDocument : public nsINode, // 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 { From 6d773951907d5378c1d2352f956292aa38d72dbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 26 Dec 2018 03:34:32 +0100 Subject: [PATCH 12/22] Bug 1516366 - Move BlockOnload and UnlockOnload to nsIDocument, and devirtualize them. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D15361 --- dom/base/nsDocument.cpp | 10 +++++----- dom/base/nsDocument.h | 6 ------ dom/base/nsIDocument.h | 7 +++++-- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 4784ab9837ff..6d8e53cd7638 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -7607,14 +7607,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; @@ -7629,8 +7629,8 @@ void nsDocument::BlockOnload() { ++mAsyncOnloadBlockCount; if (mAsyncOnloadBlockCount == 1) { nsContentUtils::AddScriptRunner( - NewRunnableMethod("nsDocument::AsyncBlockOnload", this, - &nsDocument::AsyncBlockOnload)); + NewRunnableMethod("nsIDocument::AsyncBlockOnload", this, + &nsIDocument::AsyncBlockOnload)); } return; } @@ -7642,7 +7642,7 @@ void nsDocument::BlockOnload() { ++mOnloadBlockCount; } -void nsDocument::UnblockOnload(bool aFireSync) { +void nsIDocument::UnblockOnload(bool aFireSync) { if (mDisplayDocument) { mDisplayDocument->UnblockOnload(aFireSync); return; diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h index 5c25f8533de9..b90b1cbd72ca 100644 --- a/dom/base/nsDocument.h +++ b/dom/base/nsDocument.h @@ -112,17 +112,11 @@ class nsDocument : public nsIDocument { 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, nsINode) nsresult CloneDocHelper(nsDocument* clone) const; - // Only BlockOnload should call this! - void AsyncBlockOnload(); - protected: friend class nsNodeUtils; diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index 636a688b62fe..e50d760b6f82 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -2147,14 +2147,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; } From f7401d4d8901668a29d942350c7f75a4385c3a14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 26 Dec 2018 03:34:42 +0100 Subject: [PATCH 13/22] Bug 1516366 - Move Init, Destroy and RemovedFromDocShell to nsIDocument. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D15362 --- dom/base/nsDocument.cpp | 6 +++--- dom/base/nsDocument.h | 5 ----- dom/base/nsIDocument.h | 6 ++++-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 6d8e53cd7638..3af54bef8aa2 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -1949,7 +1949,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; } @@ -7519,7 +7519,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; @@ -7554,7 +7554,7 @@ void nsDocument::Destroy() { mExternalResourceMap.Shutdown(); } -void nsDocument::RemovedFromDocShell() { +void nsIDocument::RemovedFromDocShell() { if (mRemovedFromDocShell) return; mRemovedFromDocShell = true; diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h index b90b1cbd72ca..76fa76105b03 100644 --- a/dom/base/nsDocument.h +++ b/dom/base/nsDocument.h @@ -107,11 +107,6 @@ class nsDocument : public nsIDocument { using mozilla::dom::DocumentOrShadowRoot::GetElementsByTagName; using mozilla::dom::DocumentOrShadowRoot::GetElementsByTagNameNS; - virtual nsresult Init(); - - virtual void Destroy() override; - virtual void RemovedFromDocShell() override; - NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsDocument, nsINode) diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index e50d760b6f82..a07251fc11a0 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -2118,12 +2118,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 @@ -2131,7 +2133,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 From 1165f7d4ed2bc3e5e61bd2e3593c585b6d1eda2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 26 Dec 2018 03:34:52 +0100 Subject: [PATCH 14/22] Bug 1516366 - Move CloneDocHelper to nsIDocument. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D15363 --- dom/base/nsDocument.cpp | 8 ++++---- dom/base/nsDocument.h | 2 -- dom/base/nsIDocument.h | 1 + 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 3af54bef8aa2..9046fe720c79 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -8073,7 +8073,7 @@ void nsIDocument::RefreshLinkHrefs() { } } -nsresult nsDocument::CloneDocHelper(nsDocument* clone) const { +nsresult nsIDocument::CloneDocHelper(nsIDocument* clone) const { clone->mIsStaticDocument = mCreatingStaticClone; // Init document @@ -8110,7 +8110,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; @@ -10964,8 +10964,8 @@ void nsIDocument::DocAddSizeOfExcludingThis(nsWindowSizes& aWindowSizes) const { mNodeInfoManager->AddSizeOfIncludingThis(aWindowSizes); } - aWindowSizes.mDOMMediaQueryLists += - mDOMMediaQueryLists.sizeOfExcludingThis(aWindowSizes.mState.mMallocSizeOf); + aWindowSizes.mDOMMediaQueryLists += mDOMMediaQueryLists.sizeOfExcludingThis( + aWindowSizes.mState.mMallocSizeOf); for (const MediaQueryList* mql : mDOMMediaQueryLists) { aWindowSizes.mDOMMediaQueryLists += diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h index 76fa76105b03..27e4a6fd2094 100644 --- a/dom/base/nsDocument.h +++ b/dom/base/nsDocument.h @@ -110,8 +110,6 @@ class nsDocument : public nsIDocument { NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsDocument, nsINode) - nsresult CloneDocHelper(nsDocument* clone) const; - protected: friend class nsNodeUtils; diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index a07251fc11a0..34d5cc39bd1b 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -605,6 +605,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 From e3568cb8adb18b1cfe8bd3140a3225a226404359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 26 Dec 2018 03:35:04 +0100 Subject: [PATCH 15/22] Bug 1516366 - Move NS_DOCUMENT_NOTIFY_OBSERVERS to nsIDocument.h. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D15364 --- dom/base/nsDocument.h | 11 ----------- dom/base/nsIDocument.h | 11 +++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h index 27e4a6fd2094..a496680f8901 100644 --- a/dom/base/nsDocument.h +++ b/dom/base/nsDocument.h @@ -113,17 +113,6 @@ class nsDocument : public nsIDocument { protected: friend class nsNodeUtils; -#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) - explicit nsDocument(const char* aContentType); virtual ~nsDocument(); diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index 34d5cc39bd1b..5863c9916f02 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -463,6 +463,17 @@ class nsIDocument : public nsINode, NS_DECL_ADDSIZEOFEXCLUDINGTHIS +#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 From b833919871f705c01eb9c5ead89c25b9698eba00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 26 Dec 2018 03:35:16 +0100 Subject: [PATCH 16/22] Bug 1516366 - Move CC / nsISupports bits to nsIDocument. r=smaug This allows us to remove the MOZ_CRASH-ing implementation I added earlier in this series. Differential Revision: https://phabricator.services.mozilla.com/D15365 --- dom/base/nsDocument.cpp | 78 +++++++++++++++++------------------------ dom/base/nsDocument.h | 20 ----------- dom/base/nsIDocument.h | 6 +++- 3 files changed, 37 insertions(+), 67 deletions(-) diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 9046fe720c79..6fc4ab617ee1 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -1625,45 +1625,31 @@ nsDocument::~nsDocument() { mPlugins.Clear(); } -// In practice these three are always overriden by the nsDocument version, we -// just need them to avoid making nsIDocument::AddRef / Release ambiguous. -// -// We can get rid of these once we merge nsIDocument and nsDocument. -NS_IMETHODIMP_(MozExternalRefCountType) nsIDocument::Release() { - MOZ_CRASH("Should never be reachable"); -} -NS_IMETHODIMP_(MozExternalRefCountType) nsIDocument::AddRef() { - MOZ_CRASH("Should never be reachable"); -} -NS_IMETHODIMP nsIDocument::QueryInterface(REFNSIID aIID, void** aInstancePtr) { - MOZ_CRASH("Should never be reachable"); -} - -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; @@ -1682,9 +1668,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) { @@ -1694,11 +1680,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 @@ -1706,7 +1692,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; @@ -1719,14 +1705,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)) { @@ -1837,11 +1823,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 @@ -1854,7 +1840,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); @@ -1918,7 +1904,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. @@ -2949,7 +2935,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) { @@ -4354,10 +4340,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(); diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h index a496680f8901..415b5d2b231d 100644 --- a/dom/base/nsDocument.h +++ b/dom/base/nsDocument.h @@ -93,36 +93,16 @@ class nsOnloadBlocker final : public nsIRequest { // Base class for our document implementations. class nsDocument : public nsIDocument { - friend class nsIDocument; - - public: - typedef mozilla::dom::Element Element; - typedef mozilla::net::ReferrerPolicy ReferrerPolicy; - - NS_DECL_CYCLE_COLLECTING_ISUPPORTS - public: using mozilla::dom::DocumentOrShadowRoot::GetElementById; using mozilla::dom::DocumentOrShadowRoot::GetElementsByClassName; using mozilla::dom::DocumentOrShadowRoot::GetElementsByTagName; using mozilla::dom::DocumentOrShadowRoot::GetElementsByTagNameNS; - NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsDocument, - nsINode) - - protected: - friend class nsNodeUtils; - explicit nsDocument(const char* aContentType); virtual ~nsDocument(); - public: - - friend class nsCallRequestFullscreen; - private: - friend class nsUnblockOnloadEvent; - // These are not implemented and not supported. nsDocument(const nsDocument& aOther); nsDocument& operator=(const nsDocument& aOther); diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index 5863c9916f02..91313fd094d7 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -459,10 +459,14 @@ class nsIDocument : public nsINode, typedef mozilla::dom::SVGElement SVGElement; NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_IID) - NS_DECL_ISUPPORTS_INHERITED + + 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, \ From 006a4ab94ae263e66db03e1ea32395101e88735e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 26 Dec 2018 03:35:30 +0100 Subject: [PATCH 17/22] Bug 1516366 - Move nsOnloadBlocker and nsDocumentOnStack to nsDocument.cpp, and shrink nsDocument.h to the minimmum. r=smaug This needs to add a few of includes in other places which were relying on the massive (now gone) list in nsDocument.h. I also needed to move an AnimationTimeline destructor out of line because it relied on dom::Animation being defined, yet Animation.h includes AnimationTimeline.h, so include hell. Differential Revision: https://phabricator.services.mozilla.com/D15366 --- dom/animation/AnimationTimeline.cpp | 2 + dom/animation/AnimationTimeline.h | 2 +- dom/base/Element.cpp | 1 + dom/base/FragmentOrElement.cpp | 1 + dom/base/nsDOMWindowUtils.cpp | 1 + dom/base/nsDocument.cpp | 28 +++++++- dom/base/nsDocument.h | 95 ++-------------------------- dom/base/nsNodeUtils.cpp | 1 + dom/console/Console.cpp | 1 + dom/html/nsHTMLDocument.h | 3 + dom/xbl/nsXBLProtoImplField.cpp | 1 + dom/xbl/nsXBLProtoImplMethod.cpp | 1 + dom/xhr/XMLHttpRequestMainThread.cpp | 1 + dom/xul/XULDocument.cpp | 1 + image/VectorImage.cpp | 8 +-- xpfe/appshell/nsWebShellWindow.cpp | 1 + 16 files changed, 51 insertions(+), 97 deletions(-) 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/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index a1b69f423e02..fae43589b2a3 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 6fc4ab617ee1..eaa405a12b7d 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 @@ -7025,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; diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h index 415b5d2b231d..5aef98593d1e 100644 --- a/dom/base/nsDocument.h +++ b/dom/base/nsDocument.h @@ -13,110 +13,23 @@ #include "nsIDocument.h" -#include "jsfriendapi.h" -#include "nsCOMPtr.h" -#include "nsAutoPtr.h" -#include "nsCRT.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 "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: - using mozilla::dom::DocumentOrShadowRoot::GetElementById; - using mozilla::dom::DocumentOrShadowRoot::GetElementsByClassName; - using mozilla::dom::DocumentOrShadowRoot::GetElementsByTagName; - using mozilla::dom::DocumentOrShadowRoot::GetElementsByTagNameNS; + protected: explicit nsDocument(const char* aContentType); virtual ~nsDocument(); - private: - // 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(); } + // Don't add stuff here, add to nsIDocument instead. private: - nsIDocument* mDoc; + nsDocument(const nsDocument& aOther) = delete; + nsDocument& operator=(const nsDocument& aOther) = delete; }; #endif /* nsDocument_h___ */ 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/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/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/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 d74b2698880b..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" diff --git a/dom/xul/XULDocument.cpp b/dom/xul/XULDocument.cpp index 4e17ff3a2242..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" 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/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" From ba92e1a0b5e592d99803721a8bdc9c769eda5126 Mon Sep 17 00:00:00 2001 From: Cristina Coroiu Date: Sat, 29 Dec 2018 05:26:00 +0200 Subject: [PATCH 18/22] Bug 1418778 - disable create_alwaysMatch.py on windows ccov for frequent failures. r=jmaher --- .../meta/webdriver/tests/new_session/create_alwaysMatch.py.ini | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 testing/web-platform/meta/webdriver/tests/new_session/create_alwaysMatch.py.ini diff --git a/testing/web-platform/meta/webdriver/tests/new_session/create_alwaysMatch.py.ini b/testing/web-platform/meta/webdriver/tests/new_session/create_alwaysMatch.py.ini new file mode 100644 index 000000000000..2d0b7df9793d --- /dev/null +++ b/testing/web-platform/meta/webdriver/tests/new_session/create_alwaysMatch.py.ini @@ -0,0 +1,3 @@ +[create_alwaysMatch.py] + disabled: + if ccov and (os == "win") and (bits == 64) and (version == "10.0.15063") # bug 1418778 From 359ed8eddc9a9fd39a118d1a1ee91c4c94b76362 Mon Sep 17 00:00:00 2001 From: longsonr Date: Sat, 29 Dec 2018 22:19:55 +0000 Subject: [PATCH 19/22] Bug 1516727 - Part 1 simplify creation of SVGAngle objects r=jwatt --- dom/svg/SVGAngle.cpp | 6 ++++++ dom/svg/SVGAngle.h | 9 +++++++++ dom/svg/SVGSVGElement.cpp | 6 +----- 3 files changed, 16 insertions(+), 5 deletions(-) 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() { From 9173ebd659c0719ac5bfb8e3fc93bd34eb088e2f Mon Sep 17 00:00:00 2001 From: Andreea Pavel Date: Sun, 30 Dec 2018 01:37:47 +0200 Subject: [PATCH 20/22] Backed out changeset dc37a2bc9cda (bug 1418778) for failing wd tests on a CLOSED TREE --- .../meta/webdriver/tests/new_session/create_alwaysMatch.py.ini | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 testing/web-platform/meta/webdriver/tests/new_session/create_alwaysMatch.py.ini diff --git a/testing/web-platform/meta/webdriver/tests/new_session/create_alwaysMatch.py.ini b/testing/web-platform/meta/webdriver/tests/new_session/create_alwaysMatch.py.ini deleted file mode 100644 index 2d0b7df9793d..000000000000 --- a/testing/web-platform/meta/webdriver/tests/new_session/create_alwaysMatch.py.ini +++ /dev/null @@ -1,3 +0,0 @@ -[create_alwaysMatch.py] - disabled: - if ccov and (os == "win") and (bits == 64) and (version == "10.0.15063") # bug 1418778 From 95b755e3c8ff7ab3fc4249b5cb0431fd872cca0c Mon Sep 17 00:00:00 2001 From: Andreea Pavel Date: Sat, 29 Dec 2018 14:34:00 +0200 Subject: [PATCH 21/22] Bug 1511256 - disabled test_videocontrols.html on linux r=jmaher --HG-- extra : rebase_source : 2e78219ed1d980881dd317cb8fa831d8d8be67a8 --- toolkit/content/tests/widgets/xbl/mochitest.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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] From 0a64cd8214c9f2e60d6528270f7c18ecc930ee7f Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Sat, 29 Dec 2018 22:07:02 -0500 Subject: [PATCH 22/22] Bug 1455848 - output useful information about font file attributes with error. r=me --- gfx/layers/wr/WebRenderBridgeParent.cpp | 1 + 1 file changed, 1 insertion(+) 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;