Chromium Code Reviews| Index: chrome/browser/android/vr_shell/ui_scene_manager.cc |
| diff --git a/chrome/browser/android/vr_shell/ui_scene_manager.cc b/chrome/browser/android/vr_shell/ui_scene_manager.cc |
| index 543aa48e437854e5ffa63c8a95138f871142c0a5..915f86b2991bc0d8fd412ecd873b41d51680e29f 100644 |
| --- a/chrome/browser/android/vr_shell/ui_scene_manager.cc |
| +++ b/chrome/browser/android/vr_shell/ui_scene_manager.cc |
| @@ -12,24 +12,56 @@ namespace vr_shell { |
| namespace { |
| -enum Elements { |
| - // For now, use fixed element IDs, and ensure they do not collide with HTML UI |
| - // dynamically-chosen ID numbers. |
| - SecureOriginWarning = 1000, |
| -}; |
| +static constexpr int kWarningTimeoutSeconds = 30; |
| +static constexpr float kWarningDistance = 0.7; |
| +static constexpr float kWarningAngleRadians = 16.3 * M_PI / 180.0; |
| } // namespace |
| UiSceneManager::UiSceneManager(UiScene* scene) |
| : scene_(scene), weak_ptr_factory_(this) { |
| - // Create an invisible dummy warning quad. Actual security warnings will come |
| - // in a follow-on chance. |
| - auto warning = base::MakeUnique<UiElement>(); |
| - warning->id = Elements::SecureOriginWarning; |
| - warning->name = "test quad"; |
| - warning->translation = {0, 0, -1}; |
| - warning->fill = vr_shell::Fill::NONE; |
| - scene_->AddUiElement(std::move(warning)); |
| + std::unique_ptr<UiElement> element; |
| + |
| + // For now, use an ID range that does not conflict with the HTML UI. |
| + int id = 1000; |
| + |
| + // Permanent WebVR security warning. |
| + element = base::MakeUnique<UiElement>(); |
| + element->id = id++; |
| + element->name = "Permanent security warning"; |
| + // TODO(cjgrant): Map to Skia-generated texture with correct size. |
| + // element->fill = vr_shell::Fill::OPAQUE_GRADIENT; |
| + // element->edge_color = {128, 128, 128, 0.5}; |
| + // element->center_color = {128, 128, 128, 0.5}; |
| + element->fill = vr_shell::Fill::NONE; |
| + element->size = {0.226f, 0.078f, 1}; |
| + element->scale = {kWarningDistance, kWarningDistance, 1}; |
| + element->translation = {0, kWarningDistance * sin(kWarningAngleRadians), |
| + -kWarningDistance * cos(kWarningAngleRadians)}; |
| + element->rotation = {1.0f, 0, 0, kWarningAngleRadians}; |
| + element->visible = false; |
| + element->hit_testable = false; |
| + element->lock_to_fov = true; |
| + permanent_security_warning_ = element.get(); |
| + scene_->AddUiElement(std::move(element)); |
| + |
| + // Transient WebVR security warning. |
| + element = base::MakeUnique<UiElement>(); |
| + element->id = id++; |
| + element->name = "Transient security warning"; |
| + // TODO(cjgrant): Map to Skia-generated texture with correct size. |
| + // element->fill = vr_shell::Fill::OPAQUE_GRADIENT; |
| + // element->edge_color = {128, 128, 128, 0.5}; |
| + // element->center_color = {128, 128, 128, 0.5}; |
| + 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
|
| + element->size = {0.512f, 0.160f, 1}; |
| + element->scale = {kWarningDistance, kWarningDistance, 1}; |
| + element->translation = {0, 0, -kWarningDistance}; |
| + element->visible = false; |
| + element->hit_testable = false; |
| + element->lock_to_fov = true; |
| + transient_security_warning_ = element.get(); |
| + scene_->AddUiElement(std::move(element)); |
| } |
| UiSceneManager::~UiSceneManager() {} |
| @@ -44,10 +76,29 @@ void UiSceneManager::UpdateScene(std::unique_ptr<base::ListValue> commands) { |
| void UiSceneManager::SetWebVRMode(bool web_vr) { |
| web_vr_mode_ = web_vr; |
| + ConfigureSecurityWarnings(); |
| } |
| void UiSceneManager::SetWebVRSecureOrigin(bool secure) { |
| secure_origin_ = secure; |
| + ConfigureSecurityWarnings(); |
| +} |
| + |
| +void UiSceneManager::ConfigureSecurityWarnings() { |
| + bool enabled = web_vr_mode_ && !secure_origin_; |
| + permanent_security_warning_->visible = enabled; |
| + transient_security_warning_->visible = enabled; |
| + if (enabled) { |
| + security_warning_timer_.Start( |
| + FROM_HERE, base::TimeDelta::FromSeconds(kWarningTimeoutSeconds), this, |
| + &UiSceneManager::OnSecurityWarningTimer); |
| + } else { |
| + security_warning_timer_.Stop(); |
| + } |
| +} |
| + |
| +void UiSceneManager::OnSecurityWarningTimer() { |
| + transient_security_warning_->visible = false; |
| } |
| } // namespace vr_shell |