nsCOMPtr<nsIURI> targetURI; targetDoc->GetDocumentURL(getter_AddRefs(targetURI)); rv = secMgr->CheckSameOrigin(nsnull, targetURI);
rv = secMgr->CheckSameOrigin(nsnull, targetDoc->GetDocumentURL());
nsresult ChangePrincipal(nsIDOMDocument* aDocument){  if (!aDocument)    return NS_OK;  nsresult rv;  nsCOMPtr<nsIScriptSecurityManager> secMgr =     do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);  NS_ENSURE_SUCCESS(rv, rv);    nsCOMPtr<nsIDocument> targetDoc(do_QueryInterface(aDocument, &rv));  NS_ENSURE_SUCCESS(rv, rv);    nsCOMPtr<nsIURI> targetURI;  targetDoc->GetDocumentURL(getter_AddRefs(targetURI));  rv = secMgr->CheckSameOrigin(nsnull, targetURI);  // change the principal only if the script security   // manager has denied access.  if (NS_FAILED(rv)) {    nsCOMPtr<nsIPrincipal> subjectPrincipal;    rv = secMgr->GetSubjectPrincipal(getter_AddRefs(subjectPrincipal));    if (NS_SUCCEEDED(rv))      targetDoc->SetPrincipal(subjectPrincipal);  }  return rv;}