Chromium Code Reviews| 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 #include "chrome/browser/android/vr_shell/vr_shell.h" | 5 #include "chrome/browser/android/vr_shell/vr_shell.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "chrome/browser/android/vr_shell/ui_elements.h" | 8 #include "chrome/browser/android/vr_shell/ui_elements.h" |
| 9 #include "chrome/browser/android/vr_shell/ui_interface.h" | 9 #include "chrome/browser/android/vr_shell/ui_interface.h" |
| 10 #include "chrome/browser/android/vr_shell/ui_scene.h" | 10 #include "chrome/browser/android/vr_shell/ui_scene.h" |
| 11 #include "chrome/browser/android/vr_shell/vr_compositor.h" | 11 #include "chrome/browser/android/vr_shell/vr_compositor.h" |
| 12 #include "chrome/browser/android/vr_shell/vr_controller.h" | 12 #include "chrome/browser/android/vr_shell/vr_controller.h" |
| 13 #include "chrome/browser/android/vr_shell/vr_gl_util.h" | 13 #include "chrome/browser/android/vr_shell/vr_gl_util.h" |
| 14 #include "chrome/browser/android/vr_shell/vr_input_manager.h" | 14 #include "chrome/browser/android/vr_shell/vr_input_manager.h" |
| 15 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" | 15 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" |
| 16 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" | 16 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" |
| 17 #include "chrome/browser/android/vr_shell/vr_usage_monitor.h" | 17 #include "chrome/browser/android/vr_shell/vr_usage_monitor.h" |
| 18 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h" | 18 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "components/rappor/rappor_utils.h" | 20 #include "components/rappor/rappor_utils.h" |
| 21 #include "content/public/browser/browser_thread.h" | |
| 21 #include "content/public/browser/navigation_controller.h" | 22 #include "content/public/browser/navigation_controller.h" |
| 22 #include "content/public/browser/render_view_host.h" | 23 #include "content/public/browser/render_view_host.h" |
| 23 #include "content/public/browser/render_widget_host.h" | 24 #include "content/public/browser/render_widget_host.h" |
| 24 #include "content/public/browser/render_widget_host_view.h" | 25 #include "content/public/browser/render_widget_host_view.h" |
| 25 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 26 #include "content/public/common/referrer.h" | 27 #include "content/public/common/referrer.h" |
| 27 #include "device/vr/android/gvr/gvr_device_provider.h" | 28 #include "device/vr/android/gvr/gvr_device_provider.h" |
| 28 #include "jni/VrShellImpl_jni.h" | 29 #include "jni/VrShellImpl_jni.h" |
| 29 #include "ui/android/view_android.h" | 30 #include "ui/android/view_android.h" |
| 30 #include "ui/android/window_android.h" | 31 #include "ui/android/window_android.h" |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 | 229 |
| 229 void VrShell::GvrInit(JNIEnv* env, | 230 void VrShell::GvrInit(JNIEnv* env, |
| 230 const JavaParamRef<jobject>& obj, | 231 const JavaParamRef<jobject>& obj, |
| 231 jlong native_gvr_api) { | 232 jlong native_gvr_api) { |
| 232 base::AutoLock lock(gvr_init_lock_); | 233 base::AutoLock lock(gvr_init_lock_); |
| 233 | 234 |
| 234 // set the initial webvr state | 235 // set the initial webvr state |
| 235 metrics_helper_->SetWebVREnabled(webvr_mode_); | 236 metrics_helper_->SetWebVREnabled(webvr_mode_); |
| 236 metrics_helper_->SetVRActive(true); | 237 metrics_helper_->SetVRActive(true); |
| 237 | 238 |
| 239 SetShowingOverscrollGlow(false); | |
|
bshe
2016/11/25 14:55:00
I am assuming this is the place that calling SetSh
asimjour1
2016/12/01 20:17:45
ctor of VrShell is called on UI thread, but Render
bshe
2016/12/01 20:43:41
Is it possible to call it once RVH is ready on UI
mthiesse
2016/12/01 22:15:39
Yes, please add RenderViewHostChanged to vr_web_co
asimjour1
2016/12/05 18:57:08
Done.
asimjour1
2016/12/05 18:57:08
Done.
| |
| 240 | |
| 238 gvr_api_ = | 241 gvr_api_ = |
| 239 gvr::GvrApi::WrapNonOwned(reinterpret_cast<gvr_context*>(native_gvr_api)); | 242 gvr::GvrApi::WrapNonOwned(reinterpret_cast<gvr_context*>(native_gvr_api)); |
| 240 // TODO(klausw,crbug.com/655722): should report OnGvrDelegateReady here once | 243 // TODO(klausw,crbug.com/655722): should report OnGvrDelegateReady here once |
| 241 // we switch to using a WebVR render surface. We currently need to wait for | 244 // we switch to using a WebVR render surface. We currently need to wait for |
| 242 // the compositor window's size to be known first. See also | 245 // the compositor window's size to be known first. See also |
| 243 // ContentSurfaceChanged. | 246 // ContentSurfaceChanged. |
| 244 controller_.reset( | 247 controller_.reset( |
| 245 new VrController(reinterpret_cast<gvr_context*>(native_gvr_api))); | 248 new VrController(reinterpret_cast<gvr_context*>(native_gvr_api))); |
| 246 content_input_manager_ = new VrInputManager(main_contents_); | 249 content_input_manager_ = new VrInputManager(main_contents_); |
| 247 ui_input_manager_ = new VrInputManager(ui_contents_); | 250 ui_input_manager_ = new VrInputManager(ui_contents_); |
| (...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 863 void VrShell::OnTriggerEvent(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 866 void VrShell::OnTriggerEvent(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 864 // Set a flag to handle this on the render thread at the next frame. | 867 // Set a flag to handle this on the render thread at the next frame. |
| 865 touch_pending_ = true; | 868 touch_pending_ = true; |
| 866 } | 869 } |
| 867 | 870 |
| 868 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 871 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 869 if (gvr_api_ == nullptr) | 872 if (gvr_api_ == nullptr) |
| 870 return; | 873 return; |
| 871 controller_->OnPause(); | 874 controller_->OnPause(); |
| 872 gvr_api_->PauseTracking(); | 875 gvr_api_->PauseTracking(); |
| 876 SetShowingOverscrollGlow(true); | |
| 873 | 877 |
| 874 // exit vr session | 878 // exit vr session |
| 875 metrics_helper_->SetVRActive(false); | 879 metrics_helper_->SetVRActive(false); |
| 876 } | 880 } |
| 877 | 881 |
| 878 void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 882 void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 879 if (gvr_api_ == nullptr) | 883 if (gvr_api_ == nullptr) |
| 880 return; | 884 return; |
| 881 | 885 |
| 882 gvr_api_->RefreshViewerProfile(); | 886 gvr_api_->RefreshViewerProfile(); |
| 883 gvr_api_->ResumeTracking(); | 887 gvr_api_->ResumeTracking(); |
| 884 controller_->OnResume(); | 888 controller_->OnResume(); |
| 889 SetShowingOverscrollGlow(false); | |
| 885 | 890 |
| 886 // exit vr session | 891 // exit vr session |
| 887 metrics_helper_->SetVRActive(true); | 892 metrics_helper_->SetVRActive(true); |
| 888 } | 893 } |
| 889 | 894 |
| 895 void VrShell::SetShowingOverscrollGlow(bool showing_glow) { | |
| 896 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { | |
| 897 content::BrowserThread::PostTask( | |
| 898 content::BrowserThread::UI, FROM_HERE, | |
| 899 base::Bind(&VrShell::SetShowingOverscrollGlow, | |
| 900 weak_ptr_factory_.GetWeakPtr(), showing_glow)); | |
| 901 } else { | |
| 902 main_contents_->GetRenderWidgetHostView()->SetShowingOverscrollGlow( | |
| 903 showing_glow); | |
| 904 } | |
| 905 } | |
| 906 | |
| 890 base::WeakPtr<VrShell> VrShell::GetWeakPtr( | 907 base::WeakPtr<VrShell> VrShell::GetWeakPtr( |
| 891 const content::WebContents* web_contents) { | 908 const content::WebContents* web_contents) { |
| 892 // Ensure that the WebContents requesting the VrShell instance is the one | 909 // Ensure that the WebContents requesting the VrShell instance is the one |
| 893 // we created. | 910 // we created. |
| 894 if (g_instance != nullptr && g_instance->ui_contents_ == web_contents) | 911 if (g_instance != nullptr && g_instance->ui_contents_ == web_contents) |
| 895 return g_instance->weak_ptr_factory_.GetWeakPtr(); | 912 return g_instance->weak_ptr_factory_.GetWeakPtr(); |
| 896 return base::WeakPtr<VrShell>(nullptr); | 913 return base::WeakPtr<VrShell>(nullptr); |
| 897 } | 914 } |
| 898 | 915 |
| 899 void VrShell::OnDomContentsLoaded() { | 916 void VrShell::OnDomContentsLoaded() { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1049 const JavaParamRef<jobject>& ui_web_contents, | 1066 const JavaParamRef<jobject>& ui_web_contents, |
| 1050 jlong ui_window_android) { | 1067 jlong ui_window_android) { |
| 1051 return reinterpret_cast<intptr_t>(new VrShell( | 1068 return reinterpret_cast<intptr_t>(new VrShell( |
| 1052 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), | 1069 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), |
| 1053 reinterpret_cast<ui::WindowAndroid*>(content_window_android), | 1070 reinterpret_cast<ui::WindowAndroid*>(content_window_android), |
| 1054 content::WebContents::FromJavaWebContents(ui_web_contents), | 1071 content::WebContents::FromJavaWebContents(ui_web_contents), |
| 1055 reinterpret_cast<ui::WindowAndroid*>(ui_window_android))); | 1072 reinterpret_cast<ui::WindowAndroid*>(ui_window_android))); |
| 1056 } | 1073 } |
| 1057 | 1074 |
| 1058 } // namespace vr_shell | 1075 } // namespace vr_shell |
| OLD | NEW |