chromium/ash/webui/media_app_ui/media_app_ui_untrusted.mojom

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

module ash.media_app_ui.mojom;

import "skia/public/mojom/bitmap.mojom";
import "ui/gfx/geometry/mojom/geometry.mojom";

// Factory interface to create an untrusted page handler (for the
// chrome-untrusted:// frame) communicating directly with the browser.
interface UntrustedPageHandlerFactory {
  // Create a page handler for the untrusted frame exposing OCR related APIs
  // between it and the browser via |receiver| and |page|.
  CreateOcrUntrustedPageHandler(
  pending_receiver<OcrUntrustedPageHandler> receiver,
      pending_remote<OcrUntrustedPage> page);

  // Create a page handler for the untrusted frame exposing Mahi related APIs
  // between it and the browser via `receiver` and `page`.
  CreateMahiUntrustedPageHandler(
  pending_receiver<MahiUntrustedPageHandler> receiver,
      pending_remote<MahiUntrustedPage> page,
      string file_name);
};

struct PageMetadata {
  // Opaque ID uniquely identifying a page.
  string id;
  gfx.mojom.RectF rect;
};

// Interface implemented in the browser process and called by the
// chrome-untrusted:// Media App page.
interface OcrUntrustedPageHandler {
  // Provides metadata about the document. Page metadata is always provided for
  // all pages. Called in the following cases:
  //   a) A page is rotated (only the rotated page is dirty, but potentially all
  //      pages will get updated metadata). This case is slightly special as a
  //      PageContentsUpdated() will also be called with the rotated page's ID.
  //      This method will always be called before PageContentsUpdated() for a
  //      rotated page.
  //   b) A page is deleted. The deleted page will be omitted from the provided
  //      page metadata.
  //   c) A deleted page is re-added (undo page delete). The deleted page's UUID
  //      will be added back into the page metadata in the correct array
  //      location.
  //   d) Pages are re-ordered. The array will be re-ordered to match.
  //   page_metadata: An array of the new coordinate bounds for each page in the
  //                  document, attached to each page's unique identifier.
  PageMetadataUpdated(array<PageMetadata> page_metadata);

  // Called when a page in the document becomes dirty, i.e. it needs to go
  // through OCR again. This includes when:
  //   a) A page is rotated. This is called in conjunction with the
  //      PageMetadataUpdated() API, because rotates also cause location
  //      changes.
  //   b) A page is edited. This could be a new annotation (freehand or text),
  //      or a form field edited.
  //   dirty_page_id: A string containing the unique identifier of the dirty
  //                  page.
  PageContentsUpdated(string dirty_page_id);

  // Called whenever the viewport changes, e.g. due to scrolling, zooming,
  // resizing the window, or opening and closing toolbars/panels.
  //   viewport_box: The new bounding box of the viewport.
  //   scale_factor: The ratio between CSS pixels (i.e. ignoring browser and
  //       pinch zoom) and ink units. Larger numbers indicate the document is
  //       more zoomed in.
  ViewportUpdated(gfx.mojom.RectF viewport_box, float scale_factor);
};

// Interface implemented in JavaScript by the chrome-untrusted:// page for Media
// App and called by browser process code.
interface OcrUntrustedPage {
  // Request the bitmap information for a page identified by its ID.
  RequestBitmap(string requestedPageId) => (skia.mojom.BitmapN32? page);

  // If a document is currently loaded, scrolls and zooms to the given viewport.
  // This allows certain AXActions to be implemented such as
  // `kScrollToMakeVisible` or `kSetScrollOffset`.
  //   viewport_box: The bounding box representing the new camera position.
  SetViewport(gfx.mojom.RectF viewport_box);

  // Tells the MediaApp when the OCR service has been turned on or off (either
  // due to the PDF OCR setting being changed, or the accessibility service
  // being toggled on or off).
  SetPdfOcrEnabled(bool enabled);
};


// Interfaces for Mahi support

// Interface implemented in the browser process and called by the
// chrome-untrusted:// Media App page.
interface MahiUntrustedPageHandler {
  // Notifies when media app finishes loading a PDF file. This may be used for
  // Mahi refresh availability.
  OnPdfLoaded();

  // Notifies when the file name of the loaded PDF file is updated (e.g. after
  // rename or save as), so that the Mahi UI (e.g. title on the result panel and
  // the refresh banner) can show the fresh file name.
  OnPdfFileNameUpdated(string new_name);

  // Notifies when the PDF context menu is shown. This may be used to show the
  // Mahi widget card.
  OnPdfContextMenuShow(gfx.mojom.RectF anchor);

  // Notifies when the PDF context menu is hidden. This may be used to hide the
  // Mahi widget card.
  OnPdfContextMenuHide();
};

// Interface implemented in JavaScript by the chrome-untrusted:// page for Media
// App and called by browser process code.
interface MahiUntrustedPage {
  // Hides the PDF context menu, if currently shown.
  HidePdfContextMenu();

  // Requests the text content of the PDF file.
  GetPdfContent(int32 limit) => (string? content);
};