< Summary

Class:ExternalUrlPromptHUDController
Assembly:ExternalUrlPromptHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/ExternalUrlPromptHUD/ExternalUrlPromptHUDController.cs
Covered lines:42
Uncovered lines:1
Coverable lines:43
Total lines:97
Line coverage:97.6% (42 of 43)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ExternalUrlPromptHUDController()0%220100%
SetVisibility(...)0%220100%
Dispose()0%330100%
ProcessOpenUrlRequest(...)0%440100%
OpenUrl(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/ExternalUrlPromptHUD/ExternalUrlPromptHUDController.cs

#LineLine coverage
 1using DCL;
 2using DCL.Controllers;
 3using UnityEngine;
 4using System;
 5using System.Collections.Generic;
 6using DCL.Interface;
 7using DCL.Helpers;
 8using Environment = DCL.Environment;
 9
 10public class ExternalUrlPromptHUDController : IHUD
 11{
 012    internal ExternalUrlPromptView view { get; private set; }
 13
 514    internal Dictionary<string, HashSet<string>> trustedDomains = new Dictionary<string, HashSet<string>>();
 15
 516    public ExternalUrlPromptHUDController()
 17    {
 518        view = UnityEngine.Object.Instantiate(Resources.Load<GameObject>("ExternalUrlPromptHUD")).GetComponent<ExternalU
 519        view.name = "_ExternalUrlPromptHUD";
 520        view.content.SetActive(false);
 21
 522        if (Environment.i != null)
 523            Environment.i.world.sceneController.OnOpenExternalUrlRequest += ProcessOpenUrlRequest;
 524    }
 25
 26    public void SetVisibility(bool visible)
 27    {
 1028        view.gameObject.SetActive(visible);
 29
 1030        if (visible)
 31        {
 632            view.content.SetActive(true);
 633            view.showHideAnimator.Show();
 34
 635            AudioScriptableObjects.dialogOpen.Play(true);
 636        }
 37        else
 38        {
 439            view.showHideAnimator.Hide();
 40
 441            AudioScriptableObjects.dialogClose.Play(true);
 42        }
 443    }
 44
 45    public void Dispose()
 46    {
 547        if (Environment.i != null)
 548            Environment.i.world.sceneController.OnOpenExternalUrlRequest -= ProcessOpenUrlRequest;
 49
 550        trustedDomains.Clear();
 51
 552        if (view != null)
 553            UnityEngine.Object.Destroy(view.gameObject);
 554    }
 55
 56    internal void ProcessOpenUrlRequest(IParcelScene scene, string url)
 57    {
 58        Uri uri;
 659        if (Uri.TryCreate(url, UriKind.Absolute, out uri))
 60        {
 661            if (trustedDomains.ContainsKey(scene.sceneData.id) && trustedDomains[scene.sceneData.id].Contains(uri.Host))
 62            {
 163                OpenUrl(url);
 164                return;
 65            }
 66
 567            SetVisibility(true);
 568            Utils.UnlockCursor();
 569            view.RequestOpenUrl(uri, result =>
 70            {
 71                switch (result)
 72                {
 73                    case ExternalUrlPromptView.ResultType.APPROVED_TRUSTED:
 174                        if (!trustedDomains.ContainsKey(scene.sceneData.id))
 75                        {
 176                            trustedDomains.Add(scene.sceneData.id, new HashSet<string>());
 77                        }
 78
 179                        trustedDomains[scene.sceneData.id].Add(uri.Host);
 180                        OpenUrl(url);
 181                        break;
 82                    case ExternalUrlPromptView.ResultType.APPROVED:
 183                        OpenUrl(url);
 84                        break;
 85                }
 86
 487                SetVisibility(false);
 488            });
 89        }
 590    }
 91
 92    private void OpenUrl(string url)
 93    {
 394        WebInterface.OpenURL(url);
 395        AnalyticsHelper.SendExternalLinkAnalytic(url);
 396    }
 97}