diff --git a/android/java/org/chromium/chrome/browser/BackgroundVideoPlaybackTabHelper.java b/android/java/org/chromium/chrome/browser/BackgroundVideoPlaybackTabHelper.java index 0cac21af4f59..60af28a64f3a 100644 --- a/android/java/org/chromium/chrome/browser/BackgroundVideoPlaybackTabHelper.java +++ b/android/java/org/chromium/chrome/browser/BackgroundVideoPlaybackTabHelper.java @@ -13,8 +13,8 @@ @JNINamespace("chrome::android") public class BackgroundVideoPlaybackTabHelper { - public static void toggleFullscreen(WebContents webContents, boolean isFullScreen) { - BackgroundVideoPlaybackTabHelperJni.get().toggleFullscreen(webContents, isFullScreen); + public static void setFullscreen(WebContents webContents) { + BackgroundVideoPlaybackTabHelperJni.get().setFullscreen(webContents); } public static boolean isPlayingMedia(WebContents webContents) { @@ -23,7 +23,7 @@ public static boolean isPlayingMedia(WebContents webContents) { @NativeMethods interface Natives { - void toggleFullscreen(WebContents webContents, boolean isFullScreen); + void setFullscreen(WebContents webContents); boolean isPlayingMedia(WebContents webContents); } diff --git a/android/java/org/chromium/chrome/browser/app/BraveActivity.java b/android/java/org/chromium/chrome/browser/app/BraveActivity.java index 7c989580f5d5..5a87578f72ab 100644 --- a/android/java/org/chromium/chrome/browser/app/BraveActivity.java +++ b/android/java/org/chromium/chrome/browser/app/BraveActivity.java @@ -520,7 +520,7 @@ public void onUserLeaveHint() { && isYTVideoUrl(currentTab.getUrl()) && !isInPictureInPictureMode() && BackgroundVideoPlaybackTabHelper.isPlayingMedia(currentTab.getWebContents())) { - BackgroundVideoPlaybackTabHelper.toggleFullscreen(currentTab.getWebContents(), true); + BackgroundVideoPlaybackTabHelper.setFullscreen(currentTab.getWebContents()); try { enterPictureInPictureMode(new PictureInPictureParams.Builder().build()); } catch (IllegalStateException | IllegalArgumentException e) { @@ -537,10 +537,10 @@ public void performOnConfigurationChanged(Configuration newConfig) { if (currentTab != null && currentTab.getUrl() != null && isYTVideoUrl(currentTab.getUrl()) - && !isInPictureInPictureMode()) { - BackgroundVideoPlaybackTabHelper.toggleFullscreen( - currentTab.getWebContents(), - newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE); + && !isInPictureInPictureMode() + && newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { + BackgroundVideoPlaybackTabHelper.setFullscreen( + currentTab.getWebContents()); } } diff --git a/browser/android/background_video/background_video_playback_tab_helper.cc b/browser/android/background_video/background_video_playback_tab_helper.cc index 440fcaeb67ab..66db74116062 100644 --- a/browser/android/background_video/background_video_playback_tab_helper.cc +++ b/browser/android/background_video/background_video_playback_tab_helper.cc @@ -108,15 +108,12 @@ void BackgroundVideoPlaybackTabHelper::MediaStoppedPlaying( namespace chrome { namespace android { -void JNI_BackgroundVideoPlaybackTabHelper_ToggleFullscreen( +void JNI_BackgroundVideoPlaybackTabHelper_SetFullscreen( JNIEnv* env, - const base::android::JavaParamRef& jweb_contents, - jboolean is_full_screen) { + const base::android::JavaParamRef& jweb_contents) { content::WebContents* web_contents = content::WebContents::FromJavaWebContents(jweb_contents); - // Injecting this script to make youtube video fullscreen on landscape mode - // and exit fullscreen on portrait mode. - if (is_full_screen) { + // Injecting this script to make youtube video fullscreen on landscape mode. constexpr const char16_t script[] = uR"js(if(!document.fullscreenElement) { var fullscreenBtn = @@ -142,11 +139,6 @@ void JNI_BackgroundVideoPlaybackTabHelper_ToggleFullscreen( ISOLATED_WORLD_ID_BRAVE_INTERNAL, script, blink::mojom::UserActivationOption::kActivate, blink::mojom::PromiseResultOption::kAwait, base::NullCallback()); - } else { - if (web_contents->HasActiveEffectivelyFullscreenVideo()) { - web_contents->ExitFullscreen(true); - } - } } jboolean JNI_BackgroundVideoPlaybackTabHelper_IsPlayingMedia(