Commit 8731d22c authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

VR: Open NTP when we enter VR with no tabs.

Bug: 740731
Change-Id: I7183ebf13db7a317947c3c0aa5b40080258dd60a
Reviewed-on: https://chromium-review.googlesource.com/899782Reviewed-by: default avatarYash Malik <ymalik@chromium.org>
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#534155}
parent d205c1a2
......@@ -48,7 +48,6 @@ import org.chromium.chrome.browser.ApplicationLifetime;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.UrlConstants;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
import org.chromium.chrome.browser.help.HelpAndFeedback;
import org.chromium.chrome.browser.infobar.InfoBarIdentifier;
......@@ -1098,17 +1097,6 @@ public class VrShellDelegate
boolean presenting = mRequestedWebVr || mListeningForWebVrActivate
|| (justCompletedDon && mListeningForWebVrActivateBeforePause) || mAutopresentWebVr;
if (!isVrShellEnabled(mVrSupportLevel) && !presenting) return false;
// TODO(mthiesse): We don't want to show the tab switcher in VR, and there's no easy way to
// exit it right now.
if (mActivity.isInOverviewMode() && mActivity.getCurrentTabModel().getCount() != 0) {
return false;
}
Tab tab = mActivity.getActivityTab();
if (tab != null && tab.isNativePage()
&& tab.getNativePage().getHost() == UrlConstants.NTP_HOST) {
return false;
}
return true;
}
......
......@@ -25,6 +25,7 @@ import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.ChromeTabbedActivity;
......@@ -48,6 +49,7 @@ import org.chromium.chrome.browser.tabmodel.TabModelSelectorObserver;
import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver;
import org.chromium.chrome.browser.tabmodel.TabModelUtils;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet;
import org.chromium.chrome.browser.widget.newtab.NewTabButton;
import org.chromium.content.browser.ContentViewCore;
import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.ui.base.WindowAndroid;
......@@ -92,6 +94,7 @@ public class VrShellImpl extends GvrLayout implements VrShell, SurfaceHolder.Cal
private InterceptNavigationDelegateImpl mNonVrInterceptNavigationDelegate;
private TabRedirectHandler mNonVrTabRedirectHandler;
private TabModelSelector mTabModelSelector;
private float mLastContentWidth;
private float mLastContentHeight;
......@@ -126,6 +129,7 @@ public class VrShellImpl extends GvrLayout implements VrShell, SurfaceHolder.Cal
mContentVirtualDisplay.setTo(primaryDisplay);
mContentVrWindowAndroid = new VrWindowAndroid(mActivity, mContentVirtualDisplay);
reparentAllTabs(mContentVrWindowAndroid);
mCompositorView = mActivity.getCompositorViewHolder().getCompositorView();
mVrCompositorSurfaceManager = new VrCompositorSurfaceManager(mCompositorView);
......@@ -294,8 +298,13 @@ public class VrShellImpl extends GvrLayout implements VrShell, SurfaceHolder.Cal
@SuppressLint("NewApi")
public void initializeNative(Tab currentTab, boolean forWebVr,
boolean webVrAutopresentationExpected, boolean inCct) {
// Make sure the bottom sheet (Chrome Home) is hidden.
Tab tab = mActivity.getActivityTab();
if (mActivity.isInOverviewMode() || tab == null) {
launchNTP();
tab = mActivity.getActivityTab();
}
if (mActivity.getBottomSheet() != null) {
// Make sure the bottom sheet (Chrome Home) is hidden.
mActivity.getBottomSheet().setSheetState(BottomSheet.SHEET_STATE_PEEK, false);
}
......@@ -315,7 +324,6 @@ public class VrShellImpl extends GvrLayout implements VrShell, SurfaceHolder.Cal
getGvrApi().getNativeGvrContext(), mReprojectedRendering, displayWidthMeters,
displayHeightMeters, dm.widthPixels, dm.heightPixels);
reparentAllTabs(mContentVrWindowAndroid);
swapToTab(currentTab);
createTabList();
mActivity.getTabModelSelector().addObserver(mTabModelSelectorObserver);
......@@ -871,6 +879,11 @@ public class VrShellImpl extends GvrLayout implements VrShell, SurfaceHolder.Cal
/ mContentVrWindowAndroid.getDisplay().getDipScale();
}
private void launchNTP() {
NewTabButton button = (NewTabButton) mActivity.findViewById(R.id.new_tab_button);
button.callOnClick();
}
/**
* Sets the callback that will be run when VrShellImpl's dispatchTouchEvent
* is run and the parent consumed the event.
......
......@@ -43,7 +43,6 @@ import org.chromium.content.browser.test.util.DOMUtils;
import java.lang.ref.WeakReference;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicReference;
......@@ -291,7 +290,7 @@ public class VrShellTransitionTest {
}
/**
* Tests that you can't enter VR in Overview mode with tabs.
* Tests that you can enter VR in Overview mode, and the NTP shows up.
*/
@Test
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
......@@ -307,20 +306,6 @@ public class VrShellTransitionTest {
});
Assert.assertTrue(activity.isInOverviewMode());
Assert.assertFalse(VrTransitionUtils.forceEnterVr());
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
activity.getTabModelSelector().closeAllTabs();
}
});
CriteriaHelper.pollUiThread(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return activity.getCurrentTabModel().getCount() == 0;
}
});
MockVrDaydreamApi mockApi = new MockVrDaydreamApi();
VrShellDelegateUtils.getDelegateInstance().overrideDaydreamApiForTesting(mockApi);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment