Bug 1957689 - Use atoms a bit more in IDTracker. r=smaug
Just drive-by clean-ups. Differential Revision: https://phabricator.services.mozilla.com/D244185
This commit is contained in:
@@ -585,8 +585,8 @@ void DocumentOrShadowRoot::RemoveIDTargetObserver(nsAtom* aID,
|
||||
entry->RemoveContentChangeCallback(aObserver, aData, aForImage);
|
||||
}
|
||||
|
||||
Element* DocumentOrShadowRoot::LookupImageElement(const nsAString& aId) {
|
||||
if (aId.IsEmpty()) {
|
||||
Element* DocumentOrShadowRoot::LookupImageElement(nsAtom* aId) {
|
||||
if (aId->IsEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -190,7 +190,7 @@ class DocumentOrShadowRoot {
|
||||
* @param aId the ID associated the element we want to lookup
|
||||
* @return the element associated with |aId|
|
||||
*/
|
||||
Element* LookupImageElement(const nsAString& aElementId);
|
||||
Element* LookupImageElement(nsAtom* aId);
|
||||
|
||||
/**
|
||||
* Check that aId is not empty and log a message to the console
|
||||
|
||||
@@ -21,16 +21,15 @@
|
||||
|
||||
namespace mozilla::dom {
|
||||
|
||||
static Element* LookupElement(DocumentOrShadowRoot& aDocOrShadow,
|
||||
const nsAString& aRef, bool aReferenceImage) {
|
||||
static Element* LookupElement(DocumentOrShadowRoot& aDocOrShadow, nsAtom* aRef,
|
||||
bool aReferenceImage) {
|
||||
if (aReferenceImage) {
|
||||
return aDocOrShadow.LookupImageElement(aRef);
|
||||
}
|
||||
return aDocOrShadow.GetElementById(aRef);
|
||||
}
|
||||
|
||||
static DocumentOrShadowRoot* FindTreeToWatch(nsIContent& aContent,
|
||||
const nsAString& aID,
|
||||
static DocumentOrShadowRoot* FindTreeToWatch(nsIContent& aContent, nsAtom* aID,
|
||||
bool aReferenceImage) {
|
||||
ShadowRoot* shadow = aContent.GetContainingShadow();
|
||||
|
||||
@@ -97,18 +96,17 @@ void IDTracker::ResetToURIWithFragmentID(Element& aFrom, nsIURI* aURI,
|
||||
|
||||
bool isEqualExceptRef;
|
||||
rv = aURI->EqualsExceptRef(doc->GetDocumentURI(), &isEqualExceptRef);
|
||||
RefPtr<nsAtom> refAtom = NS_Atomize(ref);
|
||||
if (NS_FAILED(rv) || !isEqualExceptRef) {
|
||||
return ResetToExternalResource(aURI, aReferrerInfo, ref, aFrom,
|
||||
return ResetToExternalResource(aURI, aReferrerInfo, refAtom, aFrom,
|
||||
aReferenceImage);
|
||||
}
|
||||
|
||||
RefPtr<nsAtom> id = NS_Atomize(ref);
|
||||
ResetToID(aFrom, id, aReferenceImage);
|
||||
ResetToID(aFrom, refAtom, aReferenceImage);
|
||||
}
|
||||
|
||||
void IDTracker::ResetToExternalResource(nsIURI* aURI,
|
||||
nsIReferrerInfo* aReferrerInfo,
|
||||
const nsAString& aRef, Element& aFrom,
|
||||
nsAtom* aRef, Element& aFrom,
|
||||
bool aReferenceImage) {
|
||||
Unlink();
|
||||
|
||||
@@ -125,9 +123,9 @@ void IDTracker::ResetToExternalResource(nsIURI* aURI,
|
||||
load->AddObserver(observer);
|
||||
}
|
||||
|
||||
mWatchID = NS_Atomize(aRef);
|
||||
mWatchID = aRef;
|
||||
mReferencingImage = aReferenceImage;
|
||||
HaveNewDocumentOrShadowRoot(resourceDoc, /* aWatch = */ true, aRef);
|
||||
HaveNewDocumentOrShadowRoot(resourceDoc, /* aWatch = */ true, mWatchID);
|
||||
}
|
||||
|
||||
static nsIURI* GetExternalResourceURIIfNeeded(nsIURI* aBaseURI,
|
||||
@@ -191,14 +189,12 @@ void IDTracker::ResetToLocalFragmentID(Element& aFrom,
|
||||
return;
|
||||
}
|
||||
|
||||
RefPtr<nsAtom> refAtom = NS_Atomize(unescaped);
|
||||
if (nsIURI* resourceUri = GetExternalResourceURIIfNeeded(aBaseURI, aFrom)) {
|
||||
NS_ConvertUTF8toUTF16 utf16ref(unescaped);
|
||||
return ResetToExternalResource(resourceUri, aReferrerInfo, utf16ref, aFrom,
|
||||
return ResetToExternalResource(resourceUri, aReferrerInfo, refAtom, aFrom,
|
||||
aReferenceImage);
|
||||
}
|
||||
|
||||
RefPtr<nsAtom> idAtom = NS_Atomize(unescaped);
|
||||
ResetToID(aFrom, idAtom, aReferenceImage);
|
||||
ResetToID(aFrom, refAtom, aReferenceImage);
|
||||
}
|
||||
|
||||
void IDTracker::ResetToID(Element& aFrom, nsAtom* aID, bool aReferenceImage) {
|
||||
@@ -213,15 +209,13 @@ void IDTracker::ResetToID(Element& aFrom, nsAtom* aID, bool aReferenceImage) {
|
||||
mWatchID = aID;
|
||||
mReferencingImage = aReferenceImage;
|
||||
|
||||
nsDependentAtomString str(aID);
|
||||
DocumentOrShadowRoot* docOrShadow =
|
||||
FindTreeToWatch(aFrom, str, aReferenceImage);
|
||||
HaveNewDocumentOrShadowRoot(docOrShadow, /*aWatch*/ true, str);
|
||||
FindTreeToWatch(aFrom, aID, aReferenceImage);
|
||||
HaveNewDocumentOrShadowRoot(docOrShadow, /*aWatch*/ true, aID);
|
||||
}
|
||||
|
||||
void IDTracker::HaveNewDocumentOrShadowRoot(DocumentOrShadowRoot* aDocOrShadow,
|
||||
bool aWatch,
|
||||
const nsAString& aRef) {
|
||||
bool aWatch, nsAtom* aID) {
|
||||
if (aWatch) {
|
||||
mWatchDocumentOrShadowRoot = nullptr;
|
||||
if (aDocOrShadow) {
|
||||
@@ -236,7 +230,7 @@ void IDTracker::HaveNewDocumentOrShadowRoot(DocumentOrShadowRoot* aDocOrShadow,
|
||||
return;
|
||||
}
|
||||
|
||||
if (Element* e = LookupElement(*aDocOrShadow, aRef, mReferencingImage)) {
|
||||
if (Element* e = LookupElement(*aDocOrShadow, aID, mReferencingImage)) {
|
||||
mElement = e;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ class IDTracker {
|
||||
protected:
|
||||
/** Requests and maybe watches an external resource doc. */
|
||||
void ResetToExternalResource(nsIURI* aURI, nsIReferrerInfo* aReferrerInfo,
|
||||
const nsAString& aRef, Element& aFrom,
|
||||
nsAtom* aRef, Element& aFrom,
|
||||
bool aReferenceImage);
|
||||
|
||||
/**
|
||||
@@ -138,7 +138,7 @@ class IDTracker {
|
||||
* null. Either aWatch must be false or aRef must be empty.
|
||||
*/
|
||||
void HaveNewDocumentOrShadowRoot(DocumentOrShadowRoot*, bool aWatch,
|
||||
const nsAString& aRef);
|
||||
nsAtom* aID);
|
||||
|
||||
private:
|
||||
static bool Observe(Element* aOldElement, Element* aNewElement, void* aData);
|
||||
@@ -183,7 +183,7 @@ class IDTracker {
|
||||
|
||||
class DocumentLoadNotification : public Notification, public nsIObserver {
|
||||
public:
|
||||
DocumentLoadNotification(IDTracker* aTarget, const nsAString& aRef)
|
||||
DocumentLoadNotification(IDTracker* aTarget, nsAtom* aRef)
|
||||
: Notification(aTarget) {
|
||||
if (!mTarget->IsPersistent()) {
|
||||
mRef = aRef;
|
||||
@@ -197,7 +197,7 @@ class IDTracker {
|
||||
|
||||
virtual void SetTo(Element* aTo) override {}
|
||||
|
||||
nsString mRef;
|
||||
RefPtr<nsAtom> mRef;
|
||||
};
|
||||
friend class DocumentLoadNotification;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user