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

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

Issue 2776243007: Enable WebVR presentation from Chrome Custom Tab (Closed)
Patch Set: Add bug Created 3 years, 9 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/VrProxyActivity.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrProxyActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrProxyActivity.java
new file mode 100644
index 0000000000000000000000000000000000000000..644c14d3ae5959952b406f41a2be4426c709cd07
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrProxyActivity.java
@@ -0,0 +1,60 @@
+// Copyright 2017 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.ActivityManager;
+import android.os.Bundle;
+import android.os.StrictMode;
+
+import org.chromium.base.Log;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+/**
+ * Dispatches incoming intents to the appropriate VR activity based on the VR intent extras.
+ */
+public class VrProxyActivity extends Activity {
+ private static final String TAG = "VrProxyActivity";
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ Log.v(TAG, "VR DON flow success, resuming Chrome in VR.");
+
+ ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
+
+ // TODO(mthiesse): See VrShellDelegate#launchInVR
+ StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
+ StrictMode.allowThreadDiskWrites();
+ File dir = VrShellDelegate.getOrCreateVRDirectory();
+ File tidFile = new File(dir, VrShellDelegate.TID_FILE);
Ted C 2017/03/31 18:17:18 Are we worried about Chrome dying while this is ha
mthiesse 2017/03/31 20:06:14 Wouldn't we have to somehow start the VrProxyActiv
+ File resultFile = new File(dir, VrShellDelegate.RESULT_SUCCESS_FILE);
Ted C 2017/03/31 18:17:18 same thing, are we not calling directly into our o
+ try {
Ted C 2017/03/31 18:17:18 you don't need nested try catches. this can be:
+ try {
+ BufferedReader stream =
+ new BufferedReader(new InputStreamReader(new FileInputStream(tidFile)));
+ String line = stream.readLine();
+ stream.close();
+ if (line == null) throw new IOException();
+ int tid = Integer.parseInt(line);
+ resultFile.createNewFile();
+ finish();
+ activityManager.moveTaskToFront(tid, 0);
Ted C 2017/03/31 18:17:18 does this need to happen after finish? I'm wonder
+ } catch (IOException | NumberFormatException e) {
+ Log.e(TAG, "Failed to read file: " + tidFile.getAbsolutePath());
+ finish();
+ return;
+ }
+ } finally {
+ tidFile.delete();
+ StrictMode.setThreadPolicy(oldPolicy);
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698