Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/tab/BrowserControlsVisibilityDelegate.java

Issue 2484293003: Use only renderer driven offsets for fullscreen state. (Closed)
Patch Set: Partially disable testControlsShownOnUnresponsiveRenderer due to timing issues with renderer logic … Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/tab/BrowserControlsVisibilityDelegate.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tab/BrowserControlsVisibilityDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/tab/BrowserControlsVisibilityDelegate.java
index bbbe518293340580df76edadc55c4dc1dfe26775..6c483906163fc52b90f07d753e4dafc0c325ac36 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/tab/BrowserControlsVisibilityDelegate.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/tab/BrowserControlsVisibilityDelegate.java
@@ -1,175 +1,20 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
+// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.tab;
-import android.os.Handler;
-import android.os.Message;
-
-import org.chromium.chrome.browser.UrlConstants;
-import org.chromium.chrome.browser.device.DeviceClassManager;
-import org.chromium.chrome.browser.util.AccessibilityUtil;
-import org.chromium.components.dom_distiller.core.DomDistillerUrlUtils;
-import org.chromium.components.security_state.ConnectionSecurityLevel;
-import org.chromium.content.browser.ContentViewCore;
-import org.chromium.content_public.browser.WebContents;
-import org.chromium.content_public.common.BrowserControlsState;
-
/**
* A delegate to determine visibility of the browser controls.
*/
-public class BrowserControlsVisibilityDelegate {
- protected static final int MSG_ID_ENABLE_FULLSCREEN_AFTER_LOAD = 1;
- /** The maximum amount of time to wait for a page to load before entering fullscreen. */
- private static final long MAX_FULLSCREEN_LOAD_DELAY_MS = 3000;
-
- private static boolean sDisableLoadingCheck;
-
- protected final Tab mTab;
-
- private boolean mIsFullscreenWaitingForLoad;
-
- /**
- * Basic constructor.
- * @param tab The associated {@link Tab}.
- */
- public BrowserControlsVisibilityDelegate(Tab tab) {
- mTab = tab;
-
- mTab.addObserver(new EmptyTabObserver() {
- private Handler mHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- if (msg == null) return;
- if (msg.what == MSG_ID_ENABLE_FULLSCREEN_AFTER_LOAD) {
- enableFullscreenAfterLoad();
- }
- }
- };
-
- private void enableFullscreenAfterLoad() {
- if (!mIsFullscreenWaitingForLoad) return;
-
- mIsFullscreenWaitingForLoad = false;
- mTab.updateFullscreenEnabledState();
- }
-
- private void cancelEnableFullscreenLoadDelay() {
- mHandler.removeMessages(MSG_ID_ENABLE_FULLSCREEN_AFTER_LOAD);
- mIsFullscreenWaitingForLoad = false;
- }
-
- private void scheduleEnableFullscreenLoadDelayIfNecessary() {
- if (mIsFullscreenWaitingForLoad
- && !mHandler.hasMessages(MSG_ID_ENABLE_FULLSCREEN_AFTER_LOAD)) {
- mHandler.sendEmptyMessageDelayed(
- MSG_ID_ENABLE_FULLSCREEN_AFTER_LOAD, MAX_FULLSCREEN_LOAD_DELAY_MS);
- }
- }
-
- @Override
- public void onWebContentsSwapped(Tab tab, boolean didStartLoad, boolean didFinishLoad) {
- if (!didStartLoad) return;
-
- // As we may have missed the main frame commit notification for the
- // swapped web contents, schedule the enabling of fullscreen now.
- scheduleEnableFullscreenLoadDelayIfNecessary();
- }
-
- @Override
- public void onDidCommitProvisionalLoadForFrame(Tab tab, long frameId,
- boolean isMainFrame, String url, int transitionType) {
- if (!isMainFrame) return;
- mHandler.removeMessages(MSG_ID_ENABLE_FULLSCREEN_AFTER_LOAD);
- mHandler.sendEmptyMessageDelayed(
- MSG_ID_ENABLE_FULLSCREEN_AFTER_LOAD, MAX_FULLSCREEN_LOAD_DELAY_MS);
- // If the loading check is disabled, forcibly show the controls to ensure the
- // renderer logic is properly initialized.
- if (sDisableLoadingCheck) {
- mTab.updateBrowserControlsState(BrowserControlsState.SHOWN, true);
- }
- mTab.updateFullscreenEnabledState();
- }
-
- @Override
- public void onPageLoadStarted(Tab tab, String url) {
- mIsFullscreenWaitingForLoad = !DomDistillerUrlUtils.isDistilledPage(url);
- mTab.updateFullscreenEnabledState();
- }
-
- @Override
- public void onPageLoadFinished(Tab tab) {
- // Handle the case where a commit or prerender swap notification failed to arrive
- // and the enable fullscreen message was never enqueued.
- scheduleEnableFullscreenLoadDelayIfNecessary();
- }
-
- @Override
- public void onPageLoadFailed(Tab tab, int errorCode) {
- cancelEnableFullscreenLoadDelay();
- mTab.updateFullscreenEnabledState();
- }
-
- @Override
- public void onHidden(Tab tab) {
- cancelEnableFullscreenLoadDelay();
- }
-
- @Override
- public void onDestroyed(Tab tab) {
- super.onDestroyed(tab);
-
- // Remove pending handler actions to prevent memory leaks.
- mHandler.removeCallbacksAndMessages(null);
- }
- });
- }
-
+public interface BrowserControlsVisibilityDelegate {
/**
* @return Whether hiding browser controls is enabled or not.
*/
- public boolean isHidingBrowserControlsEnabled() {
- WebContents webContents = mTab.getWebContents();
- if (webContents == null || webContents.isDestroyed()) return false;
-
- String url = mTab.getUrl();
- boolean enableHidingBrowserControls = url != null;
- enableHidingBrowserControls &= !url.startsWith(UrlConstants.CHROME_SCHEME);
- enableHidingBrowserControls &= !url.startsWith(UrlConstants.CHROME_NATIVE_SCHEME);
-
- int securityState = mTab.getSecurityLevel();
- enableHidingBrowserControls &= (securityState != ConnectionSecurityLevel.DANGEROUS
- && securityState != ConnectionSecurityLevel.SECURITY_WARNING);
-
- enableHidingBrowserControls &=
- !AccessibilityUtil.isAccessibilityEnabled(mTab.getApplicationContext());
-
- ContentViewCore cvc = mTab.getContentViewCore();
- enableHidingBrowserControls &= cvc == null || !cvc.isFocusedNodeEditable();
- enableHidingBrowserControls &= !mTab.isShowingErrorPage();
- enableHidingBrowserControls &= !webContents.isShowingInterstitialPage();
- enableHidingBrowserControls &= (mTab.getFullscreenManager() != null);
- enableHidingBrowserControls &= DeviceClassManager.enableFullscreen();
- if (!sDisableLoadingCheck) {
- enableHidingBrowserControls &= !mIsFullscreenWaitingForLoad;
- }
-
- return enableHidingBrowserControls;
- }
+ boolean isHidingBrowserControlsEnabled();
/**
* @return Whether showing browser controls is enabled or not.
*/
- public boolean isShowingBrowserControlsEnabled() {
- if (mTab.getFullscreenManager() == null) return true;
- return !mTab.getFullscreenManager().getPersistentFullscreenMode();
- }
-
- /**
- * Disables the logic that prevents hiding the top controls during page load for testing.
- */
- public static void disablePageLoadDelayForTests() {
- sDisableLoadingCheck = true;
- }
+ boolean isShowingBrowserControlsEnabled();
}

Powered by Google App Engine
This is Rietveld 408576698