зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1523655 - Allow non-HTML elements to attach UA Shadow Root r=emilio
A normal shadow root cannot be attached to a non-HTML element so UA Shadow Root should always be allowed. Differential Revision: https://phabricator.services.mozilla.com/D18158 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
a694ddb320
Коммит
0e57cd7404
|
@ -1095,6 +1095,19 @@ ShadowRoot* Element::GetShadowRootByMode() const {
|
|||
}
|
||||
|
||||
bool Element::CanAttachShadowDOM() const {
|
||||
/**
|
||||
* If context object’s namespace is not the HTML namespace,
|
||||
* return false.
|
||||
*
|
||||
* Deviate from the spec here to allow shadow dom attachement to
|
||||
* XUL elements.
|
||||
*/
|
||||
if (!IsHTMLElement() &&
|
||||
!(XRE_IsParentProcess() && IsXULElement() &&
|
||||
nsContentUtils::AllowXULXBLForPrincipal(NodePrincipal()))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* If context object’s local name is not
|
||||
* a valid custom element name, "article", "aside", "blockquote",
|
||||
|
@ -1126,15 +1139,6 @@ already_AddRefed<ShadowRoot> Element::AttachShadow(const ShadowRootInit& aInit,
|
|||
/**
|
||||
* 1. If context object’s namespace is not the HTML namespace,
|
||||
* then throw a "NotSupportedError" DOMException.
|
||||
*/
|
||||
if (!IsHTMLElement() &&
|
||||
!(XRE_IsParentProcess() && IsXULElement() &&
|
||||
nsContentUtils::AllowXULXBLForPrincipal(NodePrincipal()))) {
|
||||
aError.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 2. If context object’s local name is not valid to attach shadow DOM to,
|
||||
* then throw a "NotSupportedError" DOMException.
|
||||
*/
|
||||
|
@ -1144,7 +1148,7 @@ already_AddRefed<ShadowRoot> Element::AttachShadow(const ShadowRootInit& aInit,
|
|||
}
|
||||
|
||||
/**
|
||||
* 2. If context object is a shadow host, then throw
|
||||
* 3. If context object is a shadow host, then throw
|
||||
* an "InvalidStateError" DOMException.
|
||||
*/
|
||||
if (GetShadowRoot() || GetXBLBinding()) {
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
<body>
|
||||
<!-- XML root element with an known, allow-to-attch-shadow-root HTML tag name in non-HTML namespace should not trigger a crash -->
|
||||
</body>
|
|
@ -11,3 +11,4 @@ load 803586.xhtml
|
|||
load 994740-1.xhtml
|
||||
load 1038887.xhtml
|
||||
load 1405878.xml
|
||||
load 1523655.xml
|
||||
|
|
|
@ -43,6 +43,17 @@ nsresult nsXMLPrettyPrinter::PrettyPrint(Document* aDocument,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
// Find the root element
|
||||
RefPtr<Element> rootElement = aDocument->GetRootElement();
|
||||
NS_ENSURE_TRUE(rootElement, NS_ERROR_UNEXPECTED);
|
||||
|
||||
// nsXMLContentSink should not ask us to pretty print an XML doc that comes
|
||||
// with a CanAttachShadowDOM() == true root element, but just in case:
|
||||
if (rootElement->CanAttachShadowDOM()) {
|
||||
MOZ_DIAGNOSTIC_ASSERT(false, "We shouldn't be getting this root element");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
// Ok, we should prettyprint. Let's do it!
|
||||
*aDidPrettyPrint = true;
|
||||
nsresult rv = NS_OK;
|
||||
|
@ -75,10 +86,6 @@ nsresult nsXMLPrettyPrinter::PrettyPrint(Document* aDocument,
|
|||
return err.StealNSResult();
|
||||
}
|
||||
|
||||
// Find the root element
|
||||
RefPtr<Element> rootElement = aDocument->GetRootElement();
|
||||
NS_ENSURE_TRUE(rootElement, NS_ERROR_UNEXPECTED);
|
||||
|
||||
// Attach an UA Widget Shadow Root on it.
|
||||
rootElement->AttachAndSetUAShadowRoot();
|
||||
RefPtr<ShadowRoot> shadowRoot = rootElement->GetShadowRoot();
|
||||
|
|
Загрузка…
Ссылка в новой задаче