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

Side by Side Diff: chrome/browser/android/vr_shell/vr_shell_delegate.cc

Issue 2701523008: Intercept WebVR api calls and check for VrCore compatibility. (Closed)
Patch Set: Created 3 years, 10 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 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" 5 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "chrome/browser/android/vr_shell/non_presenting_gvr_delegate.h" 10 #include "chrome/browser/android/vr_shell/non_presenting_gvr_delegate.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 } 118 }
119 } 119 }
120 120
121 void VrShellDelegate::ShowTab(int id) { 121 void VrShellDelegate::ShowTab(int id) {
122 JNIEnv* env = AttachCurrentThread(); 122 JNIEnv* env = AttachCurrentThread();
123 Java_VrShellDelegate_showTab(env, j_vr_shell_delegate_.obj(), id); 123 Java_VrShellDelegate_showTab(env, j_vr_shell_delegate_.obj(), id);
124 } 124 }
125 125
126 void VrShellDelegate::SetDeviceProvider( 126 void VrShellDelegate::SetDeviceProvider(
127 device::GvrDeviceProvider* device_provider) { 127 device::GvrDeviceProvider* device_provider) {
128 JNIEnv* env = AttachCurrentThread();
129 bool vrCorecompatible = static_cast<bool>(
130 Java_VrShellDelegate_isVrCoreCompatible(env, j_vr_shell_delegate_.obj()));
131 if (!vrCorecompatible)
132 return;
133
128 CHECK(!device_provider_); 134 CHECK(!device_provider_);
129 device_provider_ = device_provider; 135 device_provider_ = device_provider;
130 if (!delegate_) 136 if (!delegate_)
131 CreateNonPresentingDelegate(); 137 CreateNonPresentingDelegate();
132 device_provider_->Device()->OnDelegateChanged(); 138 device_provider_->Device()->OnDelegateChanged();
133 } 139 }
134 140
135 void VrShellDelegate::ClearDeviceProvider() { 141 void VrShellDelegate::ClearDeviceProvider() {
136 non_presenting_delegate_ = nullptr; 142 // Clean up the non-presenting delegate.
137 JNIEnv* env = AttachCurrentThread(); 143 if (non_presenting_delegate_) {
138 Java_VrShellDelegate_shutdownNonPresentingNativeContext( 144 non_presenting_delegate_ = nullptr;
139 env, j_vr_shell_delegate_.obj()); 145 JNIEnv* env = AttachCurrentThread();
140 device_provider_->Device()->OnDelegateChanged(); 146 Java_VrShellDelegate_shutdownNonPresentingNativeContext(
147 env, j_vr_shell_delegate_.obj());
148 device_provider_->Device()->OnDelegateChanged();
149 }
141 device_provider_ = nullptr; 150 device_provider_ = nullptr;
142 } 151 }
143 152
144 void VrShellDelegate::RequestWebVRPresent( 153 void VrShellDelegate::RequestWebVRPresent(
145 const base::Callback<void(bool)>& callback) { 154 const base::Callback<void(bool)>& callback) {
146 if (!present_callback_.is_null()) { 155 if (!present_callback_.is_null()) {
147 // Can only handle one request at a time. This is also extremely unlikely to 156 // Can only handle one request at a time. This is also extremely unlikely to
148 // happen in practice. 157 // happen in practice.
149 callback.Run(false); 158 callback.Run(false);
150 return; 159 return;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 214
206 bool RegisterVrShellDelegate(JNIEnv* env) { 215 bool RegisterVrShellDelegate(JNIEnv* env) {
207 return RegisterNativesImpl(env); 216 return RegisterNativesImpl(env);
208 } 217 }
209 218
210 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { 219 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) {
211 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj)); 220 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj));
212 } 221 }
213 222
214 } // namespace vr_shell 223 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698