Skip to content

Commit

Permalink
[Merge to M103][ad density] Reset RenderFrameImpl::main_frame_viewpor…
Browse files Browse the repository at this point in the history
…t_rect_ during DidCommitNavigationInternal()

We should reset RenderFrameImpl::main_frame_viewport_rect_ during
DidCommitNavigationInternal(). Otherwise, a reload of the page that
results in the same viewport rect will see a duplicate rect and will
skip sending it to the new document.

(cherry picked from commit 17c6f5b)

Bug: 1329254
Change-Id: I25929f159e180a9c190fca03f33820e7a0ddcb49
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3668966
Reviewed-by: Stefan Zager <szager@chromium.org>
Commit-Queue: Yao Xiao <yaoxia@chromium.org>
Reviewed-by: John Delaney <johnidel@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1007640}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3677415
Commit-Queue: Krishna Govind <govind@chromium.org>
Reviewed-by: Krishna Govind <govind@chromium.org>
Owners-Override: Krishna Govind <govind@chromium.org>
Cr-Commit-Position: refs/branch-heads/5060@{#436}
Cr-Branched-From: b83393d-refs/heads/main@{#1002911}
  • Loading branch information
yaoxiachromium authored and Chromium LUCI CQ committed May 31, 2022
1 parent 3afb058 commit df42301
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
5 changes: 3 additions & 2 deletions content/renderer/render_frame_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4999,10 +4999,11 @@ void RenderFrameImpl::DidCommitNavigationInternal(
}
}

// Ensure we will propagate frame intersections when the main frame commits
// even if the intersection does not change across navigations.
// Ensure we will propagate the main frame and viewport rect when the main
// frame commits even if the rect does not change across navigations.
if (IsMainFrame()) {
main_frame_intersection_rect_.reset();
main_frame_viewport_rect_.reset();
}
}

Expand Down
24 changes: 22 additions & 2 deletions content/renderer/render_frame_impl_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,19 @@ class RenderFrameTestObserver : public RenderFrameObserver {
const gfx::Rect& intersection_rect) override {
last_intersection_rect_ = intersection_rect;
}
void OnMainFrameViewportRectangleChanged(
const gfx::Rect& viewport_rect) override {
last_viewport_rect_ = viewport_rect;
}

bool visible() { return visible_; }
gfx::Rect last_intersection_rect() { return last_intersection_rect_; }
bool visible() const { return visible_; }
gfx::Rect last_intersection_rect() const { return last_intersection_rect_; }
gfx::Rect last_viewport_rect() const { return last_viewport_rect_; }

private:
bool visible_;
gfx::Rect last_intersection_rect_;
gfx::Rect last_viewport_rect_;
};

// Verify that a frame with a RenderFrameProxy as a parent has its own
Expand Down Expand Up @@ -460,6 +466,20 @@ TEST_F(RenderFrameImplTest, MainFrameIntersectionRecorded) {
EXPECT_EQ(observer.last_intersection_rect(), mainframe_intersection);
}

TEST_F(RenderFrameImplTest, MainFrameViewportRectRecorded) {
RenderFrameTestObserver observer(GetMainRenderFrame());
gfx::Rect mainframe_viewport(0, 0, 200, 140);
GetMainRenderFrame()->OnMainFrameViewportRectangleChanged(mainframe_viewport);
EXPECT_EQ(observer.last_viewport_rect(), mainframe_viewport);

// After a navigation, the notification of `mainframe_viewport` should be
// propagated to `RenderFrameTestObserver` again for the new document.
LoadHTML(kParentFrameHTML);
RenderFrameTestObserver observer2(GetMainRenderFrame());
GetMainRenderFrame()->OnMainFrameViewportRectangleChanged(mainframe_viewport);
EXPECT_EQ(observer2.last_viewport_rect(), mainframe_viewport);
}

// Used to annotate the source of an interface request.
struct SourceAnnotation {
// The URL of the active document in the frame, at the time the interface was
Expand Down

0 comments on commit df42301

Please sign in to comment.