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::RequestUiElementInfo(JNIEnv* env, | |
403 const JavaParamRef<jobject>& obj, | |
404 jintArray element_ids, | |
405 jint callback_id) { | |
406 std::vector<int> element_ids_vector; | |
407 base::android::JavaIntArrayToIntVector(env, element_ids, &element_ids_vector); | |
408 PostToGlThreadWhenReady( | |
409 base::Bind(&VrShellGl::CreateUiElementInfos, gl_thread_->GetVrShellGl(), | |
410 element_ids_vector, callback_id, | |
411 base::Bind(&VrShell::OnUiElementInfoCreated, | |
412 weak_ptr_factory_.GetWeakPtr()))); | |
413 } | |
414 | |
400 void VrShell::UiSurfaceChanged(jobject surface) { | 415 void VrShell::UiSurfaceChanged(jobject surface) { |
401 ui_compositor_->SurfaceChanged(surface); | 416 ui_compositor_->SurfaceChanged(surface); |
402 } | 417 } |
403 | 418 |
404 void VrShell::ContentSurfaceChanged(jobject surface) { | 419 void VrShell::ContentSurfaceChanged(jobject surface) { |
405 content_surface_ = surface; | 420 content_surface_ = surface; |
406 content_compositor_->SurfaceChanged(surface); | 421 content_compositor_->SurfaceChanged(surface); |
407 JNIEnv* env = base::android::AttachCurrentThread(); | 422 JNIEnv* env = base::android::AttachCurrentThread(); |
408 Java_VrShellImpl_contentSurfaceChanged(env, j_vr_shell_.obj()); | 423 Java_VrShellImpl_contentSurfaceChanged(env, j_vr_shell_.obj()); |
409 } | 424 } |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
532 base::android::ConvertUTF16ToJavaString(env, url_string); | 547 base::android::ConvertUTF16ToJavaString(env, url_string); |
533 Java_VrShellImpl_loadURL(env, j_vr_shell_.obj(), string, | 548 Java_VrShellImpl_loadURL(env, j_vr_shell_.obj(), string, |
534 ui::PageTransition::PAGE_TRANSITION_TYPED); | 549 ui::PageTransition::PAGE_TRANSITION_TYPED); |
535 break; | 550 break; |
536 } | 551 } |
537 default: | 552 default: |
538 NOTREACHED(); | 553 NOTREACHED(); |
539 } | 554 } |
540 } | 555 } |
541 | 556 |
557 void VrShell::OnUiElementInfoCreated( | |
558 int callback_id, | |
559 std::unique_ptr<base::DictionaryValue> info) { | |
560 std::string json_reply; | |
561 base::JSONWriter::Write(*info, &json_reply); | |
bsheedy
2017/03/24 18:47:54
Converting to a JSON string in native then back to
tiborg
2017/03/27 15:14:33
I'm not aware of a better solution either. I think
| |
562 JNIEnv* env = base::android::AttachCurrentThread(); | |
563 Java_VrShellImpl_replyToUiElementInfoRequest( | |
564 env, j_vr_shell_.obj(), | |
565 base::android::ConvertUTF8ToJavaString(env, json_reply), callback_id); | |
566 } | |
567 | |
542 void VrShell::RenderViewHostChanged(content::RenderViewHost* old_host, | 568 void VrShell::RenderViewHostChanged(content::RenderViewHost* old_host, |
543 content::RenderViewHost* new_host) { | 569 content::RenderViewHost* new_host) { |
544 content::RenderWidgetHostView* view = new_host->GetWidget()->GetView(); | 570 content::RenderWidgetHostView* view = new_host->GetWidget()->GetView(); |
545 view->SetBackgroundColor(SK_ColorTRANSPARENT); | 571 view->SetBackgroundColor(SK_ColorTRANSPARENT); |
546 view->SetIsInVR(true); | 572 view->SetIsInVR(true); |
547 } | 573 } |
548 | 574 |
549 void VrShell::MainFrameWasResized(bool width_changed) { | 575 void VrShell::MainFrameWasResized(bool width_changed) { |
550 display::Display display = | 576 display::Display display = |
551 display::Screen::GetScreen()->GetDisplayNearestView( | 577 display::Screen::GetScreen()->GetDisplayNearestView( |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
779 jboolean reprojected_rendering) { | 805 jboolean reprojected_rendering) { |
780 return reinterpret_cast<intptr_t>(new VrShell( | 806 return reinterpret_cast<intptr_t>(new VrShell( |
781 env, obj, reinterpret_cast<ui::WindowAndroid*>(content_window_android), | 807 env, obj, reinterpret_cast<ui::WindowAndroid*>(content_window_android), |
782 content::WebContents::FromJavaWebContents(ui_web_contents), | 808 content::WebContents::FromJavaWebContents(ui_web_contents), |
783 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), for_web_vr, | 809 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), for_web_vr, |
784 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), | 810 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), |
785 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); | 811 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); |
786 } | 812 } |
787 | 813 |
788 } // namespace vr_shell | 814 } // namespace vr_shell |
OLD | NEW |