Rename WebContents::GetCapturerCount() to IsBeingCaptured().
Callers don't need to know the number of capturers.
This change is a prerequisite to expose IsBeingCaptured() on
RenderWidgetHostDelegate, to let RenderWidgetHostViews
determine by themselves whether they need to render
content.
Bug: 788827
Change-Id: If1f7d6b51901bf845d3ec3c8bb93a16f48fefaf1
Reviewed-on: https://chromium-review.googlesource.com/796932
Commit-Queue: François Doray <[email protected]>
Reviewed-by: Jochen Eisinger <[email protected]>
Cr-Commit-Position: refs/heads/master@{#523120}
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 47657d0..d1bf2f5 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -1379,7 +1379,7 @@
if (is_being_destroyed_)
return;
- if (capturer_count_ == 0) {
+ if (!IsBeingCaptured()) {
const gfx::Size old_size = preferred_size_for_capture_;
preferred_size_for_capture_ = gfx::Size();
OnPreferredSizeChanged(old_size);
@@ -1394,8 +1394,8 @@
}
}
-int WebContentsImpl::GetCapturerCount() const {
- return capturer_count_;
+bool WebContentsImpl::IsBeingCaptured() const {
+ return capturer_count_ > 0;
}
bool WebContentsImpl::IsAudioMuted() const {
@@ -1530,7 +1530,7 @@
void WebContentsImpl::WasHidden() {
// If there are entities capturing screenshots or video (e.g., mirroring),
// don't activate the "disable rendering" optimization.
- if (capturer_count_ == 0) {
+ if (!IsBeingCaptured()) {
// |GetRenderViewHost()| can be NULL if the user middle clicks a link to
// open a tab in the background, then closes the tab before selecting it.
// This is because closing the tab calls WebContentsImpl::Destroy(), which
@@ -1588,7 +1588,7 @@
}
void WebContentsImpl::WasOccluded() {
- if (capturer_count_ == 0) {
+ if (!IsBeingCaptured()) {
for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree())
view->WasOccluded();
}
@@ -1597,7 +1597,7 @@
}
void WebContentsImpl::WasUnOccluded() {
- if (capturer_count_ == 0)
+ if (!IsBeingCaptured())
DoWasUnOccluded();
should_normally_be_occluded_ = false;
@@ -3479,7 +3479,7 @@
}
gfx::Size WebContentsImpl::GetPreferredSize() const {
- return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
+ return IsBeingCaptured() ? preferred_size_for_capture_ : preferred_size_;
}
bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
@@ -5728,7 +5728,7 @@
}
bool WebContentsImpl::IsHidden() {
- return capturer_count_ == 0 && !should_normally_be_visible_;
+ return !IsBeingCaptured() && !should_normally_be_visible_;
}
int WebContentsImpl::GetOuterDelegateFrameTreeNodeId() {
diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h
index f66256f..fba08e3 100644
--- a/content/browser/web_contents/web_contents_impl.h
+++ b/content/browser/web_contents/web_contents_impl.h
@@ -339,7 +339,7 @@
const std::string& GetEncoding() const override;
void IncrementCapturerCount(const gfx::Size& capture_size) override;
void DecrementCapturerCount() override;
- int GetCapturerCount() const override;
+ bool IsBeingCaptured() const override;
bool IsAudioMuted() const override;
void SetAudioMuted(bool mute) override;
bool IsCurrentlyAudible() override;
diff --git a/content/browser/web_contents/web_contents_impl_unittest.cc b/content/browser/web_contents/web_contents_impl_unittest.cc
index 2e9ea19..28dc21a4 100644
--- a/content/browser/web_contents/web_contents_impl_unittest.cc
+++ b/content/browser/web_contents/web_contents_impl_unittest.cc
@@ -2720,40 +2720,40 @@
// With no capturers, expect the preferred size to be the one propagated into
// WebContentsImpl via the RenderViewHostDelegate interface.
- EXPECT_EQ(contents()->GetCapturerCount(), 0);
+ EXPECT_FALSE(contents()->IsBeingCaptured());
EXPECT_EQ(original_preferred_size, contents()->GetPreferredSize());
// Increment capturer count, but without specifying a capture size. Expect
// a "not set" preferred size.
contents()->IncrementCapturerCount(gfx::Size());
- EXPECT_EQ(1, contents()->GetCapturerCount());
+ EXPECT_TRUE(contents()->IsBeingCaptured());
EXPECT_EQ(gfx::Size(), contents()->GetPreferredSize());
// Increment capturer count again, but with an overriding capture size.
// Expect preferred size to now be overridden to the capture size.
const gfx::Size capture_size(1280, 720);
contents()->IncrementCapturerCount(capture_size);
- EXPECT_EQ(2, contents()->GetCapturerCount());
+ EXPECT_TRUE(contents()->IsBeingCaptured());
EXPECT_EQ(capture_size, contents()->GetPreferredSize());
// Increment capturer count a third time, but the expect that the preferred
// size is still the first capture size.
const gfx::Size another_capture_size(720, 480);
contents()->IncrementCapturerCount(another_capture_size);
- EXPECT_EQ(3, contents()->GetCapturerCount());
+ EXPECT_TRUE(contents()->IsBeingCaptured());
EXPECT_EQ(capture_size, contents()->GetPreferredSize());
// Decrement capturer count twice, but expect the preferred size to still be
// overridden.
contents()->DecrementCapturerCount();
contents()->DecrementCapturerCount();
- EXPECT_EQ(1, contents()->GetCapturerCount());
+ EXPECT_TRUE(contents()->IsBeingCaptured());
EXPECT_EQ(capture_size, contents()->GetPreferredSize());
// Decrement capturer count, and since the count has dropped to zero, the
// original preferred size should be restored.
contents()->DecrementCapturerCount();
- EXPECT_EQ(0, contents()->GetCapturerCount());
+ EXPECT_FALSE(contents()->IsBeingCaptured());
EXPECT_EQ(original_preferred_size, contents()->GetPreferredSize());
}