Ejemplo n.º 1
0
 @Override
 public void onConfirmInfoBarButtonClicked(ConfirmInfoBar infoBar, boolean confirm) {
   if (mPendingRequest.hasDownloadId()) {
     nativeDangerousDownloadValidated(mTab, mPendingRequest.getDownloadId(), confirm);
     if (confirm) {
       showDownloadStartNotification();
     }
     closeBlankTab();
   } else if (confirm) {
     // User confirmed the download.
     if (mPendingRequest.isGETRequest()) {
       enqueueDownloadManagerRequest(mPendingRequest);
     } else {
       DownloadInfo newDownloadInfo =
           DownloadInfo.Builder.fromDownloadInfo(mPendingRequest).setIsSuccessful(true).build();
       DownloadManagerService.getDownloadManagerService(mContext)
           .onDownloadCompleted(newDownloadInfo);
     }
   } else {
     // User did not accept the download, discard the file if it is a POST download.
     if (!mPendingRequest.isGETRequest()) {
       discardFile(mPendingRequest.getFilePath());
     }
   }
   mPendingRequest = null;
   infoBar.dismissJavaOnlyInfoBar();
 }
  @Override
  public void onConfirmInfoBarButtonClicked(ConfirmInfoBar infoBar, boolean confirm) {
    assert mTab != null;
    if (mPendingRequest.hasDownloadId()) {
      nativeDangerousDownloadValidated(mTab, mPendingRequest.getDownloadId(), confirm);
      if (confirm) {
        showDownloadStartNotification();
      }
      closeBlankTab();
    } else if (confirm) {
      // User confirmed the download.
      if (mPendingRequest.isGETRequest()) {
        final DownloadInfo info = mPendingRequest;
        new AsyncTask<Void, Void, Pair<String, String>>() {
          @Override
          protected Pair<String, String> doInBackground(Void... params) {
            Pair<String, String> result = getDownloadDirectoryNameAndFullPath();
            String fullDirPath = result.second;
            return doesFileAlreadyExists(fullDirPath, info.getFileName()) ? result : null;
          }

          @Override
          protected void onPostExecute(Pair<String, String> result) {
            if (result != null) {
              // File already exists.
              String dirName = result.first;
              String fullDirPath = result.second;
              launchDownloadInfoBar(info, dirName, fullDirPath);
            } else {
              enqueueDownloadManagerRequest(info);
            }
          }
        }.execute();
      } else {
        DownloadInfo newDownloadInfo =
            DownloadInfo.Builder.fromDownloadInfo(mPendingRequest).setIsSuccessful(true).build();
        DownloadManagerService.getDownloadManagerService(mContext)
            .onDownloadCompleted(newDownloadInfo);
      }
    } else {
      // User did not accept the download, discard the file if it is a POST download.
      if (!mPendingRequest.isGETRequest()) {
        discardFile(mPendingRequest.getFilePath());
      }
    }
    mPendingRequest = null;
    infoBar.dismissJavaOnlyInfoBar();
  }