Skip to content

Commit b2c1eea

Browse files
author
Michael Thiessen
committed
VR: Disable app button when browsing mode is disabled.
Pressing the app button would try to exit WebVR, which would trigger a non-optional DOFF, which is a really bad user experience. The button should just be disabled when it can't actually take you back to the VR browser. [email protected] (cherry picked from commit a0cdfa5) Bug: 767896 Change-Id: If31a7e8959293efb48618ec40a3cd9e132e92961 Reviewed-on: https://chromium-review.googlesource.com/718986 Reviewed-by: Christopher Grant <[email protected]> Commit-Queue: Michael Thiessen <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#509072} Reviewed-on: https://chromium-review.googlesource.com/726481 Reviewed-by: Michael Thiessen <[email protected]> Cr-Commit-Position: refs/branch-heads/3239@{#54} Cr-Branched-From: adb61db-refs/heads/master@{#508578}
1 parent 2dcf849 commit b2c1eea

File tree

10 files changed

+65
-39
lines changed

10 files changed

+65
-39
lines changed

chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellDelegate.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ private static void unregisterDaydreamIntent(VrDaydreamApi daydreamApi) {
548548
/**
549549
* @return Whether or not VR Shell is currently enabled.
550550
*/
551-
private static boolean isVrShellEnabled(int vrSupportLevel) {
551+
/* package */ static boolean isVrShellEnabled(int vrSupportLevel) {
552552
// Only enable ChromeVR (VrShell) on Daydream devices as it currently needs a Daydream
553553
// controller.
554554
if (vrSupportLevel != VR_DAYDREAM) return false;
@@ -709,6 +709,11 @@ private void updateVrSupportLevel(Integer vrCorePackageVersion) {
709709
mVrSupportLevel = supportLevel;
710710
}
711711

712+
@VrSupportLevel
713+
/* package */ int getVrSupportLevel() {
714+
return mVrSupportLevel;
715+
}
716+
712717
private void onVrServicesMaybeUpdated() {
713718
int vrCorePackageVersion = getVrCorePackageVersion();
714719
if (mCachedVrCorePackageVersion == vrCorePackageVersion) return;

chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellImpl.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,11 @@ public void initializeNative(Tab currentTab, boolean forWebVr,
328328
float displayHeightMeters = (dm.heightPixels / dm.ydpi) * INCHES_TO_METERS;
329329

330330
mContentVrWindowAndroid = new VrWindowAndroid(mActivity, mContentVirtualDisplay);
331+
boolean browsingDisabled = !VrShellDelegate.isVrShellEnabled(mDelegate.getVrSupportLevel());
331332
mNativeVrShell = nativeInit(mDelegate, mContentVrWindowAndroid.getNativePointer(), forWebVr,
332-
webVrAutopresentationExpected, inCct, getGvrApi().getNativeGvrContext(),
333-
mReprojectedRendering, displayWidthMeters, displayHeightMeters, dm.widthPixels,
334-
dm.heightPixels);
333+
webVrAutopresentationExpected, inCct, browsingDisabled,
334+
getGvrApi().getNativeGvrContext(), mReprojectedRendering, displayWidthMeters,
335+
displayHeightMeters, dm.widthPixels, dm.heightPixels);
335336

336337
reparentAllTabs(mContentVrWindowAndroid);
337338
swapToTab(currentTab);
@@ -825,9 +826,10 @@ public View getPresentationViewForTesting() {
825826
}
826827

827828
private native long nativeInit(VrShellDelegate delegate, long nativeWindowAndroid,
828-
boolean forWebVR, boolean webVrAutopresentationExpected, boolean inCct, long gvrApi,
829-
boolean reprojectedRendering, float displayWidthMeters, float displayHeightMeters,
830-
int displayWidthPixels, int displayHeightPixels);
829+
boolean forWebVR, boolean webVrAutopresentationExpected, boolean inCct,
830+
boolean browsingDisabled, long gvrApi, boolean reprojectedRendering,
831+
float displayWidthMeters, float displayHeightMeters, int displayWidthPixels,
832+
int displayHeightPixels);
831833
private native void nativeSetSurface(long nativeVrShell, Surface surface);
832834
private native void nativeSwapContents(
833835
long nativeVrShell, Tab tab, AndroidUiGestureTarget androidUiGestureTarget);

chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/WebVrInputTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.chromium.base.test.util.MinAndroidSdkLevel;
3636
import org.chromium.base.test.util.Restriction;
3737
import org.chromium.base.test.util.RetryOnFailure;
38+
import org.chromium.chrome.browser.ChromeFeatureList;
3839
import org.chromium.chrome.browser.ChromeSwitches;
3940
import org.chromium.chrome.browser.vr_shell.util.VrTestRuleUtils;
4041
import org.chromium.chrome.browser.vr_shell.util.VrTransitionUtils;
@@ -211,6 +212,25 @@ public void testAppButtonExitsPresentation() throws InterruptedException {
211212
POLL_TIMEOUT_SHORT_MS, mVrTestFramework.getFirstTabWebContents()));
212213
}
213214

215+
/**
216+
* Verifies that pressing the Daydream controller's 'app' button does not cause the user to exit
217+
* WebVR presentation when VR browsing is disabled.
218+
*/
219+
@Test
220+
@MediumTest
221+
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
222+
@CommandLineFlags.Add({"disable-features=" + ChromeFeatureList.VR_SHELL})
223+
public void testAppButtonNoopsWhenBrowsingDisabled() throws InterruptedException {
224+
mVrTestFramework.loadUrlAndAwaitInitialization(
225+
VrTestFramework.getHtmlTestFile("generic_webvr_page"), PAGE_LOAD_TIMEOUT_S);
226+
VrTransitionUtils.enterPresentationOrFail(mVrTestFramework.getFirstTabCvc());
227+
EmulatedVrController controller = new EmulatedVrController(mVrTestRule.getActivity());
228+
controller.pressReleaseAppButton();
229+
Assert.assertFalse("App button exited WebVR presentation",
230+
VrTestFramework.pollJavaScriptBoolean("!vrDisplay.isPresenting",
231+
POLL_TIMEOUT_SHORT_MS, mVrTestFramework.getFirstTabWebContents()));
232+
}
233+
214234
/**
215235
* Tests that focus loss updates synchronously.
216236
*/

chrome/browser/android/vr_shell/vr_gl_thread.cc

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "chrome/browser/android/vr_shell/vr_shell_gl.h"
1212
#include "chrome/browser/vr/browser_ui_interface.h"
1313
#include "chrome/browser/vr/toolbar_state.h"
14-
#include "chrome/browser/vr/ui.h"
1514
#include "third_party/skia/include/core/SkBitmap.h"
1615

1716
namespace vr_shell {
@@ -20,18 +19,14 @@ VrGLThread::VrGLThread(
2019
const base::WeakPtr<VrShell>& weak_vr_shell,
2120
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner,
2221
gvr_context* gvr_api,
23-
bool initially_web_vr,
24-
bool web_vr_autopresentation_expected,
25-
bool in_cct,
22+
const vr::UiInitialState& ui_initial_state,
2623
bool reprojected_rendering,
2724
bool daydream_support)
2825
: base::android::JavaHandlerThread("VrShellGL"),
2926
weak_vr_shell_(weak_vr_shell),
3027
main_thread_task_runner_(std::move(main_thread_task_runner)),
3128
gvr_api_(gvr_api),
32-
initially_web_vr_(initially_web_vr),
33-
web_vr_autopresentation_expected_(web_vr_autopresentation_expected),
34-
in_cct_(in_cct),
29+
ui_initial_state_(ui_initial_state),
3530
reprojected_rendering_(reprojected_rendering),
3631
daydream_support_(daydream_support) {}
3732

@@ -44,14 +39,8 @@ base::WeakPtr<VrShellGl> VrGLThread::GetVrShellGl() {
4439
}
4540

4641
void VrGLThread::Init() {
47-
vr::UiInitialState ui_initial_state;
48-
ui_initial_state.in_cct = in_cct_;
49-
ui_initial_state.in_web_vr = initially_web_vr_;
50-
ui_initial_state.web_vr_autopresentation_expected =
51-
web_vr_autopresentation_expected_;
52-
5342
vr_shell_gl_ =
54-
base::MakeUnique<VrShellGl>(this, this, ui_initial_state, gvr_api_,
43+
base::MakeUnique<VrShellGl>(this, this, ui_initial_state_, gvr_api_,
5544
reprojected_rendering_, daydream_support_);
5645

5746
browser_ui_ = vr_shell_gl_->GetBrowserUiWeakPtr();

chrome/browser/android/vr_shell/vr_gl_thread.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "base/single_thread_task_runner.h"
1414
#include "chrome/browser/android/vr_shell/gl_browser_interface.h"
1515
#include "chrome/browser/vr/browser_ui_interface.h"
16+
#include "chrome/browser/vr/ui.h"
1617
#include "chrome/browser/vr/ui_browser_interface.h"
1718
#include "chrome/browser/vr/ui_interface.h"
1819
#include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/gvr_types.h"
@@ -31,9 +32,7 @@ class VrGLThread : public base::android::JavaHandlerThread,
3132
const base::WeakPtr<VrShell>& weak_vr_shell,
3233
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner,
3334
gvr_context* gvr_api,
34-
bool initially_web_vr,
35-
bool web_vr_autopresentation_expected,
36-
bool in_cct,
35+
const vr::UiInitialState& ui_initial_state,
3736
bool reprojected_rendering,
3837
bool daydream_support);
3938

@@ -94,9 +93,7 @@ class VrGLThread : public base::android::JavaHandlerThread,
9493
// This state is used for initializing vr_shell_gl_.
9594
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
9695
gvr_context* gvr_api_;
97-
bool initially_web_vr_;
98-
bool web_vr_autopresentation_expected_;
99-
bool in_cct_;
96+
vr::UiInitialState ui_initial_state_;
10097
bool reprojected_rendering_;
10198
bool daydream_support_;
10299

chrome/browser/android/vr_shell/vr_shell.cc

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ void SetIsInVR(content::WebContents* contents, bool is_in_vr) {
121121
VrShell::VrShell(JNIEnv* env,
122122
const JavaParamRef<jobject>& obj,
123123
ui::WindowAndroid* window,
124-
bool for_web_vr,
125-
bool web_vr_autopresentation_expected,
126-
bool in_cct,
124+
const vr::UiInitialState& ui_initial_state,
127125
VrShellDelegate* delegate,
128126
gvr_context* gvr_api,
129127
bool reprojected_rendering,
@@ -147,15 +145,16 @@ VrShell::VrShell(JNIEnv* env,
147145

148146
gl_thread_ = base::MakeUnique<VrGLThread>(
149147
weak_ptr_factory_.GetWeakPtr(), main_thread_task_runner_, gvr_api,
150-
for_web_vr, web_vr_autopresentation_expected, in_cct,
151-
reprojected_rendering_, HasDaydreamSupport(env));
148+
ui_initial_state, reprojected_rendering_, HasDaydreamSupport(env));
152149
ui_ = gl_thread_.get();
153150
toolbar_ = base::MakeUnique<vr::ToolbarHelper>(ui_, this);
154151

155152
gl_thread_->Start();
156153

157-
if (for_web_vr || web_vr_autopresentation_expected)
158-
UMA_HISTOGRAM_BOOLEAN("VRAutopresentedWebVR", !for_web_vr);
154+
if (ui_initial_state.in_web_vr ||
155+
ui_initial_state.web_vr_autopresentation_expected) {
156+
UMA_HISTOGRAM_BOOLEAN("VRAutopresentedWebVR", !ui_initial_state.in_web_vr);
157+
}
159158
}
160159

161160
void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) {
@@ -868,15 +867,23 @@ jlong Init(JNIEnv* env,
868867
jboolean for_web_vr,
869868
jboolean web_vr_autopresentation_expected,
870869
jboolean in_cct,
870+
jboolean browsing_disabled,
871871
jlong gvr_api,
872872
jboolean reprojected_rendering,
873873
jfloat display_width_meters,
874874
jfloat display_height_meters,
875875
jint display_width_pixels,
876876
jint display_pixel_height) {
877+
vr::UiInitialState ui_initial_state;
878+
ui_initial_state.browsing_disabled = browsing_disabled;
879+
ui_initial_state.in_cct = in_cct;
880+
ui_initial_state.in_web_vr = for_web_vr;
881+
ui_initial_state.web_vr_autopresentation_expected =
882+
web_vr_autopresentation_expected;
883+
877884
return reinterpret_cast<intptr_t>(new VrShell(
878885
env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android),
879-
for_web_vr, web_vr_autopresentation_expected, in_cct,
886+
ui_initial_state,
880887
VrShellDelegate::GetNativeVrShellDelegate(env, delegate),
881888
reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering,
882889
display_width_meters, display_height_meters, display_width_pixels,

chrome/browser/android/vr_shell/vr_shell.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "base/single_thread_task_runner.h"
1616
#include "chrome/browser/ui/toolbar/chrome_toolbar_model_delegate.h"
1717
#include "chrome/browser/vr/exit_vr_prompt_choice.h"
18+
#include "chrome/browser/vr/ui.h"
1819
#include "chrome/browser/vr/ui_unsupported_mode.h"
1920
#include "content/public/browser/web_contents_observer.h"
2021
#include "device/geolocation/public/interfaces/geolocation_config.mojom.h"
@@ -70,9 +71,7 @@ class VrShell : device::GvrGamepadDataProvider,
7071
VrShell(JNIEnv* env,
7172
const base::android::JavaParamRef<jobject>& obj,
7273
ui::WindowAndroid* window,
73-
bool for_web_vr,
74-
bool web_vr_autopresentation_expected,
75-
bool in_cct,
74+
const vr::UiInitialState& ui_initial_state,
7675
VrShellDelegate* delegate,
7776
gvr_context* gvr_api,
7877
bool reprojected_rendering,

chrome/browser/vr/ui.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct UiInitialState {
3030
bool in_cct = false;
3131
bool in_web_vr = false;
3232
bool web_vr_autopresentation_expected = false;
33+
bool browsing_disabled = false;
3334
};
3435

3536
// This class manages all GLThread owned objects and GL rendering for VrShell.

chrome/browser/vr/ui_scene_manager.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ UiSceneManager::UiSceneManager(UiBrowserInterface* browser,
8585
started_for_autopresentation_(
8686
ui_initial_state.web_vr_autopresentation_expected),
8787
showing_web_vr_splash_screen_(
88-
ui_initial_state.web_vr_autopresentation_expected) {
88+
ui_initial_state.web_vr_autopresentation_expected),
89+
browsing_disabled_(ui_initial_state.browsing_disabled) {
8990
Create2dBrowsingSubtreeRoots();
9091
CreateWebVrRoot();
9192
CreateBackground();
@@ -797,6 +798,10 @@ void UiSceneManager::OnAppButtonClicked() {
797798
if (started_for_autopresentation_)
798799
return;
799800

801+
// If browsing mode is disabled, the app button should no-op.
802+
if (browsing_disabled_)
803+
return;
804+
800805
// App button click exits the WebVR presentation and fullscreen.
801806
browser_->ExitPresent();
802807
browser_->ExitFullscreen();

chrome/browser/vr/ui_scene_manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ class UiSceneManager {
194194
bool showing_web_vr_splash_screen_ = false;
195195
bool prompting_to_exit_ = false;
196196
bool exiting_ = false;
197+
bool browsing_disabled_ = false;
197198

198199
bool fullscreen_ = false;
199200
bool incognito_ = false;

0 commit comments

Comments
 (0)