chromium/chrome/browser/ui/webui/downloads/downloads.mojom

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module downloads.mojom;

import "mojo/public/mojom/base/string16.mojom";
import "url/mojom/url.mojom";

// Represents the possible responses to the survey on the chrome://downloads
// dangerous download interstitial.
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
//
// LINT.IfChange(DangerousDownloadInterstitialSurveyOptions)
enum DangerousDownloadInterstitialSurveyOptions{
  kNoResponse = 0,
  kCreatedFile = 1,
  kTrustSite = 2,
  kAcceptRisk = 3,
};
// LINT.ThenChange(//tools/metrics/histograms/metadata/download/enums.xml:DangerousDownloadInterstitialSurveyOptions)

// This is a subset of download::DownloadDangerType.
enum DangerType {
  // This is the catch-all value for DownloadDangerTypes that are not relevant
  // to the UI.
  kNoApplicableDangerType,
  kDangerousFile,
  kDangerousUrl,
  kDangerousContent,
  kCookieTheft,
  kUncommonContent,
  kDangerousHost,
  kPotentiallyUnwanted,
  kAsyncScanning,
  kAsyncLocalPasswordScanning,
  kBlockedPasswordProtected,
  kBlockedTooLarge,
  kSensitiveContentWarning,
  kSensitiveContentBlock,
  kDeepScannedFailed,
  kDeepScannedSafe,
  kDeepScannedOpenedDangerous,
  kBlockedScanFailed,
};

// This corresponds to DownloadUIModel::TailoredWarningType.
enum TailoredWarningType {
  kNoApplicableTailoredWarningType,
  kCookieTheft,
  kCookieTheftWithAccountInfo,
  kSuspiciousArchive,
};

// Represents the state of a download in the UI.
enum State {
  kInProgress,
  kCancelled,
  kComplete,
  kPaused,
  kDangerous,
  kInterrupted,
  kInsecure,
  // See download::DownloadDangerType for more details on the scanning States.
  kAsyncScanning,
  kPromptForScanning,
  kPromptForLocalPasswordScanning,
};

// This corresponds to safe_browsing::SafeBrowsingState.
enum SafeBrowsingState {
  kNoSafeBrowsing,
  kStandardProtection,
  kEnhancedProtection,
};

// This is the information associated with a download used for rendering in the
// UI.
struct Data {
  bool file_externally_removed;
  bool is_dangerous;
  [RenamedFrom=is_mixed_content]
  bool is_insecure;
  bool is_reviewable;
  // |otr| stands for off-the-record and is true when a download entry is
  // created during an incognito or guest profile session.
  bool otr;
  bool resume;
  bool retry;
  int32 percent;
  int32 started;
  int64 total;
  string by_ext_id;
  string by_ext_name;
  DangerType danger_type;
  TailoredWarningType tailored_warning_type;
  string date_string;
  string file_name;
  string file_path;
  string file_url;
  // Used to display tailored warnings with account information.
  string account_email;
  string id;
  string last_reason_text;
  string progress_status_text;
  string show_in_folder_text;
  string since_string;
  // |state| indicates the current state of the download. A download data entry
  // can be dangerous or insecure which can be expressed as a state to
  // indicate the download needs confirmation before initiating. After
  // confirmation, the state will indicate the download is in progress, complete
  // or cancelled.
  State state;
  // The referrer URL of the download item. Present if this field is populated
  // with the referrer URL. Omitted if the URL is unknown.
  url.mojom.Url? referrer_url;
  // The display string for the referrer URL in the UI. May be truncated/elided
  // from the original URL, and IDN domains may be converted to Unicode.
  mojo_base.mojom.String16 display_referrer_url;

  // The URL of the download item. Present if this field is populated with the
  // original URL. Omitted if the URL should not be clickable on the downloads
  // page, due to URL size limits requiring truncation.
  url.mojom.Url? url;
  // The display string for the URL in the UI. May be truncated/elided from the
  // original URL, and IDN domains may be converted to Unicode.
  mojo_base.mojom.String16 display_url;
  // Safe Browsing protection level of the profile in which the item was
  // downloaded. Used to determine whether to show a special warning message.
  SafeBrowsingState safe_browsing_state;
  // Whether the download had a Safe Browsing verdict. This is used to determine
  // whether to call a file type warning "suspicious" or "unverified".
  bool has_safe_browsing_verdict;
};

// The parameter "id" is the id of the current download
interface PageHandlerFactory {
  CreatePageHandler(pending_remote<Page> page,
                    pending_receiver<PageHandler> handler);
};

// TODO(crbug.com/351865738): Consider combining methods that take an id
// into their own stateless interface.
interface PageHandler {
  GetDownloads(array<string> search_terms);
  OpenFileRequiringGesture(string id);
  Drag(string id);

  // Called when "Download suspicious file" is clicked from the
  // chrome://downloads overflow menu, for suspicious/unverified files. Does not
  // show a prompt.
  SaveSuspiciousRequiringGesture(string id);

  // Called when "Download dangerous file" is clicked from the
  // chrome://downloads overflow menu to open the warning bypass dialog, for
  // dangerous files. Only records the opening of the warning bypass dialog.
  RecordOpenBypassWarningDialog(string id);

  // Called when "Download dangerous file" is clicked from the
  // chrome://downloads overflow menu to open the warning bypass interstitial,
  // for dangerous files. Only records the opening of the warning bypass
  // interstitial.
  RecordOpenBypassWarningInterstitial(string id);

  // Called when "Download anyway" is clicked on the chrome://downloads warning
  // bypass interstitial, for dangerous files.
  RecordOpenSurveyOnDangerousInterstitial(string id);

  // Called when "Download dangerous file" is clicked from the
  // chrome://downloads warning dialog, for dangerous files.
  SaveDangerousFromDialogRequiringGesture(string id);

  // Called when "Download <dangerous file name>" is clicked from the
  // chrome://downloads warning interstitial, for dangerous files.
  SaveDangerousFromInterstitialNeedGesture(string id,
    DangerousDownloadInterstitialSurveyOptions response);

  // Called when "Cancel" is clicked on the chrome://downloads warning bypass
  // dialog, or the dialog is closed by dismissing it. Only records the event
  // and potentially sends a report.
  RecordCancelBypassWarningDialog(string id);

  // Called when "Cancel" is clicked on the chrome://downloads warning bypass
  // interstitial. Only records the event and potentially sends a report.
  RecordCancelBypassWarningInterstitial(string id);

  DiscardDangerous(string id);
  RetryDownload(string id);
  Show(string id);
  Pause(string id);
  Resume(string id);
  Remove(string id);
  Undo();
  Cancel(string id);
  ClearAll();
  OpenDownloadsFolderRequiringGesture();

  // The two methods below are for the ESB Download Row Promo.
  // Opens the chrome://settings/security page with a IPH Promotion
  // on the ESB radio button.
  OpenEsbSettings();

  // Logs when the user actually sees the ESB Download Row Promo.
  LogEsbPromotionRowViewed();

  // Opens this download with the given |id| while it is being scanned by Safe
  // Browsing. This completes the scan early. This requires a user gesture on
  // the WebUI.
  OpenDuringScanningRequiringGesture(string id);

  // Opens a review dialog for the download with the given |id| after it has
  // received a warning deep scanning verdict. This requires a user gesture on
  // the WebUI.
  ReviewDangerousRequiringGesture(string id);

  // Performs deep scan for the download with the given |id|.
  DeepScan(string id);

  // Bypass deep scan for download with the given |id|. This requires a user
  // gesture on the WebUI.
  BypassDeepScanRequiringGesture(string id);

  // Checks whether an ESB Promotion can be shown on this profile.
  IsEligibleForEsbPromo() => (bool result);
};

interface Page {
  RemoveItem(int32 index);
  UpdateItem(int32 index, Data data);
  InsertItems(int32 index, array<Data> items);
  ClearAll();
};