зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1593222: part 7) Move `nsNodeUtils::Adopt` to `nsINode`. r=smaug
Depends on D51821 Differential Revision: https://phabricator.services.mozilla.com/D51823 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
a1dadb0aaf
Коммит
941b8066a4
|
@ -9351,8 +9351,8 @@ nsINode* Document::AdoptNode(nsINode& aAdoptedNode, ErrorResult& rv) {
|
|||
}
|
||||
|
||||
nsCOMArray<nsINode> nodesWithProperties;
|
||||
nsNodeUtils::Adopt(adoptedNode, sameDocument ? nullptr : mNodeInfoManager,
|
||||
newScope, nodesWithProperties, rv);
|
||||
adoptedNode->Adopt(sameDocument ? nullptr : mNodeInfoManager, newScope,
|
||||
nodesWithProperties, rv);
|
||||
if (rv.Failed()) {
|
||||
// Disconnect all nodes from their parents, since some have the old document
|
||||
// as their ownerDocument and some have this as their ownerDocument.
|
||||
|
|
|
@ -2824,6 +2824,36 @@ void nsINode::AddAnimationObserverUnlessExists(
|
|||
OwnerDoc()->SetMayHaveAnimationObservers();
|
||||
}
|
||||
|
||||
void nsINode::Adopt(nsNodeInfoManager* aNewNodeInfoManager,
|
||||
JS::Handle<JSObject*> aReparentScope,
|
||||
nsCOMArray<nsINode>& aNodesWithProperties,
|
||||
mozilla::ErrorResult& aError) {
|
||||
if (aNewNodeInfoManager) {
|
||||
mozilla::dom::Document* afterAdoptDoc = aNewNodeInfoManager->GetDocument();
|
||||
mozilla::dom::Document* beforeAdoptDoc = OwnerDoc();
|
||||
|
||||
if (afterAdoptDoc && beforeAdoptDoc &&
|
||||
(afterAdoptDoc->GetDocGroup() != beforeAdoptDoc->GetDocGroup())) {
|
||||
// This is a temporary solution for Bug 1590526 to only limit
|
||||
// the restriction to chrome level documents because web extensions
|
||||
// rely on content to content node adoption.
|
||||
if (nsContentUtils::IsChromeDoc(afterAdoptDoc) ||
|
||||
nsContentUtils::IsChromeDoc(beforeAdoptDoc)) {
|
||||
aError.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Just need to store the return value of CloneAndAdopt in a
|
||||
// temporary nsCOMPtr to make sure we release it.
|
||||
nsCOMPtr<nsINode> node = nsNodeUtils::CloneAndAdopt(
|
||||
this, false, true, aNewNodeInfoManager, aReparentScope,
|
||||
&aNodesWithProperties, nullptr, aError);
|
||||
|
||||
nsMutationGuard::DidMutate();
|
||||
}
|
||||
|
||||
already_AddRefed<nsINode> nsINode::Clone(
|
||||
bool aDeep, nsNodeInfoManager* aNewNodeInfoManager,
|
||||
nsCOMArray<nsINode>* aNodesWithProperties, mozilla::ErrorResult& aError) {
|
||||
|
|
|
@ -1057,6 +1057,28 @@ class nsINode : public mozilla::dom::EventTarget {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Walks the node, its attributes and descendant nodes. If aNewNodeInfoManager
|
||||
* is not null, it is used to create new nodeinfos for the nodes. Also
|
||||
* reparents the XPConnect wrappers for the nodes into aReparentScope if
|
||||
* non-null. aNodesWithProperties will be filled with all the nodes that have
|
||||
* properties.
|
||||
*
|
||||
* @param aNewNodeInfoManager The nodeinfo manager to use to create new
|
||||
* nodeinfos for the node and its attributes and
|
||||
* descendants. May be null if the nodeinfos
|
||||
* shouldn't be changed.
|
||||
* @param aReparentScope New scope for the wrappers, or null if no reparenting
|
||||
* should be done.
|
||||
* @param aNodesWithProperties All nodes (from amongst the node and its
|
||||
* descendants) with properties.
|
||||
* @param aError The error, if any.
|
||||
*/
|
||||
void Adopt(nsNodeInfoManager* aNewNodeInfoManager,
|
||||
JS::Handle<JSObject*> aReparentScope,
|
||||
nsCOMArray<nsINode>& aNodesWithProperties,
|
||||
mozilla::ErrorResult& aError);
|
||||
|
||||
/**
|
||||
* Clones the node, its attributes and, if aDeep is true, its descendant nodes
|
||||
* If aNewNodeInfoManager is not null, it is used to create new nodeinfos for
|
||||
|
|
|
@ -141,55 +141,6 @@ class nsNodeUtils {
|
|||
static void AnimationChanged(mozilla::dom::Animation* aAnimation);
|
||||
static void AnimationRemoved(mozilla::dom::Animation* aAnimation);
|
||||
|
||||
/**
|
||||
* Walks aNode, its attributes and descendant nodes. If aNewNodeInfoManager is
|
||||
* not null, it is used to create new nodeinfos for the nodes. Also reparents
|
||||
* the XPConnect wrappers for the nodes into aReparentScope if non-null.
|
||||
* aNodesWithProperties will be filled with all the nodes that have
|
||||
* properties.
|
||||
*
|
||||
* @param aNode Node to adopt.
|
||||
* @param aNewNodeInfoManager The nodeinfo manager to use to create new
|
||||
* nodeinfos for aNode and its attributes and
|
||||
* descendants. May be null if the nodeinfos
|
||||
* shouldn't be changed.
|
||||
* @param aReparentScope New scope for the wrappers, or null if no reparenting
|
||||
* should be done.
|
||||
* @param aNodesWithProperties All nodes (from amongst aNode and its
|
||||
* descendants) with properties.
|
||||
* @param aError The error, if any.
|
||||
*/
|
||||
static void Adopt(nsINode* aNode, nsNodeInfoManager* aNewNodeInfoManager,
|
||||
JS::Handle<JSObject*> aReparentScope,
|
||||
nsCOMArray<nsINode>& aNodesWithProperties,
|
||||
mozilla::ErrorResult& aError) {
|
||||
if (aNode && aNewNodeInfoManager) {
|
||||
mozilla::dom::Document* afterAdoptDoc =
|
||||
aNewNodeInfoManager->GetDocument();
|
||||
mozilla::dom::Document* beforeAdoptDoc = aNode->OwnerDoc();
|
||||
|
||||
if (afterAdoptDoc && beforeAdoptDoc &&
|
||||
(afterAdoptDoc->GetDocGroup() != beforeAdoptDoc->GetDocGroup())) {
|
||||
// This is a temporary solution for Bug 1590526 to only limit
|
||||
// the restriction to chrome level documents because web extensions
|
||||
// rely on content to content node adoption.
|
||||
if (nsContentUtils::IsChromeDoc(afterAdoptDoc) ||
|
||||
nsContentUtils::IsChromeDoc(beforeAdoptDoc)) {
|
||||
aError.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Just need to store the return value of CloneAndAdopt in a
|
||||
// temporary nsCOMPtr to make sure we release it.
|
||||
nsCOMPtr<nsINode> node =
|
||||
CloneAndAdopt(aNode, false, true, aNewNodeInfoManager, aReparentScope,
|
||||
&aNodesWithProperties, nullptr, aError);
|
||||
|
||||
nsMutationGuard::DidMutate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Walks aNode, its attributes and, if aDeep is true, its descendant nodes.
|
||||
* If aClone is true the nodes will be cloned. If aNewNodeInfoManager is
|
||||
|
|
Загрузка…
Ссылка в новой задаче