chromium/third_party/blink/public/mojom/page/page.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 blink.mojom;
import "mojo/public/mojom/base/time.mojom";
import "mojo/public/mojom/base/unguessable_token.mojom";
import "skia/public/mojom/skcolor.mojom";
import "services/network/public/mojom/attribution.mojom";
import "third_party/blink/public/mojom/frame/frame_replication_state.mojom";
import "third_party/blink/public/mojom/frame/remote_frame.mojom";
import "third_party/blink/public/mojom/frame/view_transition_state.mojom";
import "third_party/blink/public/mojom/navigation/was_activated_option.mojom";
import "third_party/blink/public/mojom/page/browsing_context_group_info.mojom";
import "third_party/blink/public/mojom/page/page_visibility_state.mojom";
import "third_party/blink/public/mojom/tokens/tokens.mojom";
import "third_party/blink/public/mojom/webpreferences/web_preferences.mojom";
import "third_party/blink/public/mojom/renderer_preferences.mojom";
import "ui/color/color_id.mojom";

enum PagehideDispatch {
  // We haven't dispatched pagehide and should do so when appropriate.
  kNotDispatched,
  // We've dispatched pagehide with persisted == false.
  kDispatchedNotPersisted,
  // We've dispatched pagehide with persisted == true.
  kDispatchedPersisted
};

// We need this structure to be able to atomically update the state of the page
// to avoid it being in an inconsistent state (e.g. frozen but visible).
// TODO(yuzus): Replace
// third_party/blink/renderer/platform/scheduler/public/page_lifecycle_state.h
// with this struct.
struct PageLifecycleState {
  bool is_frozen;
  PageVisibilityState visibility;
  bool is_in_back_forward_cache;
  PagehideDispatch pagehide_dispatch;
  // Tells the renderer whether it is allowed to evict the page from the
  // back-forward cache. This is set to false shortly before the page is
  // taken out of the cache to make sure that evict requests from the renderer
  // do not race with the restoration flow on the browser. For example, if set
  // to false the renderer must not evict the page if javascript is executed.
  bool eviction_enabled;
};

// Additional parameters to send with SetPageLifecycleState calls when we're
// restoring a page from the back-forward cache.
struct PageRestoreParams {
  // Timestamp of the start of the navigation restoring this entry from the
  // back-forward cache.
  mojo_base.mojom.TimeTicks navigation_start;

  // The offset in the session history list for the page to be restored.
  int32 pending_history_list_offset;

  // Total size of the session history list.
  int32 current_history_list_length;

  // Holds texture references (stored in the GPU process) and geometry state for
  // the previous Document displayed by this frame. This is used to support
  // transitions when navigating between same-origin Documents.
  // See https://drafts.csswg.org/css-view-transitions-1/ for details.
  // This is analogous to CommitNavigationParams field but for the BF cache.
  blink.mojom.ViewTransitionState? view_transition_state;
};

// Contains the information necessary to construct the light, dark, forced ColorProviders.
struct ColorProviderColorMaps {
  map<color.mojom.RendererColorId, skia.mojom.SkColor> light_colors_map;
  map<color.mojom.RendererColorId, skia.mojom.SkColor> dark_colors_map;
  map<color.mojom.RendererColorId, skia.mojom.SkColor> forced_colors_map;
};

// Parameters to send with ActivatePrerenderedPage calls when we're activating a
// prerendered page.
struct PrerenderPageActivationParams {
  // Tells the renderer whether this prerender activation comes with a sticky
  // user activation.
  blink.mojom.WasActivatedOption was_user_activated;

  // Timestamp of the start of the activation navigation for use in
  // PerformanceNavigationTiming. It is 0 if this blink::WebViewImpl does not
  // host the main frame, to avoid sending the data cross-origin.
  mojo_base.mojom.TimeTicks activation_start;

  // Holds texture references (stored in the GPU process) and geometry state for
  // the previous Document displayed by this frame. This is used to support
  // transitions when navigating between same-origin Documents.
  // See https://drafts.csswg.org/css-view-transitions-1/ for details.
  // This is analogous to CommitNavigationParams field but for prerender
  // activations.
  blink.mojom.ViewTransitionState? view_transition_state;
};

// Used for broadcast messages from browser to renderer for messages that need
// to go to all blink::WebViewImpls for a given content::WebContents. There may
// be multiple blink::WebViewImpls when there are out-of-process iframes.
interface PageBroadcast {
  // Notifies the renderer about a change in the lifecycle state of the page.
  SetPageLifecycleState(
      PageLifecycleState state,
      PageRestoreParams? page_restore_params) => ();

  // Notifies the renderer when audio is started or stopped.
  AudioStateChanged(bool is_audio_playing);

  // Notifies the renderer when a prerendered page is activated. The renderer
  // is expected to update `document.prerendering` and dispatch the
  // prerenderingchange event on relevant documents.
  //
  // The renderer calls the callback once all documents in the
  // blink::WebViewImpl finished activating.
  //
  // TODO(falken): Move this to SetPageLifecycleState.
  ActivatePrerenderedPage(
      PrerenderPageActivationParams prerender_page_activation_params) => ();

  // Notifies the renderer when updating a set of blink preferences.
  UpdateWebPreferences(blink.mojom.WebPreferences preferences);

  // Updates renderer preferences.
  UpdateRendererPreferences(blink.mojom.RendererPreferences preferences);

  // Set history offset and length.
  SetHistoryOffsetAndLength(int32 offset, int32 length);

  // Sent to whole page, but should only be used by the main frame.
  SetPageBaseBackgroundColor(skia.mojom.SkColor? color);

  // Tells the renderer to create a new RemoteFrame main frame. See
  // blink.mojom.RemoteFrame.CreateRemoteChild for creating child frames
  // of RemoteFrames.
  //
  // `token`: The frame token. Used to map between RemoteFrame and
  //    RenderFrameProxyHost.
  // `opener_frame_token`: Frame token that identifies the opener frame if one
  //    exists, or std::nullopt otherwise.
  // `is_loading`: Whether to call DidStartLoading() on the new main frame.
  // `devtools_frame_token`: Used for devtools instrumentation and
  //    trace-ability. The token is shared across all frames (local or remotes)
  //    representing the same logical frame tree node, and is used by Blink and
  //    content to tag calls and requests for instrumentation purposes,
  //    allowing them to be attributed to a context frame.
  //
  //    Must not be used to look up a RenderFrameHostImpl or
  //    RenderFrameProxyHost in the browser process, as the token is shared,
  //    making the mapping ambiguous and non-authoritative.
  CreateRemoteMainFrame(
    RemoteFrameToken token,
    FrameToken? opener_frame_token,
    FrameReplicationState replication_state,
    bool is_loading,
    mojo_base.mojom.UnguessableToken devtools_frame_token,
    RemoteFrameInterfacesFromBrowser remote_frame_interfaces,
    RemoteMainFrameInterfaces remote_main_frame_interfaces);

  // Update the page's browsing context group, with the information contained
  // in `browsing_context_group_info`.
  UpdatePageBrowsingContextGroup(
    blink.mojom.BrowsingContextGroupInfo browsing_context_group_info);

  // Allows the browser to inform the renderer about a change in attribution
  // support, e.g. when the OS indicates that the OS Attribution API is
  // supported/unsupported or when attribution is enabled/disabled for
  // Android WebView.
  SetPageAttributionSupport(network.mojom.AttributionSupport support);

  // Sends an update for the ColorProviders to be used for the given page.
  // The update is sent when either occurs:
  // 1. A blink::WebView is created.
  // 2. The ColorProvider associated with the WebContents changes as a result
  // of theme changes.
  UpdateColorProviders(ColorProviderColorMaps color_provider_colors);
};