Skip to content

Commit

Permalink
Add WebContentsObserver::OnFrameVisibilityChanged()
Browse files Browse the repository at this point in the history
This new method call originates from
RenderFrameHostImpl::VisibilityChanged.

This CL also fixes visibility local root frames by calling it
from  CrossProcessFrameConnector::OnVisibilityChanged().

This will be used in a subsequent CL to track visibility of frames
in the performance manager.

Bug: 1077217
Change-Id: Ie60f89fdd89f59811dd6e3eb74bed3ec1413bcce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4629014
Reviewed-by: Avi Drissman <avi@chromium.org>
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1216636}
  • Loading branch information
plmonette-zz authored and Chromium LUCI CQ committed Oct 29, 2023
1 parent 9c64ce9 commit 214fab6
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ void CrossProcessFrameConnector::OnVisibilityChanged(

// TODO(https://crbug.com/1014212) Remove this CHECK when the bug is fixed.
CHECK(current_child_frame_host());
current_child_frame_host()->VisibilityChanged(visibility_);

// If there is an inner WebContents, it should be notified of the change in
// the visibility. The Show/Hide methods will not be called if an inner
Expand Down
5 changes: 5 additions & 0 deletions content/browser/renderer_host/render_frame_host_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,11 @@ class CONTENT_EXPORT RenderFrameHostDelegate {
virtual void OnFrameAudioStateChanged(RenderFrameHostImpl* host,
bool is_audible) {}

// Notifies observers that the frame's visibility has changed.
virtual void OnFrameVisibilityChanged(
RenderFrameHostImpl* host,
blink::mojom::FrameVisibility visibility) {}

// Returns FrameTreeNodes that are logically owned by another frame even
// though this relationship is not yet reflected in their frame trees. This
// can happen, for example, with unattached guests and orphaned portals.
Expand Down
1 change: 1 addition & 0 deletions content/browser/renderer_host/render_frame_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6900,6 +6900,7 @@ void RenderFrameHostImpl::UpdateUserGestureCarryoverInfo() {
void RenderFrameHostImpl::VisibilityChanged(
blink::mojom::FrameVisibility visibility) {
visibility_ = visibility;
delegate_->OnFrameVisibilityChanged(this, visibility_);
}

void RenderFrameHostImpl::DidChangeThemeColor(
Expand Down
9 changes: 9 additions & 0 deletions content/browser/web_contents/web_contents_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9439,6 +9439,15 @@ void WebContentsImpl::OnFrameAudioStateChanged(RenderFrameHostImpl* host,
host, is_audible);
}

void WebContentsImpl::OnFrameVisibilityChanged(
RenderFrameHostImpl* host,
blink::mojom::FrameVisibility visibility) {
OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::OnFrameVisibilityChanged",
"render_frame_host", host, "visibility", visibility);
observers_.NotifyObservers(&WebContentsObserver::OnFrameVisibilityChanged,
host, visibility);
}

media::MediaMetricsProvider::RecordAggregateWatchTimeCallback
WebContentsImpl::GetRecordAggregateWatchTimeCallback(
const GURL& page_main_frame_last_committed_url) {
Expand Down
3 changes: 3 additions & 0 deletions content/browser/web_contents/web_contents_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,9 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents,
int context_id) override;
void OnFrameAudioStateChanged(RenderFrameHostImpl* host,
bool is_audible) override;
void OnFrameVisibilityChanged(
RenderFrameHostImpl* host,
blink::mojom::FrameVisibility visibility) override;
media::MediaMetricsProvider::RecordAggregateWatchTimeCallback
GetRecordAggregateWatchTimeCallback(
const GURL& page_main_frame_last_committed_url) override;
Expand Down
8 changes: 8 additions & 0 deletions content/public/browser/web_contents_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "third_party/blink/public/mojom/css/preferred_color_scheme.mojom.h"
#include "third_party/blink/public/mojom/devtools/console_message.mojom.h"
#include "third_party/blink/public/mojom/favicon/favicon_url.mojom-forward.h"
#include "third_party/blink/public/mojom/frame/lifecycle.mojom.h"
#include "third_party/blink/public/mojom/loader/resource_load_info.mojom-forward.h"
#include "third_party/blink/public/mojom/media/capture_handle_config.mojom-forward.h"
#include "third_party/skia/include/core/SkColor.h"
Expand Down Expand Up @@ -689,6 +690,13 @@ class CONTENT_EXPORT WebContentsObserver : public base::CheckedObserver {
// Called when the audio state of an individual frame changes.
virtual void OnFrameAudioStateChanged(RenderFrameHost* rfh, bool audible) {}

// Called when an individual frame's visibility inside the viewport of the
// page changes. Note that this value is independent from the visibility of
// the page.
virtual void OnFrameVisibilityChanged(
RenderFrameHost* rfh,
blink::mojom::FrameVisibility visibility) {}

// Called when the connected to USB device state changes.
virtual void OnIsConnectedToUsbDeviceChanged(
bool is_connected_to_usb_device) {}
Expand Down

0 comments on commit 214fab6

Please sign in to comment.