Commit 67e87286 authored by Philip Rogers's avatar Philip Rogers Committed by Commit Bot

ForAllThrottledLocalFrameViews should recurse into non-throttled frames

This patch fixes a bug from https://crrev.com/740787 where
LocalFrameView::ForAllThrottledLocalFrameViews would stop at
non-throttled frames, rather than recursing into them.

Change-Id: Iaaaf129fd693fc0adb546ca09ecd78a6a4002f6c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2410526
Commit-Queue: Philip Rogers <pdr@chromium.org>
Commit-Queue: Stefan Zager <szager@chromium.org>
Auto-Submit: Philip Rogers <pdr@chromium.org>
Reviewed-by: default avatarStefan Zager <szager@chromium.org>
Reviewed-by: default avatarvmpstr <vmpstr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808102}
parent 4165f719
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <memory> #include <memory>
#include <utility> #include <utility>
#include "base/callback.h"
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/metrics/field_trial_params.h" #include "base/metrics/field_trial_params.h"
...@@ -359,10 +360,8 @@ void LocalFrameView::ForAllNonThrottledLocalFrameViews( ...@@ -359,10 +360,8 @@ void LocalFrameView::ForAllNonThrottledLocalFrameViews(
// updated, consider updating |ForAllNonThrottledLocalFrameViews| too. // updated, consider updating |ForAllNonThrottledLocalFrameViews| too.
template <typename Function> template <typename Function>
void LocalFrameView::ForAllThrottledLocalFrameViews(const Function& function) { void LocalFrameView::ForAllThrottledLocalFrameViews(const Function& function) {
if (!ShouldThrottleRendering()) if (ShouldThrottleRendering())
return; function(*this);
function(*this);
for (Frame* child = frame_->Tree().FirstChild(); child; for (Frame* child = frame_->Tree().FirstChild(); child;
child = child->Tree().NextSibling()) { child = child->Tree().NextSibling()) {
...@@ -374,6 +373,12 @@ void LocalFrameView::ForAllThrottledLocalFrameViews(const Function& function) { ...@@ -374,6 +373,12 @@ void LocalFrameView::ForAllThrottledLocalFrameViews(const Function& function) {
} }
} }
void LocalFrameView::ForAllThrottledLocalFrameViewsForTesting(
base::RepeatingCallback<void(LocalFrameView&)> callback) {
ForAllThrottledLocalFrameViews(
[&callback](LocalFrameView& view) { callback.Run(view); });
}
template <typename Function> template <typename Function>
void LocalFrameView::ForAllRemoteFrameViews(const Function& function) { void LocalFrameView::ForAllRemoteFrameViews(const Function& function) {
for (Frame* child = frame_->Tree().FirstChild(); child; for (Frame* child = frame_->Tree().FirstChild(); child;
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <memory> #include <memory>
#include "base/callback_forward.h"
#include "third_party/blink/public/common/metrics/document_update_reason.h" #include "third_party/blink/public/common/metrics/document_update_reason.h"
#include "third_party/blink/public/mojom/frame/lifecycle.mojom-blink-forward.h" #include "third_party/blink/public/mojom/frame/lifecycle.mojom-blink-forward.h"
#include "third_party/blink/public/mojom/scroll/scroll_into_view_params.mojom-blink-forward.h" #include "third_party/blink/public/mojom/scroll/scroll_into_view_params.mojom-blink-forward.h"
...@@ -860,6 +861,9 @@ class CORE_EXPORT LocalFrameView final ...@@ -860,6 +861,9 @@ class CORE_EXPORT LocalFrameView final
template <typename Function> template <typename Function>
void ForAllThrottledLocalFrameViews(const Function&); void ForAllThrottledLocalFrameViews(const Function&);
void ForAllThrottledLocalFrameViewsForTesting(
base::RepeatingCallback<void(LocalFrameView&)>);
template <typename Function> template <typename Function>
void ForAllRemoteFrameViews(const Function&); void ForAllRemoteFrameViews(const Function&);
...@@ -1064,6 +1068,7 @@ class CORE_EXPORT LocalFrameView final ...@@ -1064,6 +1068,7 @@ class CORE_EXPORT LocalFrameView final
FRIEND_TEST_ALL_PREFIXES(WebViewTest, DeviceEmulationResetScrollbars); FRIEND_TEST_ALL_PREFIXES(WebViewTest, DeviceEmulationResetScrollbars);
FRIEND_TEST_ALL_PREFIXES(FrameThrottlingTest, GraphicsLayerCollection); FRIEND_TEST_ALL_PREFIXES(FrameThrottlingTest, GraphicsLayerCollection);
FRIEND_TEST_ALL_PREFIXES(FrameThrottlingTest, ForAllThrottledLocalFrameViews);
}; };
inline void LocalFrameView::IncrementVisuallyNonEmptyCharacterCount( inline void LocalFrameView::IncrementVisuallyNonEmptyCharacterCount(
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "base/callback.h"
#include "base/test/bind_test_util.h"
#include "cc/layers/picture_layer.h" #include "cc/layers/picture_layer.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/web/web_frame_content_dumper.h" #include "third_party/blink/public/web/web_frame_content_dumper.h"
...@@ -367,6 +369,37 @@ TEST_P(FrameThrottlingTest, ...@@ -367,6 +369,37 @@ TEST_P(FrameThrottlingTest,
EXPECT_TRUE(frame_document->View()->ShouldThrottleRendering()); EXPECT_TRUE(frame_document->View()->ShouldThrottleRendering());
} }
TEST_P(FrameThrottlingTest, ForAllThrottledLocalFrameViews) {
// Create a document with a hidden cross-origin subframe.
SimRequest main_resource("https://example.com/", "text/html");
SimRequest frame_resource("https://example.com/iframe.html", "text/html");
LoadURL("https://example.com/");
main_resource.Complete(R"HTML(
<iframe id="frame" sandbox src="iframe.html"
style="transform: translateY(480px)">
)HTML");
frame_resource.Complete("<!doctype html>");
DocumentLifecycle::AllowThrottlingScope throttling_scope(
GetDocument().Lifecycle());
CompositeFrame();
auto* frame_element =
To<HTMLIFrameElement>(GetDocument().getElementById("frame"));
auto* frame_document = frame_element->contentDocument();
// Hidden cross origin frames are throttled.
EXPECT_TRUE(frame_document->View()->ShouldThrottleRendering());
// Main frame is not throttled.
EXPECT_FALSE(GetDocument().View()->ShouldThrottleRendering());
unsigned throttled_count = 0;
auto throttled_callback = base::BindLambdaForTesting(
[&throttled_count](LocalFrameView&) { throttled_count++; });
GetDocument().View()->ForAllThrottledLocalFrameViewsForTesting(
throttled_callback);
EXPECT_EQ(1u, throttled_count);
}
TEST_P(FrameThrottlingTest, HiddenCrossOriginZeroByZeroFramesAreNotThrottled) { TEST_P(FrameThrottlingTest, HiddenCrossOriginZeroByZeroFramesAreNotThrottled) {
// Create a document with doubly nested iframes. // Create a document with doubly nested iframes.
SimRequest main_resource("https://example.com/", "text/html"); SimRequest main_resource("https://example.com/", "text/html");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment