Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: chrome/browser/android/vr_shell/vr_shell.cc

Issue 2773903003: Add way to get native VR UI information from Java (Closed)
Patch Set: Remove comment Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/ui_interface.h" 24 #include "chrome/browser/android/vr_shell/ui_interface.h"
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 base::Bind(&VrShellGl::CreateContentSurface, gl_thread_->GetVrShellGl())); 414 base::Bind(&VrShellGl::CreateContentSurface, gl_thread_->GetVrShellGl()));
413 } 415 }
414 416
415 void VrShell::SetHistoryButtonsEnabled(JNIEnv* env, 417 void VrShell::SetHistoryButtonsEnabled(JNIEnv* env,
416 const JavaParamRef<jobject>& obj, 418 const JavaParamRef<jobject>& obj,
417 jboolean can_go_back, 419 jboolean can_go_back,
418 jboolean can_go_forward) { 420 jboolean can_go_forward) {
419 html_interface_->SetHistoryButtonsEnabled(can_go_back, can_go_forward); 421 html_interface_->SetHistoryButtonsEnabled(can_go_back, can_go_forward);
420 } 422 }
421 423
424 void VrShell::RequestUiElementInfoForTesting(JNIEnv* env,
425 const JavaParamRef<jobject>& obj,
426 jobjectArray element_names) {
427 std::vector<std::string> element_names_vector;
428 base::android::AppendJavaStringArrayToStringVector(env, element_names,
429 &element_names_vector);
430 PostToGlThreadWhenReady(
431 base::Bind(&VrShellGl::CreateUiElementInfos, gl_thread_->GetVrShellGl(),
432 element_names_vector,
433 base::Bind(&VrShell::OnUiElementInfoCreated,
434 weak_ptr_factory_.GetWeakPtr())));
435 }
436
422 void VrShell::UiSurfaceChanged(jobject surface) { 437 void VrShell::UiSurfaceChanged(jobject surface) {
423 ui_compositor_->SurfaceChanged(surface); 438 ui_compositor_->SurfaceChanged(surface);
424 } 439 }
425 440
426 void VrShell::ContentSurfaceChanged(jobject surface) { 441 void VrShell::ContentSurfaceChanged(jobject surface) {
427 content_surface_ = surface; 442 content_surface_ = surface;
428 content_compositor_->SurfaceChanged(surface); 443 content_compositor_->SurfaceChanged(surface);
429 JNIEnv* env = base::android::AttachCurrentThread(); 444 JNIEnv* env = base::android::AttachCurrentThread();
430 Java_VrShellImpl_contentSurfaceChanged(env, j_vr_shell_.obj()); 445 Java_VrShellImpl_contentSurfaceChanged(env, j_vr_shell_.obj());
431 } 446 }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 base::android::ConvertUTF16ToJavaString(env, url_string); 569 base::android::ConvertUTF16ToJavaString(env, url_string);
555 Java_VrShellImpl_loadURL(env, j_vr_shell_.obj(), string, 570 Java_VrShellImpl_loadURL(env, j_vr_shell_.obj(), string,
556 ui::PageTransition::PAGE_TRANSITION_TYPED); 571 ui::PageTransition::PAGE_TRANSITION_TYPED);
557 break; 572 break;
558 } 573 }
559 default: 574 default:
560 NOTREACHED(); 575 NOTREACHED();
561 } 576 }
562 } 577 }
563 578
579 void VrShell::OnUiElementInfoCreated(
580 std::unique_ptr<base::DictionaryValue> info) {
581 std::string json_reply;
582 base::JSONWriter::Write(*info, &json_reply);
583 JNIEnv* env = base::android::AttachCurrentThread();
584 Java_VrShellImpl_replyToUiElementInfoRequestForTesting(
585 env, j_vr_shell_.obj(),
586 base::android::ConvertUTF8ToJavaString(env, json_reply));
587 }
588
564 void VrShell::RenderViewHostChanged(content::RenderViewHost* old_host, 589 void VrShell::RenderViewHostChanged(content::RenderViewHost* old_host,
565 content::RenderViewHost* new_host) { 590 content::RenderViewHost* new_host) {
566 content::RenderWidgetHostView* view = new_host->GetWidget()->GetView(); 591 content::RenderWidgetHostView* view = new_host->GetWidget()->GetView();
567 view->SetBackgroundColor(SK_ColorTRANSPARENT); 592 view->SetBackgroundColor(SK_ColorTRANSPARENT);
568 view->SetIsInVR(true); 593 view->SetIsInVR(true);
569 } 594 }
570 595
571 void VrShell::MainFrameWasResized(bool width_changed) { 596 void VrShell::MainFrameWasResized(bool width_changed) {
572 display::Display display = 597 display::Display display =
573 display::Screen::GetScreen()->GetDisplayNearestView( 598 display::Screen::GetScreen()->GetDisplayNearestView(
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 jboolean reprojected_rendering) { 826 jboolean reprojected_rendering) {
802 return reinterpret_cast<intptr_t>(new VrShell( 827 return reinterpret_cast<intptr_t>(new VrShell(
803 env, obj, reinterpret_cast<ui::WindowAndroid*>(content_window_android), 828 env, obj, reinterpret_cast<ui::WindowAndroid*>(content_window_android),
804 content::WebContents::FromJavaWebContents(ui_web_contents), 829 content::WebContents::FromJavaWebContents(ui_web_contents),
805 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), for_web_vr, 830 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), for_web_vr,
806 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), 831 VrShellDelegate::GetNativeVrShellDelegate(env, delegate),
807 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); 832 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering));
808 } 833 }
809 834
810 } // namespace vr_shell 835 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell.h ('k') | chrome/browser/android/vr_shell/vr_shell_gl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698