nsCookieStatus p3pStatus = cookie_P3PDecision(aHostURI, aFirstURI, aHttpChannel);
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel); nsCookieStatus p3pStatus = cookie_P3PDecision(aHostURI, aFirstURI, httpChannel);
cookie_CheckPrefs(nsIURI         *aHostURI,                  nsIURI         *aFirstURI,                  nsIHttpChannel *aHttpChannel,                  const char     *aCookieHeader){  // pref tree:  // 0) get the scheme strings from the two URI's  // 1) disallow ftp  // 2) disallow mailnews, if pref set  // 3) go thru enumerated permissions to see which one we have:  // -> cookies disabled: return  // -> dontacceptforeign: check if cookie is foreign  // -> p3p: check p3p cookie data  // we've extended the "nsCookieStatus" type to be used for all cases now  // (used to be only for p3p), so beware that its interpretation is not p3p-  // specific anymore.  // first, get the URI scheme for further use  // if GetScheme fails on aHostURI, reject; aFirstURI is optional, so failing is ok  nsCAutoString currentURIScheme, firstURIScheme;  nsresult rv, rv2 = NS_OK;  rv = aHostURI->GetScheme(currentURIScheme);  if (aFirstURI) {    rv2 = aFirstURI->GetScheme(firstURIScheme);  }  if (NS_FAILED(rv) || NS_FAILED(rv2)) {    COOKIE_LOGFAILURE(aCookieHeader ? SET_COOKIE : GET_COOKIE, aHostURI, aCookieHeader ? "" : aCookieHeader, "couldn't get scheme of host URI");    return nsICookie::STATUS_REJECTED;  }  // don't let ftp sites get/set cookies (could be a security issue)  if (currentURIScheme.Equals(NS_LITERAL_CSTRING("ftp"))) {    COOKIE_LOGFAILURE(aCookieHeader ? SET_COOKIE : GET_COOKIE, aHostURI, aCookieHeader ? "" : aCookieHeader, "ftp sites cannot read cookies");    return nsICookie::STATUS_REJECTED;  }  // disable cookies in mailnews if user's prefs say so.  // we perform a fairly strict test here:  // if firstURI is null, we can't tell if it's from mailnews - reject  // otherwise, we test both firstURI and currentURI.  // this needs to be revisited when we get firstURI behaving correctly  // in all cases.  // XXX removed the aFirstURI check, to make cookies from javascript work  // bug 198870  if (gCookiePrefObserver->mCookiesDisabledForMailNews &&      ((aFirstURI && cookie_IsFromMailNews(firstURIScheme)) ||       cookie_IsFromMailNews(currentURIScheme))) {    COOKIE_LOGFAILURE(aCookieHeader ? SET_COOKIE : GET_COOKIE, aHostURI, aCookieHeader ? "" : aCookieHeader, "cookies disabled for mailnews");    return nsICookie::STATUS_REJECTED;  }  // check default prefs - go thru enumerated permissions  if (gCookiePrefObserver->mCookiesPermissions == PERMISSION_DontUse) {    COOKIE_LOGFAILURE(aCookieHeader ? SET_COOKIE : GET_COOKIE, aHostURI, aCookieHeader ? "" : aCookieHeader, "cookies are disabled");    return nsICookie::STATUS_REJECTED;  } else if (gCookiePrefObserver->mCookiesPermissions == PERMISSION_DontAcceptForeign) {    // check if cookie is foreign.    // if aFirstURI is null, deny by default    // note: this can be circumvented if we have http redirects within html,    // since the documentURI attribute isn't always correctly    // passed to the redirected channels. (or isn't correctly set in the first place)    if (cookie_IsForeign(aHostURI, aFirstURI)) {      COOKIE_LOGFAILURE(aCookieHeader ? SET_COOKIE : GET_COOKIE, aHostURI, aCookieHeader ? "" : aCookieHeader, "originating server test failed");      return nsICookie::STATUS_REJECTED;    }  } else if (gCookiePrefObserver->mCookiesPermissions == PERMISSION_P3P) {    // check to see if P3P conditions are satisfied.    // nsCookieStatus is an enumerated type, defined in nsCookie.idl (frozen interface):    // STATUS_UNKNOWN -- cookie collected in a previous session and this info no longer available    // STATUS_ACCEPTED -- cookie was accepted    // STATUS_DOWNGRADED -- cookie was accepted but downgraded to a session cookie    // STATUS_FLAGGED -- cookie was accepted with a warning being issued to the user    // STATUS_REJECTED    // to do this, at the moment, we need an httpChannel, but we can live without    // the two URI's (as long as no foreign checks are required).    // if the channel is null, we can fall back on "no p3p policy" prefs.    nsCookieStatus p3pStatus = cookie_P3PDecision(aHostURI, aFirstURI, aHttpChannel);    if (p3pStatus == nsICookie::STATUS_REJECTED) {      COOKIE_LOGFAILURE(aCookieHeader ? SET_COOKIE : GET_COOKIE, aHostURI, aCookieHeader ? "" : aCookieHeader, "P3P test failed");    }    return p3pStatus;  }  // if nothing has complained, accept cookie  return nsICookie::STATUS_ACCEPTED;}