[Picture in Picture] Avoid "disable rendering" optimisation in PiP mode.

WebContents activates the "disable rendering" optimisation when the
WebContents is hidden. This means that when a video is playing in
Picture-in-Picture, then the WebContents is hidden, the video will stop
playing in the Picture-in-Picture window.

Similarly to content capturing (e.g. mirroring / tab capture), this
optimisation should not be activated when in Picture-in-Picture mode.

This will only affect one tab at a time, as users cannot enter
Picture-in-Picture mode from multiple tabs.

Bug: 848812
Change-Id: I98a0e769ad4c412ea50db4de2ab63e64f3b752f2
Reviewed-on: https://chromium-review.googlesource.com/1105339
Reviewed-by: Kinuko Yasuda <[email protected]>
Commit-Queue: apacible <[email protected]>
Cr-Commit-Position: refs/heads/master@{#568496}
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index c586ac2..03990c9 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -1640,9 +1640,10 @@
 }
 
 void WebContentsImpl::WasHidden() {
-  // If there are entities capturing screenshots or video (e.g., mirroring),
-  // don't activate the "disable rendering" optimization.
-  if (!IsBeingCaptured()) {
+  // If there are entities capturing screenshots or video (e.g. mirroring),
+  // or in Picture-in-Picture mode, don't activate the "disable rendering"
+  // optimization.
+  if (!IsBeingCaptured() && !HasPictureInPictureVideo()) {
     // |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