Index: chrome/browser/android/vr_shell/vr_shell.cc |
diff --git a/chrome/browser/android/vr_shell/vr_shell.cc b/chrome/browser/android/vr_shell/vr_shell.cc |
index 947645f82e66632acb4ee8f69ed5721da5fd7bb1..6a6247537b8399f76b8c985b00429c9a53aca9b1 100644 |
--- a/chrome/browser/android/vr_shell/vr_shell.cc |
+++ b/chrome/browser/android/vr_shell/vr_shell.cc |
@@ -12,6 +12,7 @@ |
#include "chrome/browser/android/vr_shell/vr_math.h" |
#include "chrome/browser/android/vr_shell/vr_shell_delegate.h" |
#include "chrome/browser/android/vr_shell/vr_shell_renderer.h" |
+#include "chrome/grit/generated_resources.h" |
#include "content/public/browser/android/content_view_core.h" |
#include "content/public/browser/render_widget_host.h" |
#include "content/public/browser/render_widget_host_view.h" |
@@ -19,6 +20,7 @@ |
#include "jni/VrShell_jni.h" |
#include "ui/android/view_android.h" |
#include "ui/android/window_android.h" |
+#include "ui/base/l10n/l10n_util.h" |
#include "ui/gl/gl_bindings.h" |
#include "ui/gl/init/gl_factory.h" |
@@ -124,6 +126,18 @@ void VrShell::GvrInit(JNIEnv* env, |
if (delegate_) |
delegate_->OnVrShellReady(this); |
+ |
+ // We can't currently draw text in GL content due to a prerequisite |
+ // patch not being ready yet. For now, we're using compiled-in |
+ // bitmaps instead as a placeholder, their content matches the |
+ // strings in generated_resources.grd. For now, just look up the |
+ // string resources here to confirm they are properly integrated. |
+ // |
+ // TODO(klausw): use these to build localized message textures. |
+ CHECK(l10n_util::GetStringUTF8( |
+ IDS_WEBSITE_SETTINGS_INSECURE_WEBVR_CONTENT_TRANSIENT).length() > 0); |
+ CHECK(l10n_util::GetStringUTF8( |
+ IDS_WEBSITE_SETTINGS_INSECURE_WEBVR_CONTENT_PERMANENT).length() > 0); |
} |
void VrShell::InitializeGl(JNIEnv* env, |
@@ -226,6 +240,9 @@ void VrShell::DrawFrame(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
if (webvr_mode_) { |
DrawWebVr(); |
+ if (!webvr_secure_origin_) { |
+ DrawWebVrOverlay(); |
+ } |
} else { |
DrawVrShell(target_time.monotonic_system_time_nanos); |
} |
@@ -388,10 +405,76 @@ void VrShell::DrawWebVr() { |
glViewport(0, 0, render_size_.width, render_size_.height); |
vr_shell_renderer_->GetWebVrRenderer()->Draw(content_texture_id_); |
+} |
- if (!webvr_secure_origin_) { |
- // TODO(klausw): Draw the insecure origin warning here. |
+void VrShell::DrawWebVrOverlay() { |
+ // Draw WebVR security warning overlays for each eye. This uses |
+ // the eye-from-head matrices but not the pose, goal is to place |
+ // the icons in an eye-relative position so that they follow along |
+ // with head rotations. |
+ |
+ gvr::Mat4f left_eye_view_matrix = |
+ gvr_api_->GetEyeFromHeadMatrix(GVR_LEFT_EYE); |
+ gvr::Mat4f right_eye_view_matrix = |
+ gvr_api_->GetEyeFromHeadMatrix(GVR_RIGHT_EYE); |
+ |
+ buffer_viewport_list_->GetBufferViewport(GVR_LEFT_EYE, |
+ buffer_viewport_.get()); |
+ DrawWebVrEye(left_eye_view_matrix, *buffer_viewport_); |
+ buffer_viewport_list_->GetBufferViewport(GVR_RIGHT_EYE, |
+ buffer_viewport_.get()); |
+ DrawWebVrEye(right_eye_view_matrix, *buffer_viewport_); |
+} |
+ |
+void VrShell::DrawWebVrEye(const gvr::Mat4f& view_matrix, |
+ const gvr::BufferViewport& params) { |
+ gvr::Recti pixel_rect = |
+ CalculatePixelSpaceRect(render_size_, params.GetSourceUv()); |
+ glViewport(pixel_rect.left, pixel_rect.bottom, |
+ pixel_rect.right - pixel_rect.left, |
+ pixel_rect.top - pixel_rect.bottom); |
+ glScissor(pixel_rect.left, pixel_rect.bottom, |
+ pixel_rect.right - pixel_rect.left, |
+ pixel_rect.top - pixel_rect.bottom); |
+ |
+ gvr::Mat4f projection_matrix = |
+ PerspectiveMatrixFromView(params.GetSourceFov(), kZNear, kZFar); |
+ |
+ // Draw insecure content warning icons. |
+ const float warning_depth = 0.7f; // Distance in meters. |
+ |
+ // Show IDS_WEBSITE_SETTINGS_INSECURE_WEBVR_CONTENT_PERMANENT text. |
+ gvr::Mat4f icon_pos; |
+ SetIdentityM(icon_pos); |
+ const float small_icon_width = 0.15f * warning_depth; |
+ const float small_icon_height = small_icon_width / 2.0f; // 2:1 aspect. |
+ const float small_icon_angle = 20.0f * M_PI / 180.f; // Degrees to radians. |
+ ScaleM(icon_pos, icon_pos, small_icon_width, small_icon_height, 1.0f); |
+ TranslateM(icon_pos, icon_pos, 0.0f, 0.0f, -warning_depth); |
+ icon_pos = MatrixMul( |
+ QuatToMatrix(QuatFromAxisAngle(1.f, 0.f, 0.f, small_icon_angle)), |
+ icon_pos); |
+ gvr::Mat4f combined = MatrixMul(projection_matrix, |
+ MatrixMul(view_matrix, icon_pos)); |
+ vr_shell_renderer_->GetOverlayIconRenderer()->Draw( |
+ combined, ICON_INSECURE_PERMANENT); |
+ |
+ // Do we need to show the transient warning also? |
+ if (webvr_warning_frames_ == 0) { |
+ return; |
} |
+ --webvr_warning_frames_; |
+ |
+ // Show IDS_WEBSITE_SETTINGS_INSECURE_WEBVR_CONTENT_TRANSIENT text. |
+ SetIdentityM(icon_pos); |
+ const float large_icon_width = 0.25f * warning_depth; |
+ const float large_icon_height = large_icon_width / 2.0f; // 2:1 aspect. |
+ ScaleM(icon_pos, icon_pos, large_icon_width, large_icon_height, 1.0f); |
+ TranslateM(icon_pos, icon_pos, 0.0f, 0.0f, -warning_depth); |
+ combined = MatrixMul(projection_matrix, |
+ MatrixMul(view_matrix, icon_pos)); |
+ vr_shell_renderer_->GetOverlayIconRenderer()->Draw( |
+ combined, ICON_INSECURE_TRANSIENT); |
} |
void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
@@ -430,6 +513,12 @@ void VrShell::SetWebVrMode(JNIEnv* env, |
const base::android::JavaParamRef<jobject>& obj, |
bool enabled) { |
webvr_mode_ = enabled; |
+ if (enabled) { |
+ const int warning_seconds = 30; |
+ webvr_warning_frames_ = warning_seconds * 60; |
+ } else { |
+ webvr_warning_frames_ = 0; |
+ } |
} |
void VrShell::SetWebVRSecureOrigin(bool secure_origin) { |