From dfaeb3f24a3fe9521a62fd0058a7a1ea75ea23e0 Mon Sep 17 00:00:00 2001 From: Cameron Kaiser Date: Sun, 3 Dec 2017 20:08:43 -0800 Subject: [PATCH] #442: M1347639 --- dom/base/nsGenConImageContent.cpp | 3 +++ dom/base/nsImageLoadingContent.cpp | 29 +++++++---------------------- dom/base/nsImageLoadingContent.h | 4 ++++ dom/html/HTMLImageElement.h | 3 +++ dom/html/HTMLInputElement.h | 5 +++++ dom/html/HTMLObjectElement.h | 4 ++++ dom/html/HTMLSharedObjectElement.h | 4 ++++ dom/svg/SVGFEImageElement.h | 3 +++ dom/svg/SVGImageElement.h | 3 +++ 9 files changed, 36 insertions(+), 22 deletions(-) diff --git a/dom/base/nsGenConImageContent.cpp b/dom/base/nsGenConImageContent.cpp index e1b1f5a17..85c2e097b 100644 --- a/dom/base/nsGenConImageContent.cpp +++ b/dom/base/nsGenConImageContent.cpp @@ -56,6 +56,9 @@ public: } return nsXMLElement::PreHandleEvent(aVisitor); } + +protected: + nsIContent* AsContent() override { return this; } private: virtual ~nsGenConImageContent(); diff --git a/dom/base/nsImageLoadingContent.cpp b/dom/base/nsImageLoadingContent.cpp index 92cbd4386..47e2b0c49 100644 --- a/dom/base/nsImageLoadingContent.cpp +++ b/dom/base/nsImageLoadingContent.cpp @@ -868,7 +868,7 @@ nsImageLoadingContent::LoadImage(nsIURI* aNewURI, // We use the principal of aDocument to avoid having to QI |this| an extra // time. It should always be the same as the principal of this node. #ifdef DEBUG - nsCOMPtr thisContent = do_QueryInterface(static_cast(this)); + nsIContent* thisContent = AsContent(); MOZ_ASSERT(thisContent && thisContent->NodePrincipal() == aDocument->NodePrincipal(), "Principal mismatch?"); @@ -909,8 +909,7 @@ nsImageLoadingContent::LoadImage(nsIURI* aNewURI, // Not blocked. Do the load. RefPtr& req = PrepareNextRequest(aImageLoadType); - nsCOMPtr content = - do_QueryInterface(static_cast(this)); + nsIContent* content = AsContent(); nsresult rv = nsContentUtils::LoadImage(aNewURI, aDocument, aDocument->NodePrincipal(), aDocument->GetDocumentURI(), @@ -1048,10 +1047,7 @@ nsImageLoadingContent::UpdateImageState(bool aNotify) return; } - nsCOMPtr thisContent = do_QueryInterface(static_cast(this)); - if (!thisContent) { - return; - } + nsIContent* thisContent = AsContent(); mLoading = mBroken = mUserDisabled = mSuppressed = false; @@ -1115,29 +1111,19 @@ nsImageLoadingContent::UseAsPrimaryRequest(imgRequestProxy* aRequest, nsIDocument* nsImageLoadingContent::GetOurOwnerDoc() { - nsCOMPtr thisContent = - do_QueryInterface(static_cast(this)); - NS_ENSURE_TRUE(thisContent, nullptr); - - return thisContent->OwnerDoc(); + return AsContent()->OwnerDoc(); } nsIDocument* nsImageLoadingContent::GetOurCurrentDoc() { - nsCOMPtr thisContent = - do_QueryInterface(static_cast(this)); - NS_ENSURE_TRUE(thisContent, nullptr); - - return thisContent->GetComposedDoc(); + return AsContent()->GetComposedDoc(); } nsIFrame* nsImageLoadingContent::GetOurPrimaryFrame() { - nsCOMPtr thisContent = - do_QueryInterface(static_cast(this)); - return thisContent->GetPrimaryFrame(); + return AsContent()->GetPrimaryFrame(); } nsPresContext* nsImageLoadingContent::GetFramePresContext() @@ -1159,8 +1145,7 @@ nsImageLoadingContent::StringToURI(const nsAString& aSpec, NS_PRECONDITION(aURI, "Null out param"); // (1) Get the base URI - nsCOMPtr thisContent = do_QueryInterface(static_cast(this)); - NS_ASSERTION(thisContent, "An image loading content must be an nsIContent"); + nsIContent* thisContent = AsContent(); nsCOMPtr baseURL = thisContent->GetBaseURI(); // (2) Get the charset diff --git a/dom/base/nsImageLoadingContent.h b/dom/base/nsImageLoadingContent.h index 7595440cf..12966d11f 100644 --- a/dom/base/nsImageLoadingContent.h +++ b/dom/base/nsImageLoadingContent.h @@ -214,6 +214,10 @@ protected: // The nsContentPolicyType we would use for this ImageLoadType static nsContentPolicyType PolicyTypeForLoad(ImageLoadType aImageLoadType); + // Get ourselves as an nsIContent*. Not const because some of the callers + // want a non-const nsIContent. + virtual nsIContent* AsContent() = 0; + private: /** * Struct used to manage the image observers. diff --git a/dom/html/HTMLImageElement.h b/dom/html/HTMLImageElement.h index 558a797ff..a4d08f081 100644 --- a/dom/html/HTMLImageElement.h +++ b/dom/html/HTMLImageElement.h @@ -350,6 +350,9 @@ protected: virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, const nsAttrValue* aValue, bool aNotify) override; + // Override for nsImageLoadingContent. + nsIContent* AsContent() override { return this; } + // This is a weak reference that this element and the HTMLFormElement // cooperate in maintaining. HTMLFormElement* mForm; diff --git a/dom/html/HTMLInputElement.h b/dom/html/HTMLInputElement.h index 97246518d..7a297ada0 100644 --- a/dom/html/HTMLInputElement.h +++ b/dom/html/HTMLInputElement.h @@ -1254,6 +1254,11 @@ protected: */ bool IsPopupBlocked() const; + /** + * Override for nsImageLoadingContent. + */ + nsIContent* AsContent() override { return this; } + nsCOMPtr mControllers; /* diff --git a/dom/html/HTMLObjectElement.h b/dom/html/HTMLObjectElement.h index 1526a7b24..1a67c94fe 100644 --- a/dom/html/HTMLObjectElement.h +++ b/dom/html/HTMLObjectElement.h @@ -235,6 +235,10 @@ public: return GetContentDocument(); } +protected: + // Override for nsImageLoadingContent. + nsIContent* AsContent() override { return this; } + private: /** * Calls LoadObject with the correct arguments to start the plugin load. diff --git a/dom/html/HTMLSharedObjectElement.h b/dom/html/HTMLSharedObjectElement.h index 70c3e4b6b..11d9ba1b1 100644 --- a/dom/html/HTMLSharedObjectElement.h +++ b/dom/html/HTMLSharedObjectElement.h @@ -192,6 +192,10 @@ public: return GetContentDocument(); } +protected: + // Override for nsImageLoadingContent. + nsIContent* AsContent() override { return this; } + private: virtual ~HTMLSharedObjectElement(); diff --git a/dom/svg/SVGFEImageElement.h b/dom/svg/SVGFEImageElement.h index 8294c9be7..52dec0f54 100644 --- a/dom/svg/SVGFEImageElement.h +++ b/dom/svg/SVGFEImageElement.h @@ -82,6 +82,9 @@ protected: virtual SVGAnimatedPreserveAspectRatio *GetPreserveAspectRatio() override; virtual StringAttributesInfo GetStringInfo() override; + // Override for nsImageLoadingContent. + nsIContent* AsContent() override { return this; } + enum { RESULT, HREF }; nsSVGString mStringAttributes[2]; static StringInfo sStringInfo[2]; diff --git a/dom/svg/SVGImageElement.h b/dom/svg/SVGImageElement.h index 7835b9b35..7def08cca 100644 --- a/dom/svg/SVGImageElement.h +++ b/dom/svg/SVGImageElement.h @@ -83,6 +83,9 @@ protected: virtual SVGAnimatedPreserveAspectRatio *GetPreserveAspectRatio() override; virtual StringAttributesInfo GetStringInfo() override; + // Override for nsImageLoadingContent. + nsIContent* AsContent() override { return this; } + enum { ATTR_X, ATTR_Y, ATTR_WIDTH, ATTR_HEIGHT }; nsSVGLength2 mLengthAttributes[4]; static LengthInfo sLengthInfo[4];