chromium/components/services/unzip/public/mojom/unzipper.mojom

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

module unzip.mojom;

import "components/services/storage/public/mojom/filesystem/directory.mojom";
import "mojo/public/mojom/base/file_path.mojom";
import "mojo/public/mojom/base/read_only_file.mojom";
import "sandbox/policy/mojom/sandbox.mojom";

struct UnzipOptions {
  // Explicit encoding or set to "auto" to auto-detect from the ZIP file.
  // Default unpack encoding uses UTF-8.
  string encoding;
  // Password used to unpack encrypted ZIP file.
  string password;
};

struct Info {
  // Boolean set to false if broken sizes are stored in the ZIP archive.
  bool size_is_valid;
  // Predicted size as read from the ZIP archive (not trustable).
  uint64 size;
  // Boolean set to true if the ZIP contains encrypted content.
  bool is_encrypted;
  // Boolean set to true if the ZIP encrypted content uses AES.
  bool uses_aes_encryption;
};

// UnzipFilter is used to call back into the caller to check if
// the supplied |path| should be unpacked.
interface UnzipFilter {
  [Sync]
  ShouldUnzipFile(mojo_base.mojom.FilePath path) => (bool result);
};

// Listener for a ZIP extraction operation.
interface UnzipListener {
  // Regularly called during ZIP extraction operation to report progress,
  // with the total number of |bytes| processed since the last call.
  OnProgress(uint64 bytes);
};

// Interface to the out-of-process unzipper. The unzipper unzips a ZIP
// archive, often for the purpose of unpacking software updates.
[ServiceSandbox=sandbox.mojom.Sandbox.kService]
interface Unzipper {
  // Unzip |zip_file| into |output_dir|.
  // Returns true on success, false otherwise.
  // |options| contains unpacking information such as filename encoding.
  // If provided, |filter| is called for each entry of the archive (which incurs
  // one IPC for each entry) and only the entries for which it returns true are
  // extracted.
  // If provided, |listener| is called repeatedly with the bytes extracted.
  Unzip(
      mojo_base.mojom.ReadOnlyFile zip_file,
      pending_remote<storage.mojom.Directory> output_dir,
      UnzipOptions options,
      pending_remote<UnzipFilter>? filter,
      pending_remote<UnzipListener>? listener) => (bool result);

  // Detects the encoding of filenames stored in the ZIP archive.
  // Returns an Encoding as defined in
  // third_party/ced/src/util/encodings/encodings.pb.h
  // or UNKNOWN_ENCODING in case of error.
  DetectEncoding(mojo_base.mojom.ReadOnlyFile zip_file) => (int32 encoding);

  // Returns the size in bytes and metadata for the extracted archive.
  GetExtractedInfo(mojo_base.mojom.ReadOnlyFile zip_file) => (Info info);
};