Implement navigation decision policy.
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / WebViewNavigationPolicyTest.cs
1 
2 using System;
3 using Tizen.NUI;
4 using Tizen.NUI.BaseComponents;
5 using Tizen.NUI.Components;
6 using System.IO;
7 using System.Text;
8
9 namespace Tizen.NUI.Samples
10 {
11     using tlog = Tizen.Log;
12
13     public class WebViewInterceptTest : IExample
14     {
15         const string tag = "NUITEST";
16         private View root;
17         private Window win;
18         private WebView webView;
19
20         public void Activate()
21         {
22             win = NUIApplication.GetDefaultWindow();
23
24             root = new View()
25             {
26                 Size = new Size(win.Size.Width, win.Size.Height, 0),
27                 BackgroundColor = Color.Green,
28                 Layout = new LinearLayout()
29                 {
30                     LinearOrientation = LinearLayout.Orientation.Vertical,
31                     Padding = new Extents(3, 3, 3, 3),
32                 },
33             };
34             win.Add(root);
35
36             webView = new WebView();
37             webView.Url = "https://www.google.com/";
38             webView.WidthSpecification = LayoutParamPolicies.MatchParent;
39             webView.HeightSpecification = LayoutParamPolicies.MatchParent;
40             root.Add(webView);
41
42             webView.NavigationPolicyDecided += OnCallback;
43         }
44
45         private void OnCallback(object sender, WebViewPolicyDecidedEventArgs e)
46         {
47             tlog.Debug(tag, $"callback: navigation policy decided, Url: {e.ResponsePolicyDecisionMaker.Url}");
48             e.ResponsePolicyDecisionMaker.Ignore();
49         }
50
51         public void Deactivate()
52         {
53             webView.Unparent();
54             root.Unparent();
55
56             webView.Dispose();
57             root.Dispose();
58         }
59     }
60 }