chromium/third_party/blink/public/mojom/peerconnection/peer_connection_tracker.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 blink.mojom;

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

// This enum is a typemap of base::PowerObserver::DeviceThermalState.
enum DeviceThermalState {
  kUnknown,
  kNominal,
  kFair,
  kSerious,
  kCritical,
};

// This constant mirrors base::PowerThermalObserver::kSpeedLimitMax
const int32 kSpeedLimitMax = 100;

struct PeerConnectionInfo {
  // ID of the peer connection. Unique only within the renderer process.
  int32 lid;

  // Serialized version of RTCConfiguration.
  string rtc_configuration;

  // The URL of the blink::WebLocalFrame within which this peer connection
  // lives. Used for debugging purposes (displayed by WebRTC-Internals).
  // May be null for eg pages with opaque URLs.
  // TODO(1274640): Use a mojo URL instead of a string.
  string? url;
};

// This interface collects data about each peer connection and sends it to the
// browser process.
interface PeerConnectionManager {
    // Called when the browser process reports a suspend event from the OS.
    OnSuspend();

    // Called when the browser process reports a new thermal state from the OS.
    OnThermalStateChange(DeviceThermalState thermal_state);

    // Called when the browser process reports a new CPU speed limit change from
    // the OS. Values are normally between 0 and 100.
    OnSpeedLimitChange(int32 speed_limit);

    // Enable WebRtc event log output.
    StartEventLog(int32 peer_connection_local_id, int32 output_period_ms);

    // Disable WebRtc event log output.
    StopEventLog(int32 peer_connection_local_id);

    // Requests standard PeerConnection stats for webrtc-internals.
    GetStandardStats();

    // Requests a state dump for webrtc-internals.
    GetCurrentState();
};

// This interface allows forwarding PeerConnection events to WebRTCInternals in
// the browser process.
interface PeerConnectionTrackerHost {
  // PeerConnectionTrackerHost forwards these events to WebRTCInternals.
  // TODO(vm.arjun): Migrate rest of the messages,
  // https://bugs.chromium.org/p/chromium/issues/detail?id=792801

  // Notifies WebRTCInternals about the addition of the peer connection
  // whose data is specified in |info|.
  AddPeerConnection(PeerConnectionInfo info);

  // Notifies WebRTCInternals about the removal of the peer connection
  // identified with local id |lid|.
  RemovePeerConnection(int32 lid);

  // This method is called to update PeerConnection.
  // |lid| is the ID of the peer connection
  // |type| is the update type. ex: "createOffer"
  // |value| is the detail of the update.
  // ex: "options: {offerToReceiveAudio: 0}"
  UpdatePeerConnection(int32 lid, string type, string value);

  // This method is called to inform that a peer connection's session
  // description has been assigned an ID.
  OnPeerConnectionSessionIdSet(int32 lid, string session_id);

  // Lets WebRTCInternals know that a getUserMedia() call has been made.
  // |request_id| is an id assigned to the getusermedia call and its
  //   callback/error
  // |audio| is true if audio stream is requested
  // |video| is true if video stream is requested
  // |audio_constraints| is constraints for audio like audio source device id
  // |video_constraints| is constraints for video like audio source device id
  // The constraint strings are for display only and should not be parsed
  // by the browser for security reasons.
  GetUserMedia(int32 request_id, bool audio, bool video,
               string audio_constraints, string video_constraints);

  // Lets WebRTCInternals know that a getUserMedia() call has resolved.
  // |request_id| is an id assigned to the getusermedia call and its
  //   callback/error
  // |stream_id| is information about the stream such as the stream id.
  // |audio_track_info| describes the streams audio track (if any).
  // |video_track_info| describes the streams video track (if any).
  // The stream_id, audio_track_info and video_track_info strings are
  // for display only and should not be parsed by the browser for
  // security reasons.
  GetUserMediaSuccess(int32 request_id, string stream_id,
    string audio_track_info, string video_track_info);

  // Lets WebRTCInternals know that a getUserMedia() call has failed.
  // |request_id| is an id assigned to the getusermedia call and its
  //   callback/error
  // |error| the (DOM) error.
  // |error_message| the error message.
  // The error and error message strings are for display only and should not
  // be parsed by the browser for security reasons.
  GetUserMediaFailure(int32 request_id, string error, string error_message);

  // Lets WebRTCInternals know that a getUserMedia() call has been made.
  // |request_id| is an id assigned to the getusermedia call and its
  //   callback/error
  // |audio| is true if audio stream is requested
  // |video| is true if video stream is requested
  // |audio_constraints| is constraints for audio like audio source device id
  // |video_constraints| is constraints for video like audio source device id
  // The constraint strings are for display only and should not be parsed
  // by the browser for security reasons.
  GetDisplayMedia(int32 request_id, bool audio, bool video,
               string audio_constraints, string video_constraints);

  // Lets WebRTCInternals know that a getDisplayMedia() call has resolved.
  // |request_id| is an id assigned to the getusermedia call and its
  //   callback/error
  // |stream_id| is information about the stream such as the stream id.
  // |audio_track_info| describes the streams audio track (if any).
  // |video_track_info| describes the streams video track (if any).
  // The stream_id, audio_track_info and video_track_info strings are
  // for display only and should not be parsed by the browser for
  // security reasons.
  GetDisplayMediaSuccess(int32 request_id, string stream_id,
    string audio_track_info, string video_track_info);

  // Lets WebRTCInternals know that a getDisplayMedia() call has failed.
  // |request_id| is an id assigned to the getusermedia call and its
  //   callback/error
  // |error| the (DOM) error.
  // |error_message| the error message.
  // The error and error message strings are for display only and should not
  // be parsed by the browser for security reasons.
  GetDisplayMediaFailure(int32 request_id, string error, string error_message);

  // Logs WebRtc log for the connection id.
  WebRtcEventLogWrite(int32 lid, array<uint8> output);

  // Adds standard PeerConnection stats for webrtc-internals.
  // |lid| is the renderer local id,
  // |value| is the list of stats reports.
  AddStandardStats(int32 lid, mojo_base.mojom.ListValue value);

  // Adds legacy PeerConnection stats for webrtc-internals.
  // |lid| is the renderer local id,
  // |value| is the list of stats reports.
  AddLegacyStats(int32 lid, mojo_base.mojom.ListValue value);
};