Make input work for nested SurfaceEmbed [chromium/src : main]

0 views
Skip to first unread message

Liang Zhao (Gerrit)

unread,
Jul 22, 2026, 5:29:25 PM (2 days ago) Jul 22
to android-bu...@system.gserviceaccount.com, Surface Embed Reviews, Dave Risney, Chromium LUCI CQ, chromium...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, performance-m...@chromium.org, alexmo...@chromium.org, creis...@chromium.org, navigation...@chromium.org
Attention needed from Dave Risney and Liang Zhao

Message from Liang Zhao

Set Ready For Review

Open in Gerrit

Related details

Attention is currently required from:
  • Dave Risney
  • Liang Zhao
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: I27ba9dd619ddc6b681902154427e1cbb4bb2613e
Gerrit-Change-Number: 8102721
Gerrit-PatchSet: 10
Gerrit-Owner: Liang Zhao <lz...@microsoft.com>
Gerrit-Reviewer: Dave Risney <david....@microsoft.com>
Gerrit-Reviewer: Liang Zhao <lz...@microsoft.com>
Gerrit-CC: Surface Embed Reviews <surface-em...@google.com>
Gerrit-CC: gwsq
Gerrit-Attention: Dave Risney <david....@microsoft.com>
Gerrit-Attention: Liang Zhao <lz...@microsoft.com>
Gerrit-Comment-Date: Wed, 22 Jul 2026 21:29:11 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Liang Zhao (Gerrit)

unread,
Jul 22, 2026, 5:30:58 PM (2 days ago) Jul 22
to Keren Zhu, android-bu...@system.gserviceaccount.com, Surface Embed Reviews, Dave Risney, Chromium LUCI CQ, chromium...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, performance-m...@chromium.org, alexmo...@chromium.org, creis...@chromium.org, navigation...@chromium.org
Attention needed from Dave Risney and Keren Zhu

Liang Zhao added 4 comments

Patchset-level comments
File-level comment, Patchset 10 (Latest):
Liang Zhao . resolved

@kere...@chromium.org, could you also take a look at this change before I add owners for review?

File content/browser/surface_embed/surface_embed_connector_impl_browsertest.cc
Line 93, Patchset 1: struct MultiLevelTestContext {
Dave Risney . resolved

nit: In the other test file you used different casing 'Multilevel' vs 'MultiLevel' here.

Liang Zhao

Done

File content/browser/web_contents/web_contents_impl.cc
Line 1442, Patchset 1: SurfaceEmbedConnector::Detach(child);
Dave Risney . resolved

Nit: This relies on Detach calling back synchronously to have itself removed from the collection or else we end up in infinite loop. Its harder to read than more explicit code that always removes the back entry and then calls Detach if the weak ptr resolves and then the erase_if callback becomes a no-op.

Liang Zhao

swapped to a local vector before performing detaching.

Line 3746, Patchset 1: for (const auto& child_weak : surface_embed_children_) {
Dave Risney . resolved

Since we're calling into other methods during iteration - any concern that we may modify the collection we're iterating over during iteration? (same for the unregister loop below)

Liang Zhao

Should be no concern. Added comments.

Open in Gerrit

Related details

Attention is currently required from:
  • Dave Risney
  • Keren Zhu
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: I27ba9dd619ddc6b681902154427e1cbb4bb2613e
    Gerrit-Change-Number: 8102721
    Gerrit-PatchSet: 10
    Gerrit-Owner: Liang Zhao <lz...@microsoft.com>
    Gerrit-Reviewer: Dave Risney <david....@microsoft.com>
    Gerrit-Reviewer: Keren Zhu <kere...@chromium.org>
    Gerrit-Reviewer: Liang Zhao <lz...@microsoft.com>
    Gerrit-CC: Surface Embed Reviews <surface-em...@google.com>
    Gerrit-CC: gwsq
    Gerrit-Attention: Dave Risney <david....@microsoft.com>
    Gerrit-Attention: Keren Zhu <kere...@chromium.org>
    Gerrit-Comment-Date: Wed, 22 Jul 2026 21:30:44 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Dave Risney <david....@microsoft.com>
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Keren Zhu (Gerrit)

    unread,
    Jul 23, 2026, 3:31:39 PM (2 days ago) Jul 23
    to Liang Zhao, android-bu...@system.gserviceaccount.com, Surface Embed Reviews, Dave Risney, Chromium LUCI CQ, chromium...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, performance-m...@chromium.org, alexmo...@chromium.org, creis...@chromium.org, navigation...@chromium.org
    Attention needed from Dave Risney and Liang Zhao

    Keren Zhu added 1 comment

    File third_party/blink/renderer/core/exported/web_element.cc
    Line 223, Patchset 10 (Latest): if (frame && frame->GetPage()) {
    frame->GetPage()->GetFocusController().FocusDocumentView(
    frame, /*notify_embedder=*/false);
    }
    Keren Zhu . unresolved

    Is this code to give page focus to the parent page when `RequestFocus()` is called?

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Dave Risney
    • Liang Zhao
    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: I27ba9dd619ddc6b681902154427e1cbb4bb2613e
      Gerrit-Change-Number: 8102721
      Gerrit-PatchSet: 10
      Gerrit-Owner: Liang Zhao <lz...@microsoft.com>
      Gerrit-Reviewer: Dave Risney <david....@microsoft.com>
      Gerrit-Reviewer: Keren Zhu <kere...@chromium.org>
      Gerrit-Reviewer: Liang Zhao <lz...@microsoft.com>
      Gerrit-CC: Surface Embed Reviews <surface-em...@google.com>
      Gerrit-CC: gwsq
      Gerrit-Attention: Dave Risney <david....@microsoft.com>
      Gerrit-Attention: Liang Zhao <lz...@microsoft.com>
      Gerrit-Comment-Date: Thu, 23 Jul 2026 19:31:32 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Liang Zhao (Gerrit)

      unread,
      Jul 23, 2026, 3:56:49 PM (2 days ago) Jul 23
      to Keren Zhu, android-bu...@system.gserviceaccount.com, Surface Embed Reviews, Dave Risney, Chromium LUCI CQ, chromium...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, performance-m...@chromium.org, alexmo...@chromium.org, creis...@chromium.org, navigation...@chromium.org
      Attention needed from Dave Risney and Keren Zhu

      Liang Zhao added 1 comment

      File third_party/blink/renderer/core/exported/web_element.cc
      Line 223, Patchset 10 (Latest): if (frame && frame->GetPage()) {
      frame->GetPage()->GetFocusController().FocusDocumentView(
      frame, /*notify_embedder=*/false);
      }
      Keren Zhu . unresolved

      Is this code to give page focus to the parent page when `RequestFocus()` is called?

      Liang Zhao

      This makes the frame focused frame so that when element->Focus() is called, it does not trigger focused frame change event (FocusController::SetFocusedElement() calls FocusController::SetFocusedFrame which will notify browser process if focused frame changed unless notify_embedder is false. This call is to ensure that focused frame change happens with notify_embedder as false. Let me add some comments.

      The page focus update is still done by browser process and more involved.

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Dave Risney
      • Keren Zhu
      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: I27ba9dd619ddc6b681902154427e1cbb4bb2613e
      Gerrit-Change-Number: 8102721
      Gerrit-PatchSet: 10
      Gerrit-Owner: Liang Zhao <lz...@microsoft.com>
      Gerrit-Reviewer: Dave Risney <david....@microsoft.com>
      Gerrit-Reviewer: Keren Zhu <kere...@chromium.org>
      Gerrit-Reviewer: Liang Zhao <lz...@microsoft.com>
      Gerrit-CC: Surface Embed Reviews <surface-em...@google.com>
      Gerrit-CC: gwsq
      Gerrit-Attention: Dave Risney <david....@microsoft.com>
      Gerrit-Attention: Keren Zhu <kere...@chromium.org>
      Gerrit-Comment-Date: Thu, 23 Jul 2026 19:56:18 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Keren Zhu <kere...@chromium.org>
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Dave Risney (Gerrit)

      unread,
      Jul 23, 2026, 4:22:19 PM (2 days ago) Jul 23
      to Liang Zhao, Keren Zhu, android-bu...@system.gserviceaccount.com, Surface Embed Reviews, Chromium LUCI CQ, chromium...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, performance-m...@chromium.org, alexmo...@chromium.org, creis...@chromium.org, navigation...@chromium.org
      Attention needed from Keren Zhu and Liang Zhao

      Dave Risney voted Code-Review+1

      Code-Review+1
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Keren Zhu
      • Liang Zhao
      Submit Requirements:
        • requirement satisfiedCode-Coverage
        • requirement is not satisfiedCode-Owners
        • requirement 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: I27ba9dd619ddc6b681902154427e1cbb4bb2613e
        Gerrit-Change-Number: 8102721
        Gerrit-PatchSet: 10
        Gerrit-Owner: Liang Zhao <lz...@microsoft.com>
        Gerrit-Reviewer: Dave Risney <david....@microsoft.com>
        Gerrit-Reviewer: Keren Zhu <kere...@chromium.org>
        Gerrit-Reviewer: Liang Zhao <lz...@microsoft.com>
        Gerrit-CC: Surface Embed Reviews <surface-em...@google.com>
        Gerrit-CC: gwsq
        Gerrit-Attention: Keren Zhu <kere...@chromium.org>
        Gerrit-Attention: Liang Zhao <lz...@microsoft.com>
        Gerrit-Comment-Date: Thu, 23 Jul 2026 20:21:50 +0000
        Gerrit-HasComments: No
        Gerrit-Has-Labels: Yes
        satisfied_requirement
        unsatisfied_requirement
        open
        diffy

        Keren Zhu (Gerrit)

        unread,
        Jul 23, 2026, 4:32:44 PM (2 days ago) Jul 23
        to Liang Zhao, Dave Risney, android-bu...@system.gserviceaccount.com, Surface Embed Reviews, Chromium LUCI CQ, chromium...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, performance-m...@chromium.org, alexmo...@chromium.org, creis...@chromium.org, navigation...@chromium.org
        Attention needed from Liang Zhao

        Keren Zhu added 1 comment

        File third_party/blink/renderer/core/exported/web_element.cc
        Line 223, Patchset 10 (Latest): if (frame && frame->GetPage()) {
        frame->GetPage()->GetFocusController().FocusDocumentView(
        frame, /*notify_embedder=*/false);
        }
        Keren Zhu . unresolved

        Is this code to give page focus to the parent page when `RequestFocus()` is called?

        Liang Zhao

        This makes the frame focused frame so that when element->Focus() is called, it does not trigger focused frame change event (FocusController::SetFocusedElement() calls FocusController::SetFocusedFrame which will notify browser process if focused frame changed unless notify_embedder is false. This call is to ensure that focused frame change happens with notify_embedder as false. Let me add some comments.

        The page focus update is still done by browser process and more involved.

        Keren Zhu

        `WebElement::FocusFromBrowser` looks a bit scary because it is not very clear how it should differ from `Focus`.

        Looks like `WebElement::Focus()` eventually calls `RenderFrameHostImpl::DidFocusFrame()`. Since this originates from `RequestFocus` in the browser process, can we suppress the handling of `DidFocusFrame` when there is a pending `RequestFocus`?

        Open in Gerrit

        Related details

        Attention is currently required from:
        • Liang Zhao
        Submit Requirements:
        • requirement satisfiedCode-Coverage
        • requirement is not satisfiedCode-Owners
        • requirement 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: I27ba9dd619ddc6b681902154427e1cbb4bb2613e
        Gerrit-Change-Number: 8102721
        Gerrit-PatchSet: 10
        Gerrit-Owner: Liang Zhao <lz...@microsoft.com>
        Gerrit-Reviewer: Dave Risney <david....@microsoft.com>
        Gerrit-Reviewer: Keren Zhu <kere...@chromium.org>
        Gerrit-Reviewer: Liang Zhao <lz...@microsoft.com>
        Gerrit-CC: Surface Embed Reviews <surface-em...@google.com>
        Gerrit-CC: gwsq
        Gerrit-Attention: Liang Zhao <lz...@microsoft.com>
        Gerrit-Comment-Date: Thu, 23 Jul 2026 20:32:34 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        Comment-In-Reply-To: Keren Zhu <kere...@chromium.org>
        Comment-In-Reply-To: Liang Zhao <lz...@microsoft.com>
        satisfied_requirement
        unsatisfied_requirement
        open
        diffy

        Liang Zhao (Gerrit)

        unread,
        Jul 23, 2026, 4:45:29 PM (2 days ago) Jul 23
        to Dave Risney, Keren Zhu, android-bu...@system.gserviceaccount.com, Surface Embed Reviews, Chromium LUCI CQ, chromium...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, performance-m...@chromium.org, alexmo...@chromium.org, creis...@chromium.org, navigation...@chromium.org
        Attention needed from Keren Zhu

        Liang Zhao added 1 comment

        File third_party/blink/renderer/core/exported/web_element.cc
        Line 223, Patchset 10 (Latest): if (frame && frame->GetPage()) {
        frame->GetPage()->GetFocusController().FocusDocumentView(
        frame, /*notify_embedder=*/false);
        }
        Keren Zhu . unresolved

        Is this code to give page focus to the parent page when `RequestFocus()` is called?

        Liang Zhao

        This makes the frame focused frame so that when element->Focus() is called, it does not trigger focused frame change event (FocusController::SetFocusedElement() calls FocusController::SetFocusedFrame which will notify browser process if focused frame changed unless notify_embedder is false. This call is to ensure that focused frame change happens with notify_embedder as false. Let me add some comments.

        The page focus update is still done by browser process and more involved.

        Keren Zhu

        `WebElement::FocusFromBrowser` looks a bit scary because it is not very clear how it should differ from `Focus`.

        Looks like `WebElement::Focus()` eventually calls `RenderFrameHostImpl::DidFocusFrame()`. Since this originates from `RequestFocus` in the browser process, can we suppress the handling of `DidFocusFrame` when there is a pending `RequestFocus`?

        Liang Zhao

        The order of DidFocusFrame and RequestFocus callback happens on un-associated mojo interface and the order could not be guaranteed.

        This is similar to Frame::FocusImpl code used by LocalFrameMojoHandler::Focus() and RemoteFrame::Focus() methods for iframes that handles cross process focused frame changes.

        Not sure whether there is a better option.

        Open in Gerrit

        Related details

        Attention is currently required from:
        • Keren Zhu
        Submit Requirements:
        • requirement satisfiedCode-Coverage
        • requirement is not satisfiedCode-Owners
        • requirement 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: I27ba9dd619ddc6b681902154427e1cbb4bb2613e
        Gerrit-Change-Number: 8102721
        Gerrit-PatchSet: 10
        Gerrit-Owner: Liang Zhao <lz...@microsoft.com>
        Gerrit-Reviewer: Dave Risney <david....@microsoft.com>
        Gerrit-Reviewer: Keren Zhu <kere...@chromium.org>
        Gerrit-Reviewer: Liang Zhao <lz...@microsoft.com>
        Gerrit-CC: Surface Embed Reviews <surface-em...@google.com>
        Gerrit-CC: gwsq
        Gerrit-Attention: Keren Zhu <kere...@chromium.org>
        Gerrit-Comment-Date: Thu, 23 Jul 2026 20:45:15 +0000
        satisfied_requirement
        unsatisfied_requirement
        open
        diffy

        Keren Zhu (Gerrit)

        unread,
        Jul 23, 2026, 5:14:37 PM (2 days ago) Jul 23
        to Liang Zhao, Dave Risney, android-bu...@system.gserviceaccount.com, Surface Embed Reviews, Chromium LUCI CQ, chromium...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, performance-m...@chromium.org, alexmo...@chromium.org, creis...@chromium.org, navigation...@chromium.org
        Attention needed from Liang Zhao

        Keren Zhu added 1 comment

        File third_party/blink/renderer/core/exported/web_element.cc
        Line 223, Patchset 10 (Latest): if (frame && frame->GetPage()) {
        frame->GetPage()->GetFocusController().FocusDocumentView(
        frame, /*notify_embedder=*/false);
        }
        Keren Zhu . unresolved

        Is this code to give page focus to the parent page when `RequestFocus()` is called?

        Liang Zhao

        This makes the frame focused frame so that when element->Focus() is called, it does not trigger focused frame change event (FocusController::SetFocusedElement() calls FocusController::SetFocusedFrame which will notify browser process if focused frame changed unless notify_embedder is false. This call is to ensure that focused frame change happens with notify_embedder as false. Let me add some comments.

        The page focus update is still done by browser process and more involved.

        Keren Zhu

        `WebElement::FocusFromBrowser` looks a bit scary because it is not very clear how it should differ from `Focus`.

        Looks like `WebElement::Focus()` eventually calls `RenderFrameHostImpl::DidFocusFrame()`. Since this originates from `RequestFocus` in the browser process, can we suppress the handling of `DidFocusFrame` when there is a pending `RequestFocus`?

        Liang Zhao

        The order of DidFocusFrame and RequestFocus callback happens on un-associated mojo interface and the order could not be guaranteed.

        This is similar to Frame::FocusImpl code used by LocalFrameMojoHandler::Focus() and RemoteFrame::Focus() methods for iframes that handles cross process focused frame changes.

        Not sure whether there is a better option.

        Keren Zhu

        The order of DidFocusFrame and RequestFocus callback happens on un-associated mojo interface and the order could not be guaranteed.

        `DidFocusFrame` is a result of `RequestFocus`. Even if they are on associated mojo interfaces, we must receive `DidFocusFrame` after `RequestFocus`?

        Open in Gerrit

        Related details

        Attention is currently required from:
        • Liang Zhao
        Submit Requirements:
        • requirement satisfiedCode-Coverage
        • requirement is not satisfiedCode-Owners
        • requirement 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: I27ba9dd619ddc6b681902154427e1cbb4bb2613e
        Gerrit-Change-Number: 8102721
        Gerrit-PatchSet: 10
        Gerrit-Owner: Liang Zhao <lz...@microsoft.com>
        Gerrit-Reviewer: Dave Risney <david....@microsoft.com>
        Gerrit-Reviewer: Keren Zhu <kere...@chromium.org>
        Gerrit-Reviewer: Liang Zhao <lz...@microsoft.com>
        Gerrit-CC: Surface Embed Reviews <surface-em...@google.com>
        Gerrit-CC: gwsq
        Gerrit-Attention: Liang Zhao <lz...@microsoft.com>
        Gerrit-Comment-Date: Thu, 23 Jul 2026 21:14:30 +0000
        satisfied_requirement
        unsatisfied_requirement
        open
        diffy

        Liang Zhao (Gerrit)

        unread,
        Jul 23, 2026, 6:12:21 PM (2 days ago) Jul 23
        to Dave Risney, Keren Zhu, android-bu...@system.gserviceaccount.com, Surface Embed Reviews, Chromium LUCI CQ, chromium...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, performance-m...@chromium.org, alexmo...@chromium.org, creis...@chromium.org, navigation...@chromium.org
        Attention needed from Keren Zhu

        Liang Zhao added 1 comment

        File third_party/blink/renderer/core/exported/web_element.cc
        Line 223, Patchset 10 (Latest): if (frame && frame->GetPage()) {
        frame->GetPage()->GetFocusController().FocusDocumentView(
        frame, /*notify_embedder=*/false);
        }
        Keren Zhu . unresolved

        Is this code to give page focus to the parent page when `RequestFocus()` is called?

        Liang Zhao

        This makes the frame focused frame so that when element->Focus() is called, it does not trigger focused frame change event (FocusController::SetFocusedElement() calls FocusController::SetFocusedFrame which will notify browser process if focused frame changed unless notify_embedder is false. This call is to ensure that focused frame change happens with notify_embedder as false. Let me add some comments.

        The page focus update is still done by browser process and more involved.

        Keren Zhu

        `WebElement::FocusFromBrowser` looks a bit scary because it is not very clear how it should differ from `Focus`.

        Looks like `WebElement::Focus()` eventually calls `RenderFrameHostImpl::DidFocusFrame()`. Since this originates from `RequestFocus` in the browser process, can we suppress the handling of `DidFocusFrame` when there is a pending `RequestFocus`?

        Liang Zhao

        The order of DidFocusFrame and RequestFocus callback happens on un-associated mojo interface and the order could not be guaranteed.

        This is similar to Frame::FocusImpl code used by LocalFrameMojoHandler::Focus() and RemoteFrame::Focus() methods for iframes that handles cross process focused frame changes.

        Not sure whether there is a better option.

        Keren Zhu

        The order of DidFocusFrame and RequestFocus callback happens on un-associated mojo interface and the order could not be guaranteed.

        `DidFocusFrame` is a result of `RequestFocus`. Even if they are on associated mojo interfaces, we must receive `DidFocusFrame` after `RequestFocus`?

        Liang Zhao

        Method calls on associated mojo interfaces are guaranteed to be received in the other end in the same order they are called. So, if they are on associated mojo interfaces, we can wait for RequestFocus to complete before we call SetAsFocusedWebContentsIfNecessary() for WebContentsImpl::FocusOwningWebContents(), and then we could have a solution. The DidFocusFrame happens before RequestFocus callback is invoked and therefore it will be received before we do SetAsFocusedWebContentsIfNecessary().

        But we might have a solution without this new FocusFromBrowser(). If we make focused frame to be set in browser process before do RequestFocus(), then we will ignore the DidFocusFrame() when we process it in FrameTree::SetFocusedFrame(). So if we do ReqiestFocus() after SetAsFocusedWebContentsIfNecessary() in WebContentsImpl::FocusOwningWebContents(), it might work. if SetAsFocusedWebContentsIfNecessary() doesn't actually do SetFocusedFrame() in parent document, we can simply call RenderFrameHostImpl::SetFocusedFrame() before we do surface_embed_->RequestFocus().

        Let me try it out.

        Open in Gerrit

        Related details

        Attention is currently required from:
        • Keren Zhu
        Submit Requirements:
        • requirement satisfiedCode-Coverage
        • requirement is not satisfiedCode-Owners
        • requirement 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: I27ba9dd619ddc6b681902154427e1cbb4bb2613e
        Gerrit-Change-Number: 8102721
        Gerrit-PatchSet: 10
        Gerrit-Owner: Liang Zhao <lz...@microsoft.com>
        Gerrit-Reviewer: Dave Risney <david....@microsoft.com>
        Gerrit-Reviewer: Keren Zhu <kere...@chromium.org>
        Gerrit-Reviewer: Liang Zhao <lz...@microsoft.com>
        Gerrit-CC: Surface Embed Reviews <surface-em...@google.com>
        Gerrit-CC: gwsq
        Gerrit-Attention: Keren Zhu <kere...@chromium.org>
        Gerrit-Comment-Date: Thu, 23 Jul 2026 22:12:04 +0000
        satisfied_requirement
        unsatisfied_requirement
        open
        diffy

        Liang Zhao (Gerrit)

        unread,
        Jul 23, 2026, 7:21:05 PM (2 days ago) Jul 23
        to Dave Risney, Keren Zhu, android-bu...@system.gserviceaccount.com, Surface Embed Reviews, Chromium LUCI CQ, chromium...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, performance-m...@chromium.org, alexmo...@chromium.org, creis...@chromium.org, navigation...@chromium.org
        Attention needed from Dave Risney and Keren Zhu

        Liang Zhao added 1 comment

        File third_party/blink/renderer/core/exported/web_element.cc
        Line 223, Patchset 10 (Latest): if (frame && frame->GetPage()) {
        frame->GetPage()->GetFocusController().FocusDocumentView(
        frame, /*notify_embedder=*/false);
        }
        Keren Zhu . unresolved

        Is this code to give page focus to the parent page when `RequestFocus()` is called?

        Liang Zhao

        This makes the frame focused frame so that when element->Focus() is called, it does not trigger focused frame change event (FocusController::SetFocusedElement() calls FocusController::SetFocusedFrame which will notify browser process if focused frame changed unless notify_embedder is false. This call is to ensure that focused frame change happens with notify_embedder as false. Let me add some comments.

        The page focus update is still done by browser process and more involved.

        Keren Zhu

        `WebElement::FocusFromBrowser` looks a bit scary because it is not very clear how it should differ from `Focus`.

        Looks like `WebElement::Focus()` eventually calls `RenderFrameHostImpl::DidFocusFrame()`. Since this originates from `RequestFocus` in the browser process, can we suppress the handling of `DidFocusFrame` when there is a pending `RequestFocus`?

        Liang Zhao

        The order of DidFocusFrame and RequestFocus callback happens on un-associated mojo interface and the order could not be guaranteed.

        This is similar to Frame::FocusImpl code used by LocalFrameMojoHandler::Focus() and RemoteFrame::Focus() methods for iframes that handles cross process focused frame changes.

        Not sure whether there is a better option.

        Keren Zhu

        The order of DidFocusFrame and RequestFocus callback happens on un-associated mojo interface and the order could not be guaranteed.

        `DidFocusFrame` is a result of `RequestFocus`. Even if they are on associated mojo interfaces, we must receive `DidFocusFrame` after `RequestFocus`?

        Liang Zhao

        Method calls on associated mojo interfaces are guaranteed to be received in the other end in the same order they are called. So, if they are on associated mojo interfaces, we can wait for RequestFocus to complete before we call SetAsFocusedWebContentsIfNecessary() for WebContentsImpl::FocusOwningWebContents(), and then we could have a solution. The DidFocusFrame happens before RequestFocus callback is invoked and therefore it will be received before we do SetAsFocusedWebContentsIfNecessary().

        But we might have a solution without this new FocusFromBrowser(). If we make focused frame to be set in browser process before do RequestFocus(), then we will ignore the DidFocusFrame() when we process it in FrameTree::SetFocusedFrame(). So if we do ReqiestFocus() after SetAsFocusedWebContentsIfNecessary() in WebContentsImpl::FocusOwningWebContents(), it might work. if SetAsFocusedWebContentsIfNecessary() doesn't actually do SetFocusedFrame() in parent document, we can simply call RenderFrameHostImpl::SetFocusedFrame() before we do surface_embed_->RequestFocus().

        Let me try it out.

        Liang Zhao

        Trying to make browser side update its focused frame doesn't seem to work.

        There is no check on whether focused frame changed in RenderFrameHostImpl::DidFocusFrame -> FrameTreeNode::SetFocusedFrame -> WebContentsImpl::SetFocusedFrame -> WebContentsImpl::SetFocusedFrameTree code path. Updating these functions seems to have more risk.

        Also, calling  FrameTreeNode::SetFocusedFrame() or WebContentsImpl::SetFocusedFrame() would update focused frame tree which puts us in an incorrect temporarily.

        So, the only way to avoid the FocusFromBrowser() would be to make SurfaceEmbed and Frame mojo interfaces associated. A little more work, but it is possible to make the mojo interfaces associated. If we make them associated, we can simply do auto* node = embedder_rfh_->frame_tree_node() and then node->frame_tree().SetFocusedFrame(node, nullptr) in SurfaceEmbedConnectorImpl::SetFocusedFrameTree, conceptually as part of FocusOuterFrameTrees. Using associated mojo interfaces could potentially make other things more deterministic.

        @kere...@chromium.org, do you think that we should use frame associated interface? If you think that is better, I can create another CL to make the change.

        Open in Gerrit

        Related details

        Attention is currently required from:
        • Dave Risney
        • Keren Zhu
        Submit Requirements:
        • requirement satisfiedCode-Coverage
        • requirement is not satisfiedCode-Owners
        • requirement 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: I27ba9dd619ddc6b681902154427e1cbb4bb2613e
        Gerrit-Change-Number: 8102721
        Gerrit-PatchSet: 10
        Gerrit-Owner: Liang Zhao <lz...@microsoft.com>
        Gerrit-Reviewer: Dave Risney <david....@microsoft.com>
        Gerrit-Reviewer: Keren Zhu <kere...@chromium.org>
        Gerrit-Reviewer: Liang Zhao <lz...@microsoft.com>
        Gerrit-CC: Surface Embed Reviews <surface-em...@google.com>
        Gerrit-CC: gwsq
        Gerrit-Attention: Dave Risney <david....@microsoft.com>
        Gerrit-Attention: Keren Zhu <kere...@chromium.org>
        Gerrit-Comment-Date: Thu, 23 Jul 2026 23:20:39 +0000
        satisfied_requirement
        unsatisfied_requirement
        open
        diffy

        Keren Zhu (Gerrit)

        unread,
        Jul 24, 2026, 2:32:29 AM (yesterday) Jul 24
        to Liang Zhao, Dave Risney, android-bu...@system.gserviceaccount.com, Surface Embed Reviews, Chromium LUCI CQ, chromium...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, performance-m...@chromium.org, alexmo...@chromium.org, creis...@chromium.org, navigation...@chromium.org
        Attention needed from Dave Risney and Liang Zhao

        Keren Zhu added 1 comment

        File third_party/blink/renderer/core/exported/web_element.cc
        Keren Zhu

        I agreed with you that setting focused frame in the browser process to suppress `RenderFrameHostImpl::DidFocusFrame` is too risky and it leaves the browser in a temporary wrong state.

        Yes I think we should use associated interface. This has been a problem since day one which I haven't had time to look into. Now I think it is time, given that messages in surface_embed.mojom start to intertwine with messages on associated interfaces.

        The order of DidFocusFrame and RequestFocus callback happens on un-associated mojo interface and the order could not be guaranteed.

        Looking back at your previous comment, I think I missed "callback" in this comment. I was arguing that the "RequestFocus" call must happen before the "DidFocusFrame" call, but what actually matters is the firing order between "RequestFocus callback" and "DidFocusFrame", which has no guarantee. Sorry I missed that.

        And as always, thanks for looking into this.

        Open in Gerrit

        Related details

        Attention is currently required from:
        • Dave Risney
        • Liang Zhao
        Submit Requirements:
        • requirement satisfiedCode-Coverage
        • requirement is not satisfiedCode-Owners
        • requirement 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: I27ba9dd619ddc6b681902154427e1cbb4bb2613e
        Gerrit-Change-Number: 8102721
        Gerrit-PatchSet: 10
        Gerrit-Owner: Liang Zhao <lz...@microsoft.com>
        Gerrit-Reviewer: Dave Risney <david....@microsoft.com>
        Gerrit-Reviewer: Keren Zhu <kere...@chromium.org>
        Gerrit-Reviewer: Liang Zhao <lz...@microsoft.com>
        Gerrit-CC: Surface Embed Reviews <surface-em...@google.com>
        Gerrit-CC: gwsq
        Gerrit-Attention: Dave Risney <david....@microsoft.com>
        Gerrit-Attention: Liang Zhao <lz...@microsoft.com>
        Gerrit-Comment-Date: Fri, 24 Jul 2026 06:32:19 +0000
        satisfied_requirement
        unsatisfied_requirement
        open
        diffy

        Liang Zhao (Gerrit)

        unread,
        Jul 24, 2026, 2:06:33 PM (14 hours ago) Jul 24
        to Dave Risney, Keren Zhu, android-bu...@system.gserviceaccount.com, Surface Embed Reviews, Chromium LUCI CQ, chromium...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, performance-m...@chromium.org, alexmo...@chromium.org, creis...@chromium.org, navigation...@chromium.org
        Attention needed from Dave Risney and Keren Zhu

        Liang Zhao added 1 comment

        File third_party/blink/renderer/core/exported/web_element.cc
        Liang Zhao

        Created CL that moves to associated interfaces: https://chromium-review.googlesource.com/c/chromium/src/+/8142467. Will move this CL based on that one and see whether focus could work better without this FocusFromBrowser. The plan is to ensure embedder_rfh is the focused frame when we are doing FocusOuterFrameTrees, and move RequestFocus to be after SetAsFocusedWebContentsIfNecessary in FocusOwningWebContents.

        Open in Gerrit

        Related details

        Attention is currently required from:
        • Dave Risney
        • Keren Zhu
        Submit Requirements:
        • requirement satisfiedCode-Coverage
        • requirement is not satisfiedCode-Owners
        • requirement 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: I27ba9dd619ddc6b681902154427e1cbb4bb2613e
        Gerrit-Change-Number: 8102721
        Gerrit-PatchSet: 10
        Gerrit-Owner: Liang Zhao <lz...@microsoft.com>
        Gerrit-Reviewer: Dave Risney <david....@microsoft.com>
        Gerrit-Reviewer: Keren Zhu <kere...@chromium.org>
        Gerrit-Reviewer: Liang Zhao <lz...@microsoft.com>
        Gerrit-CC: Surface Embed Reviews <surface-em...@google.com>
        Gerrit-CC: gwsq
        Gerrit-Attention: Dave Risney <david....@microsoft.com>
        Gerrit-Attention: Keren Zhu <kere...@chromium.org>
        Gerrit-Comment-Date: Fri, 24 Jul 2026 18:06:15 +0000
        satisfied_requirement
        unsatisfied_requirement
        open
        diffy

        Liang Zhao (Gerrit)

        unread,
        Jul 24, 2026, 3:22:15 PM (13 hours ago) Jul 24
        to Dave Risney, Keren Zhu, android-bu...@system.gserviceaccount.com, Surface Embed Reviews, Chromium LUCI CQ, chromium...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, performance-m...@chromium.org, alexmo...@chromium.org, creis...@chromium.org, navigation...@chromium.org
        Attention needed from Dave Risney and Keren Zhu

        Liang Zhao added 1 comment

        File third_party/blink/renderer/core/exported/web_element.cc
        Line 223, Patchset 10: if (frame && frame->GetPage()) {

        frame->GetPage()->GetFocusController().FocusDocumentView(
        frame, /*notify_embedder=*/false);
        }
        Keren Zhu . resolved
        Liang Zhao

        Updated and no longer need this FocusFromBrowser().

        Open in Gerrit

        Related details

        Attention is currently required from:
        • Dave Risney
        • Keren Zhu
        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: I27ba9dd619ddc6b681902154427e1cbb4bb2613e
          Gerrit-Change-Number: 8102721
          Gerrit-PatchSet: 12
          Gerrit-Owner: Liang Zhao <lz...@microsoft.com>
          Gerrit-Reviewer: Dave Risney <david....@microsoft.com>
          Gerrit-Reviewer: Keren Zhu <kere...@chromium.org>
          Gerrit-Reviewer: Liang Zhao <lz...@microsoft.com>
          Gerrit-CC: Surface Embed Reviews <surface-em...@google.com>
          Gerrit-CC: gwsq
          Gerrit-Attention: Dave Risney <david....@microsoft.com>
          Gerrit-Attention: Keren Zhu <kere...@chromium.org>
          Gerrit-Comment-Date: Fri, 24 Jul 2026 19:22:04 +0000
          satisfied_requirement
          unsatisfied_requirement
          open
          diffy

          Liang Zhao (Gerrit)

          unread,
          Jul 24, 2026, 7:22:49 PM (9 hours ago) Jul 24
          to performance-m...@chromium.org, Dave Risney, Keren Zhu, android-bu...@system.gserviceaccount.com, Surface Embed Reviews, Chromium LUCI CQ, chromium...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, alexmo...@chromium.org, creis...@chromium.org, navigation...@chromium.org
          Attention needed from Dave Risney and Keren Zhu

          Liang Zhao removed performance-m...@chromium.org from this change

          Open in Gerrit

          Related details

          Attention is currently required from:
          • Dave Risney
          • Keren Zhu
          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: deleteReviewer
          Gerrit-Project: chromium/src
          Gerrit-Branch: main
          Gerrit-Change-Id: I27ba9dd619ddc6b681902154427e1cbb4bb2613e
          Gerrit-Change-Number: 8102721
          Gerrit-PatchSet: 14
          satisfied_requirement
          unsatisfied_requirement
          open
          diffy

          Liang Zhao (Gerrit)

          unread,
          Jul 24, 2026, 7:23:14 PM (9 hours ago) Jul 24
          to blink-...@chromium.org, Dave Risney, Keren Zhu, android-bu...@system.gserviceaccount.com, Surface Embed Reviews, Chromium LUCI CQ, chromium...@chromium.org, blink-re...@chromium.org, alexmo...@chromium.org, creis...@chromium.org, navigation...@chromium.org
          Attention needed from Dave Risney and Keren Zhu

          Liang Zhao removed blink-...@chromium.org from this change

          Deleted Reviewers:
          satisfied_requirement
          unsatisfied_requirement
          open
          diffy

          Liang Zhao (Gerrit)

          unread,
          Jul 24, 2026, 7:23:26 PM (9 hours ago) Jul 24
          to blink-re...@chromium.org, Dave Risney, Keren Zhu, android-bu...@system.gserviceaccount.com, Surface Embed Reviews, Chromium LUCI CQ, chromium...@chromium.org, alexmo...@chromium.org, creis...@chromium.org, navigation...@chromium.org
          Attention needed from Dave Risney and Keren Zhu

          Liang Zhao removed blink-re...@chromium.org from this change

          Deleted Reviewers:
          satisfied_requirement
          unsatisfied_requirement
          open
          diffy

          Keren Zhu (Gerrit)

          unread,
          1:22 AM (3 hours ago) 1:22 AM
          to Liang Zhao, Dave Risney, android-bu...@system.gserviceaccount.com, Surface Embed Reviews, Chromium LUCI CQ, chromium...@chromium.org, alexmo...@chromium.org, creis...@chromium.org, navigation...@chromium.org
          Attention needed from Dave Risney and Liang Zhao

          Keren Zhu added 7 comments

          Patchset-level comments
          File-level comment, Patchset 15 (Latest):
          Keren Zhu . resolved

          This looks great. I don't understand some parts so leave some questions.

          Commit Message
          Line 32, Patchset 15 (Latest): - SurfaceEmbedHost::OnEmbedElementFocused didn't focus on child
          webcontents when handling Tab traversal and relied on the wrong
          logic in WebContentsImpl::SetFocusedFrame to pass the test. Added
          Keren Zhu . unresolved

          What's the wrong logic? My understanding is that `<embeb>.focus()` -> `SurfaceEmbedHost::OnEmbedElementFocused` -> `child_contents_->FocusThroughTabTraversal`, which will focus the child WebContents?

          Line 37, Patchset 15 (Latest): webcontents for kPageAction event and could potentially set focused
          Keren Zhu . unresolved

          Do you mean `FocusType::kPage`?

          Line 45, Patchset 15 (Latest): element. To fix this, we set focus on the owning frame as part of
          updating outer frame tree focus when setting focused frame tree and
          File components/surface_embed/browser/surface_embed_host.cc
          Line 181, Patchset 15 (Latest): if (!focused) {
          // TODO(crbug.com/508638062): the <embed> element in the parent frame lost
          // focus. Should we remove the page focus from the embedded page?
          return;
          }
          Keren Zhu . resolved

          For my own understanding, I think this test case will fail,

          ```
          <html>
          <embed id="parent">
          <embed id="child"> ... </embed>
          <input>
          </embed>
          </html>
          ```

          Assuming the focus starts within #child then JS calls `<input>.focus()`. Expected: #parent's WebContents gets focus; Actual: #parent's WebContents is not focused and #child's WebContents remains to be focused.

          Looks like this needs to be fixed by implementing the blur logic around here (not for this CL).

          Line 211, Patchset 15 (Latest): if (!child_contents_->ContainsOrIsFocusedWebContents()) {
          child_contents_->Focus();
          }
          Keren Zhu . unresolved

          I think this is only needed because `SurfaceEmbedConnectorImpl::RequestFocus()` walks up the <embed> list. What if we walk down the list from the root <embed>?

          File content/browser/surface_embed/surface_embed_connector_impl.cc
          Line 747, Patchset 15 (Latest):void SurfaceEmbedConnectorImpl::RequestFocus() {
          Keren Zhu . unresolved

          To distinguish between focusing WebContents from focusing <embed>, maybe rename `RequestFocus()` -> `RequestFocusOnEmbedElement()`, for both `SurfaceEmbedConnectorImpl` and `SurfaceEmbedHost`.

          Open in Gerrit

          Related details

          Attention is currently required from:
          • Dave Risney
          • Liang Zhao
          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: I27ba9dd619ddc6b681902154427e1cbb4bb2613e
            Gerrit-Change-Number: 8102721
            Gerrit-PatchSet: 15
            Gerrit-Owner: Liang Zhao <lz...@microsoft.com>
            Gerrit-Reviewer: Dave Risney <david....@microsoft.com>
            Gerrit-Reviewer: Keren Zhu <kere...@chromium.org>
            Gerrit-Reviewer: Liang Zhao <lz...@microsoft.com>
            Gerrit-CC: Surface Embed Reviews <surface-em...@google.com>
            Gerrit-CC: gwsq
            Gerrit-Attention: Dave Risney <david....@microsoft.com>
            Gerrit-Attention: Liang Zhao <lz...@microsoft.com>
            Gerrit-Comment-Date: Sat, 25 Jul 2026 05:22:36 +0000
            Gerrit-HasComments: Yes
            Gerrit-Has-Labels: No
            satisfied_requirement
            unsatisfied_requirement
            open
            diffy
            Reply all
            Reply to author
            Forward
            0 new messages