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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrWindowAndroid.java

Issue 2319863005: Implement new compositor and ContentViewCore reparenting for VR Shell. (Closed)
Patch Set: Rebase onto ToT Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrWindowAndroid.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrWindowAndroid.java b/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrWindowAndroid.java
new file mode 100644
index 0000000000000000000000000000000000000000..303d24d6e8603939e92664fb782b0782d1e1e5fa
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrWindowAndroid.java
@@ -0,0 +1,106 @@
+// 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.vr_shell;
+
+import android.app.Activity;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.os.Process;
+
+import org.chromium.base.ActivityState;
+import org.chromium.base.ApiCompatibilityUtils;
+import org.chromium.base.ApplicationStatus;
+import org.chromium.base.Callback;
+import org.chromium.ui.base.AndroidPermissionDelegate;
+import org.chromium.ui.base.WindowAndroid;
+
+import java.lang.ref.WeakReference;
+import java.util.Arrays;
+
+/**
+ * The class provides the WindowAndroid's implementation which requires Activity Instance. It is
+ * only intended to be used when in VR.
+ */
+public class VrWindowAndroid
+ extends WindowAndroid
+ implements ApplicationStatus.ActivityStateListener {
+
+ public VrWindowAndroid(Context context) {
+ super(context);
+ Activity activity = activityFromContext(context);
+ if (activity == null) {
+ throw new IllegalArgumentException("Context is not and does not wrap an Activity");
+ }
+ ApplicationStatus.registerStateListenerForActivity(this, activity);
+ setAndroidPermissionDelegate(new ActivityAndroidPermissionDelegate());
+ }
+
+ // TODO(mthiesse): How do we want to handle intents that might kick us out of VR?
+ @Override
+ public int showCancelableIntent(
+ PendingIntent intent, IntentCallback callback, Integer errorId) {
+ return START_INTENT_FAILURE;
+ }
+
+ @Override
+ public int showCancelableIntent(Intent intent, IntentCallback callback, Integer errorId) {
+ return START_INTENT_FAILURE;
+ }
+
+ @Override
+ public int showCancelableIntent(Callback<Integer> intentTrigger, IntentCallback callback,
+ Integer errorId) {
+ return START_INTENT_FAILURE;
+ }
+
+ @Override
+ public void cancelIntent(int requestCode) {}
+
+ @Override
+ public WeakReference<Activity> getActivity() {
+ return new WeakReference<>(activityFromContext(getContext().get()));
+ }
+
+ @Override
+ public void onActivityStateChange(Activity activity, int newState) {
+ if (newState == ActivityState.STOPPED) {
+ onActivityStopped();
+ } else if (newState == ActivityState.STARTED) {
+ onActivityStarted();
+ }
+ }
+
+ // We can't request permissions inside of VR without getting kicked out of VR.
+ // TODO(mthiesse): Should we add some UI to ask the user to exit VR, then accept the permission?
+ // There's also the possibility that GVR will handle this in the future.
+ private class ActivityAndroidPermissionDelegate implements AndroidPermissionDelegate {
+ @Override
+ public boolean hasPermission(String permission) {
+ return ApiCompatibilityUtils.checkPermission(
+ mApplicationContext, permission, Process.myPid(), Process.myUid())
+ == PackageManager.PERMISSION_GRANTED;
+ }
+
+ @Override
+ public boolean canRequestPermission(String permission) {
+ return false;
+ }
+
+ @Override
+ public boolean isPermissionRevokedByPolicy(String permission) {
+ return false;
+ }
+
+ @Override
+ public void requestPermissions(
+ final String[] permissions, final PermissionCallback callback) {
+ int[] grantResults = new int[permissions.length];
+ Arrays.fill(grantResults, PackageManager.PERMISSION_DENIED);
+ callback.onRequestPermissionsResult(permissions, grantResults);
+ }
+ }
+}
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellInterface.java ('k') | chrome/android/java_sources.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698