NS_ENSURE_TRUE(targetDOMDocument, NS_ERROR_FAILURE);
NS_ENSURE_TRUE(targetDOMDocument, PR_TRUE);
PRBool ValidateOrigin(nsIDocShellTreeItem* aOriginTreeItem, nsIDocShellTreeItem* aTargetTreeItem){  // Get origin document uri (ignoring document.domain)  nsCOMPtr<nsIWebNavigation> originWebNav(do_QueryInterface(aOriginTreeItem));  NS_ENSURE_TRUE(originWebNav, PR_TRUE);  nsCOMPtr<nsIURI> originDocumentURI;  nsresult rv = originWebNav->GetCurrentURI(getter_AddRefs(originDocumentURI));  NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && originDocumentURI, PR_TRUE);  // Get target principal uri (including document.domain)  nsCOMPtr<nsIDOMDocument> targetDOMDocument(do_GetInterface(aTargetTreeItem));  NS_ENSURE_TRUE(targetDOMDocument, NS_ERROR_FAILURE);  nsCOMPtr<nsIDocument> targetDocument(do_QueryInterface(targetDOMDocument));  NS_ENSURE_TRUE(targetDocument, NS_ERROR_FAILURE);  nsCOMPtr<nsIPrincipal> targetPrincipal;  rv = targetDocument->GetPrincipal(getter_AddRefs(targetPrincipal));  NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && targetPrincipal, rv);  nsCOMPtr<nsIURI> targetPrincipalURI;  rv = targetPrincipal->GetURI(getter_AddRefs(targetPrincipalURI));  NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && targetPrincipalURI, PR_TRUE);  // Find out if document.domain was set for HTML documents  PRBool documentDomainSet = PR_FALSE;  nsCOMPtr<nsIHTMLDocument> targetHTMLDocument(do_QueryInterface(targetDocument));  // If we don't have an HTML document, fall through with documentDomainSet false  if (targetHTMLDocument) {    targetHTMLDocument->WasDomainSet(&documentDomainSet);  }  // Is origin same principal or a subdomain of target's document.domain  // Compare actual URI of origin document, not origin principal's URI. (Per Nav 4.x)  return SameOrSubdomainOfTarget(originDocumentURI, targetPrincipalURI, documentDomainSet);}