// 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 remoting.mojom;

import "mojo/public/mojom/base/values.mojom";
import "remoting/host/mojom/chromoting_host_services.mojom";
import "remoting/host/mojom/common.mojom";
import "services/network/public/mojom/ip_endpoint.mojom";

// Provides a set of methods to allow the Daemon process to initialize and
// control the network (a.k.a. host) process.
// The remote for this interface is owned in the high-privilege daemon process
// and the receiver is bound in the low-privilege network process.
interface RemotingHostControl {
  // Provides host configuration details to the network process such as the
  // owner email and robot account to use for authentication to service APIs.
  // This method may be called multiple times as changes are detected in the
  // host configuration file.
  [EnableIf=is_win|is_linux]
  ApplyHostConfig(mojo_base.mojom.DictionaryValue config);

  // Provides the network process with a set of platform handles which are used
  // for pairing functionality. The network process does not have access to the
  // privileged platform resource so the Daemon process must open it and provide
  // a handle to it. This method must only be called once per network process
  // instance.
  [EnableIf=is_win]
  InitializePairingRegistry(handle<platform> privileged_handle,
                            handle<platform> unprivileged_handle);

  // Requests the network process to bind a pending receiver of
  // ChromotingHostServices coming from a user-launched process. On
  // multi-process hosts, the daemon process or agent broker process is
  // responsible for brokering all mojo IPCs, but it doesn't affect where the
  // receivers and remotes are bound. Please see comments on the
  // ChromotingHostServices interface.
  [EnableIf=is_mac]
  BindChromotingHostServices(pending_receiver<ChromotingHostServices> receiver);
};

// Provides a set of methods to allow the Network process to notify the Daemon
// process of state. This is typically used for logging and is meant for
// informational purposes only (i.e. these should not trigger any service-level
// events).
// The signaling_id used throughout this interface is a string which represents
// a user in the FTL signaling service which is used for client to host
// messaging (a necessary step in establishing a P2P connection). An example
// ID would be <user_email@domain.com>/chromoting_ftl_<unique_ftl_resource_id>.
// The remote for this interface is owned in the low-privilege network process
// and the receiver is bound in the high-privilege daemon process.
[EnableIf=is_win|is_linux]
interface HostStatusObserver {
  // Called when an unauthorized user attempts to connect to the host.
  OnClientAccessDenied(string signaling_id);

  // Called when a new client is authenticated.
  OnClientAuthenticated(string signaling_id);

  // Called when all channels for an authenticated client are connected.
  OnClientConnected(string signaling_id);

  // Called when an authenticated client is disconnected.
  OnClientDisconnected(string signaling_id);

  // Called on notification of a P2P route change (e.g. Relay -> Direct).
  // |channel_name| represents an ICE channel name, it is not used for WebRTC
  // connections.
  OnClientRouteChange(string signaling_id, string channel_name,
                      TransportRoute route);

  // Called when the host is started for an account.
  OnHostStarted(string owner_email);

  // Called when the host shuts down.
  OnHostShutdown();
};
