nsCOMPtr<nsIDOMDocument> owner_doc(do_QueryInterface(aRoot));
nsIPrincipal *principal = doc->GetPrincipal();
CheckSameOrigin(nsIDOMNode *aRoot){  // Get JSContext from stack.  nsCOMPtr<nsIJSContextStack> stack =    do_GetService("@mozilla.org/js/xpc/ContextStack;1");  JSContext *cx = nsnull;  nsresult rv = NS_OK;  if (stack) {    rv = stack->Peek(&cx);    NS_ENSURE_SUCCESS(rv, rv);  }  if (cx) {    // We're called from script, make sure the caller and the root are    // from the same origin...    nsCOMPtr<nsIDOMDocument> owner_doc(do_QueryInterface(aRoot));    if (!owner_doc) {      aRoot->GetOwnerDocument(getter_AddRefs(owner_doc));    }    nsCOMPtr<nsIDocument> doc(do_QueryInterface(owner_doc));    if (doc) {      nsCOMPtr<nsIURI> root_uri;      nsIPrincipal *principal = doc->GetPrincipal();      if (principal) {        principal->GetURI(getter_AddRefs(root_uri));      }      if (root_uri) {        nsCOMPtr<nsIScriptSecurityManager> secMan =           do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);        NS_ENSURE_SUCCESS(rv, rv);        rv = secMan->CheckSameOrigin(cx, root_uri);        if (NS_FAILED(rv)) {          // The node that's being serialized comes from a different          // origin than the calling script comes from...          return rv;        }      }    }        }  return NS_OK;}