Bug 1340061 part 1 - Use source doc URI for SVG <use> anonymous content. r?bz
MozReview-Commit-ID: 2fkDfYh79b
--- a/dom/base/FragmentOrElement.cpp
+++ b/dom/base/FragmentOrElement.cpp
@@ -119,16 +119,17 @@
#include "xpcpublic.h"
#include "nsIScriptError.h"
#include "mozilla/Telemetry.h"
#include "mozilla/CORSMode.h"
#include "mozilla/dom/ShadowRoot.h"
#include "mozilla/dom/HTMLTemplateElement.h"
+#include "mozilla/dom/SVGUseElement.h"
#include "nsStyledElement.h"
#include "nsIContentInlines.h"
#include "nsChildContentList.h"
using namespace mozilla;
using namespace mozilla::dom;
@@ -337,16 +338,24 @@ nsIContent::LookupNamespaceURIInternal(c
return NS_OK;
} while ((content = content->GetParent()));
return NS_ERROR_FAILURE;
}
already_AddRefed<nsIURI>
nsIContent::GetBaseURI(bool aTryUseXHRDocBaseURI) const
{
+ if (IsInAnonymousSubtree() && IsAnonymousContentInSVGUseSubtree()) {
+ nsIContent* bindingParent = GetBindingParent();
+ MOZ_ASSERT(bindingParent);
+ SVGUseElement* useElement = static_cast<SVGUseElement*>(bindingParent);
+ // XXX Ignore xml:base as we are removing it.
+ return do_AddRef(useElement->GetContentBaseURI());
+ }
+
nsIDocument* doc = OwnerDoc();
// Start with document base
nsCOMPtr<nsIURI> base = doc->GetBaseURI(aTryUseXHRDocBaseURI);
// Collect array of xml:base attribute values up the parent chain. This
// is slightly slower for the case when there are xml:base attributes, but
// faster for the far more common case of there not being any such
// attributes.
--- a/dom/svg/SVGUseElement.cpp
+++ b/dom/svg/SVGUseElement.cpp
@@ -321,21 +321,21 @@ SVGUseElement::CreateAnonymousContent()
nsSVGElement *newElement = static_cast<nsSVGElement*>(newcontent.get());
if (mLengthAttributes[ATTR_WIDTH].IsExplicitlySet())
newElement->SetLength(nsGkAtoms::width, mLengthAttributes[ATTR_WIDTH]);
if (mLengthAttributes[ATTR_HEIGHT].IsExplicitlySet())
newElement->SetLength(nsGkAtoms::height, mLengthAttributes[ATTR_HEIGHT]);
}
- // Set up its base URI correctly
- nsCOMPtr<nsIURI> baseURI = targetContent->GetBaseURI();
- if (!baseURI)
+ // Store the base URI
+ mContentBaseURI = targetContent->GetBaseURI();
+ if (!mContentBaseURI) {
return nullptr;
- newcontent->SetExplicitBaseURI(baseURI);
+ }
targetContent->AddMutationObserver(this);
mClone = newcontent;
#ifdef DEBUG
// Our anonymous clone can get restyled by various things
// (e.g. SMIL). Reconstructing its frame is OK, though, because
// it's going to be our _only_ child in the frame tree, so can't get
--- a/dom/svg/SVGUseElement.h
+++ b/dom/svg/SVGUseElement.h
@@ -72,16 +72,17 @@ public:
// WebIDL
already_AddRefed<SVGAnimatedString> Href();
already_AddRefed<SVGAnimatedLength> X();
already_AddRefed<SVGAnimatedLength> Y();
already_AddRefed<SVGAnimatedLength> Width();
already_AddRefed<SVGAnimatedLength> Height();
nsIURI* GetSourceDocURI();
+ nsIURI* GetContentBaseURI() const { return mContentBaseURI; }
protected:
class SourceReference : public nsReferencedElement {
public:
explicit SourceReference(SVGUseElement* aContainer) : mContainer(aContainer) {}
protected:
virtual void ElementChanged(Element* aFrom, Element* aTo) override {
nsReferencedElement::ElementChanged(aFrom, aTo);
@@ -114,14 +115,15 @@ protected:
enum { HREF, XLINK_HREF };
nsSVGString mStringAttributes[2];
static StringInfo sStringInfo[2];
nsCOMPtr<nsIContent> mOriginal; // if we've been cloned, our "real" copy
nsCOMPtr<nsIContent> mClone; // cloned tree
SourceReference mSource; // observed element
+ nsCOMPtr<nsIURI> mContentBaseURI; // Base URI for its anonymous content
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_SVGUseElement_h