Beispiel #1
0
void FileRequestAsync::UpdateProgress() {
#ifndef EMSCRIPTEN
	// Fake download for testing event handlers

	if (!IsReady() && rand() % 100 == 0) {
		DownloadDone(true);
	}
#endif
}
NS_IMETHODIMP
nsUrlClassifierStreamUpdater::UpdateError(nsresult result)
{
  LOG(("nsUrlClassifierStreamUpdater::UpdateError [this=%p]", this));

  // DownloadDone() clears mUpdateErrorCallback, so we save it off here.
  nsCOMPtr<nsIUrlClassifierCallback> errorCallback = mDownloadError ? nullptr : mUpdateErrorCallback.get();

  DownloadDone();

  nsAutoCString strResult;
  strResult.AppendInt(static_cast<uint32_t>(result));
  if (errorCallback) {
    errorCallback->HandleEvent(strResult);
  }

  return NS_OK;
}
NS_IMETHODIMP
nsUrlClassifierStreamUpdater::UpdateSuccess(uint32_t requestedTimeout)
{
  LOG(("nsUrlClassifierStreamUpdater::UpdateSuccess [this=%p]", this));
  if (mPendingUpdates.Length() != 0) {
    NS_WARNING("Didn't fetch all safebrowsing update redirects");
  }

  // DownloadDone() clears mSuccessCallback, so we save it off here.
  nsCOMPtr<nsIUrlClassifierCallback> successCallback = mDownloadError ? nullptr : mSuccessCallback.get();
  DownloadDone();

  nsAutoCString strTimeout;
  strTimeout.AppendInt(requestedTimeout);
  if (successCallback) {
    successCallback->HandleEvent(strTimeout);
  }

  return NS_OK;
}
Beispiel #4
0
/*
 * DownloadDialogProc:  Dialog procedure for displaying downloading progress.
 */
BOOL CALLBACK DownloadDialogProc(HWND hDlg, UINT message, UINT wParam, LONG lParam)
{
   int fraction, i;
   HWND hGraph;
   BOOL bResult = FALSE;
   char temp[256];

   switch (message)
   {
   case WM_INITDIALOG:
      CenterWindow(hDlg, hMain);
      if (!advert)
      {
	 ShowWindow(hMain, SW_HIDE);
      }
      hDownloadDialog = hDlg;
      
      // Set up graph bar limits
      hGraph = GetDlgItem(hDlg, IDC_GRAPH);
      SendMessage(hGraph, GRPH_RANGESET, 0, 100);
      SendMessage(hGraph, GRPH_POSSET, 0, 0);
      SendMessage(hGraph, GRPH_COLORSET, GRAPHCOLOR_BAR, GetColor(COLOR_BAR1));
      SendMessage(hGraph, GRPH_COLORSET, GRAPHCOLOR_BKGND, GetColor(COLOR_BAR2));

      hGraph = GetDlgItem(hDlg, IDC_FILEGRAPH);
      SendMessage(hGraph, GRPH_RANGESET, 0, 100);
      SendMessage(hGraph, GRPH_POSSET, 0, 0);
      SendMessage(hGraph, GRPH_COLORSET, GRAPHCOLOR_BAR, GetColor(COLOR_BAR1));
      SendMessage(hGraph, GRPH_COLORSET, GRAPHCOLOR_BKGND, GetColor(COLOR_BAR2));

      hGraph = GetDlgItem(hDlg, IDC_ANIMATE1);
      bResult = Animate_Open(hGraph, MAKEINTRESOURCE(IDA_DOWNLOAD));

      abort_download = False;
      PostMessage(hDlg, BK_TRANSFERSTART, 0, 0);

      GetDlgItemText(hDlg, IDC_FILESIZE, format, sizeof(format));
      sprintf(temp, format, (int)0, (int)0);
      SetDlgItemText(hDlg, IDC_FILESIZE, temp);

      return TRUE;

   case WM_DESTROY:
      if (!advert)
      {
	 ShowWindow(hMain, SW_SHOW);
	 UpdateWindow(hMain);
      }
      hDownloadDialog = NULL;
      return TRUE;

   case BK_TRANSFERSTART:
      info->hPostWnd = hDlg;
      hThread = (HANDLE)(unsigned long)_beginthread(TransferStart, 0, info);
      TransferMessage(GetString(hInst, IDS_CONNECTING), info->machine);
      return TRUE;

   case BK_FILESIZE:  // wParam is file index, lParam is file size
      if (wParam == 0)
	 TransferMessage(GetString(hInst, IDS_RETRIEVING));

      SetDlgItemText(hDlg, IDC_FILENAME, info->files[wParam].filename);
      total = lParam;
      sprintf(temp, format, 0, total);
      SetDlgItemText(hDlg, IDC_FILESIZE, temp);
      SendDlgItemMessage(hDlg, IDC_GRAPH, GRPH_POSSET, 0, 0);
      SendDlgItemMessage(hDlg, IDC_GRAPH, GRPH_RANGESET, 0, total);
      return TRUE;

   case BK_PROGRESS:

      // Update this file's progress indicator.
      SendDlgItemMessage(hDlg, IDC_GRAPH, GRPH_POSSET, 0, lParam);

      // Update this file's progress text message.
      sprintf(temp, format, (int)lParam, (int)total);
      SetDlgItemText(hDlg, IDC_FILESIZE, temp);

      // Compute the fraction for the overall graph.
      fraction = 0;
      if (total != 0)
	 fraction = lParam * 100 / total;
      fraction = (fraction + 100 * info->current_file) / info->num_files;

      // Update overall progress indicator.
      SendDlgItemMessage(hDlg, IDC_FILEGRAPH, GRPH_POSSET, 0, fraction);

      return TRUE;

   case BK_FILEDONE:  /* lParam is index of file in info */
      if (abort_download)
      {
	 AbortDownloadDialog();
	 return TRUE;
      }

      if (DownloadDone(&info->files[lParam]))
      {
	 if (abort_download)
	 {
	    AbortDownloadDialog();
	    return TRUE;
	 }

	 // Set download time
	 DownloadSetTime(info->files[lParam].time);

	 // If we're a guest, there may be additional files that we are supposed to skip.
	 // If so, we should set our download time to the last file, so that we will skip
	 // the download on the next entry into the game.
	 if (config.guest)
	    for (i = lParam + 1; i < info->num_files; i++)
	    {
	       if (info->files[i].flags & DF_GUEST)
		  break;
	       DownloadSetTime(info->files[i].time);
	    }

	 info->current_file++;

	 // Tell transfer thread to continue
	 TransferContinue();

	 TransferMessage(GetString(hInst, IDS_RETRIEVING));
      }
      else AbortDownloadDialog();
      return TRUE;

   case BK_TRANSFERDONE: 
      EndDialog(hDlg, IDOK);
      return TRUE;

   case WM_COMMAND:
      switch(GET_WM_COMMAND_ID(wParam, lParam))
      {
      case IDCANCEL:
         abort_download = True;
	 EndDialog(hDlg, IDCANCEL);
	 return TRUE;
      }
   }
   return FALSE;
}