| 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 <android/native_window_jni.h> | 7 #include <android/native_window_jni.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/android/jni_string.h" | 12 #include "base/android/jni_string.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 16 #include "base/threading/platform_thread.h" | 16 #include "base/threading/platform_thread.h" |
| 17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
| 18 #include "base/threading/thread_restrictions.h" | 18 #include "base/threading/thread_restrictions.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| 20 #include "base/trace_event/trace_event.h" | 20 #include "base/trace_event/trace_event.h" |
| 21 #include "base/values.h" | 21 #include "base/values.h" |
| 22 #include "chrome/browser/android/tab_android.h" | 22 #include "chrome/browser/android/tab_android.h" |
| 23 #include "chrome/browser/android/vr_shell/android_ui_gesture_target.h" | 23 #include "chrome/browser/android/vr_shell/android_ui_gesture_target.h" |
| 24 #include "chrome/browser/android/vr_shell/toolbar_helper.h" |
| 24 #include "chrome/browser/android/vr_shell/ui_interface.h" | 25 #include "chrome/browser/android/vr_shell/ui_interface.h" |
| 25 #include "chrome/browser/android/vr_shell/ui_scene_manager.h" | 26 #include "chrome/browser/android/vr_shell/ui_scene_manager.h" |
| 26 #include "chrome/browser/android/vr_shell/vr_compositor.h" | 27 #include "chrome/browser/android/vr_shell/vr_compositor.h" |
| 27 #include "chrome/browser/android/vr_shell/vr_controller_model.h" | 28 #include "chrome/browser/android/vr_shell/vr_controller_model.h" |
| 28 #include "chrome/browser/android/vr_shell/vr_gl_thread.h" | 29 #include "chrome/browser/android/vr_shell/vr_gl_thread.h" |
| 29 #include "chrome/browser/android/vr_shell/vr_input_manager.h" | 30 #include "chrome/browser/android/vr_shell/vr_input_manager.h" |
| 30 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" | 31 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" |
| 31 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" | 32 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" |
| 32 #include "chrome/browser/android/vr_shell/vr_tab_helper.h" | 33 #include "chrome/browser/android/vr_shell/vr_tab_helper.h" |
| 33 #include "chrome/browser/android/vr_shell/vr_usage_monitor.h" | 34 #include "chrome/browser/android/vr_shell/vr_usage_monitor.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 DVLOG(1) << __FUNCTION__ << "=" << this; | 111 DVLOG(1) << __FUNCTION__ << "=" << this; |
| 111 DCHECK(g_instance == nullptr); | 112 DCHECK(g_instance == nullptr); |
| 112 g_instance = this; | 113 g_instance = this; |
| 113 j_vr_shell_.Reset(env, obj); | 114 j_vr_shell_.Reset(env, obj); |
| 114 | 115 |
| 115 gl_thread_ = base::MakeUnique<VrGLThread>( | 116 gl_thread_ = base::MakeUnique<VrGLThread>( |
| 116 weak_ptr_factory_.GetWeakPtr(), main_thread_task_runner_, gvr_api, | 117 weak_ptr_factory_.GetWeakPtr(), main_thread_task_runner_, gvr_api, |
| 117 for_web_vr, web_vr_autopresentation_expected, in_cct, | 118 for_web_vr, web_vr_autopresentation_expected, in_cct, |
| 118 reprojected_rendering_, HasDaydreamSupport(env)); | 119 reprojected_rendering_, HasDaydreamSupport(env)); |
| 119 ui_ = gl_thread_.get(); | 120 ui_ = gl_thread_.get(); |
| 121 toolbar_ = base::MakeUnique<ToolbarHelper>(ui_, this); |
| 120 | 122 |
| 121 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0); | 123 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0); |
| 122 options.priority = base::ThreadPriority::DISPLAY; | 124 options.priority = base::ThreadPriority::DISPLAY; |
| 123 gl_thread_->StartWithOptions(options); | 125 gl_thread_->StartWithOptions(options); |
| 124 } | 126 } |
| 125 | 127 |
| 126 void VrShell::SetSplashScreenIcon(JNIEnv* env, | 128 void VrShell::SetSplashScreenIcon(JNIEnv* env, |
| 127 const JavaParamRef<jobject>& obj, | 129 const JavaParamRef<jobject>& obj, |
| 128 const JavaParamRef<jobject>& bitmap) { | 130 const JavaParamRef<jobject>& bitmap) { |
| 129 ui_->SetSplashScreenIcon( | 131 ui_->SetSplashScreenIcon( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 156 if (!web_contents_) { | 158 if (!web_contents_) { |
| 157 android_ui_gesture_target_ = base::MakeUnique<AndroidUiGestureTarget>( | 159 android_ui_gesture_target_ = base::MakeUnique<AndroidUiGestureTarget>( |
| 158 j_motion_event_synthesizer_.obj(), | 160 j_motion_event_synthesizer_.obj(), |
| 159 Java_VrShellImpl_getNativePageScrollRatio(env, j_vr_shell_.obj())); | 161 Java_VrShellImpl_getNativePageScrollRatio(env, j_vr_shell_.obj())); |
| 160 input_manager_ = nullptr; | 162 input_manager_ = nullptr; |
| 161 vr_web_contents_observer_ = nullptr; | 163 vr_web_contents_observer_ = nullptr; |
| 162 metrics_helper_ = nullptr; | 164 metrics_helper_ = nullptr; |
| 163 return; | 165 return; |
| 164 } | 166 } |
| 165 input_manager_ = base::MakeUnique<VrInputManager>(web_contents_); | 167 input_manager_ = base::MakeUnique<VrInputManager>(web_contents_); |
| 166 vr_web_contents_observer_ = | 168 vr_web_contents_observer_ = base::MakeUnique<VrWebContentsObserver>( |
| 167 base::MakeUnique<VrWebContentsObserver>(web_contents_, ui_, this); | 169 web_contents_, this, ui_, toolbar_.get()); |
| 168 // TODO(billorr): Make VrMetricsHelper tab-aware and able to track multiple | 170 // TODO(billorr): Make VrMetricsHelper tab-aware and able to track multiple |
| 169 // tabs. crbug.com/684661 | 171 // tabs. crbug.com/684661 |
| 170 metrics_helper_ = base::MakeUnique<VrMetricsHelper>(web_contents_); | 172 metrics_helper_ = base::MakeUnique<VrMetricsHelper>(web_contents_); |
| 171 metrics_helper_->SetVRActive(true); | 173 metrics_helper_->SetVRActive(true); |
| 172 metrics_helper_->SetWebVREnabled(webvr_mode_); | 174 metrics_helper_->SetWebVREnabled(webvr_mode_); |
| 173 } | 175 } |
| 174 | 176 |
| 175 void VrShell::SetUiState() { | 177 void VrShell::SetUiState() { |
| 178 toolbar_->Update(); |
| 179 |
| 176 if (!web_contents_) { | 180 if (!web_contents_) { |
| 177 // TODO(mthiesse): Properly handle native page URLs. | |
| 178 ui_->SetURL(GURL()); | |
| 179 ui_->SetLoading(false); | 181 ui_->SetLoading(false); |
| 180 ui_->SetFullscreen(false); | 182 ui_->SetFullscreen(false); |
| 181 ui_->SetIncognito(false); | 183 ui_->SetIncognito(false); |
| 182 } else { | 184 } else { |
| 183 ui_->SetURL(web_contents_->GetVisibleURL()); | |
| 184 ui_->SetLoading(web_contents_->IsLoading()); | 185 ui_->SetLoading(web_contents_->IsLoading()); |
| 185 ui_->SetFullscreen(web_contents_->IsFullscreen()); | 186 ui_->SetFullscreen(web_contents_->IsFullscreen()); |
| 186 ui_->SetIncognito(web_contents_->GetBrowserContext()->IsOffTheRecord()); | 187 ui_->SetIncognito(web_contents_->GetBrowserContext()->IsOffTheRecord()); |
| 187 } | 188 } |
| 188 } | 189 } |
| 189 | 190 |
| 190 bool RegisterVrShell(JNIEnv* env) { | 191 bool RegisterVrShell(JNIEnv* env) { |
| 191 return RegisterNativesImpl(env); | 192 return RegisterNativesImpl(env); |
| 192 } | 193 } |
| 193 | 194 |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 void VrShell::RegisterCardboardGamepadDataFetcher( | 700 void VrShell::RegisterCardboardGamepadDataFetcher( |
| 700 device::CardboardGamepadDataFetcher* fetcher) { | 701 device::CardboardGamepadDataFetcher* fetcher) { |
| 701 DVLOG(1) << __FUNCTION__ << "(" << fetcher << ")"; | 702 DVLOG(1) << __FUNCTION__ << "(" << fetcher << ")"; |
| 702 cardboard_gamepad_data_fetcher_ = fetcher; | 703 cardboard_gamepad_data_fetcher_ = fetcher; |
| 703 } | 704 } |
| 704 | 705 |
| 705 bool VrShell::HasDaydreamSupport(JNIEnv* env) { | 706 bool VrShell::HasDaydreamSupport(JNIEnv* env) { |
| 706 return Java_VrShellImpl_hasDaydreamSupport(env, j_vr_shell_.obj()); | 707 return Java_VrShellImpl_hasDaydreamSupport(env, j_vr_shell_.obj()); |
| 707 } | 708 } |
| 708 | 709 |
| 710 content::WebContents* VrShell::GetActiveWebContents() const { |
| 711 return web_contents_; |
| 712 } |
| 713 |
| 709 // ---------------------------------------------------------------------------- | 714 // ---------------------------------------------------------------------------- |
| 710 // Native JNI methods | 715 // Native JNI methods |
| 711 // ---------------------------------------------------------------------------- | 716 // ---------------------------------------------------------------------------- |
| 712 | 717 |
| 713 jlong Init(JNIEnv* env, | 718 jlong Init(JNIEnv* env, |
| 714 const JavaParamRef<jobject>& obj, | 719 const JavaParamRef<jobject>& obj, |
| 715 const JavaParamRef<jobject>& delegate, | 720 const JavaParamRef<jobject>& delegate, |
| 716 jlong window_android, | 721 jlong window_android, |
| 717 jboolean for_web_vr, | 722 jboolean for_web_vr, |
| 718 jboolean web_vr_autopresentation_expected, | 723 jboolean web_vr_autopresentation_expected, |
| 719 jboolean in_cct, | 724 jboolean in_cct, |
| 720 jlong gvr_api, | 725 jlong gvr_api, |
| 721 jboolean reprojected_rendering) { | 726 jboolean reprojected_rendering) { |
| 722 return reinterpret_cast<intptr_t>(new VrShell( | 727 return reinterpret_cast<intptr_t>(new VrShell( |
| 723 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android), | 728 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android), |
| 724 for_web_vr, web_vr_autopresentation_expected, in_cct, | 729 for_web_vr, web_vr_autopresentation_expected, in_cct, |
| 725 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), | 730 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), |
| 726 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); | 731 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); |
| 727 } | 732 } |
| 728 | 733 |
| 729 } // namespace vr_shell | 734 } // namespace vr_shell |
| OLD | NEW |