| 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> |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" | 31 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" |
| 32 #include "chrome/browser/android/vr_shell/vr_tab_helper.h" | 32 #include "chrome/browser/android/vr_shell/vr_tab_helper.h" |
| 33 #include "chrome/browser/android/vr_shell/vr_usage_monitor.h" | 33 #include "chrome/browser/android/vr_shell/vr_usage_monitor.h" |
| 34 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h" | 34 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h" |
| 35 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" | 35 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" |
| 36 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" | 36 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" |
| 37 #include "content/public/browser/browser_thread.h" | 37 #include "content/public/browser/browser_thread.h" |
| 38 #include "content/public/browser/navigation_controller.h" | 38 #include "content/public/browser/navigation_controller.h" |
| 39 #include "content/public/browser/render_view_host.h" | 39 #include "content/public/browser/render_view_host.h" |
| 40 #include "content/public/browser/render_widget_host.h" | 40 #include "content/public/browser/render_widget_host.h" |
| 41 #include "content/public/browser/render_widget_host_iterator.h" |
| 41 #include "content/public/browser/render_widget_host_view.h" | 42 #include "content/public/browser/render_widget_host_view.h" |
| 42 #include "content/public/browser/web_contents.h" | 43 #include "content/public/browser/web_contents.h" |
| 43 #include "content/public/common/content_features.h" | 44 #include "content/public/common/content_features.h" |
| 44 #include "content/public/common/referrer.h" | 45 #include "content/public/common/referrer.h" |
| 45 #include "device/vr/android/gvr/cardboard_gamepad_data_fetcher.h" | 46 #include "device/vr/android/gvr/cardboard_gamepad_data_fetcher.h" |
| 46 #include "device/vr/android/gvr/gvr_device.h" | 47 #include "device/vr/android/gvr/gvr_device.h" |
| 47 #include "device/vr/android/gvr/gvr_device_provider.h" | 48 #include "device/vr/android/gvr/gvr_device_provider.h" |
| 48 #include "device/vr/android/gvr/gvr_gamepad_data_fetcher.h" | 49 #include "device/vr/android/gvr/gvr_gamepad_data_fetcher.h" |
| 49 #include "gpu/command_buffer/common/mailbox.h" | 50 #include "gpu/command_buffer/common/mailbox.h" |
| 50 #include "jni/VrShellImpl_jni.h" | 51 #include "jni/VrShellImpl_jni.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 61 | 62 |
| 62 using base::android::JavaParamRef; | 63 using base::android::JavaParamRef; |
| 63 using base::android::JavaRef; | 64 using base::android::JavaRef; |
| 64 | 65 |
| 65 namespace vr_shell { | 66 namespace vr_shell { |
| 66 | 67 |
| 67 namespace { | 68 namespace { |
| 68 vr_shell::VrShell* g_instance; | 69 vr_shell::VrShell* g_instance; |
| 69 | 70 |
| 70 constexpr base::TimeDelta poll_media_access_interval_ = | 71 constexpr base::TimeDelta poll_media_access_interval_ = |
| 71 base::TimeDelta::FromSecondsD(0.01); | 72 base::TimeDelta::FromSecondsD(0.1); |
| 72 | 73 |
| 73 constexpr base::TimeDelta kExitVrDueToUnsupportedModeDelay = | 74 constexpr base::TimeDelta kExitVrDueToUnsupportedModeDelay = |
| 74 base::TimeDelta::FromSeconds(5); | 75 base::TimeDelta::FromSeconds(5); |
| 75 | 76 |
| 76 void SetIsInVR(content::WebContents* contents, bool is_in_vr) { | 77 void SetIsInVR(content::WebContents* contents, bool is_in_vr) { |
| 77 if (contents && contents->GetRenderWidgetHostView()) { | 78 if (contents && contents->GetRenderWidgetHostView()) { |
| 78 // TODO(asimjour) Contents should not be aware of VR mode. Instead, we | 79 // TODO(asimjour) Contents should not be aware of VR mode. Instead, we |
| 79 // should add a flag for disabling specific UI such as the keyboard (see | 80 // should add a flag for disabling specific UI such as the keyboard (see |
| 80 // VrTabHelper for details). | 81 // VrTabHelper for details). |
| 81 contents->GetRenderWidgetHostView()->SetIsInVR(is_in_vr); | 82 contents->GetRenderWidgetHostView()->SetIsInVR(is_in_vr); |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 | 609 |
| 609 void VrShell::PollMediaAccessFlag() { | 610 void VrShell::PollMediaAccessFlag() { |
| 610 poll_capturing_media_task_.Cancel(); | 611 poll_capturing_media_task_.Cancel(); |
| 611 | 612 |
| 612 poll_capturing_media_task_.Reset( | 613 poll_capturing_media_task_.Reset( |
| 613 base::Bind(&VrShell::PollMediaAccessFlag, base::Unretained(this))); | 614 base::Bind(&VrShell::PollMediaAccessFlag, base::Unretained(this))); |
| 614 main_thread_task_runner_->PostDelayedTask( | 615 main_thread_task_runner_->PostDelayedTask( |
| 615 FROM_HERE, poll_capturing_media_task_.callback(), | 616 FROM_HERE, poll_capturing_media_task_.callback(), |
| 616 poll_media_access_interval_); | 617 poll_media_access_interval_); |
| 617 | 618 |
| 619 int num_tabs_capturing_audio = 0; |
| 620 int num_tabs_capturing_video = 0; |
| 621 int num_tabs_capturing_screen = 0; |
| 618 scoped_refptr<MediaStreamCaptureIndicator> indicator = | 622 scoped_refptr<MediaStreamCaptureIndicator> indicator = |
| 619 MediaCaptureDevicesDispatcher::GetInstance() | 623 MediaCaptureDevicesDispatcher::GetInstance() |
| 620 ->GetMediaStreamCaptureIndicator(); | 624 ->GetMediaStreamCaptureIndicator(); |
| 621 bool is_capturing_audio = indicator->IsCapturingAudio(web_contents_); | |
| 622 if (is_capturing_audio != is_capturing_audio_) | |
| 623 ui_->SetAudioCapturingIndicator(is_capturing_audio); | |
| 624 is_capturing_audio_ = is_capturing_audio; | |
| 625 | 625 |
| 626 bool is_capturing_video = indicator->IsCapturingVideo(web_contents_); | 626 std::unique_ptr<content::RenderWidgetHostIterator> widgets( |
| 627 if (is_capturing_video != is_capturing_video_) | 627 content::RenderWidgetHost::GetRenderWidgetHosts()); |
| 628 ui_->SetVideoCapturingIndicator(is_capturing_video); | 628 while (content::RenderWidgetHost* rwh = widgets->GetNextHost()) { |
| 629 is_capturing_video_ = is_capturing_video; | 629 content::RenderViewHost* rvh = content::RenderViewHost::From(rwh); |
| 630 if (!rvh) |
| 631 continue; |
| 632 content::WebContents* web_contents = |
| 633 content::WebContents::FromRenderViewHost(rvh); |
| 634 if (!web_contents) |
| 635 continue; |
| 636 if (web_contents->GetRenderViewHost() != rvh) |
| 637 continue; |
| 638 // Because a WebContents can only have one current RVH at a time, there will |
| 639 // be no duplicate WebContents here. |
| 640 if (indicator->IsCapturingAudio(web_contents)) |
| 641 num_tabs_capturing_audio++; |
| 642 if (indicator->IsCapturingVideo(web_contents)) |
| 643 num_tabs_capturing_video++; |
| 644 if (indicator->IsBeingMirrored(web_contents)) |
| 645 num_tabs_capturing_screen++; |
| 646 } |
| 630 | 647 |
| 631 bool is_capturing_screen = indicator->IsBeingMirrored(web_contents_); | 648 ui_->SetAudioCapturingIndicator(num_tabs_capturing_audio > 0); |
| 632 if (is_capturing_screen != is_capturing_screen_) | 649 ui_->SetVideoCapturingIndicator(num_tabs_capturing_video > 0); |
| 633 ui_->SetScreenCapturingIndicator(is_capturing_screen); | 650 ui_->SetScreenCapturingIndicator(num_tabs_capturing_screen > 0); |
| 634 is_capturing_screen_ = is_capturing_screen; | |
| 635 } | 651 } |
| 636 | 652 |
| 637 void VrShell::SetContentCssSize(float width, float height, float dpr) { | 653 void VrShell::SetContentCssSize(float width, float height, float dpr) { |
| 638 JNIEnv* env = base::android::AttachCurrentThread(); | 654 JNIEnv* env = base::android::AttachCurrentThread(); |
| 639 Java_VrShellImpl_setContentCssSize(env, j_vr_shell_.obj(), width, height, | 655 Java_VrShellImpl_setContentCssSize(env, j_vr_shell_.obj(), width, height, |
| 640 dpr); | 656 dpr); |
| 641 } | 657 } |
| 642 | 658 |
| 643 void VrShell::ProcessContentGesture( | 659 void VrShell::ProcessContentGesture( |
| 644 std::unique_ptr<blink::WebInputEvent> event) { | 660 std::unique_ptr<blink::WebInputEvent> event) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 jlong gvr_api, | 711 jlong gvr_api, |
| 696 jboolean reprojected_rendering) { | 712 jboolean reprojected_rendering) { |
| 697 return reinterpret_cast<intptr_t>(new VrShell( | 713 return reinterpret_cast<intptr_t>(new VrShell( |
| 698 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android), | 714 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android), |
| 699 for_web_vr, in_cct, | 715 for_web_vr, in_cct, |
| 700 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), | 716 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), |
| 701 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); | 717 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); |
| 702 } | 718 } |
| 703 | 719 |
| 704 } // namespace vr_shell | 720 } // namespace vr_shell |
| OLD | NEW |