Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/ui_scene_manager.h" | 5 #include "chrome/browser/android/vr_shell/ui_scene_manager.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "chrome/browser/android/vr_shell/ui_element.h" | 8 #include "chrome/browser/android/vr_shell/ui_element.h" |
| 9 #include "chrome/browser/android/vr_shell/ui_scene.h" | 9 #include "chrome/browser/android/vr_shell/ui_scene.h" |
| 10 | 10 |
| 11 namespace vr_shell { | 11 namespace vr_shell { |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 enum Elements { | 15 static constexpr int kWarningTimeoutSeconds = 30; |
| 16 // For now, use fixed element IDs, and ensure they do not collide with HTML UI | 16 static constexpr float kWarningDistance = 0.7; |
| 17 // dynamically-chosen ID numbers. | 17 static constexpr float kWarningAngleRadians = 16.3 * M_PI / 180.0; |
| 18 SecureOriginWarning = 1000, | |
| 19 }; | |
| 20 | 18 |
| 21 } // namespace | 19 } // namespace |
| 22 | 20 |
| 23 UiSceneManager::UiSceneManager(UiScene* scene) | 21 UiSceneManager::UiSceneManager(UiScene* scene) |
| 24 : scene_(scene), weak_ptr_factory_(this) { | 22 : scene_(scene), weak_ptr_factory_(this) { |
| 25 // Create an invisible dummy warning quad. Actual security warnings will come | 23 std::unique_ptr<UiElement> element; |
| 26 // in a follow-on chance. | 24 |
| 27 auto warning = base::MakeUnique<UiElement>(); | 25 // For now, use an ID range that does not conflict with the HTML UI. |
| 28 warning->id = Elements::SecureOriginWarning; | 26 int id = 1000; |
| 29 warning->name = "test quad"; | 27 |
| 30 warning->translation = {0, 0, -1}; | 28 // Permanent WebVR security warning. |
| 31 warning->fill = vr_shell::Fill::NONE; | 29 element = base::MakeUnique<UiElement>(); |
| 32 scene_->AddUiElement(std::move(warning)); | 30 element->id = id++; |
| 31 element->name = "Permanent security warning"; | |
| 32 // TODO(cjgrant): Map to Skia-generated texture with correct size. | |
| 33 // element->fill = vr_shell::Fill::OPAQUE_GRADIENT; | |
| 34 // element->edge_color = {128, 128, 128, 0.5}; | |
| 35 // element->center_color = {128, 128, 128, 0.5}; | |
| 36 element->fill = vr_shell::Fill::NONE; | |
| 37 element->size = {0.226f, 0.078f, 1}; | |
| 38 element->scale = {kWarningDistance, kWarningDistance, 1}; | |
| 39 element->translation = {0, kWarningDistance * sin(kWarningAngleRadians), | |
| 40 -kWarningDistance * cos(kWarningAngleRadians)}; | |
| 41 element->rotation = {1.0f, 0, 0, kWarningAngleRadians}; | |
| 42 element->visible = false; | |
| 43 element->hit_testable = false; | |
| 44 element->lock_to_fov = true; | |
| 45 permanent_security_warning_ = element.get(); | |
| 46 scene_->AddUiElement(std::move(element)); | |
| 47 | |
| 48 // Transient WebVR security warning. | |
| 49 element = base::MakeUnique<UiElement>(); | |
| 50 element->id = id++; | |
| 51 element->name = "Transient security warning"; | |
| 52 // TODO(cjgrant): Map to Skia-generated texture with correct size. | |
| 53 // element->fill = vr_shell::Fill::OPAQUE_GRADIENT; | |
| 54 // element->edge_color = {128, 128, 128, 0.5}; | |
| 55 // element->center_color = {128, 128, 128, 0.5}; | |
| 56 element->fill = vr_shell::Fill::NONE; | |
|
acondor_
2017/04/11 21:01:17
What about a new Fill type for the Skia texture?
cjgrant
2017/04/11 21:05:38
Possibly, but if it did, that would come with your
| |
| 57 element->size = {0.512f, 0.160f, 1}; | |
| 58 element->scale = {kWarningDistance, kWarningDistance, 1}; | |
| 59 element->translation = {0, 0, -kWarningDistance}; | |
| 60 element->visible = false; | |
| 61 element->hit_testable = false; | |
| 62 element->lock_to_fov = true; | |
| 63 transient_security_warning_ = element.get(); | |
| 64 scene_->AddUiElement(std::move(element)); | |
| 33 } | 65 } |
| 34 | 66 |
| 35 UiSceneManager::~UiSceneManager() {} | 67 UiSceneManager::~UiSceneManager() {} |
| 36 | 68 |
| 37 base::WeakPtr<UiSceneManager> UiSceneManager::GetWeakPtr() { | 69 base::WeakPtr<UiSceneManager> UiSceneManager::GetWeakPtr() { |
| 38 return weak_ptr_factory_.GetWeakPtr(); | 70 return weak_ptr_factory_.GetWeakPtr(); |
| 39 } | 71 } |
| 40 | 72 |
| 41 void UiSceneManager::UpdateScene(std::unique_ptr<base::ListValue> commands) { | 73 void UiSceneManager::UpdateScene(std::unique_ptr<base::ListValue> commands) { |
| 42 scene_->HandleCommands(std::move(commands), base::TimeTicks::Now()); | 74 scene_->HandleCommands(std::move(commands), base::TimeTicks::Now()); |
| 43 } | 75 } |
| 44 | 76 |
| 45 void UiSceneManager::SetWebVRMode(bool web_vr) { | 77 void UiSceneManager::SetWebVRMode(bool web_vr) { |
| 46 web_vr_mode_ = web_vr; | 78 web_vr_mode_ = web_vr; |
| 79 ConfigureSecurityWarnings(); | |
| 47 } | 80 } |
| 48 | 81 |
| 49 void UiSceneManager::SetWebVRSecureOrigin(bool secure) { | 82 void UiSceneManager::SetWebVRSecureOrigin(bool secure) { |
| 50 secure_origin_ = secure; | 83 secure_origin_ = secure; |
| 84 ConfigureSecurityWarnings(); | |
| 85 } | |
| 86 | |
| 87 void UiSceneManager::ConfigureSecurityWarnings() { | |
| 88 bool enabled = web_vr_mode_ && !secure_origin_; | |
| 89 permanent_security_warning_->visible = enabled; | |
| 90 transient_security_warning_->visible = enabled; | |
| 91 if (enabled) { | |
| 92 security_warning_timer_.Start( | |
| 93 FROM_HERE, base::TimeDelta::FromSeconds(kWarningTimeoutSeconds), this, | |
| 94 &UiSceneManager::OnSecurityWarningTimer); | |
| 95 } else { | |
| 96 security_warning_timer_.Stop(); | |
| 97 } | |
| 98 } | |
| 99 | |
| 100 void UiSceneManager::OnSecurityWarningTimer() { | |
| 101 transient_security_warning_->visible = false; | |
| 51 } | 102 } |
| 52 | 103 |
| 53 } // namespace vr_shell | 104 } // namespace vr_shell |
| OLD | NEW |