| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 DVLOG(1) << __FUNCTION__ << "=" << this; | 110 DVLOG(1) << __FUNCTION__ << "=" << this; |
| 110 DCHECK(g_instance == nullptr); | 111 DCHECK(g_instance == nullptr); |
| 111 g_instance = this; | 112 g_instance = this; |
| 112 j_vr_shell_.Reset(env, obj); | 113 j_vr_shell_.Reset(env, obj); |
| 113 | 114 |
| 114 gl_thread_ = base::MakeUnique<VrGLThread>( | 115 gl_thread_ = base::MakeUnique<VrGLThread>( |
| 115 weak_ptr_factory_.GetWeakPtr(), main_thread_task_runner_, gvr_api, | 116 weak_ptr_factory_.GetWeakPtr(), main_thread_task_runner_, gvr_api, |
| 116 for_web_vr, web_vr_autopresented, in_cct, reprojected_rendering_, | 117 for_web_vr, web_vr_autopresented, in_cct, reprojected_rendering_, |
| 117 HasDaydreamSupport(env)); | 118 HasDaydreamSupport(env)); |
| 118 ui_ = gl_thread_.get(); | 119 ui_ = gl_thread_.get(); |
| 120 toolbar_ = base::MakeUnique<ToolbarHelper>(ui_, this); |
| 119 | 121 |
| 120 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0); | 122 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0); |
| 121 options.priority = base::ThreadPriority::DISPLAY; | 123 options.priority = base::ThreadPriority::DISPLAY; |
| 122 gl_thread_->StartWithOptions(options); | 124 gl_thread_->StartWithOptions(options); |
| 123 } | 125 } |
| 124 | 126 |
| 125 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 127 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 126 delete this; | 128 delete this; |
| 127 } | 129 } |
| 128 | 130 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 148 if (!web_contents_) { | 150 if (!web_contents_) { |
| 149 android_ui_gesture_target_ = base::MakeUnique<AndroidUiGestureTarget>( | 151 android_ui_gesture_target_ = base::MakeUnique<AndroidUiGestureTarget>( |
| 150 j_motion_event_synthesizer_.obj(), | 152 j_motion_event_synthesizer_.obj(), |
| 151 Java_VrShellImpl_getNativePageScrollRatio(env, j_vr_shell_.obj())); | 153 Java_VrShellImpl_getNativePageScrollRatio(env, j_vr_shell_.obj())); |
| 152 input_manager_ = nullptr; | 154 input_manager_ = nullptr; |
| 153 vr_web_contents_observer_ = nullptr; | 155 vr_web_contents_observer_ = nullptr; |
| 154 metrics_helper_ = nullptr; | 156 metrics_helper_ = nullptr; |
| 155 return; | 157 return; |
| 156 } | 158 } |
| 157 input_manager_ = base::MakeUnique<VrInputManager>(web_contents_); | 159 input_manager_ = base::MakeUnique<VrInputManager>(web_contents_); |
| 158 vr_web_contents_observer_ = | 160 vr_web_contents_observer_ = base::MakeUnique<VrWebContentsObserver>( |
| 159 base::MakeUnique<VrWebContentsObserver>(web_contents_, ui_, this); | 161 web_contents_, this, ui_, toolbar_.get()); |
| 160 // TODO(billorr): Make VrMetricsHelper tab-aware and able to track multiple | 162 // TODO(billorr): Make VrMetricsHelper tab-aware and able to track multiple |
| 161 // tabs. crbug.com/684661 | 163 // tabs. crbug.com/684661 |
| 162 metrics_helper_ = base::MakeUnique<VrMetricsHelper>(web_contents_); | 164 metrics_helper_ = base::MakeUnique<VrMetricsHelper>(web_contents_); |
| 163 metrics_helper_->SetVRActive(true); | 165 metrics_helper_->SetVRActive(true); |
| 164 metrics_helper_->SetWebVREnabled(webvr_mode_); | 166 metrics_helper_->SetWebVREnabled(webvr_mode_); |
| 165 } | 167 } |
| 166 | 168 |
| 167 void VrShell::SetUiState() { | 169 void VrShell::SetUiState() { |
| 170 toolbar_->Update(); |
| 171 |
| 168 if (!web_contents_) { | 172 if (!web_contents_) { |
| 169 // TODO(mthiesse): Properly handle native page URLs. | |
| 170 ui_->SetURL(GURL()); | |
| 171 ui_->SetLoading(false); | 173 ui_->SetLoading(false); |
| 172 ui_->SetFullscreen(false); | 174 ui_->SetFullscreen(false); |
| 173 ui_->SetIncognito(false); | 175 ui_->SetIncognito(false); |
| 174 } else { | 176 } else { |
| 175 ui_->SetURL(web_contents_->GetVisibleURL()); | |
| 176 ui_->SetLoading(web_contents_->IsLoading()); | 177 ui_->SetLoading(web_contents_->IsLoading()); |
| 177 ui_->SetFullscreen(web_contents_->IsFullscreen()); | 178 ui_->SetFullscreen(web_contents_->IsFullscreen()); |
| 178 ui_->SetIncognito(web_contents_->GetBrowserContext()->IsOffTheRecord()); | 179 ui_->SetIncognito(web_contents_->GetBrowserContext()->IsOffTheRecord()); |
| 179 } | 180 } |
| 180 } | 181 } |
| 181 | 182 |
| 182 bool RegisterVrShell(JNIEnv* env) { | 183 bool RegisterVrShell(JNIEnv* env) { |
| 183 return RegisterNativesImpl(env); | 184 return RegisterNativesImpl(env); |
| 184 } | 185 } |
| 185 | 186 |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 void VrShell::RegisterCardboardGamepadDataFetcher( | 693 void VrShell::RegisterCardboardGamepadDataFetcher( |
| 693 device::CardboardGamepadDataFetcher* fetcher) { | 694 device::CardboardGamepadDataFetcher* fetcher) { |
| 694 DVLOG(1) << __FUNCTION__ << "(" << fetcher << ")"; | 695 DVLOG(1) << __FUNCTION__ << "(" << fetcher << ")"; |
| 695 cardboard_gamepad_data_fetcher_ = fetcher; | 696 cardboard_gamepad_data_fetcher_ = fetcher; |
| 696 } | 697 } |
| 697 | 698 |
| 698 bool VrShell::HasDaydreamSupport(JNIEnv* env) { | 699 bool VrShell::HasDaydreamSupport(JNIEnv* env) { |
| 699 return Java_VrShellImpl_hasDaydreamSupport(env, j_vr_shell_.obj()); | 700 return Java_VrShellImpl_hasDaydreamSupport(env, j_vr_shell_.obj()); |
| 700 } | 701 } |
| 701 | 702 |
| 703 content::WebContents* VrShell::GetActiveWebContents() const { |
| 704 return web_contents_; |
| 705 } |
| 706 |
| 702 // ---------------------------------------------------------------------------- | 707 // ---------------------------------------------------------------------------- |
| 703 // Native JNI methods | 708 // Native JNI methods |
| 704 // ---------------------------------------------------------------------------- | 709 // ---------------------------------------------------------------------------- |
| 705 | 710 |
| 706 jlong Init(JNIEnv* env, | 711 jlong Init(JNIEnv* env, |
| 707 const JavaParamRef<jobject>& obj, | 712 const JavaParamRef<jobject>& obj, |
| 708 const JavaParamRef<jobject>& delegate, | 713 const JavaParamRef<jobject>& delegate, |
| 709 jlong window_android, | 714 jlong window_android, |
| 710 jboolean for_web_vr, | 715 jboolean for_web_vr, |
| 711 jboolean web_vr_autopresented, | 716 jboolean web_vr_autopresented, |
| 712 jboolean in_cct, | 717 jboolean in_cct, |
| 713 jlong gvr_api, | 718 jlong gvr_api, |
| 714 jboolean reprojected_rendering) { | 719 jboolean reprojected_rendering) { |
| 715 return reinterpret_cast<intptr_t>(new VrShell( | 720 return reinterpret_cast<intptr_t>(new VrShell( |
| 716 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android), | 721 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android), |
| 717 for_web_vr, web_vr_autopresented, in_cct, | 722 for_web_vr, web_vr_autopresented, in_cct, |
| 718 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), | 723 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), |
| 719 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); | 724 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); |
| 720 } | 725 } |
| 721 | 726 |
| 722 } // namespace vr_shell | 727 } // namespace vr_shell |
| OLD | NEW |