Commit b77fd84e authored by Sean Feng's avatar Sean Feng Committed by Matthew Finkel
Browse files

Bug 1467970 - Unsupport cross docGroup adoption r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D43135

--HG--
extra : moz-landing-system : lando
parent e75c87ac
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -192,7 +192,7 @@
    is(anode, node.accessibleNode, "an AccessibleNode is properly cached");

    // Adopting node to another document doesn't change .accessibleNode
    let anotherDoc = document.implementation.createDocument("", "", null);
    let anotherDoc = ifrDoc.implementation.createDocument("", "", null);
    let adopted_node = anotherDoc.adoptNode(node);
    is(anode, adopted_node.accessibleNode, "adopting node to another document doesn't change node.accessibleNode");

+1 −1
Original line number Diff line number Diff line
@@ -597,7 +597,7 @@
      this.invoke = () => {
        // trigger a tree update.
        let doc = getNode("t9_container").contentDocument;
        doc.body.appendChild(document.createElement("p"));
        doc.body.appendChild(doc.createElement("p"));
      };

      this.finalCheck = () => {
+2 −2
Original line number Diff line number Diff line
@@ -9949,10 +9949,10 @@ TabModalPromptBox.prototype = {
  },

  appendPrompt(args, onCloseCallback) {
    let newPrompt = new TabModalPrompt(window);
    let browser = this.browser;
    let newPrompt = new TabModalPrompt(browser.ownerGlobal);
    this.prompts.set(newPrompt.element, newPrompt);

    let browser = this.browser;
    browser.parentNode.insertBefore(
      newPrompt.element,
      browser.nextElementSibling
+13 −1
Original line number Diff line number Diff line
@@ -1622,8 +1622,20 @@ var WalkerActor = protocol.ActorClassWithSpec(walkerSpec, {
      return;
    }

    const parsedDOM = new DOMParser().parseFromString(value, "text/html");
    const rawNode = node.rawNode;
    const doc = nodeDocument(rawNode);
    const win = doc.defaultView;
    let parser;
    if (!win) {
      throw new Error("The window object shouldn't be null");
    } else {
      // We create DOMParser under window object because we want a content
      // DOMParser, which means all the DOM objects created by this DOMParser
      // will be in the same DocGroup as rawNode.parentNode. Then the newly
      // created nodes can be adopted into rawNode.parentNode.
      parser = new win.DOMParser();
    }
    const parsedDOM = parser.parseFromString(value, "text/html");
    const parentNode = rawNode.parentNode;

    // Special case for head and body.  Setting document.body.outerHTML
+17 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
#include "nsNetUtil.h"
#include "nsDOMString.h"
#include "MainThreadUtils.h"
#include "SystemPrincipal.h"
#include "nsIStreamListener.h"
#include "nsStringStream.h"
#include "nsIScriptError.h"
@@ -103,6 +104,22 @@ already_AddRefed<Document> DOMParser::ParseFromString(const nsAString& aStr,
                         aType, aRv);
}

already_AddRefed<Document> DOMParser::ParseFromSafeString(const nsAString& aStr,
                                                          SupportedType aType,
                                                          ErrorResult& aRv) {
  // Since we disable cross docGroup node adoption, it is safe to create
  // new document with the system principal, then the new document will be
  // placed in the same docGroup as the chrome document.
  nsCOMPtr<nsIPrincipal> docPrincipal = mPrincipal;
  if (!nsContentUtils::IsSystemPrincipal(mPrincipal)) {
    mPrincipal = SystemPrincipal::Create();
  }

  RefPtr<Document> ret = ParseFromString(aStr, aType, aRv);
  mPrincipal = docPrincipal;
  return ret.forget();
}

already_AddRefed<Document> DOMParser::ParseFromBuffer(const Uint8Array& aBuf,
                                                      SupportedType aType,
                                                      ErrorResult& aRv) {
Loading