Cherry-pick: [WebView] Create PowerSaveBlocker for fullscreen video.

Cherry-picked from chromium:
https://crrev.com/ec9b8860c670221d8bfcfbe628f0597a5b6bd4f6

BUG:17653054

Original description:

[WebView] Create PowerSaveBlocker for fullscreen video.

BUG=417623
Committed: https://crrev.com/ec9b8860c670221d8bfcfbe628f0597a5b6bd4f6
Cr-Commit-Position: refs/heads/master@{#296738}

Change-Id: Ic58ff0fd7684cec4276950887d9a5ea186f2f8f6
diff --git a/android_webview/lib/main/aw_main_delegate.cc b/android_webview/lib/main/aw_main_delegate.cc
index fe098a1..7ffb997 100644
--- a/android_webview/lib/main/aw_main_delegate.cc
+++ b/android_webview/lib/main/aw_main_delegate.cc
@@ -79,6 +79,12 @@
   // File system API not supported (requires some new API; internal bug 6930981)
   cl->AppendSwitch(switches::kDisableFileSystem);
 
+  // For fullscreen video we create a new container view to host the
+  // WebContents, ie. the FullscreenView. As a result we cannot reuse the
+  // embedded video blocker attached to the old container view, so we create a
+  // new blocker instead attached to the ContentVideoView.
+  cl->AppendSwitch(switches::kEnableContentVideoViewPowerSaveBlocker);
+
 #if defined(VIDEO_HOLE)
   // Support EME/L1 with hole-punching.
   cl->AppendSwitch(switches::kMediaDrmEnableNonCompositing);
diff --git a/content/browser/android/content_video_view.cc b/content/browser/android/content_video_view.cc
index 5407032..684477f 100644
--- a/content/browser/android/content_video_view.cc
+++ b/content/browser/android/content_video_view.cc
@@ -224,17 +224,18 @@
 }
 
 void ContentVideoView::CreatePowerSaveBlocker() {
-  if (!CommandLine::ForCurrentProcess()->HasSwitch(
-      switches::kDisableOverlayFullscreenVideoSubtitle)) {
-    return;
+  if (CommandLine::ForCurrentProcess()->HasSwitch(
+      switches::kEnableContentVideoViewPowerSaveBlocker)) {
+    // In fullscreen Clank reuses the power save blocker attached to the
+    // container view that was created for embedded video. The WebView cannot
+    // reuse that so we create a new blocker instead.
+    if (power_save_blocker_) return;
+
+    power_save_blocker_ = PowerSaveBlocker::Create(
+        PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep,
+        "Playing video").Pass();
+    static_cast<PowerSaveBlockerImpl*>(power_save_blocker_.get())->
+        InitDisplaySleepBlocker(GetNativeView());
   }
-
-  if (power_save_blocker_) return;
-
-  power_save_blocker_ = PowerSaveBlocker::Create(
-      PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep,
-      "Playing video").Pass();
-  static_cast<PowerSaveBlockerImpl*>(power_save_blocker_.get())->
-      InitDisplaySleepBlocker(GetNativeView());
 }
 }  // namespace content
diff --git a/content/public/common/content_switches.cc b/content/public/common/content_switches.cc
index f10bed1..5f1f1d4 100644
--- a/content/public/common/content_switches.cc
+++ b/content/public/common/content_switches.cc
@@ -920,6 +920,10 @@
 // WebRTC is enabled by default on Android.
 const char kDisableWebRTC[]                 = "disable-webrtc";
 
+// Enable the PowerSaveBlocker in ContentVideoView. Android only.
+const char kEnableContentVideoViewPowerSaveBlocker[] =
+    "enable-content-video-view-power-save-blocker";
+
 // Enable the recognition part of the Web Speech API.
 const char kEnableSpeechRecognition[]       = "enable-speech-recognition";
 
diff --git a/content/public/common/content_switches.h b/content/public/common/content_switches.h
index 6b7042a..1cbc23a 100644
--- a/content/public/common/content_switches.h
+++ b/content/public/common/content_switches.h
@@ -260,6 +260,7 @@
 CONTENT_EXPORT extern const char kDisableClickDelay[];
 CONTENT_EXPORT extern const char kDisableOverscrollEdgeEffect[];
 CONTENT_EXPORT extern const char kDisableWebRTC[];
+CONTENT_EXPORT extern const char kEnableContentVideoViewPowerSaveBlocker[];
 CONTENT_EXPORT extern const char kEnableSpeechRecognition[];
 CONTENT_EXPORT extern const char kForceUseOverlayEmbeddedVideo[];
 CONTENT_EXPORT extern const char kHideScrollbars[];