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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellImpl.java

Issue 2891423002: Disable NTP URL bar while in VR on Android. (Closed)
Patch Set: javadoc Created 3 years, 7 months 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.vr_shell; 5 package org.chromium.chrome.browser.vr_shell;
6 6
7 import android.annotation.SuppressLint; 7 import android.annotation.SuppressLint;
8 import android.graphics.Canvas; 8 import android.graphics.Canvas;
9 import android.graphics.Point; 9 import android.graphics.Point;
10 import android.os.StrictMode; 10 import android.os.StrictMode;
(...skipping 11 matching lines...) Expand all
22 22
23 import org.chromium.base.CommandLine; 23 import org.chromium.base.CommandLine;
24 import org.chromium.base.ThreadUtils; 24 import org.chromium.base.ThreadUtils;
25 import org.chromium.base.VisibleForTesting; 25 import org.chromium.base.VisibleForTesting;
26 import org.chromium.base.annotations.CalledByNative; 26 import org.chromium.base.annotations.CalledByNative;
27 import org.chromium.base.annotations.JNINamespace; 27 import org.chromium.base.annotations.JNINamespace;
28 import org.chromium.chrome.browser.ChromeActivity; 28 import org.chromium.chrome.browser.ChromeActivity;
29 import org.chromium.chrome.browser.ChromeSwitches; 29 import org.chromium.chrome.browser.ChromeSwitches;
30 import org.chromium.chrome.browser.NativePage; 30 import org.chromium.chrome.browser.NativePage;
31 import org.chromium.chrome.browser.UrlConstants; 31 import org.chromium.chrome.browser.UrlConstants;
32 import org.chromium.chrome.browser.ntp.NewTabPage;
32 import org.chromium.chrome.browser.tab.EmptyTabObserver; 33 import org.chromium.chrome.browser.tab.EmptyTabObserver;
33 import org.chromium.chrome.browser.tab.Tab; 34 import org.chromium.chrome.browser.tab.Tab;
34 import org.chromium.chrome.browser.tab.TabObserver; 35 import org.chromium.chrome.browser.tab.TabObserver;
35 import org.chromium.chrome.browser.tab.TabRedirectHandler; 36 import org.chromium.chrome.browser.tab.TabRedirectHandler;
36 import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver; 37 import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver;
37 import org.chromium.chrome.browser.tabmodel.TabModel; 38 import org.chromium.chrome.browser.tabmodel.TabModel;
38 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; 39 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType;
39 import org.chromium.chrome.browser.tabmodel.TabModelSelector; 40 import org.chromium.chrome.browser.tabmodel.TabModelSelector;
40 import org.chromium.chrome.browser.tabmodel.TabModelSelectorObserver; 41 import org.chromium.chrome.browser.tabmodel.TabModelSelectorObserver;
41 import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver; 42 import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 // Restore proper focus on the old CVC. 158 // Restore proper focus on the old CVC.
158 if (mContentViewCore != null) mContentViewCore.onWindowFocusChan ged(false); 159 if (mContentViewCore != null) mContentViewCore.onWindowFocusChan ged(false);
159 mContentViewCore = null; 160 mContentViewCore = null;
160 if (mNativeVrShell == 0) return; 161 if (mNativeVrShell == 0) return;
161 if (tab.isShowingSadTab()) { 162 if (tab.isShowingSadTab()) {
162 // For now we don't support the sad tab page. crbug.com/6616 09. 163 // For now we don't support the sad tab page. crbug.com/6616 09.
163 forceExitVr(); 164 forceExitVr();
164 return; 165 return;
165 } 166 }
166 if (mNativePage != null) { 167 if (mNativePage != null) {
167 UiUtils.removeViewFromParent(mNativePage.getView()); 168 restoreNativePageFromVR();
168 mNativePage = null; 169 mNativePage = null;
169 mMotionEventSynthesizer = null;
170 if (tab.getNativePage() == null) { 170 if (tab.getNativePage() == null) {
171 nativeRestoreContentSurface(mNativeVrShell); 171 nativeRestoreContentSurface(mNativeVrShell);
172 mRenderToSurfaceLayoutParent.setVisibility(View.INVISIBL E); 172 mRenderToSurfaceLayoutParent.setVisibility(View.INVISIBL E);
173 mSurface = null; 173 mSurface = null;
174 } 174 }
175 } 175 }
176 if (tab.getNativePage() != null) { 176 if (tab.getNativePage() != null) {
177 mRenderToSurfaceLayoutParent.setVisibility(View.VISIBLE); 177 mRenderToSurfaceLayoutParent.setVisibility(View.VISIBLE);
178 mNativePage = tab.getNativePage(); 178 mNativePage = tab.getNativePage();
179 initializeNativePageForVR();
179 if (mSurface == null) mSurface = nativeTakeContentSurface(mN ativeVrShell); 180 if (mSurface == null) mSurface = nativeTakeContentSurface(mN ativeVrShell);
180 mRenderToSurfaceLayout.addView(mNativePage.getView(),
181 new FrameLayout.LayoutParams(
182 LayoutParams.MATCH_PARENT, LayoutParams.MATC H_PARENT));
183 mNativePage.getView().invalidate();
184 mMotionEventSynthesizer =
185 new MotionEventSynthesizer(mRenderToSurfaceLayout, V rShellImpl.this);
186 } 181 }
187 setContentCssSize(mLastContentWidth, mLastContentHeight, mLastCo ntentDpr); 182 setContentCssSize(mLastContentWidth, mLastContentHeight, mLastCo ntentDpr);
188 if (tab.getNativePage() == null && tab.getContentViewCore() != n ull) { 183 if (tab.getNativePage() == null && tab.getContentViewCore() != n ull) {
189 mContentViewCore = tab.getContentViewCore(); 184 mContentViewCore = tab.getContentViewCore();
190 mContentViewCore.onAttachedToWindow(); 185 mContentViewCore.onAttachedToWindow();
191 mContentViewCore.getContainerView().requestFocus(); 186 mContentViewCore.getContainerView().requestFocus();
192 // We need the CVC to think it has Window Focus so it doesn' t blur the page, 187 // We need the CVC to think it has Window Focus so it doesn' t blur the page,
193 // even though we're drawing VR layouts over top of it. 188 // even though we're drawing VR layouts over top of it.
194 mContentViewCore.onWindowFocusChanged(true); 189 mContentViewCore.onWindowFocusChanged(true);
195 nativeSwapContents(mNativeVrShell, mContentViewCore.getWebCo ntents(), null); 190 nativeSwapContents(mNativeVrShell, mContentViewCore.getWebCo ntents(), null);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 public boolean onPreDraw() { 262 public boolean onPreDraw() {
268 if (mRenderToSurfaceLayout.isDirty()) { 263 if (mRenderToSurfaceLayout.isDirty()) {
269 mRenderToSurfaceLayout.invalidate(); 264 mRenderToSurfaceLayout.invalidate();
270 if (mNativePage != null) mNativePage.getView().invalidate(); 265 if (mNativePage != null) mNativePage.getView().invalidate();
271 } 266 }
272 return true; 267 return true;
273 } 268 }
274 }); 269 });
275 mRenderToSurfaceLayoutParent.addView(mRenderToSurfaceLayout); 270 mRenderToSurfaceLayoutParent.addView(mRenderToSurfaceLayout);
276 addView(mRenderToSurfaceLayoutParent); 271 addView(mRenderToSurfaceLayoutParent);
272 mMotionEventSynthesizer =
273 new MotionEventSynthesizer(mRenderToSurfaceLayout, VrShellImpl.t his);
277 } 274 }
278 275
279 @Override 276 @Override
280 public void initializeNative(Tab currentTab, boolean forWebVr, boolean inCct ) { 277 public void initializeNative(Tab currentTab, boolean forWebVr, boolean inCct ) {
281 mContentVrWindowAndroid = new VrWindowAndroid(mActivity, mContentVirtual Display); 278 mContentVrWindowAndroid = new VrWindowAndroid(mActivity, mContentVirtual Display);
282 mNativeVrShell = nativeInit(mDelegate, mContentVrWindowAndroid.getNative Pointer(), forWebVr, 279 mNativeVrShell = nativeInit(mDelegate, mContentVrWindowAndroid.getNative Pointer(), forWebVr,
283 inCct, getGvrApi().getNativeGvrContext(), mReprojectedRendering) ; 280 inCct, getGvrApi().getNativeGvrContext(), mReprojectedRendering) ;
284 281
285 // Set the UI and content sizes before we load the UI. 282 // Set the UI and content sizes before we load the UI.
286 if (forWebVr) { 283 if (forWebVr) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 mTab.setTabRedirectHandler(mTabRedirectHandler); 342 mTab.setTabRedirectHandler(mTabRedirectHandler);
346 } 343 }
347 344
348 private void restoreTabFromVR() { 345 private void restoreTabFromVR() {
349 mTab.setTabRedirectHandler(mNonVrTabRedirectHandler); 346 mTab.setTabRedirectHandler(mNonVrTabRedirectHandler);
350 mTab.updateWindowAndroid(mOriginalWindowAndroid); 347 mTab.updateWindowAndroid(mOriginalWindowAndroid);
351 mOriginalWindowAndroid = null; 348 mOriginalWindowAndroid = null;
352 mNonVrTabRedirectHandler = null; 349 mNonVrTabRedirectHandler = null;
353 } 350 }
354 351
352 private void initializeNativePageForVR() {
353 if (mNativePage instanceof NewTabPage) {
354 ((NewTabPage) mNativePage).setUrlBarInputEnabled(false);
355 }
356 mRenderToSurfaceLayout.addView(mNativePage.getView(),
357 new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutPa rams.MATCH_PARENT));
358 mNativePage.getView().invalidate();
359 mRenderToSurfaceLayout.invalidate();
360 }
361
362 private void restoreNativePageFromVR() {
363 if (mNativePage instanceof NewTabPage) {
364 ((NewTabPage) mNativePage).setUrlBarInputEnabled(true);
365 }
366 UiUtils.removeViewFromParent(mNativePage.getView());
367 }
368
355 // Exits VR, telling the user to remove their headset, and returning to Chro mium. 369 // Exits VR, telling the user to remove their headset, and returning to Chro mium.
356 @CalledByNative 370 @CalledByNative
357 public void forceExitVr() { 371 public void forceExitVr() {
358 mDelegate.shutdownVr(false /* isPausing */, true /* showTransition */); 372 mDelegate.shutdownVr(false /* isPausing */, true /* showTransition */);
359 } 373 }
360 374
361 @CalledByNative 375 @CalledByNative
362 public void setContentCssSize(float width, float height, float dpr) { 376 public void setContentCssSize(float width, float height, float dpr) {
363 ThreadUtils.assertOnUiThread(); 377 ThreadUtils.assertOnUiThread();
364 mLastContentWidth = width; 378 mLastContentWidth = width;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 nativeOnPause(mNativeVrShell); 461 nativeOnPause(mNativeVrShell);
448 } 462 }
449 } 463 }
450 464
451 @Override 465 @Override
452 public void shutdown() { 466 public void shutdown() {
453 if (mNativeVrShell != 0) { 467 if (mNativeVrShell != 0) {
454 nativeDestroy(mNativeVrShell); 468 nativeDestroy(mNativeVrShell);
455 mNativeVrShell = 0; 469 mNativeVrShell = 0;
456 } 470 }
457 if (mNativePage != null) UiUtils.removeViewFromParent(mNativePage.getVie w()); 471 if (mNativePage != null) restoreNativePageFromVR();
458 mTabModelSelector.removeObserver(mTabModelSelectorObserver); 472 mTabModelSelector.removeObserver(mTabModelSelectorObserver);
459 mTabModelSelectorTabObserver.destroy(); 473 mTabModelSelectorTabObserver.destroy();
460 mTab.removeObserver(mTabObserver); 474 mTab.removeObserver(mTabObserver);
461 restoreTabFromVR(); 475 restoreTabFromVR();
462 mContentVirtualDisplay.destroy(); 476 mContentVirtualDisplay.destroy();
463 super.shutdown(); 477 super.shutdown();
464 } 478 }
465 479
466 @Override 480 @Override
467 public void pause() { 481 public void pause() {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 private native void nativeOnTabListCreated(long nativeVrShell, Tab[] mainTab s, 642 private native void nativeOnTabListCreated(long nativeVrShell, Tab[] mainTab s,
629 Tab[] incognitoTabs); 643 Tab[] incognitoTabs);
630 private native void nativeOnTabUpdated(long nativeVrShell, boolean incognito , int id, 644 private native void nativeOnTabUpdated(long nativeVrShell, boolean incognito , int id,
631 String title); 645 String title);
632 private native void nativeOnTabRemoved(long nativeVrShell, boolean incognito , int id); 646 private native void nativeOnTabRemoved(long nativeVrShell, boolean incognito , int id);
633 private native Surface nativeTakeContentSurface(long nativeVrShell); 647 private native Surface nativeTakeContentSurface(long nativeVrShell);
634 private native void nativeRestoreContentSurface(long nativeVrShell); 648 private native void nativeRestoreContentSurface(long nativeVrShell);
635 private native void nativeSetHistoryButtonsEnabled( 649 private native void nativeSetHistoryButtonsEnabled(
636 long nativeVrShell, boolean canGoBack, boolean canGoForward); 650 long nativeVrShell, boolean canGoBack, boolean canGoForward);
637 } 651 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698