it->SetDocument(mDocument, PR_FALSE);
it->SetDocument(mDocument, PR_FALSE, PR_TRUE);
HTMLContentSink::ProcessMETATag(const nsIParserNode& aNode){  nsresult rv = NS_OK;  nsIHTMLContent* parent = nsnull;    if(mCurrentContext!=nsnull) {    parent=mCurrentContext->mStack[mCurrentContext->mStackPos-1].mContent;  }  if (nsnull != parent) {    // Create content object    nsCOMPtr<nsINodeInfo> nodeInfo;    rv = mNodeInfoManager->GetNodeInfo(NS_ConvertASCIItoUCS2("meta"), nsnull,                                       kNameSpaceID_None,                                       *getter_AddRefs(nodeInfo));    NS_ENSURE_SUCCESS(rv, rv);    nsIHTMLContent* it;    rv = NS_NewHTMLMetaElement(&it, nodeInfo);    if (NS_OK == rv) {      // Add in the attributes and add the meta content object to the      // head container.      it->SetDocument(mDocument, PR_FALSE);      rv = AddAttributes(aNode, it);      if (NS_OK != rv) {        NS_RELEASE(it);        return rv;      }      parent->AppendChildTo(it, PR_FALSE);                  // XXX It's just not sufficient to check if the parent is head. Also check for      // the preference.      if(!mInsideNoXXXTag) {        // set any HTTP-EQUIV data into document's header data as well as url        nsAutoString header;        it->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::httpEquiv, header);        if (header.Length() > 0) {          nsAutoString result;          it->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::content, result);          if (result.Length() > 0) {            // XXX necko isn't going to process headers coming in from the parser            //NS_WARNING("need to fix how necko adds mime headers (in HTMLContentSink::ProcessMETATag)");                      nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(mWebShell, &rv);            if (NS_FAILED(rv)) return rv;                // see if we have a refresh "header".            if (!header.CompareWithConversion("refresh", PR_TRUE)) {                // Refresh headers are parsed with the following format in mind                // <META HTTP-EQUIV=REFRESH CONTENT="5; URL=http://uri">                // By the time we are here, the following is true:                // header = "REFRESH"                // result = "5; URL=http://uri" // note the URL attribute is                // optional, if it is absent, the currently loaded url is used.                //                 // We need to handle the following strings.                //  - X is a set of digits                //  - URI is either a relative or absolute URI                //  - FOO is any text                //                // ""                 //  empty string. use the currently loaded URI                //  and refresh immediately.                // "X"                //  Refresh the currently loaded URI in X milliseconds.                // "X; URI"                //  Refresh using URI as the destination in X milliseconds.                // "X; URI; Blah"                //  Refresh using URI as the destination in X milliseconds,                //  ignoring "Blah"                // "URI"                //  Refresh immediately using URI as the destination.                // "URI; Blah"                //  Refresh immediately using URI as the destination,                //  ignoring "Blah"                //                 // Note that we need to remove any tokens wrapping the URI.                // These tokens currently include spaces, double and single                // quotes.                 // first get our baseURI                nsCOMPtr<nsIURI> baseURI;                rv = docShell->GetCurrentURI(getter_AddRefs(baseURI));                if (NS_FAILED(rv)) return rv;                PRInt32 millis = -1;                PRUnichar *uriAttrib = nsnull;                    PRInt32 semiColon = result.FindCharInSet(";,");                nsAutoString token;                if (semiColon > -1)                    result.Left(token, semiColon);                else                    token = result;                    PRBool done = PR_FALSE;                while (!done && !token.IsEmpty()) {                    token.CompressWhitespace();                    if (millis == -1 && nsCRT::IsAsciiDigit(token.First())) {                        PRInt32 i = 0;                        PRUnichar value = nsnull;                        while ((value = token[i++])) {                            if (!nsCRT::IsAsciiDigit(value)) {                                i = -1;                                break;                            }                        }                                    if (i > -1) {                            PRInt32 err;                            millis = token.ToInteger(&err) * 1000;                        } else {                            done = PR_TRUE;                        }                    } else {                        done = PR_TRUE;                    }                    if (done) {                        PRInt32 loc = token.FindChar('=');                        if (loc > -1)                            token.Cut(0, loc+1);                        token.Trim(" \"'");                        uriAttrib = token.ToNewUnicode();                    } else {                        // Increment to the next token.                        if (semiColon > -1) {                            semiColon++;                            PRInt32 semiColon2 = result.FindCharInSet(";,", semiColon);                            if (semiColon2 == -1) semiColon2 = result.Length();                            result.Mid(token, semiColon, semiColon2 - semiColon);                            semiColon = semiColon2;                        } else {                            done = PR_TRUE;                        }                    }                } // end while                nsCOMPtr<nsIURI> uri;                if (!uriAttrib) {                    uri = baseURI;                } else {                    rv = NS_NewURI(getter_AddRefs(uri), uriAttrib, baseURI);                    nsAllocator::Free(uriAttrib);                }                if (NS_SUCCEEDED(rv)) {                    NS_WITH_SERVICE(nsIScriptSecurityManager,                                    securityManager,                                     NS_SCRIPTSECURITYMANAGER_PROGID,                                    &rv);                    if (NS_SUCCEEDED(rv)) {                        rv = securityManager->CheckLoadURI(baseURI,                                                           uri,                                                           PR_TRUE);                        if (NS_SUCCEEDED(rv)) {                            nsCOMPtr<nsIRefreshURI> reefer =                                 do_QueryInterface(mWebShell);                            if (reefer) {                                if (millis == -1) millis = 0;                                rv = reefer->RefreshURI(uri, millis,                                                         PR_FALSE);                                if (NS_FAILED(rv)) return rv;                            }                        }                    }                }            } // END refresh            else if (!header.CompareWithConversion("set-cookie", PR_TRUE)) {                nsCOMPtr<nsICookieService> cookieServ = do_GetService(NS_COOKIESERVICE_PROGID, &rv);                if (NS_FAILED(rv)) return rv;                nsCOMPtr<nsIURI> baseURI;                rv = docShell->GetCurrentURI(getter_AddRefs(baseURI));                if (NS_FAILED(rv)) return rv;                rv = cookieServ->SetCookieString(baseURI, result);                if (NS_FAILED(rv)) return rv;            } // END set-cookie            header.ToLowerCase();            nsIAtom* fieldAtom = NS_NewAtom(header);            mDocument->SetHeaderData(fieldAtom, result);            if (fieldAtom == nsHTMLAtoms::headerDefaultStyle) {              mPreferredStyle = result;              mCSSLoader->SetPreferredSheet(mPreferredStyle);            }            else if (fieldAtom == nsHTMLAtoms::link) {              rv = ProcessLink(it, result);            }            else if (fieldAtom == nsHTMLAtoms::headerContentBase) {              ProcessBaseHref(result);            }            else if (fieldAtom == nsHTMLAtoms::headerWindowTarget) {              ProcessBaseTarget(result);            }            NS_IF_RELEASE(fieldAtom);          }//if (result.Length() > 0)         }//if (header.Length() > 0)       }//if(!mInsideNoXXXTag)      NS_RELEASE(it);    }//if (NS_OK == rv)   }//if (nsnull != parent)  return rv;}