chromium/chromeos/crosapi/mojom/download_controller.mojom

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

module crosapi.mojom;

import "mojo/public/mojom/base/file_path.mojom";
import "mojo/public/mojom/base/time.mojom";

// This mirrors `download::DownloadItem::DownloadState`, anything added or
// removed here must also be added or removed there.
[Stable, Extensible]
enum DownloadState {
    [Default] kUnknown = 0,
    kInProgress,
    kComplete,
    kCancelled,
    kInterrupted
};

// This mirrors `download::DownloadDangerType`, anything added or removed here
// must also be added or removed there.
[Stable, Extensible]
enum DownloadDangerType {
  [Default] kDownloadDangerTypeInvalid = -1,
  kDownloadDangerTypeNotDangerous = 0,
  kDownloadDangerTypeDangerousFile = 1,
  kDownloadDangerTypeDangerousUrl = 2,
  kDownloadDangerTypeDangerousContent = 3,
  kDownloadDangerTypeMaybeDangerousContent = 4,
  kDownloadDangerTypeUncommonContent = 5,
  kDownloadDangerTypeUserValidated = 6,
  kDownloadDangerTypeDangerousHost = 7,
  kDownloadDangerTypePotentiallyUnwanted = 8,
  kDownloadDangerTypeAllowlistedByPolicy = 9,
  kDownloadDangerTypeAsyncScanning = 10,
  kDownloadDangerTypeBlockedPasswordProtected = 11,
  kDownloadDangerTypeBlockedTooLarge = 12,
  kDownloadDangerTypeSensitiveContentWarning = 13,
  kDownloadDangerTypeSensitiveContentBlock = 14,
  kDownloadDangerTypeDeepScannedSafe = 15,
  kDownloadDangerTypeDeepScannedOpenedDangerous = 16,
  kDownloadDangerTypePromptForScanning = 17,
  kDownloadDangerTypeDeprecated18 = 18,
  kDownloadDangerTypeDangerousAccountCompromise = 19,
  [MinVersion=1] kDownloadDangerTypeDeepScannedFailed = 20,
  [MinVersion=2] kDownloadDangerTypePromptForLocalPasswordScanning = 21,
  [MinVersion=2] kDownloadDangerTypeAsyncLocalPasswordScanning = 22,
  [MinVersion=3] kDownloadDangerTypeBlockedScanFailed = 23,
};

// This mirrors `download::DownloadItem::InsecureDownloadStatus`, anything
// added or removed here must also be added or removed there.
[Stable, Extensible, RenamedFrom="crosapi.mojom.DownloadMixedContentStatus"]
enum InsecureDownloadStatus {
  [Default] kInvalid = -1,
  kUnknown = 0,
  kSafe = 1,
  kValidated = 2,
  kWarn = 3,
  kBlock = 4,
  kSilentBlock = 5,
};

// This mirrors `download::DownloadItem`. See:
// https://source.chromium.org/chromium/chromium/src/+/main:components/download/public/common/download_item.h?q=download_item.h
//
// NOTE: Starting in Version 1, `has_field` is added for every new
// non-nullable `field`. This is for backwards compatibility, so that older
// clients know when values are present or are absent by default.
//
// Next MinVersion: 5
// Next ID: 20
[Stable, RenamedFrom="crosapi.mojom.DownloadEvent"]
struct DownloadItem {
  DownloadState state@0;
  mojo_base.mojom.FilePath target_file_path@1;
  bool is_from_incognito_profile@2;
  [MinVersion=1] string? guid@3;
  [MinVersion=1] mojo_base.mojom.FilePath? full_path@4;
  [MinVersion=1] bool has_is_paused@5;
  [MinVersion=1] bool is_paused@6;
  [MinVersion=1] bool has_open_when_complete@7;
  [MinVersion=1] bool open_when_complete@8;
  [MinVersion=1] bool has_received_bytes@9;
  [MinVersion=1] int64 received_bytes@10;
  [MinVersion=1] bool has_total_bytes@11;
  [MinVersion=1] int64 total_bytes@12;
  [MinVersion=2] mojo_base.mojom.Time? start_time@13;
  [MinVersion=3] bool has_is_dangerous@14;
  [MinVersion=3] bool is_dangerous@15;
  [MinVersion=3] bool has_is_insecure@16;
  [MinVersion=3] bool is_insecure@17;
  [MinVersion=4] DownloadDangerType danger_type@18;
  [MinVersion=4] InsecureDownloadStatus insecure_download_status@19;
};

// A client implemented in lacros-chrome for the DownloadController which is
// implemented in ash-chrome.
//
// Next MinVersion: 2
// Next ID: 6
[Stable, Uuid="eccf720b-538a-4943-a6fd-d073639c4140"]
interface DownloadControllerClient {
  // Returns all downloads, no matter the type or state, sorted chronologically
  // by start time. This method will ultimately invoke
  // `download::SimpleDownloadManager::GetAllDownloads()`.
  [MinVersion=1] GetAllDownloads@5() => (array<DownloadItem> downloads);

  // Pauses the download associated with the specified `download_guid`. This
  // method will ultimately invoke `download::DownloadItem::Pause()`.
  Pause@1(string download_guid);

  // Resumes the download associated with the specified `download_guid`. If
  // `user_resume` is set to `true`, it signifies that this invocation was
  // triggered by an explicit user action. This method will ultimately invoke
  // `download::DownloadItem::Resume()`.
  Resume@2(string download_guid, bool user_resume);

  // Cancels the download associated with the specified `download_guid`. If
  // `user_cancel` is set to `true`, it signifies that this invocation was
  // triggered by an explicit user action. This method will ultimately invoke
  // `download::DownloadItem::Cancel()`.
  Cancel@3(string download_guid, bool user_cancel);

  // Marks the download associated with the specified `download_guid` to be
  // `open_when_complete`. This method will ultimately invoke
  // `download::DownloadItem::SetOpenWhenComplete()`.
  SetOpenWhenComplete@4(string download_guid, bool open_when_complete);
};

// Allows lacros to pass download information to ash-chrome.
// Implemented in ash-chrome.
//
// Next MinVersion: 2
// Next ID: 4
[Stable, Uuid="c3d8bd4b-1fc9-4529-aeb2-76770b0ad1c3"]
interface DownloadController {
  // Binds the DownloadControllerClient interface, which allows the
  // DownloadController implemented in ash-chrome to communicate with its client
  // which is implemented in lacros-chrome.
  [MinVersion=1] BindClient@3(
    pending_remote<DownloadControllerClient> client);

  // Called when a download is created. Comes from `content::DownloadManager`,
  // and will only pass events once that's initialized.
  OnDownloadCreated@0(crosapi.mojom.DownloadItem download);

  // Called whenever a `download::DownloadItem` is updated.
  OnDownloadUpdated@1(crosapi.mojom.DownloadItem download);

  // Called when a `download::DownloadItem` is destroyed.
  OnDownloadDestroyed@2(crosapi.mojom.DownloadItem download);
};