diff --git a/content/browser/webid/federated_auth_request_impl.cc b/content/browser/webid/federated_auth_request_impl.cc index 2a8a19580f6abb..b2717870cd40ec 100644 --- a/content/browser/webid/federated_auth_request_impl.cc +++ b/content/browser/webid/federated_auth_request_impl.cc @@ -399,6 +399,11 @@ absl::optional GetIframeOriginForDisplay( return iframe_for_display; } +bool IsFrameVisible(RenderFrameHost* frame) { + return frame && frame->IsActive() && + frame->GetVisibilityState() == content::PageVisibilityState::kVisible; +} + } // namespace FederatedAuthRequestImpl::FetchData::FetchData() = default; @@ -1189,9 +1194,7 @@ void FederatedAuthRequestImpl::MaybeShowAccountsDialog() { // if the RenderFrameHost is hidden because the user does not seem interested // in the contents of the current page. if (!fetch_data_.for_idp_signin) { - bool is_visible = (render_frame_host().IsActive() && - render_frame_host().GetVisibilityState() == - content::PageVisibilityState::kVisible); + bool is_visible = IsFrameVisible(render_frame_host().GetMainFrame()); fedcm_metrics_->RecordWebContentsVisibilityUponReadyToShowDialog( is_visible); @@ -1377,10 +1380,7 @@ void FederatedAuthRequestImpl::HandleAccountsFetchFailure( return; } - bool is_visible = (render_frame_host().IsActive() && - render_frame_host().GetVisibilityState() == - content::PageVisibilityState::kVisible); - if (!is_visible) { + if (!IsFrameVisible(render_frame_host().GetMainFrame())) { CompleteRequestWithError(FederatedAuthRequestResult::kErrorRpPageNotVisible, TokenStatus::kRpPageNotVisible, /*should_delay_callback=*/true); diff --git a/third_party/blink/web_tests/external/wpt/credential-management/fedcm-iframe.https.html b/third_party/blink/web_tests/external/wpt/credential-management/fedcm-iframe.https.html index 964ebf4c44df4e..dc0c17dea695e6 100644 --- a/third_party/blink/web_tests/external/wpt/credential-management/fedcm-iframe.https.html +++ b/third_party/blink/web_tests/external/wpt/credential-management/fedcm-iframe.https.html @@ -16,13 +16,16 @@ const remoteBaseURL = host.HTTPS_REMOTE_ORIGIN + basePath; const localhostBaseURL = "http://localhost:" + host.HTTP_PORT + basePath; -async function createIframeAndWaitForMessage(test, iframeUrl, setPermissionPolicy) { +async function createIframeAndWaitForMessage(test, iframeUrl, setPermissionPolicy, style = "") { const messageWatcher = new EventWatcher(test, window, "message"); var iframe = document.createElement("iframe"); iframe.src = iframeUrl; if (setPermissionPolicy) { iframe.allow = "identity-credentials-get"; } + if (style !== "") { + iframe.style = style; + } document.body.appendChild(iframe); const message = await messageWatcher.wait_for("message"); return message.data; @@ -44,6 +47,14 @@ assert_equals(message.token, "token"); }, "FedCM enabled in 2 level deep nested iframe. FedCM should be enabled regardless of iframe nesting depth"); +fedcm_test(async t => { + const message = await createIframeAndWaitForMessage( + t, remoteBaseURL + "support/fedcm-iframe.html", + /*setPermissionPolicy=*/true, /*style=*/"display:none;"); + assert_equals(message.result, "Pass"); + assert_equals(message.token, "token"); +}, "FedCM enabled in invisible iframe. FedCM should be enabled as long as the top frame is visible"); + fedcm_test(async t => { const message = await createIframeAndWaitForMessage( t, remoteBaseURL + "support/fedcm-iframe-level2.html",