chromium/extensions/common/mojom/renderer.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 extensions.mojom;

import "extensions/common/mojom/api_permission_id.mojom";
import "extensions/common/mojom/channel.mojom";
import "extensions/common/mojom/feature_session_type.mojom";
import "extensions/common/mojom/host_id.mojom";
import "extensions/common/mojom/manifest.mojom";
import "extensions/common/mojom/permission_set.mojom";
import "extensions/common/mojom/url_pattern_set.mojom";
import "mojo/public/mojom/base/file_path.mojom";
import "mojo/public/mojom/base/shared_memory.mojom";
import "mojo/public/mojom/base/unguessable_token.mojom";
import "mojo/public/mojom/base/values.mojom";

// Mojo struct to be used as argument on the LoadExtension method.
struct ExtensionLoadedParams {
  // The subset of the extension manifest data we send to renderers.
  mojo_base.mojom.DictionaryValue manifest;

  // The location the extension was installed from. This is used in the renderer
  // only to generate the extension ID for extensions that are loaded unpacked.
  ManifestLocation location;

  // The path the extension was loaded from.
  mojo_base.mojom.FilePath path;

  // The extension's active and withheld permissions.
  PermissionSet active_permissions;
  PermissionSet withheld_permissions;
  map<int32, PermissionSet> tab_specific_permissions;

  // Contains URLPatternSets defining which URLs an extension may not interact
  // with by policy.
  URLPatternSet policy_blocked_hosts;
  URLPatternSet policy_allowed_hosts;

  // If the extension uses the default list of blocked / allowed URLs.
  bool uses_default_policy_blocked_allowed_hosts;

  // We keep this separate so that it can be used in logging and testing.
  string id;

  // If this extension is Service Worker based, then this contains the
  // activation token of the extension
  mojo_base.mojom.UnguessableToken? worker_activation_token;

  // Send creation flags so that extension is initialized identically.
  int32 creation_flags;

  // Reuse the extension guid when creating the extension in the renderer.
  string guid;
};

// Settings for a given user script world.
struct UserScriptWorldInfo {
  // The corresponding extension ID.
  string extension_id;

  // The ID of the world to configure. If omitted, configures the default
  // user script world.
  string? world_id;

  // A custom CSP for the user script world, if any.
  string? csp;

  // Whether to enable messaging APIs in the isolated world.
  bool enable_messaging;
};

// This should be used for implementing browser-to-renderer control messages
// which need to retain FIFO with respect to other mojo interfaces like
// content.mojom.Renderer.
interface Renderer {
  // Marks an extension as 'active' in an extension process. 'Active' extensions
  // have more privileges than other extension content that might end up running
  // in the process (e.g. because of iframes or content scripts).
  ActivateExtension(string extension_id);

  // Tells the renderer whether or not activity logging is enabled. This is only
  // sent if logging is or was previously enabled; not being enabled is assumed
  // otherwise.
  SetActivityLoggingEnabled(bool enabled);

  // Notifies the renderer that extensions were loaded in the browser.
  LoadExtensions(array<ExtensionLoadedParams> params);

  // Notifies the renderer that an extension was unloaded in the browser.
  UnloadExtension(string extension_id);

  // Tells the page to dispatch the suspend event. If we complete a round of
  // ShouldSuspend Mojo method and the reply without the lazy background page
  // becoming active again, we are ready to unload.
  SuspendExtension(string extension_id) => ();

  // Cancels suspending the extension.
  CancelSuspendExtension(string extension_id);

  // Informs the renderer whether or not the developer mode is enabled.
  SetDeveloperMode(bool developer_mode_only);

  // Informs the renderer what channel (dev, beta, stable, etc) and user session
  // type is running. |is_lock_screen_context| represents whether the browser
  // context is associated with Chrome OS lock screen.
  SetSessionInfo(Channel channel,
                 FeatureSessionType session,
                 bool is_lock_screen_context);

  // Tells the renderer process the platform's system font.
  SetSystemFont(string font_family, string font_size);

  // Reports the WebView partition ID to the WebView guest renderer process.
  SetWebViewPartitionID(string partition_id);

  // Updates the scripting allowlist for extensions in the render process. This
  // is only used for testing.
  SetScriptingAllowlist(array<string> extension_ids);

  // Updates the user script worlds accordiging to `infos`.
  UpdateUserScriptWorlds(array<UserScriptWorldInfo> infos);

  // Clears configurations associated with the given `extension_id` and
  // `world_id`.
  ClearUserScriptWorldConfig(string extension_id,
                             string? world_id);

  // Asks the lazy background page if it is ready to be suspended and replies
  // back to the browser. This is sent when the page is considered idle.
  ShouldSuspend() => ();

  // Sent by the browser to indicate a Blob handle has been transferred to the
  // renderer. The reply is sent back to the browser when it has received the
  // Blob handle.
  // This is sent after the actual extension response, and depends on the
  // sequential nature of IPCs so that the blob has already been caught.
  TransferBlobs() => ();

  // Tells the renderer to update an extension's permission set.
  UpdatePermissions(string extension_id,
                    PermissionSet active_permissions,
                    PermissionSet withheld_permissions,
                    URLPatternSet policy_blocked_hosts,
                    URLPatternSet policy_allowed_hosts,
                    bool uses_default_policy_host_restrictions);

  // Tells the renderer to update an extension's policy_blocked_hosts set.
  UpdateDefaultPolicyHostRestrictions(
        URLPatternSet default_policy_blocked_hosts,
        URLPatternSet default_policy_allowed_hosts);

  // Tells the renderer to update the collection of user-restricted hosts.
  UpdateUserHostRestrictions(
        URLPatternSet user_blocked_hosts,
        URLPatternSet user_allowed_hosts);

  // Tells the render view about new tab-specific permissions for an extension.
  UpdateTabSpecificPermissions(string extension_id,
                               URLPatternSet new_hosts,
                               int32 tab_id,
                               bool update_origin_allowlist);

  // Notifies the renderer that the user scripts have been updated. It has one
  // ReadOnlySharedMemoryRegion argument consisting of the pickled script data.
  // This memory region is valid in the context of the renderer.
  // |owner| must not be empty, and all scripts from |owner| will be updated.
  UpdateUserScripts(mojo_base.mojom.ReadOnlySharedMemoryRegion region,
                    HostID owner);

  // Tells the render view to clear tab-specific permissions for some
  // extensions.
  ClearTabSpecificPermissions(array<string> extension_ids,
                              int32 tab_id,
                              bool update_origin_allowlist);

  // Notifies the renderer that an extension wants notifications when certain
  // searches match the active page. This method replaces the old set of
  // searches, and triggers extensions::mojom::LocalFrameHost::WatchedPageChange
  // from each tab to keep the browser updated about changes.
  WatchPages(array<string> css_selectors);
};