NS_IMETHODIMP nsMailDatabase::GetSummaryValid(PRBool *aResult)
{
  NS_ENSURE_ARG_POINTER(aResult);
  PRUint32 folderSize;
  PRUint32  folderDate;
  PRUint32  actualFolderTimeStamp;
  PRInt32 numUnreadMessages;
  nsAutoString errorMsg;

        
  *aResult = PR_FALSE;
  
  if (m_folderFile && m_dbFolderInfo)
  {
    actualFolderTimeStamp = GetMailboxModDate();
  
    m_dbFolderInfo->GetNumUnreadMessages(&numUnreadMessages);
    m_dbFolderInfo->GetFolderSize(&folderSize);
    m_dbFolderInfo->GetFolderDate(&folderDate);

    // compare current version of db versus filed out version info, 
    // and file size in db vs file size on disk.
    PRUint32 version;

    m_dbFolderInfo->GetVersion(&version);
    nsCOMPtr <nsIFile> copyFolderFile;
    // clone file because nsLocalFile caches sizes.
    nsresult rv = m_folderFile->Clone(getter_AddRefs(copyFolderFile));
    NS_ENSURE_SUCCESS(rv, rv);
    PRInt64 fileSize;
    copyFolderFile->GetFileSize(&fileSize);
    if (folderSize == fileSize &&
        numUnreadMessages >= 0 && GetCurVersion() == version)
    {
      GetGlobalPrefs();
      // if those values are ok, check time stamp
      if (gTimeStampLeeway == 0)
        *aResult = folderDate == actualFolderTimeStamp;
      else
        *aResult = PR_ABS((PRInt32) (actualFolderTimeStamp - folderDate)) <= gTimeStampLeeway;
#ifndef PUTUP_ALERT_ON_INVALID_DB
    }
  }
#else
      if (!*aResult)
      {
        errorMsg.AppendLiteral("time stamp didn't match delta = ");
        errorMsg.AppendInt(actualFolderTimeStamp - folderDate);
        errorMsg.AppendLiteral(" leeway = ");
        errorMsg.AppendInt(gTimeStampLeeway);
      }
    }
Beispiel #2
0
PRBool
tls13_InWindow(const sslSocket *ss, const sslSessionID *sid)
{
    PRInt32 timeDelta;

    /* Calculate the difference between the client's view of the age of the
     * ticket (in |ss->xtnData.ticketAge|) and the server's view, which we now
     * calculate.  The result should be close to zero.  timeDelta is signed to
     * make the comparisons below easier. */
    timeDelta = ss->xtnData.ticketAge -
                ((ssl_TimeUsec() - sid->creationTime) / PR_USEC_PER_MSEC);

    /* Only allow the time delta to be at most half of our window.  This is
     * symmetrical, though it doesn't need to be; this assumes that clock errors
     * on server and client will tend to cancel each other out.
     *
     * There are two anti-replay filters that roll over each window.  In the
     * worst case, immediately after a rollover of the filters, we only have a
     * single window worth of recorded 0-RTT attempts.  Thus, the period in
     * which we can accept 0-RTT is at most one window wide.  This uses PR_ABS()
     * and half the window so that the first attempt can be up to half a window
     * early and then replays will be caught until the attempts are half a
     * window late.
     *
     * For example, a 0-RTT attempt arrives early, but near the end of window 1.
     * The attempt is then recorded in window 1.  Rollover to window 2 could
     * occur immediately afterwards.  Window 1 is still checked for new 0-RTT
     * attempts for the remainder of window 2.  Therefore, attempts to replay
     * are detected because the value is recorded in window 1.  When rollover
     * occurs again, window 1 is erased and window 3 instated.  If we allowed an
     * attempt to be late by more than half a window, then this check would not
     * prevent the same 0-RTT attempt from being accepted during window 1 and
     * later window 3.
     */
    return PR_ABS(timeDelta) < (ssl_anti_replay.window / 2);
}
nsresult
nsQueryContentEventHandler::QueryRectFor(nsQueryContentEvent* aEvent,
        nsIRange* aRange,
        nsICaret* aCaret)
{
    PRInt32 offsetInFrame;
    nsIFrame* frame;
    nsresult rv = GetStartFrameAndOffset(aRange, &frame, &offsetInFrame);
    NS_ENSURE_SUCCESS(rv, rv);

    nsPoint posInFrame;
    rv = frame->GetPointFromOffset(aRange->StartOffset(), &posInFrame);
    NS_ENSURE_SUCCESS(rv, rv);

    aEvent->mReply.mRect.y = posInFrame.y;
    aEvent->mReply.mRect.height = frame->GetSize().height;

    if (aEvent->message == NS_QUERY_CHARACTER_RECT) {
        nsPoint nextPos;
        rv = frame->GetPointFromOffset(aRange->EndOffset(), &nextPos);
        NS_ENSURE_SUCCESS(rv, rv);
        aEvent->mReply.mRect.x = PR_MIN(posInFrame.x, nextPos.x);
        aEvent->mReply.mRect.width = PR_ABS(posInFrame.x - nextPos.x);
    } else {
        aEvent->mReply.mRect.x = posInFrame.x;
        aEvent->mReply.mRect.width = aCaret->GetCaretRect().width;
    }

    // The coordinates are app units here, they will be converted to system
    // coordinates by view manager.
    rv = ConvertToRootViewRelativeOffset(frame, aEvent->mReply.mRect);
    NS_ENSURE_SUCCESS(rv, rv);

    aEvent->mSucceeded = PR_TRUE;
    return NS_OK;
}
// static
void
nsSHistory::EvictGlobalContentViewer()
{
  // true until the total number of content viewers is <= total max
  // The usual case is that we only need to evict one content viewer.
  // However, if somebody resets the pref value, we might occasionally
  // need to evict more than one.
  PRBool shouldTryEviction = PR_TRUE;
  while (shouldTryEviction) {
    // Walk through our list of SHistory objects, looking for content
    // viewers in the possible active window of all of the SHEntry objects.
    // Keep track of the SHEntry object that has a ContentViewer and is
    // farthest from the current focus in any SHistory object.  The
    // ContentViewer associated with that SHEntry will be evicted
    PRInt32 distanceFromFocus = 0;
    nsCOMPtr<nsISHEntry> evictFromSHE;
    nsCOMPtr<nsIContentViewer> evictViewer;
    PRInt32 totalContentViewers = 0;
    nsSHistory* shist = static_cast<nsSHistory*>
                                   (PR_LIST_HEAD(&gSHistoryList));
    while (shist != &gSHistoryList) {
      // Calculate the window of SHEntries that could possibly have a content
      // viewer.  There could be up to gHistoryMaxViewers content viewers,
      // but we don't know whether they are before or after the mIndex position
      // in the SHEntry list.  Just check both sides, to be safe.
      PRInt32 startIndex = PR_MAX(0, shist->mIndex - gHistoryMaxViewers);
      PRInt32 endIndex = PR_MIN(shist->mLength - 1,
                                shist->mIndex + gHistoryMaxViewers);
      nsCOMPtr<nsISHTransaction> trans;
      shist->GetTransactionAtIndex(startIndex, getter_AddRefs(trans));
      
      for (PRInt32 i = startIndex; i <= endIndex; ++i) {
        nsCOMPtr<nsISHEntry> entry;
        trans->GetSHEntry(getter_AddRefs(entry));
        nsCOMPtr<nsIContentViewer> viewer;
        nsCOMPtr<nsISHEntry> ownerEntry;
        entry->GetAnyContentViewer(getter_AddRefs(ownerEntry),
                                   getter_AddRefs(viewer));

#ifdef DEBUG_PAGE_CACHE
        nsCOMPtr<nsIURI> uri;
        if (ownerEntry) {
          ownerEntry->GetURI(getter_AddRefs(uri));
        } else {
          entry->GetURI(getter_AddRefs(uri));
        }
        nsCAutoString spec;
        if (uri) {
          uri->GetSpec(spec);
          printf("Considering for eviction: %s\n", spec.get());
        }
#endif
        
        // This SHEntry has a ContentViewer, so check how far away it is from
        // the currently used SHEntry within this SHistory object
        if (viewer) {
          PRInt32 distance = PR_ABS(shist->mIndex - i);
          
#ifdef DEBUG_PAGE_CACHE
          printf("Has a cached content viewer: %s\n", spec.get());
          printf("mIndex: %d i: %d\n", shist->mIndex, i);
#endif
          totalContentViewers++;
          if (distance > distanceFromFocus) {
            
#ifdef DEBUG_PAGE_CACHE
            printf("Choosing as new eviction candidate: %s\n", spec.get());
#endif

            distanceFromFocus = distance;
            evictFromSHE = ownerEntry;
            evictViewer = viewer;
          }
        }
        nsISHTransaction* temp = trans;
        temp->GetNext(getter_AddRefs(trans));
      }
      shist = static_cast<nsSHistory*>(PR_NEXT_LINK(shist));
    }

#ifdef DEBUG_PAGE_CACHE
    printf("Distance from focus: %d\n", distanceFromFocus);
    printf("Total max viewers: %d\n", sHistoryMaxTotalViewers);
    printf("Total number of viewers: %d\n", totalContentViewers);
#endif

    if (totalContentViewers > sHistoryMaxTotalViewers && evictViewer) {
#ifdef DEBUG_PAGE_CACHE
      nsCOMPtr<nsIURI> uri;
      evictFromSHE->GetURI(getter_AddRefs(uri));
      nsCAutoString spec;
      if (uri) {
        uri->GetSpec(spec);
        printf("Evicting content viewer: %s\n", spec.get());
      }
#endif

      // Drop the presentation state before destroying the viewer, so that
      // document teardown is able to correctly persist the state.
      evictFromSHE->SetContentViewer(nsnull);
      evictFromSHE->SyncPresentationState();
      evictViewer->Destroy();

      // If we only needed to evict one content viewer, then we are done.
      // Otherwise, continue evicting until we reach the max total limit.
      if (totalContentViewers - sHistoryMaxTotalViewers == 1) {
        shouldTryEviction = PR_FALSE;
      }
    } else {
      // couldn't find a content viewer to evict, so we are done
      shouldTryEviction = PR_FALSE;
    }
  }  // while shouldTryEviction
}
NS_IMETHODIMP
nsHTMLEditor::MouseMove(nsIDOMEvent* aMouseEvent)
{
  NS_NAMED_LITERAL_STRING(leftStr, "left");
  NS_NAMED_LITERAL_STRING(topStr, "top");

  if (mIsResizing) {
    // we are resizing and the mouse pointer's position has changed
    // we have to resdisplay the shadow
    nsCOMPtr<nsIDOMMouseEvent> mouseEvent ( do_QueryInterface(aMouseEvent) );
    PRInt32 clientX, clientY;
    mouseEvent->GetClientX(&clientX);
    mouseEvent->GetClientY(&clientY);

    PRInt32 newX = GetNewResizingX(clientX, clientY);
    PRInt32 newY = GetNewResizingY(clientX, clientY);
    PRInt32 newWidth  = GetNewResizingWidth(clientX, clientY);
    PRInt32 newHeight = GetNewResizingHeight(clientX, clientY);

    mHTMLCSSUtils->SetCSSPropertyPixels(mResizingShadow,
                                        leftStr,
                                        newX);
    mHTMLCSSUtils->SetCSSPropertyPixels(mResizingShadow,
                                        topStr,
                                        newY);
    mHTMLCSSUtils->SetCSSPropertyPixels(mResizingShadow,
                                        NS_LITERAL_STRING("width"),
                                        newWidth);
    mHTMLCSSUtils->SetCSSPropertyPixels(mResizingShadow,
                                        NS_LITERAL_STRING("height"),
                                        newHeight);

    return SetResizingInfoPosition(newX, newY, newWidth, newHeight);
  }

  if (mGrabberClicked) {
    nsCOMPtr<nsIDOMMouseEvent> mouseEvent ( do_QueryInterface(aMouseEvent) );
    PRInt32 clientX, clientY;
    mouseEvent->GetClientX(&clientX);
    mouseEvent->GetClientY(&clientY);

    nsCOMPtr<nsILookAndFeel> look = do_GetService(kLookAndFeelCID);
    NS_ASSERTION(look, "Look and feel service must be implemented for this toolkit");

    PRInt32 xThreshold=1, yThreshold=1;
    look->GetMetric(nsILookAndFeel::eMetric_DragThresholdX, xThreshold);
    look->GetMetric(nsILookAndFeel::eMetric_DragThresholdY, yThreshold);

    if (PR_ABS(clientX - mOriginalX ) * 2 >= xThreshold ||
        PR_ABS(clientY - mOriginalY ) * 2 >= yThreshold) {
      mGrabberClicked = PR_FALSE;
      StartMoving(nsnull);
    }
  }
  if (mIsMoving) {
    nsCOMPtr<nsIDOMMouseEvent> mouseEvent ( do_QueryInterface(aMouseEvent) );
    PRInt32 clientX, clientY;
    mouseEvent->GetClientX(&clientX);
    mouseEvent->GetClientY(&clientY);

    PRInt32 newX = mPositionedObjectX + clientX - mOriginalX;
    PRInt32 newY = mPositionedObjectY + clientY - mOriginalY;

    SnapToGrid(newX, newY);

    mHTMLCSSUtils->SetCSSPropertyPixels(mPositioningShadow, leftStr, newX);
    mHTMLCSSUtils->SetCSSPropertyPixels(mPositioningShadow, topStr, newY);
  }
  return NS_OK;
}
Beispiel #6
0
NS_IMETHODIMP
nsAccelerometer::AccelerationChanged(double alpha, double beta, double gamma)
{
  if (!mEnabled)
    return NS_ERROR_NOT_INITIALIZED;

  if (alpha > 360)
    alpha = 360;
  if (alpha < 0)
    alpha = 0;

  if (beta > 180)
    beta = 180;
  if (beta < -180)
    beta = -180;

  if (gamma > 90)
    gamma = 90;
  if (gamma < -90)
    gamma = -90;

  if (!mNewListener) {
    if (PR_ABS(mLastAlpha - alpha) < 1 &&
        PR_ABS(mLastBeta - beta) < 1 &&
        PR_ABS(mLastGamma - gamma) < 1)
      return NS_OK;
  }

  mLastAlpha = alpha;
  mLastBeta = beta;
  mLastGamma = gamma;
  mNewListener = PR_FALSE;

  for (PRUint32 i = mListeners.Count(); i > 0 ; ) {
    --i;
    nsRefPtr<nsIAcceleration> a = new nsAcceleration(alpha, beta, gamma);
    mListeners[i]->OnAccelerationChange(a);
  }

  for (PRUint32 i = mWindowListeners.Count(); i > 0 ; ) {
    --i;

    nsCOMPtr<nsIDOMDocument> domdoc;
    mWindowListeners[i]->GetDocument(getter_AddRefs(domdoc));

    nsCOMPtr<nsIDOMDocumentEvent> docevent(do_QueryInterface(domdoc));
    nsCOMPtr<nsIDOMEvent> event;

    PRBool defaultActionEnabled = PR_TRUE;

    if (docevent) {
      docevent->CreateEvent(NS_LITERAL_STRING("DeviceOrientationEvent"), getter_AddRefs(event));

      nsCOMPtr<nsIDOMDeviceOrientationEvent> oe = do_QueryInterface(event);

      if (event) {
        oe->InitDeviceOrientationEvent(NS_LITERAL_STRING("deviceorientation"),
                                       PR_TRUE,
                                       PR_FALSE,
                                       alpha,
                                       beta,
                                       gamma,
                                       PR_TRUE);

        nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(event);
        if (privateEvent)
          privateEvent->SetTrusted(PR_TRUE);
        
        nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(mWindowListeners[i]);
        target->DispatchEvent(event, &defaultActionEnabled);
      }
    }
  }
  return NS_OK;
}
nsresult
nsHTMLEditor::SetResizingInfoPosition(PRInt32 aX, PRInt32 aY, PRInt32 aW, PRInt32 aH)
{
  nsCOMPtr<nsIDOMDocument> domdoc;
  nsEditor::GetDocument(getter_AddRefs(domdoc));

  nsCOMPtr<nsIDocument> doc (do_QueryInterface(domdoc));
  if (!doc)
    return NS_ERROR_UNEXPECTED;

  // get the root content
  nsCOMPtr<nsIDOMNSHTMLElement> nsElement = do_QueryInterface(doc->GetRootContent());
  if (!nsElement) {return NS_ERROR_NULL_POINTER; }

  // let's get the size of the document
  PRInt32 w, h;
  nsElement->GetOffsetWidth(&w);
  nsElement->GetOffsetHeight(&h);
  
  if (mInfoXIncrement < 0)
    aX = w - aX ;
  if (mInfoYIncrement < 0)
    aY = h - aY;

  NS_NAMED_LITERAL_STRING(rightStr, "right");
  NS_NAMED_LITERAL_STRING(leftStr, "left");
  NS_NAMED_LITERAL_STRING(topStr, "top");
  NS_NAMED_LITERAL_STRING(bottomStr, "bottom");
  mHTMLCSSUtils->SetCSSPropertyPixels(mResizingInfo,
                                      (mInfoXIncrement < 0) ? rightStr : leftStr,
                                      aX + PR_ABS(mInfoXIncrement));
  mHTMLCSSUtils->SetCSSPropertyPixels(mResizingInfo,
                                      (mInfoYIncrement < 0) ? bottomStr : topStr,
                                      aY + PR_ABS(mInfoYIncrement));

  mHTMLCSSUtils->RemoveCSSProperty(mResizingInfo,
                                   (mInfoXIncrement >= 0) ? rightStr  : leftStr);
  mHTMLCSSUtils->RemoveCSSProperty(mResizingInfo,
                                   (mInfoYIncrement >= 0) ? bottomStr  : topStr);

  // let's make sure the info box does not go beyond the limits of the viewport
  nsAutoString value;
  float f;
  nsCOMPtr<nsIAtom> unit;
  if (mInfoXIncrement < 0) {
    mHTMLCSSUtils->GetComputedProperty(mResizingInfo, nsEditProperty::cssLeft, value);
    mHTMLCSSUtils->ParseLength(value, &f, getter_AddRefs(unit));
    if (f <= 0) {
      mHTMLCSSUtils->SetCSSPropertyPixels(mResizingInfo, leftStr, 0);
      mHTMLCSSUtils->RemoveCSSProperty(mResizingInfo,
                                       rightStr);
    }
  }
  if (mInfoYIncrement < 0) {
    mHTMLCSSUtils->GetComputedProperty(mResizingInfo, nsEditProperty::cssTop, value);
    mHTMLCSSUtils->ParseLength(value, &f, getter_AddRefs(unit));
    if (f <= 0) {
      mHTMLCSSUtils->SetCSSPropertyPixels(mResizingInfo, topStr, 0);
      mHTMLCSSUtils->RemoveCSSProperty(mResizingInfo,
                                       bottomStr);
    }
  }

  nsCOMPtr<nsIDOMNode> textInfo;
  nsresult res = mResizingInfo->GetFirstChild(getter_AddRefs(textInfo));
  if (NS_FAILED(res)) return res;
  nsCOMPtr<nsIDOMNode> junk;
  if (textInfo) {
    res = mResizingInfo->RemoveChild(textInfo, getter_AddRefs(junk));
    if (NS_FAILED(res)) return res;
    textInfo = nsnull;
    junk = nsnull;
  }

  nsAutoString widthStr, heightStr, diffWidthStr, diffHeightStr;
  widthStr.AppendInt(aW);
  heightStr.AppendInt(aH);
  PRInt32 diffWidth  = aW - mResizedObjectWidth;
  PRInt32 diffHeight = aH - mResizedObjectHeight;
  if (diffWidth > 0)
    diffWidthStr.AssignLiteral("+");
  if (diffHeight > 0)
    diffHeightStr.AssignLiteral("+");
  diffWidthStr.AppendInt(diffWidth);
  diffHeightStr.AppendInt(diffHeight);

  nsAutoString info(widthStr + NS_LITERAL_STRING(" x ") + heightStr +
                    NS_LITERAL_STRING(" (") + diffWidthStr +
                    NS_LITERAL_STRING(", ") + diffHeightStr +
                    NS_LITERAL_STRING(")"));

  nsCOMPtr<nsIDOMText> nodeAsText;
  res = domdoc->CreateTextNode(info, getter_AddRefs(nodeAsText));
  if (NS_FAILED(res)) return res;
  textInfo = do_QueryInterface(nodeAsText);
  res =  mResizingInfo->AppendChild(textInfo, getter_AddRefs(junk));
  if (NS_FAILED(res)) return res;

  PRBool hasClass = PR_FALSE;
  if (NS_SUCCEEDED(mResizingInfo->HasAttribute(NS_LITERAL_STRING("class"), &hasClass )) && hasClass)
    res = mResizingInfo->RemoveAttribute(NS_LITERAL_STRING("class"));

  return res;
}