chromium/chromecast/browser/webui/mojom/webui.mojom

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

module chromecast.mojom;

import "mojo/public/mojom/base/ref_counted_memory.mojom";
import "mojo/public/mojom/base/values.mojom";

// =============================================================================
// These interfaces allow a remote client to control Chromium Web UIs in the
// Cast Browser. The client will provide resources to specific Web UIs based on
// host name. The only intended client for these interfaces is the Cast Service,
// which currently lives in the browser process. Eventually Cast will be moved
// to its own process, which is why these IPC interfaces are needed.
// =============================================================================

// Wraps a repeating callback which is invoked by the Web UI messenger.
interface MessageCallback {
  // Receive a message with generic parameters.
  OnMessage(mojo_base.mojom.ListValue list);
};

// Use this interface to control the Web UI. This interface is hosted in the
// Cast Browser process.
interface WebUi {
  // Register a repeating message callback for a Web UI.
  RegisterMessageCallback(string message, pending_remote<MessageCallback> cb);

  // Execute a Javascript |function| with |args|.
  CallJavascriptFunction(string function, mojo_base.mojom.ListValue args);
};

// Implement this interface to provide resources for a given host. This
// interface is owned by the Cast Service process.
interface Resources {
  // Resources are requested for <host>/|path|.
  RequestResourceBytes(string path) => (mojo_base.mojom.RefCountedMemory bytes);
};

// Implement this interface to control Chromium Web UI pages. This interface
// is implemented by the Cast Service process.
interface WebUiClient {
  // Called whenever a Web UI is about to be launched. The client must bind
  // |resources|. The resources will only be used by the matching Web UI |host|.
  CreateController(string host,
                   pending_remote<WebUi> web_ui,
                   pending_receiver<Resources> resources);

  // Requests the client to create a resource provider for |host|. These
  // resources may be used by multiple Web UI pages.
  CreateResources(string host,
                  pending_receiver<Resources> resources);
};