forked from mirrors/gecko-dev
Bug 1712140 - Part 4: Add parseHTMLUnsafe and setHTMLUnsafe methods. r=dom-core,webidl,hsivonen
Differential Revision: https://phabricator.services.mozilla.com/D193676
This commit is contained in:
parent
b1b5653ef5
commit
1b0ccf0e14
11 changed files with 63 additions and 0 deletions
|
|
@ -18999,4 +18999,31 @@ bool Document::AllowsDeclarativeShadowRoots() const {
|
|||
return mAllowDeclarativeShadowRoots;
|
||||
}
|
||||
|
||||
/* static */
|
||||
already_AddRefed<Document> Document::ParseHTMLUnsafe(GlobalObject& aGlobal,
|
||||
const nsAString& aHTML) {
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_NewURI(getter_AddRefs(uri), "about:blank");
|
||||
if (!uri) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<Document> doc;
|
||||
nsresult rv =
|
||||
NS_NewHTMLDocument(getter_AddRefs(doc), aGlobal.GetSubjectPrincipal(),
|
||||
aGlobal.GetSubjectPrincipal());
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
doc->SetAllowDeclarativeShadowRoots(true);
|
||||
doc->SetDocumentURI(uri);
|
||||
rv = nsContentUtils::ParseDocumentHTML(aHTML, doc, false);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return doc.forget();
|
||||
}
|
||||
|
||||
} // namespace mozilla::dom
|
||||
|
|
|
|||
|
|
@ -5347,6 +5347,9 @@ class Document : public nsINode,
|
|||
void LoadEventFired();
|
||||
|
||||
RadioGroupContainer& OwnedRadioGroupContainer();
|
||||
|
||||
static already_AddRefed<Document> ParseHTMLUnsafe(GlobalObject& aGlobal,
|
||||
const nsAString& aHTML);
|
||||
};
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(Document, NS_IDOCUMENT_IID)
|
||||
|
|
|
|||
|
|
@ -5045,4 +5045,8 @@ EditorBase* Element::GetEditorWithoutCreation() const {
|
|||
return docShell ? docShell->GetHTMLEditorInternal() : nullptr;
|
||||
}
|
||||
|
||||
void Element::SetHTMLUnsafe(const nsAString& aHTML) {
|
||||
nsContentUtils::SetHTMLUnsafe(this, this, aHTML);
|
||||
}
|
||||
|
||||
} // namespace mozilla::dom
|
||||
|
|
|
|||
|
|
@ -2087,6 +2087,9 @@ class Element : public FragmentOrElement {
|
|||
|
||||
virtual bool Translate() const;
|
||||
|
||||
MOZ_CAN_RUN_SCRIPT
|
||||
virtual void SetHTMLUnsafe(const nsAString& aHTML);
|
||||
|
||||
protected:
|
||||
enum class ReparseAttributes { No, Yes };
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -877,3 +877,8 @@ nsresult ShadowRoot::Clone(dom::NodeInfo* aNodeInfo, nsINode** aResult) const {
|
|||
*aResult = nullptr;
|
||||
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
||||
}
|
||||
|
||||
void ShadowRoot::SetHTMLUnsafe(const nsAString& aHTML) {
|
||||
RefPtr<Element> host = GetHost();
|
||||
nsContentUtils::SetHTMLUnsafe(this, host, aHTML);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -245,6 +245,9 @@ class ShadowRoot final : public DocumentFragment, public DocumentOrShadowRoot {
|
|||
|
||||
bool IsClonable() const { return mIsClonable == Clonable::Yes; }
|
||||
|
||||
MOZ_CAN_RUN_SCRIPT
|
||||
void SetHTMLUnsafe(const nsAString& aHTML);
|
||||
|
||||
protected:
|
||||
// FIXME(emilio): This will need to become more fine-grained.
|
||||
void ApplicableRulesChanged();
|
||||
|
|
|
|||
|
|
@ -102,4 +102,9 @@ bool HTMLTemplateElement::ParseAttribute(int32_t aNamespaceID,
|
|||
aMaybeScriptedPrincipal, aResult);
|
||||
}
|
||||
|
||||
void HTMLTemplateElement::SetHTMLUnsafe(const nsAString& aHTML) {
|
||||
RefPtr<DocumentFragment> content = mContent;
|
||||
nsContentUtils::SetHTMLUnsafe(content, this, aHTML);
|
||||
}
|
||||
|
||||
} // namespace mozilla::dom
|
||||
|
|
|
|||
|
|
@ -59,6 +59,9 @@ class HTMLTemplateElement final : public nsGenericHTMLElement {
|
|||
IgnoredErrorResult());
|
||||
}
|
||||
|
||||
MOZ_CAN_RUN_SCRIPT
|
||||
void SetHTMLUnsafe(const nsAString& aHTML) final;
|
||||
|
||||
protected:
|
||||
virtual ~HTMLTemplateElement();
|
||||
|
||||
|
|
|
|||
|
|
@ -151,6 +151,8 @@ interface Document : Node {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/dom.html#the-document-object
|
||||
partial interface Document {
|
||||
static Document parseHTMLUnsafe(DOMString html);
|
||||
|
||||
[PutForwards=href, LegacyUnforgeable] readonly attribute Location? location;
|
||||
[SetterThrows] attribute DOMString domain;
|
||||
readonly attribute DOMString referrer;
|
||||
|
|
|
|||
|
|
@ -404,3 +404,7 @@ partial interface Element {
|
|||
[SecureContext, UseCounter, Throws, Pref="dom.security.setHTML.enabled"]
|
||||
undefined setHTML(DOMString aInnerHTML, optional SetHTMLOptions options = {});
|
||||
};
|
||||
|
||||
partial interface Element {
|
||||
undefined setHTMLUnsafe(DOMString html);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -56,4 +56,8 @@ interface ShadowRoot : DocumentFragment
|
|||
boolean isUAWidget();
|
||||
};
|
||||
|
||||
partial interface ShadowRoot {
|
||||
undefined setHTMLUnsafe(DOMString html);
|
||||
};
|
||||
|
||||
ShadowRoot includes DocumentOrShadowRoot;
|
||||
|
|
|
|||
Loading…
Reference in a new issue