Don't throttle hidden tab in Picture-in-Picture

This CL makes sure a tab is not throttled when hidden if it has a
Picture-in-Picture video. Renderer is still informed though that the tab
was hidden.

Bug: 917303, 921460, 921478
Change-Id: Ia0c5c4841b48d8f62f8ddbc12653522e0b59f6b5
Reviewed-on: https://chromium-review.googlesource.com/c/1419841
Reviewed-by: Jochen Eisinger <[email protected]>
Commit-Queue: François Beaufort <[email protected]>
Cr-Commit-Position: refs/heads/master@{#624096}
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 5f747b54..01fff8b0 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -1668,8 +1668,9 @@
 
 void WebContentsImpl::WasHidden() {
   // If there are entities capturing screenshots or video (e.g. mirroring),
-  // don't activate the "disable rendering" optimization.
-  if (!IsBeingCaptured()) {
+  // or in Picture-in-Picture mode, don't activate the "disable rendering"
+  // optimization.
+  if (!IsBeingCaptured() && !HasPictureInPictureVideo()) {
     // This hides the individual RenderWidgets before hiding the Page, as
     // RenderWidgets will work to produce compositor frames and handle input
     // until they are hidden. But the Page and other classes do not expect to
@@ -1687,10 +1688,13 @@
 
     if (!ShowingInterstitialPage())
       SetVisibilityForChildViews(false);
-
-    SendPageMessage(new PageMsg_WasHidden(MSG_ROUTING_NONE));
   }
 
+  // Inform the renderer that the page was hidden if there are no entities
+  // capturing screenshots or video (e.g. mirroring).
+  if (!IsBeingCaptured())
+    SendPageMessage(new PageMsg_WasHidden(MSG_ROUTING_NONE));
+
   SetVisibility(Visibility::HIDDEN);
 }