if (!foundCookie && !cookie->isSession && nsInt64(cookie->expires) < currentTime) {
if (!foundCookie && !cookie->isSession && nsInt64(cookie->expires) <= currentTime) {
cookie_SetCookieInternal(nsIURI             *aHostURI,                         nsDependentCString &aCookieHeader,                         nsInt64            aServerTime,                         nsCookieStatus     aStatus,                         nsCookiePolicy     aPolicy){  nsresult rv;  // keep a |const char*| version of the unmodified aCookieHeader,  // for logging purposes  const char *cookieHeader = aCookieHeader.get();  nsInt64 expiryTime, currentTime = NOW_IN_SECONDS;  PRBool isSession, foundCookie;  nsCOMPtr<nsICookie> thisCookie;  nsCOMPtr<nsICookiePermission> cookiePermission;  // cookie stores all the attributes parsed from the cookie;  // expires and maxage are separate, because we have to process them to find the expiry.  // create a new cookie to store the attributes  cookie_CookieStruct *cookie = new cookie_CookieStruct;  if (!cookie) {    COOKIE_LOGFAILURE(SET_COOKIE, aHostURI, cookieHeader, "unable to allocate memory for new cookie");    // if we fail here, abort all processing of subsequent cookies by SetCookie()    return PR_FALSE;  }  nsCAutoString expiresAttribute, maxageAttribute;  // newCookie says whether there are multiple cookies in the header; so we can handle them separately.  // after this function, we don't need the cookieHeader string for processing this cookie anymore;  // so this function uses it as an outparam to point to the next cookie, if there is one.  PRBool newCookie = cookie_ParseAttributes(aCookieHeader, cookie, expiresAttribute, maxageAttribute);  // reject cookie if it's over the size limit, per RFC2109  if ((cookie->name.Length() + cookie->cookie.Length()) > MAX_BYTES_PER_COOKIE) {    COOKIE_LOGFAILURE(SET_COOKIE, aHostURI, cookieHeader, "cookie too big (> 4kb)");    goto failure;  }  // calculate expiry time of cookie. we need to pass in cookieStatus, since  // the cookie may have been downgraded to a session cookie by p3p.  isSession = cookie_GetExpiry(maxageAttribute, expiresAttribute, aServerTime,                               expiryTime, currentTime, aStatus);  // put remaining information into cookieStruct  cookie->expires = expiryTime;  cookie->lastAccessed = currentTime;  cookie->isSession = isSession;  cookie->status = aStatus;  cookie->policy = aPolicy;  // domain & path checks  if (!cookie_CheckDomain(cookie, aHostURI)) {    COOKIE_LOGFAILURE(SET_COOKIE, aHostURI, cookieHeader, "failed the domain tests");    goto failure;  }  if (!cookie_CheckPath(cookie, aHostURI)) {    COOKIE_LOGFAILURE(SET_COOKIE, aHostURI, cookieHeader, "failed the path tests");    goto failure;  }  // count the number of cookies from this host, and find whether a previous cookie  // has been set, for prompting purposes  PRUint32 countFromHost;  foundCookie = cookie_FindCookiesFromHost(cookie, countFromHost, currentTime);  // check if the cookie we're trying to set is already expired, and return.  // but we need to check there's no previous cookie first, because servers use  // this as a trick for deleting previous cookies.  if (!foundCookie && !cookie->isSession && nsInt64(cookie->expires) < currentTime) {    COOKIE_LOGFAILURE(SET_COOKIE, aHostURI, cookieHeader, "cookie has already expired");    goto failure;  }  // create a new nsICookie and copy the cookie data,  // for passing to the permission manager  thisCookie = COOKIE_ChangeFormat(cookie);  // we want to cache this ptr when we merge everything into nsCookieService  cookiePermission = do_GetService(NS_COOKIEPERMISSION_CONTRACTID, &rv);  // check permissions from site permission list, or ask the user,  // to determine if we can set the cookie  if (NS_SUCCEEDED(rv)) {    PRBool permission;    // we need to think about prompters/parent windows here - TestPermission    // needs one to prompt, so right now it has to fend for itself to get one    rv = cookiePermission->TestPermission(aHostURI, thisCookie, nsnull,                                          countFromHost, foundCookie,                                          gCookiePrefObserver->mCookiesAskPermission,                                          &permission);    if (!permission) {      COOKIE_LOGFAILURE(SET_COOKIE, aHostURI, cookieHeader, "cookies are blocked for this site");      goto failure;    }  }  // add the cookie to the list  rv = COOKIE_Add(cookie, NOW_IN_SECONDS, aHostURI, cookieHeader);  if (NS_FAILED(rv)) {    // no need to log a failure here, Add() does it for us    goto failure;  }  // notify observers if the cookie was downgraded or flagged (only for p3p  // at this point). this occurs only if the cookie was set successfully.  if (aStatus == nsICookie::STATUS_DOWNGRADED ||      aStatus == nsICookie::STATUS_FLAGGED) {    nsCOMPtr<nsIObserverService> os(do_GetService("@mozilla.org/observer-service;1"));    if (os) {      os->NotifyObservers(nsnull, "cookieIcon", NS_LITERAL_STRING("on").get());    }  }  COOKIE_LOGSUCCESS(SET_COOKIE, aHostURI, cookieHeader, cookie);  return newCookie;  // something failed - free the cookie  failure:    delete cookie;    return newCookie;}