Bug 1493210 - Remove XUL forward references. r=bzbarsky

These are no longer needed after the removal of overlays.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Brendan Dahl 2018-09-24 16:43:42 +00:00
Родитель 824c0797e2
Коммит 3b90617635
5 изменённых файлов: 6 добавлений и 297 удалений

Просмотреть файл

@ -107,17 +107,6 @@ using namespace mozilla::dom;
static NS_DEFINE_CID(kParserCID, NS_PARSER_CID); static NS_DEFINE_CID(kParserCID, NS_PARSER_CID);
//----------------------------------------------------------------------
//
// Miscellaneous Constants
//
const nsForwardReference::Phase nsForwardReference::kPasses[] = {
nsForwardReference::eConstruction,
nsForwardReference::eHookup,
nsForwardReference::eDone
};
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// //
// Statics // Statics
@ -160,7 +149,6 @@ XULDocument::XULDocument(void)
mOffThreadCompiling(false), mOffThreadCompiling(false),
mOffThreadCompileStringBuf(nullptr), mOffThreadCompileStringBuf(nullptr),
mOffThreadCompileStringLength(0), mOffThreadCompileStringLength(0),
mResolutionPhase(nsForwardReference::eStart),
mBroadcasterMap(nullptr), mBroadcasterMap(nullptr),
mInitialLayoutComplete(false), mInitialLayoutComplete(false),
mHandlingDelayedAttrChange(false), mHandlingDelayedAttrChange(false),
@ -182,10 +170,6 @@ XULDocument::~XULDocument()
NS_ASSERTION(mNextSrcLoadWaiter == nullptr, NS_ASSERTION(mNextSrcLoadWaiter == nullptr,
"unreferenced document still waiting for script source to load?"); "unreferenced document still waiting for script source to load?");
// In case we failed somewhere early on and the forward observer
// decls never got resolved.
mForwardReferences.Clear();
// Destroy our broadcaster map. // Destroy our broadcaster map.
delete mBroadcasterMap; delete mBroadcasterMap;
@ -232,7 +216,6 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(XULDocument)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(XULDocument, XMLDocument) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(XULDocument, XMLDocument)
NS_ASSERTION(!nsCCUncollectableMarker::InGeneration(cb, tmp->GetMarkedCCGeneration()), NS_ASSERTION(!nsCCUncollectableMarker::InGeneration(cb, tmp->GetMarkedCCGeneration()),
"Shouldn't traverse XULDocument!"); "Shouldn't traverse XULDocument!");
// XXX tmp->mForwardReferences?
// XXX tmp->mContextStack? // XXX tmp->mContextStack?
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCurrentPrototype) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCurrentPrototype)
@ -815,8 +798,7 @@ XULDocument::AttributeChanged(Element* aElement, int32_t aNameSpaceID,
} }
// checks for modifications in broadcasters // checks for modifications in broadcasters
bool listener, resolved; CheckBroadcasterHookup(aElement);
CheckBroadcasterHookup(aElement, &listener, &resolved);
// See if there is anything we need to persist in the localstore. // See if there is anything we need to persist in the localstore.
// //
@ -876,75 +858,6 @@ XULDocument::ContentRemoved(nsIContent* aChild, nsIContent* aPreviousSibling)
RemoveSubtreeFromDocument(aChild); RemoveSubtreeFromDocument(aChild);
} }
nsresult
XULDocument::AddForwardReference(nsForwardReference* aRef)
{
if (mResolutionPhase < aRef->GetPhase()) {
if (!mForwardReferences.AppendElement(aRef)) {
delete aRef;
return NS_ERROR_OUT_OF_MEMORY;
}
}
else {
NS_ERROR("forward references have already been resolved");
delete aRef;
}
return NS_OK;
}
nsresult
XULDocument::ResolveForwardReferences()
{
if (mResolutionPhase == nsForwardReference::eDone)
return NS_OK;
NS_ASSERTION(mResolutionPhase == nsForwardReference::eStart,
"nested ResolveForwardReferences()");
// Resolve each outstanding 'forward' reference. We iterate
// through the list of forward references until no more forward
// references can be resolved. This annealing process is
// guaranteed to converge because we've "closed the gate" to new
// forward references.
const nsForwardReference::Phase* pass = nsForwardReference::kPasses;
while ((mResolutionPhase = *pass) != nsForwardReference::eDone) {
uint32_t previous = 0;
while (mForwardReferences.Length() &&
mForwardReferences.Length() != previous) {
previous = mForwardReferences.Length();
for (uint32_t i = 0; i < mForwardReferences.Length(); ++i) {
nsForwardReference* fwdref = mForwardReferences[i];
if (fwdref->GetPhase() == *pass) {
nsForwardReference::Result result = fwdref->Resolve();
switch (result) {
case nsForwardReference::eResolve_Succeeded:
case nsForwardReference::eResolve_Error:
mForwardReferences.RemoveElementAt(i);
// fixup because we removed from list
--i;
break;
case nsForwardReference::eResolve_Later:
// do nothing. we'll try again later
;
}
}
}
}
++pass;
}
mForwardReferences.Clear();
return NS_OK;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// //
// nsIDocument interface // nsIDocument interface
@ -1020,18 +933,9 @@ XULDocument::AddElementToDocumentPre(Element* aElement)
// 2. Check for a broadcaster hookup attribute, in which case // 2. Check for a broadcaster hookup attribute, in which case
// we'll hook the node up as a listener on a broadcaster. // we'll hook the node up as a listener on a broadcaster.
bool listener, resolved; rv = CheckBroadcasterHookup(aElement);
rv = CheckBroadcasterHookup(aElement, &listener, &resolved);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
// If it's not there yet, we may be able to defer hookup until
// later.
if (listener && !resolved && (mResolutionPhase != nsForwardReference::eDone)) {
BroadcasterHookup* hookup = new BroadcasterHookup(this, aElement);
rv = AddForwardReference(hookup);
if (NS_FAILED(rv)) return rv;
}
return NS_OK; return NS_OK;
} }
@ -1797,8 +1701,6 @@ XULDocument::ResumeWalk()
// If we get here, there is nothing left for us to walk. The content // If we get here, there is nothing left for us to walk. The content
// model is built and ready for layout. // model is built and ready for layout.
rv = ResolveForwardReferences();
if (NS_FAILED(rv)) return rv;
ApplyPersistentAttributes(); ApplyPersistentAttributes();
@ -2348,52 +2250,6 @@ XULDocument::AddAttributes(nsXULPrototypeElement* aPrototype,
} }
//----------------------------------------------------------------------
//
// XULDocument::BroadcasterHookup
//
nsForwardReference::Result
XULDocument::BroadcasterHookup::Resolve()
{
nsresult rv;
bool listener;
rv = mDocument->CheckBroadcasterHookup(mObservesElement, &listener, &mResolved);
if (NS_FAILED(rv)) return eResolve_Error;
return mResolved ? eResolve_Succeeded : eResolve_Later;
}
XULDocument::BroadcasterHookup::~BroadcasterHookup()
{
if (MOZ_LOG_TEST(gXULLog, LogLevel::Warning) && !mResolved) {
// Tell the world we failed
nsAutoString broadcasterID;
nsAutoString attribute;
if (mObservesElement->IsXULElement(nsGkAtoms::observes)) {
mObservesElement->GetAttr(kNameSpaceID_None, nsGkAtoms::element, broadcasterID);
mObservesElement->GetAttr(kNameSpaceID_None, nsGkAtoms::attribute, attribute);
}
else {
mObservesElement->GetAttr(kNameSpaceID_None, nsGkAtoms::observes, broadcasterID);
attribute.Assign('*');
}
nsAutoCString attributeC,broadcasteridC;
LossyCopyUTF16toASCII(attribute, attributeC);
LossyCopyUTF16toASCII(broadcasterID, broadcasteridC);
MOZ_LOG(gXULLog, LogLevel::Warning,
("xul: broadcaster hookup failed <%s attribute='%s'> to %s",
nsAtomCString(mObservesElement->NodeInfo()->NameAtom()).get(),
attributeC.get(),
broadcasteridC.get()));
}
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
nsresult nsresult
@ -2466,10 +2322,9 @@ XULDocument::FindBroadcaster(Element* aElement,
// Try to find the broadcaster element in the document. // Try to find the broadcaster element in the document.
*aBroadcaster = GetElementById(aBroadcasterID); *aBroadcaster = GetElementById(aBroadcasterID);
// If we can't find the broadcaster, then we'll need to defer the // The broadcaster element is missing.
// hookup. We may need to resolve some more content first.
if (! *aBroadcaster) { if (! *aBroadcaster) {
return NS_FINDBROADCASTER_AWAIT_OVERLAYS; return NS_FINDBROADCASTER_NOT_FOUND;
} }
NS_ADDREF(*aBroadcaster); NS_ADDREF(*aBroadcaster);
@ -2478,17 +2333,13 @@ XULDocument::FindBroadcaster(Element* aElement,
} }
nsresult nsresult
XULDocument::CheckBroadcasterHookup(Element* aElement, XULDocument::CheckBroadcasterHookup(Element* aElement)
bool* aNeedsHookup,
bool* aDidResolve)
{ {
// Resolve a broadcaster hookup. Look at the element that we're // Resolve a broadcaster hookup. Look at the element that we're
// trying to resolve: it could be an '<observes>' element, or just // trying to resolve: it could be an '<observes>' element, or just
// a vanilla element with an 'observes' attribute on it. // a vanilla element with an 'observes' attribute on it.
nsresult rv; nsresult rv;
*aDidResolve = false;
nsCOMPtr<Element> listener; nsCOMPtr<Element> listener;
nsAutoString broadcasterID; nsAutoString broadcasterID;
nsAutoString attribute; nsAutoString attribute;
@ -2498,10 +2349,6 @@ XULDocument::CheckBroadcasterHookup(Element* aElement,
broadcasterID, attribute, getter_AddRefs(broadcaster)); broadcasterID, attribute, getter_AddRefs(broadcaster));
switch (rv) { switch (rv) {
case NS_FINDBROADCASTER_NOT_FOUND: case NS_FINDBROADCASTER_NOT_FOUND:
*aNeedsHookup = false;
return NS_OK;
case NS_FINDBROADCASTER_AWAIT_OVERLAYS:
*aNeedsHookup = true;
return NS_OK; return NS_OK;
case NS_FINDBROADCASTER_FOUND: case NS_FINDBROADCASTER_FOUND:
break; break;
@ -2535,8 +2382,6 @@ XULDocument::CheckBroadcasterHookup(Element* aElement,
broadcasteridC.get())); broadcasteridC.get()));
} }
*aNeedsHookup = false;
*aDidResolve = true;
return NS_OK; return NS_OK;
} }

Просмотреть файл

@ -13,7 +13,6 @@
#include "mozilla/dom/XMLDocument.h" #include "mozilla/dom/XMLDocument.h"
#include "mozilla/StyleSheet.h" #include "mozilla/StyleSheet.h"
#include "nsForwardReference.h"
#include "nsIContent.h" #include "nsIContent.h"
#include "nsCOMArray.h" #include "nsCOMArray.h"
#include "nsIURI.h" #include "nsIURI.h"
@ -293,61 +292,6 @@ protected:
protected: protected:
/* Declarations related to forward references.
*
* Forward references are declarations which are added to the temporary
* list (mForwardReferences) during the document (or overlay) load and
* are resolved later, when the document loading is almost complete.
*/
/**
* The list of different types of forward references to resolve. After
* a reference is resolved, it is removed from this array (and
* automatically deleted)
*/
nsTArray<nsAutoPtr<nsForwardReference> > mForwardReferences;
/** Indicates what kind of forward references are still to be processed. */
nsForwardReference::Phase mResolutionPhase;
/**
* Adds aRef to the mForwardReferences array. Takes the ownership of aRef.
*/
nsresult AddForwardReference(nsForwardReference* aRef);
/**
* Resolve all of the document's forward references.
*/
nsresult ResolveForwardReferences();
/**
* Used to resolve broadcaster references
*/
class BroadcasterHookup : public nsForwardReference
{
protected:
XULDocument* mDocument; // [WEAK]
RefPtr<Element> mObservesElement; // [OWNER]
bool mResolved;
public:
BroadcasterHookup(XULDocument* aDocument,
Element* aObservesElement)
: mDocument(aDocument),
mObservesElement(aObservesElement),
mResolved(false)
{
}
virtual ~BroadcasterHookup();
virtual Phase GetPhase() override { return eHookup; }
virtual Result Resolve() override;
};
friend class BroadcasterHookup;
// The out params of FindBroadcaster only have values that make sense when // The out params of FindBroadcaster only have values that make sense when
// the method returns NS_FINDBROADCASTER_FOUND. In all other cases, the // the method returns NS_FINDBROADCASTER_FOUND. In all other cases, the
// values of the out params should not be relied on (though *aListener and // values of the out params should not be relied on (though *aListener and
@ -360,9 +304,7 @@ protected:
Element** aBroadcaster); Element** aBroadcaster);
nsresult nsresult
CheckBroadcasterHookup(Element* aElement, CheckBroadcasterHookup(Element* aElement);
bool* aNeedsHookup,
bool* aDidResolve);
void void
SynchronizeBroadcastListener(Element *aBroadcaster, SynchronizeBroadcastListener(Element *aBroadcaster,

Просмотреть файл

@ -1,76 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsForwardReference_h__
#define nsForwardReference_h__
class nsForwardReference
{
protected:
nsForwardReference() {}
public:
virtual ~nsForwardReference() {}
/**
* Priority codes returned from GetPhase()
*/
enum Phase {
/** A dummy marker, used to indicate unstarted resolution */
eStart,
/** The initial pass, after which the content model will be
fully built */
eConstruction,
/** A second pass, after which all 'magic attribute' hookup
will have been performed */
eHookup,
/** A dummy marker, used in kPasses to indicate termination */
eDone
};
/**
* Forward references are categorized by 'priority', and all
* forward references in a higher priority are resolved before any
* reference in a lower priority. This variable specifies this
* ordering. The last Priority is guaranteed to be eDone.
*/
static const Phase kPasses[];
/**
* Get the state in which the forward reference should be resolved.
* 'eConstruction' references are all resolved before 'eHookup' references
* are resolved.
*
* @return the Phase in which the reference needs to be resolved
*/
virtual Phase GetPhase() = 0;
/**
* Result codes returned from Resolve()
*/
enum Result {
/** Resolution succeeded, I'm done. */
eResolve_Succeeded,
/** Couldn't resolve, but try me later. */
eResolve_Later,
/** Something bad happened, don't try again. */
eResolve_Error
};
/**
* Attempt to resolve the forward reference.
*
* @return a Result that tells the resolver how to treat
* the reference.
*/
virtual Result Resolve() = 0;
};
#endif // nsForwardReference_h__

Просмотреть файл

@ -17,7 +17,6 @@
#include "jsfriendapi.h" #include "jsfriendapi.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsForwardReference.h"
#include "nsHTMLStyleSheet.h" #include "nsHTMLStyleSheet.h"
#include "nsIContentSink.h" #include "nsIContentSink.h"
#include "nsIDocument.h" #include "nsIDocument.h"

Просмотреть файл

@ -863,7 +863,6 @@ with modules["CONTENT"]:
# Error codes for FindBroadcaster in XULDocument.cpp # Error codes for FindBroadcaster in XULDocument.cpp
errors["NS_FINDBROADCASTER_NOT_FOUND"] = SUCCESS(12) errors["NS_FINDBROADCASTER_NOT_FOUND"] = SUCCESS(12)
errors["NS_FINDBROADCASTER_FOUND"] = SUCCESS(13) errors["NS_FINDBROADCASTER_FOUND"] = SUCCESS(13)
errors["NS_FINDBROADCASTER_AWAIT_OVERLAYS"] = SUCCESS(14)
# ======================================================================= # =======================================================================