NS_IMETHODIMP
nsIncrementalDownload::Cancel(nsresult status)
{
  NS_ENSURE_ARG(NS_FAILED(status));

  // Ignore this cancelation if we're already canceled.
  if (NS_FAILED(mStatus))
    return NS_OK;

  mStatus = status;

  // Nothing more to do if callbacks aren't pending.
  if (!mIsPending)
    return NS_OK;

  if (mChannel) {
    mChannel->Cancel(mStatus);
    NS_ASSERTION(!mTimer, "what is this timer object doing here?");
  }
  else {
    // dispatch a timer callback event to drive invoking our listener's
    // OnStopRequest.
    if (mTimer)
      mTimer->Cancel();
    StartTimer(0);
  }

  return NS_OK;
}
Ejemplo n.º 2
0
NS_IMETHODIMP
PendingLookup::Notify(nsITimer* aTimer)
{
  LOG(("Remote lookup timed out [this = %p]", this));
  MOZ_ASSERT(aTimer == mTimeoutTimer);
  mChannel->Cancel(NS_ERROR_NET_TIMEOUT);
  mTimeoutTimer->Cancel();
  return NS_OK;
}
Ejemplo n.º 3
0
NS_IMETHODIMP
PendingLookup::Notify(nsITimer* aTimer)
{
  LOG(("Remote lookup timed out [this = %p]", this));
  MOZ_ASSERT(aTimer == mTimeoutTimer);
  Accumulate(mozilla::Telemetry::APPLICATION_REPUTATION_REMOTE_LOOKUP_TIMEOUT,
    true);
  mChannel->Cancel(NS_ERROR_NET_TIMEOUT);
  mTimeoutTimer->Cancel();
  return NS_OK;
}
Ejemplo n.º 4
0
///////////////////////////////////////////////////////////////////////////////
// nsIObserver implementation
NS_IMETHODIMP
PendingLookup::Observe(nsISupports *aSubject, const char *aTopic,
                       const char16_t *aData)
{
  if (!strcmp(aTopic, "quit-application")) {
    if (mTimeoutTimer) {
      mTimeoutTimer->Cancel();
      mTimeoutTimer = nullptr;
    }
    if (mChannel) {
      mChannel->Cancel(NS_ERROR_ABORT);
    }
  }
  return NS_OK;
}
Ejemplo n.º 5
0
nsresult
PendingLookup::OnComplete(bool shouldBlock, nsresult rv, uint32_t verdict)
{
  MOZ_ASSERT(!shouldBlock ||
             verdict != nsIApplicationReputationService::VERDICT_SAFE);

  if (NS_FAILED(rv)) {
    nsAutoCString errorName;
    mozilla::GetErrorName(rv, errorName);
    LOG(("Failed sending remote query for application reputation "
         "[rv = %s, this = %p]", errorName.get(), this));
  }

  if (mTimeoutTimer) {
    mTimeoutTimer->Cancel();
    mTimeoutTimer = nullptr;
  }

  Accumulate(mozilla::Telemetry::APPLICATION_REPUTATION_SHOULD_BLOCK,
    shouldBlock);
  double t = (TimeStamp::Now() - mStartTime).ToMilliseconds();
  LOG(("Application Reputation verdict is %lu, obtained in %f ms [this = %p]",
       verdict, t, this));
  if (shouldBlock) {
    LOG(("Application Reputation check failed, blocking bad binary [this = %p]",
        this));
  } else {
    LOG(("Application Reputation check passed [this = %p]", this));
  }
  nsresult res = mCallback->OnComplete(shouldBlock, rv, verdict);
  return res;
}
Ejemplo n.º 6
0
void
DisableBatteryNotifications()
{
#if MOZ_WINSDK_TARGETVER >= MOZ_NTDDI_LONGHORN
  if (IsVistaOrLater()) {
    if (sPowerHandle) {
      sUnregisterPowerSettingNotification(sPowerHandle);
      sPowerHandle = nsnull;
    }

    if (sCapacityHandle) {
      sUnregisterPowerSettingNotification(sCapacityHandle);
      sCapacityHandle = nsnull;
    }

    if (sHWnd) {
      DestroyWindow(sHWnd);
      sHWnd = nsnull;
    }
  } else
#endif
  {
    if (sUpdateTimer) {
      sUpdateTimer->Cancel();
      sUpdateTimer = nsnull;
    }
  }
}
Ejemplo n.º 7
0
void
DisableBatteryNotifications()
{
  if (IsVistaOrLater()) {
    if (sPowerHandle) {
      sUnregisterPowerSettingNotification(sPowerHandle);
      sPowerHandle = nullptr;
    }

    if (sCapacityHandle) {
      sUnregisterPowerSettingNotification(sCapacityHandle);
      sCapacityHandle = nullptr;
    }

    if (sHWnd) {
      DestroyWindow(sHWnd);
      sHWnd = nullptr;
    }
  } else
  {
    if (sUpdateTimer) {
      sUpdateTimer->Cancel();
      sUpdateTimer = nullptr;
    }
  }
}
Ejemplo n.º 8
0
void
WindowsGamepadService::ScanForDevices()
{
  for (int i = mGamepads.Length() - 1; i >= 0; i--) {
    mGamepads[i].present = false;
  }

  if (mHID) {
    ScanForRawInputDevices();
  }
  if (mXInput) {
    mXInputPollTimer->Cancel();
    if (ScanForXInputDevices()) {
      mXInputPollTimer->InitWithFuncCallback(XInputPollTimerCallback,
                                             this,
                                             kXInputPollInterval,
                                             nsITimer::TYPE_REPEATING_SLACK);
    }
  }

  // Look for devices that are no longer present and remove them.
  for (int i = mGamepads.Length() - 1; i >= 0; i--) {
    if (!mGamepads[i].present) {
      RemoveGamepad(mGamepads[i].id);
      mGamepads.RemoveElementAt(i);
    }
  }
}
Ejemplo n.º 9
0
void
nsListScrollSmoother::Stop()
{
  if ( mRepeatTimer ) {
    mRepeatTimer->Cancel();
    mRepeatTimer = nullptr;
  }
}
Ejemplo n.º 10
0
void
WindowsGamepadService::Cleanup()
{
  if (mXInputPollTimer) {
    mXInputPollTimer->Cancel();
  }
  mGamepads.Clear();
}
Ejemplo n.º 11
0
// This may be called before or after OnLookupComplete
void
PendingPACQuery::Complete(nsresult status, const nsCString &pacString)
{
  if (!mCallback)
    return;

  mCallback->OnQueryComplete(status, pacString);
  mCallback = nsnull;

  if (mDNSRequest) {
    mDNSRequest->Cancel(NS_ERROR_ABORT);
    mDNSRequest = nsnull;
  }
}
Ejemplo n.º 12
0
nsresult
PendingLookup::OnComplete(bool shouldBlock, nsresult rv)
{
  if (mTimeoutTimer) {
    mTimeoutTimer->Cancel();
    mTimeoutTimer = nullptr;
  }

  Accumulate(mozilla::Telemetry::APPLICATION_REPUTATION_SHOULD_BLOCK,
    shouldBlock);
  double t = (TimeStamp::Now() - mStartTime).ToMilliseconds();
  if (shouldBlock) {
    LOG(("Application Reputation check failed, blocking bad binary in %f ms "
         "[this = %p]", t, this));
  } else {
    LOG(("Application Reputation check passed in %f ms [this = %p]", t, this));
  }
  nsresult res = mCallback->OnComplete(shouldBlock, rv);
  return res;
}
Ejemplo n.º 13
0
// There needs to be a means of distinguishing between connection errors
// that the SOCKS server reports when it rejects a connection request, and
// connection errors that happen while attempting to connect to the SOCKS
// server. Otherwise, Firefox will report incorrectly that the proxy server
// is refusing connections when a SOCKS request is rejected by the proxy.
// When a SOCKS handshake failure occurs, the PR error is set to
// PR_UNKNOWN_ERROR, and the real error code is returned via the OS error.
void
nsSOCKSSocketInfo::HandshakeFinished(PRErrorCode err)
{
    if (err == 0) {
        mState = SOCKS_CONNECTED;
    } else {
        mState = SOCKS_FAILED;
        PR_SetError(PR_UNKNOWN_ERROR, err);
    }

    // We don't need the buffer any longer, so free it.
    delete [] mData;
    mData = nullptr;
    mDataIoPtr = nullptr;
    mDataLength = 0;
    mReadOffset = 0;
    mAmountToRead = 0;
    if (mLookup) {
        mLookup->Cancel(NS_ERROR_FAILURE);
        mLookup = nullptr;
    }
}
Ejemplo n.º 14
0
NS_IMETHODIMP
nsSoftKeyBoard::HandleEvent(nsIDOMEvent* aEvent)
{
  if (!aEvent)
    return NS_OK;

  nsCOMPtr<nsIDOMNSEvent> nsevent(do_QueryInterface(aEvent));

  nsCOMPtr<nsIDOMEventTarget> target;
  nsevent->GetOriginalTarget(getter_AddRefs(target));
  nsCOMPtr<nsIContent> targetContent = do_QueryInterface(target);


  if (!targetContent || !targetContent->IsNodeOfType(nsINode::eHTML_FORM_CONTROL))
    return NS_OK;

  nsCOMPtr<nsIFormControl> formControl(do_QueryInterface(targetContent));
  if (!formControl)
    return NS_OK;


  PRInt32 controlType = formControl->GetType();
      
  if (controlType != NS_FORM_TEXTAREA       &&  controlType != NS_FORM_INPUT_TEXT &&
      controlType != NS_FORM_INPUT_PASSWORD &&  controlType != NS_FORM_INPUT_FILE) 
  {
    return NS_OK;
  }

  nsAutoString eventType;
  aEvent->GetType(eventType);

  if (eventType.EqualsLiteral("keypress"))
  {
    PRUint32 keyCode;
    nsCOMPtr<nsIDOMKeyEvent> keyEvent(do_QueryInterface(aEvent));
    
    if (!keyEvent)
      return NS_OK;
    
    if (NS_FAILED(keyEvent->GetKeyCode(&keyCode)))
      return NS_OK;
    
    if (keyCode == nsIDOMKeyEvent::DOM_VK_RETURN && controlType != NS_FORM_TEXTAREA)
    {
      nsSoftKeyBoardService::CloseSIP();
    }

#ifdef WINCE

    if (IsSmartphone())
    {

      PRUint32 charCode;
      keyEvent->GetCharCode(&charCode);

#if 0
      char buffer[2];
      sprintf(buffer, "%d = %d", keyCode, charCode);
      MessageBox(0, buffer, buffer, 0);
#endif
     
      /* value determined by inspection */
      if (keyCode == 120)
      {
        // We're using this key, no one else should
        aEvent->StopPropagation();
        aEvent->PreventDefault();

        if (mTimer)
          mTimer->Cancel(); 

        keybd_event(VK_SPACE, 0, 0, 0);
        keybd_event(VK_SPACE, 0, KEYEVENTF_KEYUP, 0);

        return NS_OK;
      }

      /* value determined by inspection */
      if (keyCode == 119)
      {
        // We're using this key, no one else should
        aEvent->StopPropagation();
        aEvent->PreventDefault();

        if (mTimer)
          mTimer->Cancel(); 
        
        mUsage++;
        if (mUsage>eUpperCase) 
          mUsage=eNumbers;

        return NS_OK;
      }

      if (mUsage == eNumbers)
        return NS_OK;

      if ( charCode > nsIDOMKeyEvent::DOM_VK_0 && charCode <= nsIDOMKeyEvent::DOM_VK_9) // [0-9)
      {
        // We're using this key, no one else should
        aEvent->StopPropagation();
        aEvent->PreventDefault();

        if (mTimer)
          mTimer->Cancel();
        
        if (mCurrentDigit != charCode)
        {
          mCurrentDigit = charCode;
          mCurrentDigitCount = 1;
        }
        else
        {
          mCurrentDigitCount++;
        }

        mTimer = do_CreateInstance("@mozilla.org/timer;1");
        if (!mTimer)
          return NS_OK;

        BYTE key = GetKeyPress(mCurrentDigit, mCurrentDigitCount);

        if (mUsage == eUpperCase)
          key = _toupper(key);

        PRUint32 closure = key;
        
        mTimer->InitWithFuncCallback(SoftKeyboardTimerCB,
                                     (void*)closure,
                                     700, 
                                     nsITimer::TYPE_ONE_SHOT);
        return NS_OK;
      }
      else
      {
        mCurrentDigit = 0;
        mCurrentDigitCount = 0;
      }
      
    }
#endif

    return NS_OK;
  }

  if (eventType.EqualsLiteral("click"))
  {
    nsSoftKeyBoardService::OpenSIP();
    return NS_OK;
  }

  PRBool popupConditions = PR_FALSE;
  nsCOMPtr<nsPIDOMWindow> privateWindow = do_QueryInterface(mTopWindow);
  if (!privateWindow)
    return NS_OK;

  nsIDOMWindowInternal *rootWindow = privateWindow->GetPrivateRoot();
  if (!rootWindow)
    return NS_OK;

  nsCOMPtr<nsIDOMWindow> windowContent;
  rootWindow->GetContent(getter_AddRefs(windowContent));
  privateWindow = do_QueryInterface(windowContent);

  if (privateWindow)
    popupConditions = privateWindow->IsLoadingOrRunningTimeout();
  
  if (eventType.EqualsLiteral("focus"))
  {
    //    if (popupConditions == PR_FALSE)
    nsSoftKeyBoardService::OpenSIP();
  }
  else
    nsSoftKeyBoardService::CloseSIP();
  
  return NS_OK;
}