chromium/components/performance_manager/public/mojom/coordination_unit.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 performance_manager.mojom;

import "mojo/public/mojom/base/process_id.mojom";
import "mojo/public/mojom/base/time.mojom";
import "components/performance_manager/public/mojom/lifecycle.mojom";
import "components/performance_manager/public/mojom/v8_contexts.mojom";
import "components/performance_manager/public/mojom/web_memory.mojom";
import "third_party/blink/public/mojom/tokens/tokens.mojom";

// Any new type here needs to be mirrored between coordination_unit_types.h and
// coordination_unit.mojom, and have mappings between the two defined in
// coordination_unit_mojom_traits.h/.cc (see comment in coordination_unit_id.h).
enum CoordinationUnitType {
  kFrame,
  kPage,
  kProcess,
  kSystem,
};

// Interface used by a blink::Document to communicate state associated with
// resource management to the embedder.
interface DocumentCoordinationUnit {
  // Property signals.
  SetNetworkAlmostIdle();
  SetLifecycleState(LifecycleState state);
  SetHasNonEmptyBeforeUnload(bool has_nonempty_beforeunload);

  // Called the first time a form in this document is interacted with.
  SetHadFormInteraction();

  // Called the first time the user has edited the content of an element. This
  // is a superset of `SetHadFormInteraction()`: form interactions trigger both
  // events but changes to e.g. a `<div>` with the `contenteditable` property
  // will only trigger `SetHadUserEdits()`.
  SetHadUserEdits();

  // Called when the document starts using WebRTC.
  OnStartedUsingWebRTC();

  // Called when the document stops using WebRTC.
  OnStoppedUsingWebRTC();

  // Called whenever the frame associated with this document is tagged or
  // untagged as an ad, providing the new status.
  SetIsAdFrame(bool is_ad_frame);

  // Called when the associated frame has caused a non-persistent notification
  // to be created.
  OnNonPersistentNotificationCreated();

  // Invoked when the frame associated with this document has had a first
  // contentful paint, as defined here:
  // https://developers.google.com/web/tools/lighthouse/audits/first-contentful-paint
  // This may not fire for all frames, depending on if the load is interrupted
  // or if the content is even visible. It will fire at most once for a given
  // frame. It will only fire for main-frame nodes.
  OnFirstContentfulPaint(mojo_base.mojom.TimeDelta time_since_navigation_start);

  // Invoked when JS in the renderer requests a memory measurement via
  // the performance.measureUserAgentSpecificMemory API.
  OnWebMemoryMeasurementRequested(WebMemoryMeasurement.Mode mode) =>
      (WebMemoryMeasurement measurement);
};

// Interface used by the RendererResourceCoordinator singleton to send state
// associated with resource management of a renderer process to the embedder.
interface ProcessCoordinationUnit {
  // Property signals.
  SetMainThreadTaskLoadIsLow(bool main_thread_task_load_is_low);

  //////////////////////////////////////////////////////////////////////////////
  // V8 context tracking.

  // Notifies the browser of a V8Context being created in a renderer
  // process. If the context is associated with an ExecutionContext (EC) then
  // |description.execution_context_token| will be provided. If the EC is a
  // frame, and the parent of that frame is also in the same process, then
  // |iframe_attribution_data| will be provided, otherwise these will be empty.
  // See the V8ContextWorldType enum for a description of the relationship
  // between world types, world names and execution contexts (in
  // v8_contexts.mojom).
  OnV8ContextCreated(V8ContextDescription description,
                     IframeAttributionData? iframe_attribution_data);

  // Notifies the browser that a V8Context is now detached from its associated
  // ExecutionContext (if one was provided during OnV8ContextCreated). If the
  // context stays detached for a long time this is indicative of a Javascript
  // leak, with the context being kept alive by a stray reference from another
  // context. All ExecutionContext-associated V8Contexts will have this method
  // called before they are destroyed, and it will not be called for other
  // V8Contexts (they are never considered detached). It is possible that this
  // is never called for contexts in a renderer processes that crashes or is
  // otherwise terminated.
  OnV8ContextDetached(blink.mojom.V8ContextToken v8_context_token);

  // Notifies the browser that a V8Context has been garbage collected. This will
  // only be called after OnV8ContextDetached if the OnV8ContextCreated had a
  // non-empty |description.execution_context_token|. It is possible that this
  // is never called for contexts in a renderer processes that crashes or is
  // otherwise terminated.
  OnV8ContextDestroyed(blink.mojom.V8ContextToken v8_context_token);

  // Called when a RemoteFrame is attached as the content of a local iframe.
  // The browser process will use this to maintain a map from the RemoteFrame's
  // token to the iframe's attribution information as seen by the renderer
  // process.
  OnRemoteIframeAttached(blink.mojom.LocalFrameToken parent_frame_token,
                        blink.mojom.RemoteFrameToken remote_frame_token,
                        IframeAttributionData iframe_attribution_data);

  // Called when a RemoteFrame that was the content of a local iframe is
  // removed from the frame. Only the frame token is needed because the
  // iframe's attribution information was previously associated with the token
  // by OnRemoteIframeAttached.
  OnRemoteIframeDetached(blink.mojom.LocalFrameToken parent_frame_token,
                         blink.mojom.RemoteFrameToken remote_frame_token);

  // Called when a renderer has observed an allow-listed performance.mark
  // trigger event. The browser will reconfirm that the trigger is indeed
  // allow-listed before firing the background tracing trigger, which can result
  // in a trace being uploaded to the background tracing pipeline.
  FireBackgroundTracingTrigger(string trigger_name);
};