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_array.h" |
12 #include "base/android/jni_string.h" | 13 #include "base/android/jni_string.h" |
| 14 #include "base/json/json_writer.h" |
13 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
14 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
15 #include "base/threading/platform_thread.h" | 17 #include "base/threading/platform_thread.h" |
16 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
17 #include "base/threading/thread_restrictions.h" | 19 #include "base/threading/thread_restrictions.h" |
18 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
19 #include "base/values.h" | 21 #include "base/values.h" |
20 #include "chrome/browser/android/tab_android.h" | 22 #include "chrome/browser/android/tab_android.h" |
21 #include "chrome/browser/android/vr_shell/android_ui_gesture_target.h" | 23 #include "chrome/browser/android/vr_shell/android_ui_gesture_target.h" |
22 #include "chrome/browser/android/vr_shell/vr_compositor.h" | 24 #include "chrome/browser/android/vr_shell/vr_compositor.h" |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 base::Bind(&VrShellGl::CreateContentSurface, gl_thread_->GetVrShellGl())); | 392 base::Bind(&VrShellGl::CreateContentSurface, gl_thread_->GetVrShellGl())); |
391 } | 393 } |
392 | 394 |
393 void VrShell::SetHistoryButtonsEnabled(JNIEnv* env, | 395 void VrShell::SetHistoryButtonsEnabled(JNIEnv* env, |
394 const JavaParamRef<jobject>& obj, | 396 const JavaParamRef<jobject>& obj, |
395 jboolean can_go_back, | 397 jboolean can_go_back, |
396 jboolean can_go_forward) { | 398 jboolean can_go_forward) { |
397 html_interface_->SetHistoryButtonsEnabled(can_go_back, can_go_forward); | 399 html_interface_->SetHistoryButtonsEnabled(can_go_back, can_go_forward); |
398 } | 400 } |
399 | 401 |
| 402 void VrShell::RequestUiElementInfoForTesting(JNIEnv* env, |
| 403 const JavaParamRef<jobject>& obj, |
| 404 jobjectArray element_names, |
| 405 jint callback_id) { |
| 406 std::vector<std::string> element_names_vector; |
| 407 base::android::AppendJavaStringArrayToStringVector(env, element_names, |
| 408 &element_names_vector); |
| 409 PostToGlThreadWhenReady( |
| 410 base::Bind(&VrShellGl::CreateUiElementInfos, gl_thread_->GetVrShellGl(), |
| 411 element_names_vector, callback_id, |
| 412 base::Bind(&VrShell::OnUiElementInfoCreated, |
| 413 weak_ptr_factory_.GetWeakPtr()))); |
| 414 } |
| 415 |
400 void VrShell::UiSurfaceChanged(jobject surface) { | 416 void VrShell::UiSurfaceChanged(jobject surface) { |
401 ui_compositor_->SurfaceChanged(surface); | 417 ui_compositor_->SurfaceChanged(surface); |
402 } | 418 } |
403 | 419 |
404 void VrShell::ContentSurfaceChanged(jobject surface) { | 420 void VrShell::ContentSurfaceChanged(jobject surface) { |
405 content_surface_ = surface; | 421 content_surface_ = surface; |
406 content_compositor_->SurfaceChanged(surface); | 422 content_compositor_->SurfaceChanged(surface); |
407 JNIEnv* env = base::android::AttachCurrentThread(); | 423 JNIEnv* env = base::android::AttachCurrentThread(); |
408 Java_VrShellImpl_contentSurfaceChanged(env, j_vr_shell_.obj()); | 424 Java_VrShellImpl_contentSurfaceChanged(env, j_vr_shell_.obj()); |
409 } | 425 } |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 base::android::ConvertUTF16ToJavaString(env, url_string); | 548 base::android::ConvertUTF16ToJavaString(env, url_string); |
533 Java_VrShellImpl_loadURL(env, j_vr_shell_.obj(), string, | 549 Java_VrShellImpl_loadURL(env, j_vr_shell_.obj(), string, |
534 ui::PageTransition::PAGE_TRANSITION_TYPED); | 550 ui::PageTransition::PAGE_TRANSITION_TYPED); |
535 break; | 551 break; |
536 } | 552 } |
537 default: | 553 default: |
538 NOTREACHED(); | 554 NOTREACHED(); |
539 } | 555 } |
540 } | 556 } |
541 | 557 |
| 558 void VrShell::OnUiElementInfoCreated( |
| 559 int callback_id, |
| 560 std::unique_ptr<base::DictionaryValue> info) { |
| 561 std::string json_reply; |
| 562 base::JSONWriter::Write(*info, &json_reply); |
| 563 JNIEnv* env = base::android::AttachCurrentThread(); |
| 564 Java_VrShellImpl_replyToUiElementInfoRequestForTesting( |
| 565 env, j_vr_shell_.obj(), |
| 566 base::android::ConvertUTF8ToJavaString(env, json_reply), callback_id); |
| 567 } |
| 568 |
542 void VrShell::RenderViewHostChanged(content::RenderViewHost* old_host, | 569 void VrShell::RenderViewHostChanged(content::RenderViewHost* old_host, |
543 content::RenderViewHost* new_host) { | 570 content::RenderViewHost* new_host) { |
544 content::RenderWidgetHostView* view = new_host->GetWidget()->GetView(); | 571 content::RenderWidgetHostView* view = new_host->GetWidget()->GetView(); |
545 view->SetBackgroundColor(SK_ColorTRANSPARENT); | 572 view->SetBackgroundColor(SK_ColorTRANSPARENT); |
546 view->SetIsInVR(true); | 573 view->SetIsInVR(true); |
547 } | 574 } |
548 | 575 |
549 void VrShell::MainFrameWasResized(bool width_changed) { | 576 void VrShell::MainFrameWasResized(bool width_changed) { |
550 display::Display display = | 577 display::Display display = |
551 display::Screen::GetScreen()->GetDisplayNearestView( | 578 display::Screen::GetScreen()->GetDisplayNearestView( |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 jboolean reprojected_rendering) { | 806 jboolean reprojected_rendering) { |
780 return reinterpret_cast<intptr_t>(new VrShell( | 807 return reinterpret_cast<intptr_t>(new VrShell( |
781 env, obj, reinterpret_cast<ui::WindowAndroid*>(content_window_android), | 808 env, obj, reinterpret_cast<ui::WindowAndroid*>(content_window_android), |
782 content::WebContents::FromJavaWebContents(ui_web_contents), | 809 content::WebContents::FromJavaWebContents(ui_web_contents), |
783 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), for_web_vr, | 810 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), for_web_vr, |
784 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), | 811 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), |
785 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); | 812 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); |
786 } | 813 } |
787 | 814 |
788 } // namespace vr_shell | 815 } // namespace vr_shell |
OLD | NEW |