Add webview API for url,change event.
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / WebView.cs
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 using System;
19 using System.ComponentModel;
20 using System.Collections.Generic;
21 using System.Runtime.InteropServices;
22 using Tizen.NUI.BaseComponents;
23 using Tizen.NUI.Binding;
24
25 namespace Tizen.NUI
26 {
27     /// <summary>
28     /// WebView
29     /// </summary>
30     [EditorBrowsable(EditorBrowsableState.Never)]
31     public class WebView : View
32     {
33         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
34         private delegate void WebViewPageLoadCallback(string pageUrl);
35
36         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
37         private delegate void WebViewPageLoadErrorCallback(string pageUrl, int errorCode);
38
39         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
40         private delegate void WebViewScrollEdgeReachedCallback(int edge);
41
42         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
43         private delegate void WebViewUrlChangedCallbackDelegate(string pageUrl);
44
45         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
46         private delegate void WebViewPolicyDecidedCallback(IntPtr maker);
47
48         private EventHandler<WebViewPageLoadEventArgs> pageLoadStartedEventHandler;
49         private WebViewPageLoadCallback pageLoadStartedCallback;
50
51         private EventHandler<WebViewPageLoadEventArgs> pageLoadFinishedEventHandler;
52         private WebViewPageLoadCallback pageLoadFinishedCallback;
53
54         private EventHandler<WebViewPageLoadErrorEventArgs> pageLoadErrorEventHandler;
55         private WebViewPageLoadErrorCallback pageLoadErrorCallback;
56
57         private EventHandler<WebViewScrollEdgeReachedEventArgs> scrollEdgeReachedEventHandler;
58         private WebViewScrollEdgeReachedCallback scrollEdgeReachedCallback;
59
60         private EventHandler<WebViewUrlChangedEventArgs> urlChangedEventHandler;
61         private WebViewUrlChangedCallbackDelegate urlChangedCallback;
62
63         private EventHandler<WebViewPolicyDecidedEventArgs> navigationPolicyDecidedEventHandler;
64         private WebViewPolicyDecidedCallback navigationPolicyDecidedCallback;
65
66         private PlainTextReceivedCallback plainTextReceivedCallback;
67
68         /// <summary>
69         /// The callback function that is invoked when the plain text of the current page is received.
70         /// </summary>
71         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
72         [EditorBrowsable(EditorBrowsableState.Never)]
73         public delegate void PlainTextReceivedCallback(string plainText);
74
75         internal WebView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.WebView.WebView_SWIGUpcast(cPtr), cMemoryOwn)
76         {
77             BackForwardList = new WebBackForwardList(Interop.WebView.GetWebBackForwardList(SwigCPtr), false);
78             Context = new WebContext(Interop.WebView.GetWebContext(SwigCPtr), false);
79             CookieManager = new WebCookieManager(Interop.WebView.GetWebCookieManager(SwigCPtr), false);
80             Settings = new WebSettings(Interop.WebView.GetWebSettings(SwigCPtr), false);
81         }
82
83         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(WebView obj)
84         {
85             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
86         }
87
88         internal WebView Assign(WebView webView)
89         {
90             WebView ret = new WebView(Interop.WebView.WebView_Assign(swigCPtr, WebView.getCPtr(webView)), false);
91             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
92             return ret;
93         }
94
95         internal static WebView DownCast(BaseHandle handle)
96         {
97             WebView ret = new WebView(Interop.WebView.WebView_DownCast(BaseHandle.getCPtr(handle)), true);
98             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
99             return ret;
100         }
101
102         /// <summary>
103         /// Dispose for IDisposable pattern
104         /// </summary>
105         [EditorBrowsable(EditorBrowsableState.Never)]
106         protected override void Dispose(DisposeTypes type)
107         {
108             if (disposed)
109             {
110                 return;
111             }
112
113             if (type == DisposeTypes.Explicit)
114             {
115                 //Called by User
116                 //Release your own managed resources here.
117                 //You should release all of your own disposable objects here.
118                 BackForwardList.Dispose();
119                 Context.Dispose();
120                 CookieManager.Dispose();
121                 Settings.Dispose();
122             }
123
124             base.Dispose(type);
125         }
126
127         /// This will not be public opened.
128         /// <param name="swigCPtr"></param>
129         [EditorBrowsable(EditorBrowsableState.Never)]
130         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
131         {
132             Interop.WebView.delete_WebView(swigCPtr);
133         }
134
135         private void OnPageLoadStarted(string pageUrl)
136         {
137             WebViewPageLoadEventArgs e = new WebViewPageLoadEventArgs();
138
139             e.WebView = this;
140             e.PageUrl = pageUrl;
141
142             pageLoadStartedEventHandler?.Invoke(this, e);
143         }
144
145         private void OnPageLoadFinished(string pageUrl)
146         {
147             WebViewPageLoadEventArgs e = new WebViewPageLoadEventArgs();
148
149             e.WebView = this;
150             e.PageUrl = pageUrl;
151
152             pageLoadFinishedEventHandler?.Invoke(this, e);
153         }
154
155         private void OnPageLoadError(string pageUrl, int errorCode)
156         {
157             WebViewPageLoadErrorEventArgs e = new WebViewPageLoadErrorEventArgs();
158
159             e.WebView = this;
160             e.PageUrl = pageUrl;
161             e.ErrorCode = (WebViewPageLoadErrorEventArgs.LoadErrorCode)errorCode;
162
163             pageLoadErrorEventHandler?.Invoke(this, e);
164         }
165
166         private void OnScrollEdgeReached(int edge)
167         {
168             scrollEdgeReachedEventHandler?.Invoke(this, new WebViewScrollEdgeReachedEventArgs((WebViewScrollEdgeReachedEventArgs.Edge)edge));
169         }
170
171         private void OnUrlChanged(string pageUrl)
172         {
173             urlChangedEventHandler?.Invoke(this, new WebViewUrlChangedEventArgs(pageUrl));
174         }
175
176         private void OnNavigationPolicyDecided(IntPtr maker)
177         {
178             navigationPolicyDecidedEventHandler?.Invoke(this, new WebViewPolicyDecidedEventArgs(new WebPolicyDecisionMaker(maker, true)));
179         }
180
181         internal static new class Property
182         {
183             internal static readonly int URL = Interop.WebView.WebView_Property_URL_get();
184             internal static readonly int USER_AGENT = Interop.WebView.WebView_Property_USER_AGENT_get();
185             internal static readonly int ScrollPosition = Interop.WebView.ScrollPositionGet();
186             internal static readonly int ScrollSize = Interop.WebView.ScrollSizeGet();
187             internal static readonly int ContentSize = Interop.WebView.ContentSizeGet();
188             internal static readonly int Title = Interop.WebView.TitleGet();
189             internal static readonly int VideoHoleEnabled = Interop.WebView.VideoHoleEnabledGet();
190         }
191
192         private static readonly BindableProperty UrlProperty = BindableProperty.Create(nameof(Url), typeof(string), typeof(WebView), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
193         {
194             var webview = (WebView)bindable;
195             if (newValue != null)
196             {
197                 Tizen.NUI.Object.SetProperty(webview.swigCPtr, WebView.Property.URL, new Tizen.NUI.PropertyValue((string)newValue));
198             }
199         },
200         defaultValueCreator: (bindable) =>
201         {
202             var webview = (WebView)bindable;
203             string temp;
204             Tizen.NUI.Object.GetProperty(webview.swigCPtr, WebView.Property.URL).Get(out temp);
205             return temp;
206         });
207
208         private static readonly BindableProperty UserAgentProperty = BindableProperty.Create(nameof(UserAgent), typeof(string), typeof(WebView), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
209         {
210             var webview = (WebView)bindable;
211             if (newValue != null)
212             {
213                 Tizen.NUI.Object.SetProperty(webview.swigCPtr, WebView.Property.USER_AGENT, new Tizen.NUI.PropertyValue((string)newValue));
214             }
215         },
216         defaultValueCreator: (bindable) =>
217         {
218             var webview = (WebView)bindable;
219             string temp;
220             Tizen.NUI.Object.GetProperty(webview.swigCPtr, WebView.Property.USER_AGENT).Get(out temp);
221             return temp;
222         });
223
224         private static readonly BindableProperty ScrollPositionProperty = BindableProperty.Create(nameof(ScrollPosition), typeof(Vector2), typeof(WebView), null, propertyChanged: (bindable, oldValue, newValue) =>
225         {
226             var webview = (WebView)bindable;
227             if (newValue != null)
228             {
229                 Tizen.NUI.Object.SetProperty(webview.SwigCPtr, WebView.Property.ScrollPosition, new Tizen.NUI.PropertyValue((Vector2)newValue));
230             }
231         },
232         defaultValueCreator: (bindable) =>
233         {
234             var webview = (WebView)bindable;
235             Vector2 temp = new Vector2(0.0f, 0.0f);
236             Tizen.NUI.Object.GetProperty(webview.SwigCPtr, WebView.Property.ScrollPosition).Get(temp);
237             return temp;
238         });
239
240         private static readonly BindableProperty ScrollSizeProperty = BindableProperty.Create(nameof(ScrollSize), typeof(Vector2), typeof(WebView), null, defaultValueCreator: (bindable) =>
241         {
242             var webview = (WebView)bindable;
243             Vector2 temp = new Vector2(0.0f, 0.0f);
244             Tizen.NUI.Object.GetProperty(webview.SwigCPtr, WebView.Property.ScrollSize).Get(temp);
245             return temp;
246         });
247
248         private static readonly BindableProperty ContentSizeProperty = BindableProperty.Create(nameof(ContentSize), typeof(Vector2), typeof(WebView), null, defaultValueCreator: (bindable) =>
249         {
250             var webview = (WebView)bindable;
251             Vector2 temp = new Vector2(0.0f, 0.0f);
252             Tizen.NUI.Object.GetProperty(webview.SwigCPtr, WebView.Property.ContentSize).Get(temp);
253             return temp;
254         });
255
256         private static readonly BindableProperty TitleProperty = BindableProperty.Create(nameof(Title), typeof(string), typeof(WebView), null, defaultValueCreator: (bindable) =>
257         {
258             var webview = (WebView)bindable;
259             string title;
260             Tizen.NUI.Object.GetProperty(webview.SwigCPtr, WebView.Property.Title).Get(out title);
261             return title;
262         });
263
264         private static readonly BindableProperty VideoHoleEnabledProperty = BindableProperty.Create(nameof(VideoHoleEnabled), typeof(bool), typeof(WebView), true, propertyChanged: (bindable, oldValue, newValue) =>
265         {
266             var webview = (WebView)bindable;
267             if (newValue != null)
268             {
269                 Tizen.NUI.Object.SetProperty(webview.SwigCPtr, WebView.Property.VideoHoleEnabled, new Tizen.NUI.PropertyValue((bool)newValue));
270             }
271         },
272         defaultValueCreator: (bindable) =>
273         {
274             var webview = (WebView)bindable;
275             bool temp;
276             Tizen.NUI.Object.GetProperty(webview.SwigCPtr, WebView.Property.VideoHoleEnabled).Get(out temp);
277             return temp;
278         });
279
280         /// <summary>
281         /// Creates a WebView.
282         /// </summary>
283         [EditorBrowsable(EditorBrowsableState.Never)]
284         public WebView() : this(Interop.WebView.WebView_New(), true)
285         {
286             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
287         }
288
289         /// <summary>
290         /// Creates a WebView with local language and time zone.
291         /// <param name="locale">The locale language of Web</param>
292         /// <param name="timezoneId">The time zone Id of Web</param>
293         /// </summary>
294         [EditorBrowsable(EditorBrowsableState.Never)]
295         public WebView(string locale, string timezoneId) : this(Interop.WebView.WebView_New_2(locale, timezoneId), true)
296         {
297             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
298         }
299
300         /// <summary>
301         /// Creates a WebView with an args list.
302         /// <param name="args">args array. The first value of array must be program's name.</param>
303         /// </summary>
304         [EditorBrowsable(EditorBrowsableState.Never)]
305         public WebView(string[] args) : this(Interop.WebView.WebView_New_3(args?.Length ?? 0, args), true)
306         {
307             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
308         }
309
310         /// <summary>
311         /// Copy constructor.
312         /// <param name="webView">WebView to copy. The copied WebView will point at the same implementation</param>
313         /// </summary>
314         [EditorBrowsable(EditorBrowsableState.Never)]
315         public WebView(WebView webView) : this(Interop.WebView.new_WebView__SWIG_1(WebView.getCPtr(webView)), true)
316         {
317             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
318         }
319
320         /// <summary>
321         /// BackForwardList.
322         /// </summary>
323         [EditorBrowsable(EditorBrowsableState.Never)]
324         public WebBackForwardList BackForwardList { get; }
325
326         /// <summary>
327         /// Context.
328         /// </summary>
329         [EditorBrowsable(EditorBrowsableState.Never)]
330         public WebContext Context { get; }
331
332         /// <summary>
333         /// CookieManager.
334         /// </summary>
335         [EditorBrowsable(EditorBrowsableState.Never)]
336         public WebCookieManager CookieManager { get; }
337
338         /// <summary>
339         /// BackForwardList.
340         /// </summary>
341         [EditorBrowsable(EditorBrowsableState.Never)]
342         public WebSettings Settings { get; }
343
344         /// <summary>
345         /// The url to load.
346         /// </summary>
347         [EditorBrowsable(EditorBrowsableState.Never)]
348         public string Url
349         {
350             get
351             {
352                 return (string)GetValue(UrlProperty);
353             }
354             set
355             {
356                 SetValue(UrlProperty, value);
357                 NotifyPropertyChanged();
358             }
359         }
360
361         /// <summary>
362         /// Deprecated. The cache model of the current WebView.
363         /// </summary>
364         [EditorBrowsable(EditorBrowsableState.Never)]
365         public CacheModel CacheModel
366         {
367             get
368             {
369                 return (CacheModel)Context.CacheModel;
370             }
371             set
372             {
373                 Context.CacheModel = (WebContext.CacheModelType)value;
374             }
375         }
376
377         /// <summary>
378         /// Deprecated. The cookie acceptance policy.
379         /// </summary>
380         [EditorBrowsable(EditorBrowsableState.Never)]
381         public CookieAcceptPolicy CookieAcceptPolicy
382         {
383             get
384             {
385                 return (CookieAcceptPolicy)CookieManager.CookieAcceptPolicy;
386             }
387             set
388             {
389                 CookieManager.CookieAcceptPolicy = (WebCookieManager.CookieAcceptPolicyType)value;
390             }
391         }
392
393         /// <summary>
394         /// The user agent string.
395         /// </summary>
396         [EditorBrowsable(EditorBrowsableState.Never)]
397         public string UserAgent
398         {
399             get
400             {
401                 return (string)GetValue(UserAgentProperty);
402             }
403             set
404             {
405                 SetValue(UserAgentProperty, value);
406                 NotifyPropertyChanged();
407             }
408         }
409
410         /// <summary>
411         /// Deprecated. Whether JavaScript is enabled.
412         /// </summary>
413         [EditorBrowsable(EditorBrowsableState.Never)]
414         public bool EnableJavaScript
415         {
416             get
417             {
418                 return Settings.EnableJavaScript;
419             }
420             set
421             {
422                 Settings.EnableJavaScript = value;
423             }
424         }
425
426         /// <summary>
427         /// Deprecated. Whether images can be loaded automatically.
428         /// </summary>
429         [EditorBrowsable(EditorBrowsableState.Never)]
430         public bool LoadImagesAutomatically
431         {
432             get
433             {
434                 return Settings.AllowImagesLoadAutomatically;
435             }
436             set
437             {
438                 Settings.AllowImagesLoadAutomatically = value;
439             }
440         }
441
442         /// <summary>
443         /// The default text encoding name.<br />
444         /// e.g. "UTF-8"<br />
445         /// </summary>
446         [EditorBrowsable(EditorBrowsableState.Never)]
447         public string DefaultTextEncodingName
448         {
449             get
450             {
451                 return Settings.DefaultTextEncodingName;
452             }
453             set
454             {
455                 Settings.DefaultTextEncodingName = value;
456             }
457         }
458
459         /// <summary>
460         /// The default font size in pixel.
461         /// </summary>
462         [EditorBrowsable(EditorBrowsableState.Never)]
463         public int DefaultFontSize
464         {
465             get
466             {
467                 return Settings.DefaultFontSize;
468             }
469             set
470             {
471                 Settings.DefaultFontSize = value;
472             }
473         }
474
475         /// <summary>
476         /// The postion of scroll.
477         /// </summary>
478         [EditorBrowsable(EditorBrowsableState.Never)]
479         public Position ScrollPosition
480         {
481             get
482             {
483                 Vector2 pv = (Vector2)GetValue(ScrollPositionProperty);
484                 return new Position(pv.X, pv.Y);
485             }
486             set
487             {
488                 if (value != null)
489                 {
490                     Position pv = value;
491                     Vector2 vpv = new Vector2(pv.X, pv.Y);
492                     SetValue(ScrollPositionProperty, vpv);
493                     NotifyPropertyChanged();
494                 }
495             }
496         }
497
498         /// <summary>
499         /// The size of scroll, read-only.
500         /// </summary>
501         [EditorBrowsable(EditorBrowsableState.Never)]
502         public Size ScrollSize
503         {
504             get
505             {
506                 Vector2 sv = (Vector2)GetValue(ScrollSizeProperty);
507                 return new Size(sv.Width, sv.Height);
508             }
509         }
510
511         /// <summary>
512         /// The size of content, read-only.
513         /// </summary>
514         [EditorBrowsable(EditorBrowsableState.Never)]
515         public Size ContentSize
516         {
517             get
518             {
519                 Vector2 sv = (Vector2)GetValue(ContentSizeProperty);
520                 return new Size(sv.Width, sv.Height);
521             }
522         }
523
524         /// <summary>
525         /// Whether video hole is enabled or not.
526         /// </summary>
527         [EditorBrowsable(EditorBrowsableState.Never)]
528         public bool VideoHoleEnabled
529         {
530             get
531             {
532                 return (bool)GetValue(VideoHoleEnabledProperty);
533             }
534             set
535             {
536                 SetValue(VideoHoleEnabledProperty, value);
537                 NotifyPropertyChanged();
538             }
539         }
540
541         /// <summary>
542         /// Event for the PageLoadStarted signal which can be used to subscribe or unsubscribe the event handler.<br />
543         /// This signal is emitted when page loading has started.<br />
544         /// </summary>
545         [EditorBrowsable(EditorBrowsableState.Never)]
546         public event EventHandler<WebViewPageLoadEventArgs> PageLoadStarted
547         {
548             add
549             {
550                 if (pageLoadStartedEventHandler == null)
551                 {
552                     pageLoadStartedCallback = OnPageLoadStarted;
553                     IntPtr ip = Marshal.GetFunctionPointerForDelegate(pageLoadStartedCallback);
554                     Interop.WebView.RegisterPageLoadStartedCallback(SwigCPtr, new HandleRef(this, ip));
555                 }
556                 pageLoadStartedEventHandler += value;
557             }
558             remove
559             {
560                 pageLoadStartedEventHandler -= value;
561             }
562         }
563
564         /// <summary>
565         /// Event for the PageLoadFinished signal which can be used to subscribe or unsubscribe the event handler.<br />
566         /// This signal is emitted when page loading has finished.<br />
567         /// </summary>
568         [EditorBrowsable(EditorBrowsableState.Never)]
569         public event EventHandler<WebViewPageLoadEventArgs> PageLoadFinished
570         {
571             add
572             {
573                 if (pageLoadFinishedEventHandler == null)
574                 {
575                     pageLoadFinishedCallback = OnPageLoadFinished;
576                     IntPtr ip = Marshal.GetFunctionPointerForDelegate(pageLoadFinishedCallback);
577                     Interop.WebView.RegisterPageLoadFinishedCallback(SwigCPtr, new HandleRef(this, ip));
578                 }
579                 pageLoadFinishedEventHandler += value;
580             }
581             remove
582             {
583                 pageLoadFinishedEventHandler -= value;
584             }
585         }
586
587         /// <summary>
588         /// Event for the PageLoadError signal which can be used to subscribe or unsubscribe the event handler.<br />
589         /// This signal is emitted when there's an error in page loading.<br />
590         /// </summary>
591         [EditorBrowsable(EditorBrowsableState.Never)]
592         public event EventHandler<WebViewPageLoadErrorEventArgs> PageLoadError
593         {
594             add
595             {
596                 pageLoadErrorCallback = OnPageLoadError;
597                 IntPtr ip = Marshal.GetFunctionPointerForDelegate(pageLoadErrorCallback);
598                 Interop.WebView.RegisterPageLoadErrorCallback(SwigCPtr, new HandleRef(this, ip));
599             }
600             remove
601             {
602                 pageLoadErrorEventHandler -= value;
603             }
604         }
605
606         /// <summary>
607         /// Event for the ScrollEdgeReached signal which can be used to subscribe or unsubscribe the event handler.<br />
608         /// This signal is emitted when web view is scrolled to edge.<br />
609         /// </summary>
610         [EditorBrowsable(EditorBrowsableState.Never)]
611         public event EventHandler<WebViewScrollEdgeReachedEventArgs> ScrollEdgeReached
612         {
613             add
614             {
615                 scrollEdgeReachedCallback = OnScrollEdgeReached;
616                 IntPtr ip = Marshal.GetFunctionPointerForDelegate(scrollEdgeReachedCallback);
617                 Interop.WebView.RegisterScrollEdgeReachedCallback(SwigCPtr, new HandleRef(this, ip));
618             }
619             remove
620             {
621                 scrollEdgeReachedEventHandler -= value;
622             }
623         }
624
625         /// <summary>
626         /// Event for the UrlChanged signal which can be used to subscribe or unsubscribe the event handler.<br />
627         /// This signal is emitted when url is changed.<br />
628         /// </summary>
629         [EditorBrowsable(EditorBrowsableState.Never)]
630         public event EventHandler<WebViewUrlChangedEventArgs> UrlChanged
631         {
632             add
633             {
634                 if (urlChangedEventHandler == null)
635                 {
636                     urlChangedCallback = OnUrlChanged;
637                     IntPtr ip = Marshal.GetFunctionPointerForDelegate(urlChangedCallback);
638                     Interop.WebView.RegisterUrlChangedCallback(SwigCPtr, new HandleRef(this, ip));
639                 }
640                 urlChangedEventHandler += value;
641             }
642             remove
643             {
644                 urlChangedEventHandler -= value;
645             }
646         }
647
648         /// <summary>
649         /// Event for the NavigationPolicyDecided signal which can be used to subscribe or unsubscribe the event handler.<br />
650         /// This signal is emitted when response policy would be decided.<br />
651         /// </summary>
652         [EditorBrowsable(EditorBrowsableState.Never)]
653         public event EventHandler<WebViewPolicyDecidedEventArgs> NavigationPolicyDecided
654         {
655             add
656             {
657                 if (navigationPolicyDecidedEventHandler == null)
658                 {
659                     navigationPolicyDecidedCallback = OnNavigationPolicyDecided;
660                     IntPtr ip = Marshal.GetFunctionPointerForDelegate(navigationPolicyDecidedCallback);
661                     Interop.WebView.RegisterNavigationPolicyDecidedCallback(SwigCPtr, new HandleRef(this, ip));
662                 }
663                 navigationPolicyDecidedEventHandler += value;
664             }
665             remove
666             {
667                 navigationPolicyDecidedEventHandler -= value;
668             }
669         }
670
671         /// <summary>
672         /// Gets title of web page.
673         /// </summary>
674         [EditorBrowsable(EditorBrowsableState.Never)]
675         public string Title
676         {
677             get
678             {
679                 return (string)GetValue(TitleProperty);
680             }
681         }
682
683         /// <summary>
684         /// Gets fav icon.
685         /// </summary>
686         [EditorBrowsable(EditorBrowsableState.Never)]
687         public ImageView Favicon
688         {
689             get
690             {
691                 global::System.IntPtr imageView = Interop.WebView.WebView_GetFavicon(swigCPtr);
692                 if (imageView == IntPtr.Zero)
693                     return null;
694                 return new ImageView(imageView, false);
695             }
696         }
697
698         /// <summary>
699         /// Loads a html.
700         /// <param name="url">The path of Web</param>
701         /// </summary>
702         [EditorBrowsable(EditorBrowsableState.Never)]
703         public void LoadUrl(string url)
704         {
705             Interop.WebView.WebView_LoadUrl(swigCPtr, url);
706             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
707         }
708
709         /// <summary>
710         /// Deprecated. Loads a html by string.
711         /// <param name="data">The data of Web</param>
712         /// </summary>
713         [EditorBrowsable(EditorBrowsableState.Never)]
714         public void LoadHTMLString(string data)
715         {
716             Interop.WebView.LoadHtmlString(SwigCPtr, data);
717             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
718         }
719
720         /// <summary>
721         /// Loads a html by string.
722         /// <param name="data">The data of Web</param>
723         /// </summary>
724         [EditorBrowsable(EditorBrowsableState.Never)]
725         public void LoadHtmlString(string data)
726         {
727             Interop.WebView.LoadHtmlString(SwigCPtr, data);
728             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
729         }
730
731         /// <summary>
732         /// Reloads the Web
733         /// </summary>
734         [EditorBrowsable(EditorBrowsableState.Never)]
735         public void Reload()
736         {
737             Interop.WebView.WebView_Reload(swigCPtr);
738             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
739         }
740
741         /// <summary>
742         /// Stops loading the Web
743         /// </summary>
744         [EditorBrowsable(EditorBrowsableState.Never)]
745         public void StopLoading()
746         {
747             Interop.WebView.WebView_StopLoading(swigCPtr);
748             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
749         }
750
751         /// <summary>
752         /// Suspends the operation.
753         /// </summary>
754         [EditorBrowsable(EditorBrowsableState.Never)]
755         public void Suspend()
756         {
757             Interop.WebView.WebView_Suspend(swigCPtr);
758             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
759         }
760
761         /// <summary>
762         /// Resumes the operation after calling Suspend()
763         /// </summary>
764         [EditorBrowsable(EditorBrowsableState.Never)]
765         public void Resume()
766         {
767             Interop.WebView.WebView_Resume(swigCPtr);
768             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
769         }
770
771         /// <summary>
772         /// Scroll web view by deltaX and detlaY.
773         /// <param name="deltaX">The deltaX of scroll</param>
774         /// <param name="deltaY">The deltaY of scroll</param>
775         /// </summary>
776         [EditorBrowsable(EditorBrowsableState.Never)]
777         public void ScrollBy(int deltaX, int deltaY)
778         {
779             Interop.WebView.ScrollBy(SwigCPtr, deltaX, deltaY);
780             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
781         }
782
783         /// <summary>
784         /// Goes to the back
785         /// </summary>
786         [EditorBrowsable(EditorBrowsableState.Never)]
787         public void GoBack()
788         {
789             Interop.WebView.WebView_GoBack(swigCPtr);
790             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
791         }
792
793         /// <summary>
794         /// Goes to the forward
795         /// </summary>
796         [EditorBrowsable(EditorBrowsableState.Never)]
797         public void GoForward()
798         {
799             Interop.WebView.WebView_GoForward(swigCPtr);
800             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
801         }
802
803         /// <summary>
804         /// Returns whether backward is possible.
805         /// <returns>True if backward is possible, false otherwise</returns>
806         /// </summary>
807         [EditorBrowsable(EditorBrowsableState.Never)]
808         public bool CanGoBack()
809         {
810             bool ret = Interop.WebView.WebView_CanGoBack(swigCPtr);
811             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
812             return ret;
813         }
814
815         /// <summary>
816         /// Returns whether forward is possible.
817         /// <returns>True if forward is possible, false otherwise</returns>
818         /// </summary>
819         [EditorBrowsable(EditorBrowsableState.Never)]
820         public bool CanGoForward()
821         {
822             bool ret = Interop.WebView.WebView_CanGoForward(swigCPtr);
823             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
824             return ret;
825         }
826
827         /// <summary>
828         /// The callback function that is invoked when the message is received from the script.
829         /// </summary>
830         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
831         [EditorBrowsable(EditorBrowsableState.Never)]
832         public delegate void JavaScriptMessageHandler(string message);
833
834         /// <summary>
835         /// Evaluates JavaScript code represented as a string.
836         /// <param name="script">The JavaScript code</param>
837         /// </summary>
838         [EditorBrowsable(EditorBrowsableState.Never)]
839         public void EvaluateJavaScript(string script)
840         {
841             Interop.WebView.WebView_EvaluateJavaScript(swigCPtr, script, new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero));
842             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
843         }
844
845         // For rooting handlers
846         internal Dictionary<string, JavaScriptMessageHandler> handlerRootMap = new Dictionary<string, JavaScriptMessageHandler>();
847
848         /// <summary>
849         /// Add a message handler into the WebView.
850         /// <param name="objectName">The name of exposed object</param>
851         /// <param name="handler">The callback function</param>
852         /// </summary>
853         [EditorBrowsable(EditorBrowsableState.Never)]
854         public void AddJavaScriptMessageHandler(string objectName, JavaScriptMessageHandler handler)
855         {
856             if (handlerRootMap.ContainsKey(objectName))
857             {
858                 return;
859             }
860
861             handlerRootMap.Add(objectName, handler);
862
863             System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(handler);
864             Interop.WebView.WebView_AddJavaScriptMessageHandler(swigCPtr, objectName, new System.Runtime.InteropServices.HandleRef(this, ip));
865
866             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
867         }
868
869         /// <summary>
870         /// Clears title resources of current WebView.
871         /// </summary>
872         [EditorBrowsable(EditorBrowsableState.Never)]
873         public void ClearAllTilesResources()
874         {
875             Interop.WebView.WebView_ClearAllTilesResources(swigCPtr);
876             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
877         }
878
879         /// <summary>
880         /// Clears the history of current WebView.
881         /// </summary>
882         [EditorBrowsable(EditorBrowsableState.Never)]
883         public void ClearHistory()
884         {
885             Interop.WebView.WebView_ClearHistory(swigCPtr);
886             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
887         }
888
889         /// <summary>
890         /// Deprecated. Clears the cache of current WebView.
891         /// </summary>
892         [EditorBrowsable(EditorBrowsableState.Never)]
893         public void ClearCache()
894         {
895             Context.ClearCache();
896         }
897
898         /// <summary>
899         /// Deprecated. Clears all the cookies of current WebView.
900         /// </summary>
901         [EditorBrowsable(EditorBrowsableState.Never)]
902         public void ClearCookies()
903         {
904             CookieManager.ClearCookies();
905         }
906
907         /// <summary>
908         /// Sets the tts focus to the webview.
909         /// Please note that it only works when the webview does not have keyinput focus.
910         /// If the webview has a keyinput focus, it also has tts focus so calling SetTtsFocus(false) is ignored.
911         /// </summary>
912         [EditorBrowsable(EditorBrowsableState.Never)]
913         public void SetTtsFocus(bool focused)
914         {
915             Interop.WebView.SetTtsFocus(SwigCPtr, focused);
916             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
917         }
918
919         /// <summary>
920         /// Get a plain text of current web page asynchronously.
921         /// Please note that it gets plain text of currently loaded page so please call this method after page load finished.
922         /// <param name="callback">The callback for getting plain text</param>
923         /// </summary>
924         [EditorBrowsable(EditorBrowsableState.Never)]
925         public void GetPlainTextAsynchronously(PlainTextReceivedCallback callback)
926         {
927             plainTextReceivedCallback = callback;
928             System.IntPtr ip = Marshal.GetFunctionPointerForDelegate(plainTextReceivedCallback);
929             Interop.WebView.GetPlainTextAsynchronously(SwigCPtr, new HandleRef(this, ip));
930             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
931         }
932     }
933 }