| OLD | NEW |
| 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; |
| 11 import android.view.MotionEvent; | 11 import android.view.MotionEvent; |
| 12 import android.view.Surface; | 12 import android.view.Surface; |
| 13 import android.view.SurfaceHolder; | 13 import android.view.SurfaceHolder; |
| 14 import android.view.SurfaceView; | 14 import android.view.SurfaceView; |
| 15 import android.view.View; | 15 import android.view.View; |
| 16 import android.view.ViewTreeObserver.OnPreDrawListener; | 16 import android.view.ViewTreeObserver.OnPreDrawListener; |
| 17 import android.widget.FrameLayout; | 17 import android.widget.FrameLayout; |
| 18 import android.widget.FrameLayout.LayoutParams; | 18 import android.widget.FrameLayout.LayoutParams; |
| 19 | 19 |
| 20 import com.google.vr.ndk.base.AndroidCompat; | 20 import com.google.vr.ndk.base.AndroidCompat; |
| 21 import com.google.vr.ndk.base.GvrLayout; | 21 import com.google.vr.ndk.base.GvrLayout; |
| 22 | 22 |
| 23 import org.chromium.base.CommandLine; | 23 import org.chromium.base.CommandLine; |
| 24 import org.chromium.base.Log; | 24 import org.chromium.base.Log; |
| 25 import org.chromium.base.ThreadUtils; | 25 import org.chromium.base.ThreadUtils; |
| 26 import org.chromium.base.VisibleForTesting; | |
| 27 import org.chromium.base.annotations.CalledByNative; | 26 import org.chromium.base.annotations.CalledByNative; |
| 28 import org.chromium.base.annotations.JNINamespace; | 27 import org.chromium.base.annotations.JNINamespace; |
| 29 import org.chromium.chrome.browser.ChromeActivity; | 28 import org.chromium.chrome.browser.ChromeActivity; |
| 30 import org.chromium.chrome.browser.ChromeSwitches; | 29 import org.chromium.chrome.browser.ChromeSwitches; |
| 31 import org.chromium.chrome.browser.ChromeVersionInfo; | 30 import org.chromium.chrome.browser.ChromeVersionInfo; |
| 32 import org.chromium.chrome.browser.NativePage; | 31 import org.chromium.chrome.browser.NativePage; |
| 33 import org.chromium.chrome.browser.UrlConstants; | 32 import org.chromium.chrome.browser.UrlConstants; |
| 34 import org.chromium.chrome.browser.WebContentsFactory; | 33 import org.chromium.chrome.browser.WebContentsFactory; |
| 35 import org.chromium.chrome.browser.omnibox.geo.GeolocationHeader; | 34 import org.chromium.chrome.browser.omnibox.geo.GeolocationHeader; |
| 36 import org.chromium.chrome.browser.tab.EmptyTabObserver; | 35 import org.chromium.chrome.browser.tab.EmptyTabObserver; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 private boolean mReprojectedRendering; | 111 private boolean mReprojectedRendering; |
| 113 | 112 |
| 114 private TabRedirectHandler mNonVrTabRedirectHandler; | 113 private TabRedirectHandler mNonVrTabRedirectHandler; |
| 115 private TabModelSelector mTabModelSelector; | 114 private TabModelSelector mTabModelSelector; |
| 116 private float mLastContentWidth; | 115 private float mLastContentWidth; |
| 117 private float mLastContentHeight; | 116 private float mLastContentHeight; |
| 118 private float mLastContentDpr; | 117 private float mLastContentDpr; |
| 119 | 118 |
| 120 private MotionEventSynthesizer mMotionEventSynthesizer; | 119 private MotionEventSynthesizer mMotionEventSynthesizer; |
| 121 | 120 |
| 122 private OnDispatchTouchEventCallback mOnDispatchTouchEventForTesting; | |
| 123 | |
| 124 public VrShellImpl( | 121 public VrShellImpl( |
| 125 ChromeActivity activity, VrShellDelegate delegate, TabModelSelector
tabModelSelector) { | 122 ChromeActivity activity, VrShellDelegate delegate, TabModelSelector
tabModelSelector) { |
| 126 super(activity); | 123 super(activity); |
| 127 mActivity = activity; | 124 mActivity = activity; |
| 128 mDelegate = delegate; | 125 mDelegate = delegate; |
| 129 mTabModelSelector = tabModelSelector; | 126 mTabModelSelector = tabModelSelector; |
| 130 mUiCVCContainer = new FrameLayout(getContext()) { | 127 mUiCVCContainer = new FrameLayout(getContext()) { |
| 131 @Override | 128 @Override |
| 132 public boolean dispatchTouchEvent(MotionEvent event) { | 129 public boolean dispatchTouchEvent(MotionEvent event) { |
| 133 return true; | 130 return true; |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 if (mSurface != null || mNativePage == null) return; | 436 if (mSurface != null || mNativePage == null) return; |
| 440 mSurface = nativeTakeContentSurface(mNativeVrShell); | 437 mSurface = nativeTakeContentSurface(mNativeVrShell); |
| 441 mNativePage.getView().invalidate(); | 438 mNativePage.getView().invalidate(); |
| 442 } | 439 } |
| 443 | 440 |
| 444 @Override | 441 @Override |
| 445 public boolean dispatchTouchEvent(MotionEvent event) { | 442 public boolean dispatchTouchEvent(MotionEvent event) { |
| 446 // Normally, touch event is dispatched to presentation view only if the
phone is paired with | 443 // Normally, touch event is dispatched to presentation view only if the
phone is paired with |
| 447 // a Cardboard viewer. This is annoying when we just want to quickly ver
ify a Cardboard | 444 // a Cardboard viewer. This is annoying when we just want to quickly ver
ify a Cardboard |
| 448 // behavior. This allows us to trigger cardboard trigger event without p
air to a Cardboard. | 445 // behavior. This allows us to trigger cardboard trigger event without p
air to a Cardboard. |
| 449 boolean cardboardTriggered = false; | |
| 450 if (CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_VR_SHELL_D
EV) | 446 if (CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_VR_SHELL_D
EV) |
| 451 && event.getActionMasked() == MotionEvent.ACTION_DOWN) { | 447 && event.getActionMasked() == MotionEvent.ACTION_DOWN) { |
| 452 nativeOnTriggerEvent(mNativeVrShell); | 448 nativeOnTriggerEvent(mNativeVrShell); |
| 453 cardboardTriggered = true; | |
| 454 } | 449 } |
| 455 boolean parentConsumed = super.dispatchTouchEvent(event); | 450 return super.dispatchTouchEvent(event); |
| 456 if (mOnDispatchTouchEventForTesting != null) { | |
| 457 mOnDispatchTouchEventForTesting.onDispatchTouchEvent( | |
| 458 parentConsumed, cardboardTriggered); | |
| 459 } | |
| 460 return parentConsumed; | |
| 461 } | 451 } |
| 462 | 452 |
| 463 @Override | 453 @Override |
| 464 public void onResume() { | 454 public void onResume() { |
| 465 super.onResume(); | 455 super.onResume(); |
| 466 if (mNativeVrShell != 0) { | 456 if (mNativeVrShell != 0) { |
| 467 // Refreshing the viewer profile accesses disk, so we need to tempor
arily allow disk | 457 // Refreshing the viewer profile accesses disk, so we need to tempor
arily allow disk |
| 468 // reads. The GVR team promises this will be fixed when they launch. | 458 // reads. The GVR team promises this will be fixed when they launch. |
| 469 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(
); | 459 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(
); |
| 470 try { | 460 try { |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 public WindowAndroid getWindowAndroid() { | 621 public WindowAndroid getWindowAndroid() { |
| 632 return mContentVrWindowAndroid; | 622 return mContentVrWindowAndroid; |
| 633 } | 623 } |
| 634 | 624 |
| 635 @Override | 625 @Override |
| 636 public void addWindowAndroidChangedObserver(WindowAndroidChangedObserver obs
erver) {} | 626 public void addWindowAndroidChangedObserver(WindowAndroidChangedObserver obs
erver) {} |
| 637 | 627 |
| 638 @Override | 628 @Override |
| 639 public void removeWindowAndroidChangedObserver(WindowAndroidChangedObserver
observer) {} | 629 public void removeWindowAndroidChangedObserver(WindowAndroidChangedObserver
observer) {} |
| 640 | 630 |
| 641 /** | |
| 642 * Sets the runnable that will be run when VrShellImpl's dispatchTouchEvent | |
| 643 * is run and the parent consumed the event. | |
| 644 * @param runnable The Runnable that will be run | |
| 645 */ | |
| 646 @VisibleForTesting | |
| 647 public void setOnDispatchTouchEventForTesting(OnDispatchTouchEventCallback c
allback) { | |
| 648 mOnDispatchTouchEventForTesting = callback; | |
| 649 } | |
| 650 | |
| 651 private native long nativeInit(WebContents uiWebContents, long nativeContent
WindowAndroid, | 631 private native long nativeInit(WebContents uiWebContents, long nativeContent
WindowAndroid, |
| 652 long nativeUiWindowAndroid, boolean forWebVR, VrShellDelegate delega
te, long gvrApi, | 632 long nativeUiWindowAndroid, boolean forWebVR, VrShellDelegate delega
te, long gvrApi, |
| 653 boolean reprojectedRendering); | 633 boolean reprojectedRendering); |
| 654 private native void nativeSetSurface(long nativeVrShell, Surface surface); | 634 private native void nativeSetSurface(long nativeVrShell, Surface surface); |
| 655 private native void nativeSwapContents( | 635 private native void nativeSwapContents( |
| 656 long nativeVrShell, WebContents webContents, MotionEventSynthesizer
eventSynthesizer); | 636 long nativeVrShell, WebContents webContents, MotionEventSynthesizer
eventSynthesizer); |
| 657 private native void nativeLoadUIContent(long nativeVrShell); | 637 private native void nativeLoadUIContent(long nativeVrShell); |
| 658 private native void nativeDestroy(long nativeVrShell); | 638 private native void nativeDestroy(long nativeVrShell); |
| 659 private native void nativeOnTriggerEvent(long nativeVrShell); | 639 private native void nativeOnTriggerEvent(long nativeVrShell); |
| 660 private native void nativeOnPause(long nativeVrShell); | 640 private native void nativeOnPause(long nativeVrShell); |
| 661 private native void nativeOnResume(long nativeVrShell); | 641 private native void nativeOnResume(long nativeVrShell); |
| 662 private native void nativeOnLoadProgressChanged(long nativeVrShell, double p
rogress); | 642 private native void nativeOnLoadProgressChanged(long nativeVrShell, double p
rogress); |
| 663 private native void nativeContentPhysicalBoundsChanged(long nativeVrShell, i
nt width, | 643 private native void nativeContentPhysicalBoundsChanged(long nativeVrShell, i
nt width, |
| 664 int height, float dpr); | 644 int height, float dpr); |
| 665 private native void nativeUIPhysicalBoundsChanged(long nativeVrShell, int wi
dth, int height, | 645 private native void nativeUIPhysicalBoundsChanged(long nativeVrShell, int wi
dth, int height, |
| 666 float dpr); | 646 float dpr); |
| 667 private native void nativeSetWebVrMode(long nativeVrShell, boolean enabled); | 647 private native void nativeSetWebVrMode(long nativeVrShell, boolean enabled); |
| 668 private native void nativeOnTabListCreated(long nativeVrShell, Tab[] mainTab
s, | 648 private native void nativeOnTabListCreated(long nativeVrShell, Tab[] mainTab
s, |
| 669 Tab[] incognitoTabs); | 649 Tab[] incognitoTabs); |
| 670 private native void nativeOnTabUpdated(long nativeVrShell, boolean incognito
, int id, | 650 private native void nativeOnTabUpdated(long nativeVrShell, boolean incognito
, int id, |
| 671 String title); | 651 String title); |
| 672 private native void nativeOnTabRemoved(long nativeVrShell, boolean incognito
, int id); | 652 private native void nativeOnTabRemoved(long nativeVrShell, boolean incognito
, int id); |
| 673 private native Surface nativeTakeContentSurface(long nativeVrShell); | 653 private native Surface nativeTakeContentSurface(long nativeVrShell); |
| 674 private native void nativeRestoreContentSurface(long nativeVrShell); | 654 private native void nativeRestoreContentSurface(long nativeVrShell); |
| 675 private native void nativeSetHistoryButtonsEnabled( | 655 private native void nativeSetHistoryButtonsEnabled( |
| 676 long nativeVrShell, boolean canGoBack, boolean canGoForward); | 656 long nativeVrShell, boolean canGoBack, boolean canGoForward); |
| 677 } | 657 } |
| OLD | NEW |