ImageReplacement: Introduce blink mojom interfaces for image replacement. [chromium/src : main]

0 views
Skip to first unread message

Adithya Srinivasan (Gerrit)

unread,
Mar 4, 2026, 11:02:59 AM (3 days ago) Mar 4
to Jeremy Roman, Chromium LUCI CQ, AyeAye, blink-re...@chromium.org, kinuko...@chromium.org, blink-rev...@chromium.org, blink-...@chromium.org
Attention needed from Adithya Srinivasan and Jeremy Roman

Adithya Srinivasan voted and added 1 comment

Votes added by Adithya Srinivasan

Commit-Queue+1

1 comment

Patchset-level comments
File-level comment, Patchset 8 (Latest):
Adithya Srinivasan . resolved

+jbroman if you have any early thoughts

I want to flesh out the follow up (browser-side) before added a mojo reviewer, because I think they'll ask to see how the frame token is being used.

Open in Gerrit

Related details

Attention is currently required from:
  • Adithya Srinivasan
  • Jeremy Roman
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I998a19fc0afeeaa6cb4e9d9f779a76133288fc13
Gerrit-Change-Number: 7621609
Gerrit-PatchSet: 8
Gerrit-Owner: Adithya Srinivasan <adit...@chromium.org>
Gerrit-Reviewer: Adithya Srinivasan <adit...@chromium.org>
Gerrit-Reviewer: Jeremy Roman <jbr...@chromium.org>
Gerrit-Attention: Jeremy Roman <jbr...@chromium.org>
Gerrit-Attention: Adithya Srinivasan <adit...@chromium.org>
Gerrit-Comment-Date: Wed, 04 Mar 2026 16:02:54 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Jeremy Roman (Gerrit)

unread,
Mar 4, 2026, 4:10:42 PM (2 days ago) Mar 4
to Adithya Srinivasan, Jeremy Roman, Chromium LUCI CQ, AyeAye, blink-re...@chromium.org, kinuko...@chromium.org, blink-rev...@chromium.org, blink-...@chromium.org
Attention needed from Adithya Srinivasan

Jeremy Roman added 3 comments

Patchset-level comments
Jeremy Roman . resolved

mostly makes sense, just trying to keep us out of the way of core/ development as much as possible

File third_party/blink/public/mojom/image_replacement/image_replacement.mojom
Line 12, Patchset 8 (Latest):interface ImageReplacement {
Jeremy Roman . unresolved

Maybe suggest explicitly that features using image replacement will need to send the browser a pending_remote<ImageReplacement> from the renderer process.

File third_party/blink/renderer/core/html/html_image_element.h
Line 301, Patchset 8 (Latest):
HeapMojoReceiver<mojom::blink::ImageReplacement, HTMLImageElement>
image_replacement_receiver_;
HeapMojoRemote<mojom::blink::ImageReplacementHost> image_replacement_host_;
Jeremy Roman . unresolved

I'm a bit worried about paying this size for every HTMLImageElement. Both for size and clearer code separation, mind seeing if we can split this into a separate class (ImageReplacement or something like that) and look it up in a (per-doc?) HTMLImageElement->ImageReplacement map?

Some things will need to remain here of course, but hoping we can keep the <img> element itself from gaining too much of the complexity directly.

Open in Gerrit

Related details

Attention is currently required from:
  • Adithya Srinivasan
Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: I998a19fc0afeeaa6cb4e9d9f779a76133288fc13
    Gerrit-Change-Number: 7621609
    Gerrit-PatchSet: 8
    Gerrit-Owner: Adithya Srinivasan <adit...@chromium.org>
    Gerrit-Reviewer: Adithya Srinivasan <adit...@chromium.org>
    Gerrit-Reviewer: Jeremy Roman <jbr...@chromium.org>
    Gerrit-Attention: Adithya Srinivasan <adit...@chromium.org>
    Gerrit-Comment-Date: Wed, 04 Mar 2026 21:10:32 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Adithya Srinivasan (Gerrit)

    unread,
    Mar 6, 2026, 10:29:13 AM (16 hours ago) Mar 6
    to Jeremy Roman, Chromium LUCI CQ, AyeAye, blink-re...@chromium.org, kinuko...@chromium.org, blink-rev...@chromium.org, blink-...@chromium.org
    Attention needed from Jeremy Roman

    Adithya Srinivasan added 2 comments

    File third_party/blink/public/mojom/image_replacement/image_replacement.mojom
    Line 12, Patchset 8:interface ImageReplacement {
    Jeremy Roman . resolved

    Maybe suggest explicitly that features using image replacement will need to send the browser a pending_remote<ImageReplacement> from the renderer process.

    Adithya Srinivasan

    Done

    File third_party/blink/renderer/core/html/html_image_element.h

    HeapMojoReceiver<mojom::blink::ImageReplacement, HTMLImageElement>
    image_replacement_receiver_;
    HeapMojoRemote<mojom::blink::ImageReplacementHost> image_replacement_host_;
    Jeremy Roman . resolved

    I'm a bit worried about paying this size for every HTMLImageElement. Both for size and clearer code separation, mind seeing if we can split this into a separate class (ImageReplacement or something like that) and look it up in a (per-doc?) HTMLImageElement->ImageReplacement map?

    Some things will need to remain here of course, but hoping we can keep the <img> element itself from gaining too much of the complexity directly.

    Adithya Srinivasan

    Done.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Jeremy Roman
    Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement is not satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: I998a19fc0afeeaa6cb4e9d9f779a76133288fc13
      Gerrit-Change-Number: 7621609
      Gerrit-PatchSet: 11
      Gerrit-Owner: Adithya Srinivasan <adit...@chromium.org>
      Gerrit-Reviewer: Adithya Srinivasan <adit...@chromium.org>
      Gerrit-Reviewer: Jeremy Roman <jbr...@chromium.org>
      Gerrit-Attention: Jeremy Roman <jbr...@chromium.org>
      Gerrit-Comment-Date: Fri, 06 Mar 2026 15:29:07 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Jeremy Roman <jbr...@chromium.org>
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Jeremy Roman (Gerrit)

      unread,
      Mar 6, 2026, 11:31:12 AM (15 hours ago) Mar 6
      to Adithya Srinivasan, Jeremy Roman, Chromium LUCI CQ, AyeAye, blink-re...@chromium.org, kinuko...@chromium.org, blink-rev...@chromium.org, blink-...@chromium.org
      Attention needed from Adithya Srinivasan

      Jeremy Roman voted and added 10 comments

      Votes added by Jeremy Roman

      Code-Review+1

      10 comments

      Patchset-level comments
      File-level comment, Patchset 12 (Latest):
      Jeremy Roman . resolved

      lgtm overall

      File third_party/blink/renderer/core/html/html_image_element.h
      Line 40, Patchset 11:#include "third_party/blink/renderer/platform/mojo/heap_mojo_receiver.h"
      #include "third_party/blink/renderer/platform/mojo/heap_mojo_remote.h"
      Jeremy Roman . unresolved

      unused

      Line 29, Patchset 11:#include "third_party/blink/public/mojom/image_replacement/image_replacement.mojom-blink.h"
      Jeremy Roman . unresolved

      I think mojom-blink-forward will suffice here and avoid bringing too much more stuff in for other translation units of this header. If you take my other suggestion and move CreateImageReplacement elsewhere, it will be entirely unnecessary in this file.

      File third_party/blink/renderer/core/html/html_image_element.cc
      Line 1151, Patchset 11: if (!base::FeatureList::IsEnabled(features::kImageReplacement)) {
      return base::unexpected("ImageReplacement feature is not enabled.");
      }

      if (!isConnected()) {
      return base::unexpected("HTMLImageElement is not connected to a document.");
      }

      DocumentImageReplacements* replacements =
      DocumentImageReplacements::GetOrCreateFrom(GetDocument());
      if (replacements->GetImageReplacement(this)) {
      return base::unexpected(
      "HTMLImageElement already has a pending/active replacement.");
      }

      if (complete()) {
      ImageResourceContent* image_content = CachedImage();
      if (!image_content) {
      return base::unexpected("HTMLImageElement has no src");
      }
      if (image_content->ErrorOccurred()) {
      return base::unexpected("HTMLImageElement had a loading error");
      }
      }
      if (!IsPrimaryContent()) {
      return base::unexpected(
      "HTMLImageElement is not displaying primary content.");
      }

      ImageReplacement* replacement = MakeGarbageCollected<ImageReplacement>(*this);
      replacements->RegisterImageReplacement(this, replacement);
      return replacement->BindReceiver();
      Jeremy Roman . unresolved

      nit: Not a huge deal as this is much smaller now, but maybe this could even be flipped to be something like `static base::expected<...> ImageReplacement::CreateAndBindReceiver(HTMLImageElement*)` and keep even less of it here?

      File third_party/blink/renderer/core/html/html_image_element_test.cc
      Line 10, Patchset 11:#include "mojo/public/cpp/bindings/pending_receiver.h"
      #include "mojo/public/cpp/bindings/pending_remote.h"
      #include "mojo/public/cpp/bindings/receiver.h"
      #include "mojo/public/cpp/bindings/remote.h"
      Jeremy Roman . unresolved

      almost surely this file can be reverted and needs no new includes, if you haven't made any other changes to it?

      File third_party/blink/renderer/core/image_replacement/build.gni
      Line 1, Patchset 11:# Copyright 2025 The Chromium Authors
      Jeremy Roman . unresolved

      nit: it's 2026

      File third_party/blink/renderer/core/image_replacement/document_image_replacements.h
      Line 20, Patchset 11: static DocumentImageReplacements* From(Document&);
      static DocumentImageReplacements* GetOrCreateFrom(Document&);
      Jeremy Roman . unresolved

      nits: I slightly prefer From/FromIfExists, but I don't feel strongly. Also, the version that always works should probably return a reference (&) nowadays.

      File-level comment, Patchset 11:
      Jeremy Roman . unresolved

      copyright boilerplate, here and .cc

      File third_party/blink/renderer/core/image_replacement/document_image_replacements.cc
      Line 41, Patchset 11: auto it = replacements_.find(element);
      if (it != replacements_.end()) {
      ImageReplacement* replacement = it->value.Get();
      replacements_.erase(it);
      return replacement;
      }
      return nullptr;
      Jeremy Roman . unresolved

      nit: I think this is equivalent to `return replacements_.Take(element);`? Not a huge deal either way.

      File third_party/blink/renderer/core/image_replacement/image_replacement.cc
      Line 13, Patchset 11:#include "third_party/blink/renderer/core/image_replacement/document_image_replacements.h"
      Jeremy Roman . unresolved

      unused right now (might change as a result of other comments)

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Adithya Srinivasan
      Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement satisfiedCode-Owners
      • requirement satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: I998a19fc0afeeaa6cb4e9d9f779a76133288fc13
      Gerrit-Change-Number: 7621609
      Gerrit-PatchSet: 12
      Gerrit-Owner: Adithya Srinivasan <adit...@chromium.org>
      Gerrit-Reviewer: Adithya Srinivasan <adit...@chromium.org>
      Gerrit-Reviewer: Jeremy Roman <jbr...@chromium.org>
      Gerrit-Attention: Adithya Srinivasan <adit...@chromium.org>
      Gerrit-Comment-Date: Fri, 06 Mar 2026 16:31:02 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Jeremy Roman (Gerrit)

      unread,
      Mar 6, 2026, 11:32:05 AM (15 hours ago) Mar 6
      to Adithya Srinivasan, Jeremy Roman, Chromium LUCI CQ, AyeAye, blink-re...@chromium.org, kinuko...@chromium.org, blink-rev...@chromium.org, blink-...@chromium.org
      Attention needed from Adithya Srinivasan

      Jeremy Roman voted and added 1 comment

      Votes added by Jeremy Roman

      Code-Review+0

      1 comment

      Patchset-level comments
      Jeremy Roman . resolved

      (Obviously you still need an ipc/SECURITY_OWNERS at a minimum. A rendering/layout person wouldn't hurt either.)

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Adithya Srinivasan
      Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement is not satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: I998a19fc0afeeaa6cb4e9d9f779a76133288fc13
      Gerrit-Change-Number: 7621609
      Gerrit-PatchSet: 12
      Gerrit-Owner: Adithya Srinivasan <adit...@chromium.org>
      Gerrit-Reviewer: Adithya Srinivasan <adit...@chromium.org>
      Gerrit-Reviewer: Jeremy Roman <jbr...@chromium.org>
      Gerrit-Attention: Adithya Srinivasan <adit...@chromium.org>
      Gerrit-Comment-Date: Fri, 06 Mar 2026 16:31:56 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Jeremy Roman (Gerrit)

      unread,
      Mar 6, 2026, 11:32:38 AM (15 hours ago) Mar 6
      to Adithya Srinivasan, Jeremy Roman, Chromium LUCI CQ, AyeAye, blink-re...@chromium.org, kinuko...@chromium.org, blink-rev...@chromium.org, blink-...@chromium.org
      Attention needed from Adithya Srinivasan

      Jeremy Roman added 1 comment

      Commit Message
      Line 7, Patchset 12 (Latest):ImageReplacement: Introduce blink mojom interfaces for image replacement.
      Jeremy Roman . unresolved

      Oh, and this headline is a bit misleading as while it does introduce the mojo interfaces, it does a few other things, too, and the first line should summarize the overall effect

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Adithya Srinivasan
      Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement is not satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: I998a19fc0afeeaa6cb4e9d9f779a76133288fc13
      Gerrit-Change-Number: 7621609
      Gerrit-PatchSet: 12
      Gerrit-Owner: Adithya Srinivasan <adit...@chromium.org>
      Gerrit-Reviewer: Adithya Srinivasan <adit...@chromium.org>
      Gerrit-Reviewer: Jeremy Roman <jbr...@chromium.org>
      Gerrit-Attention: Adithya Srinivasan <adit...@chromium.org>
      Gerrit-Comment-Date: Fri, 06 Mar 2026 16:32:28 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Jeremy Roman (Gerrit)

      unread,
      Mar 6, 2026, 11:33:01 AM (15 hours ago) Mar 6
      to Adithya Srinivasan, Jeremy Roman, Chromium LUCI CQ, AyeAye, blink-re...@chromium.org, kinuko...@chromium.org, blink-rev...@chromium.org, blink-...@chromium.org
      Attention needed from Adithya Srinivasan

      Jeremy Roman voted and added 1 comment

      Votes added by Jeremy Roman

      Code-Review+1

      1 comment

      Patchset-level comments
      Jeremy Roman . resolved

      and yet it removed by CR vote, whoops

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Adithya Srinivasan
      Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement satisfiedCode-Owners
      • requirement satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: I998a19fc0afeeaa6cb4e9d9f779a76133288fc13
      Gerrit-Change-Number: 7621609
      Gerrit-PatchSet: 12
      Gerrit-Owner: Adithya Srinivasan <adit...@chromium.org>
      Gerrit-Reviewer: Adithya Srinivasan <adit...@chromium.org>
      Gerrit-Reviewer: Jeremy Roman <jbr...@chromium.org>
      Gerrit-Attention: Adithya Srinivasan <adit...@chromium.org>
      Gerrit-Comment-Date: Fri, 06 Mar 2026 16:32:50 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy
      Reply all
      Reply to author
      Forward
      0 new messages