nsCOMPtr<nsIURI> base_uri; doc->GetBaseURL(getter_AddRefs(base_uri));
nsIURI *base_uri = doc->GetBaseURL();
nsFrameLoader::LoadFrame(){  NS_ENSURE_TRUE(mOwnerContent, NS_ERROR_NOT_INITIALIZED);  nsresult rv = EnsureDocShell();  NS_ENSURE_SUCCESS(rv, rv);  nsIDocument* doc = mOwnerContent->GetDocument();  if (!doc) {    return NS_OK;  }  nsAutoString src;  GetURL(src);  src.Trim(" \t\n\r");  if (src.IsEmpty()) {    src.Assign(NS_LITERAL_STRING("about:blank"));  }  // Make an absolute URI  nsCOMPtr<nsIURI> base_uri;  doc->GetBaseURL(getter_AddRefs(base_uri));  nsCAutoString doc_charset;  doc->GetDocumentCharacterSet(doc_charset);  nsCOMPtr<nsIURI> uri;  rv = NS_NewURI(getter_AddRefs(uri), src,                 doc_charset.IsEmpty() ? nsnull :                 doc_charset.get(), base_uri);  NS_ENSURE_SUCCESS(rv, rv);  // Check for security  nsCOMPtr<nsIScriptSecurityManager> secMan =    do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);  NS_ENSURE_SUCCESS(rv, rv);  nsCOMPtr<nsIDocShellLoadInfo> loadInfo;  mDocShell->CreateLoadInfo(getter_AddRefs(loadInfo));  NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE);  // Get referring URL  nsCOMPtr<nsIURI> referrer;  nsCOMPtr<nsIPrincipal> principal;  rv = secMan->GetSubjectPrincipal(getter_AddRefs(principal));  NS_ENSURE_SUCCESS(rv, rv);  // If we were called from script, get the referring URL from the script  if (principal) {    rv = principal->GetURI(getter_AddRefs(referrer));    NS_ENSURE_SUCCESS(rv, rv);    // Pass the script principal to the docshell    loadInfo->SetOwner(principal);  }  if (!referrer) {    // We're not being called form script, tell the docshell    // to inherit an owner from the current document.    loadInfo->SetInheritOwner(PR_TRUE);    referrer = base_uri;  }  loadInfo->SetReferrer(referrer);  // Check if we are allowed to load absURL  rv = secMan->CheckLoadURI(referrer, uri,                            nsIScriptSecurityManager::STANDARD);  if (NS_FAILED(rv)) {    return rv; // We're not  }  // Bug 136580: Check for recursive frame loading  // pre-grab these for speed  nsCAutoString prepath;  nsCAutoString filepath;  nsCAutoString query;  nsCAutoString param;  rv = uri->GetPrePath(prepath);  NS_ENSURE_SUCCESS(rv,rv);  nsCOMPtr<nsIURL> aURL(do_QueryInterface(uri, &rv)); // QI can fail  if (NS_SUCCEEDED(rv)) {    rv = aURL->GetFilePath(filepath);    NS_ENSURE_SUCCESS(rv,rv);    rv = aURL->GetQuery(query);    NS_ENSURE_SUCCESS(rv,rv);    rv = aURL->GetParam(param);    NS_ENSURE_SUCCESS(rv,rv);  } else {    // Not a URL, so punt and just take the whole path.  Note that if you    // have a self-referential-via-refs non-URL (can't happen via nsSimpleURI,    // but could in theory with an external protocol handler) frameset it will    // recurse down to the depth limit before stopping, but it will stop.    rv = uri->GetPath(filepath);    NS_ENSURE_SUCCESS(rv,rv);  }  PRInt32 matchCount = 0;  nsCOMPtr<nsIDocShellTreeItem> treeItem = do_QueryInterface(mDocShell);  nsCOMPtr<nsIDocShellTreeItem> parentAsItem;  treeItem->GetParent(getter_AddRefs(parentAsItem));  while (parentAsItem) {    // Only interested in checking for recursion in content    PRInt32 parentType;    parentAsItem->GetItemType(&parentType);    if (parentType != nsIDocShellTreeItem::typeContent) {      break; // Not content    }    // Check the parent URI with the URI we're loading    nsCOMPtr<nsIWebNavigation> parentAsNav(do_QueryInterface(parentAsItem));    if (parentAsNav) {      // Does the URI match the one we're about to load?      nsCOMPtr<nsIURI> parentURI;      parentAsNav->GetCurrentURI(getter_AddRefs(parentURI));      if (parentURI) {        // Bug 98158/193011: We need to ignore data after the #        // Note that this code is back-stopped by the maximum-depth checks.                // Check prepath (foo://blah@bar:port/) and filepath        // (/dir/dir/file.ext), but not # extensions.        // There's no easy way to get the URI without extension        // directly, so check prepath, filepath and query/param (if any)        // Note that while in theory a CGI could return different data for        // the same query string, the spec states that it shouldn't, so        // we'll compare queries (and params).        nsCAutoString parentPrePath;        nsCAutoString parentFilePath;        nsCAutoString parentQuery;        nsCAutoString parentParam;        rv = parentURI->GetPrePath(parentPrePath);        NS_ENSURE_SUCCESS(rv,rv);        nsCOMPtr<nsIURL> parentURL(do_QueryInterface(parentURI, &rv)); // QI can fail        if (NS_SUCCEEDED(rv)) {          rv = parentURL->GetFilePath(parentFilePath);          NS_ENSURE_SUCCESS(rv,rv);          rv = parentURL->GetQuery(parentQuery);          NS_ENSURE_SUCCESS(rv,rv);          rv = parentURL->GetParam(parentParam);          NS_ENSURE_SUCCESS(rv,rv);        } else {          rv = uri->GetPath(filepath);          NS_ENSURE_SUCCESS(rv,rv);        }                // filepath will often not match; test it first        if (filepath.Equals(parentFilePath) &&            query.Equals(parentQuery) &&            prepath.Equals(parentPrePath) &&            param.Equals(parentParam))        {          matchCount++;          if (matchCount >= MAX_SAME_URL_CONTENT_FRAMES) {            NS_WARNING("Too many nested content frames have the same url (recursion?) so giving up");            return NS_ERROR_UNEXPECTED;          }        }      }    }    nsIDocShellTreeItem* temp = parentAsItem;    temp->GetParent(getter_AddRefs(parentAsItem));  }    // Kick off the load...  rv = mDocShell->LoadURI(uri, loadInfo, nsIWebNavigation::LOAD_FLAGS_NONE,                          PR_FALSE);  NS_ASSERTION(NS_SUCCEEDED(rv), "failed to load URL");  return rv;}