[NUI] Implement APIs for form repost decision & frame rendered. (#2843)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / WebView / 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         private readonly WebViewPageLoadSignal pageLoadStartedSignal;
34         private EventHandler<WebViewPageLoadEventArgs> pageLoadStartedEventHandler;
35         private WebViewPageLoadCallbackDelegate pageLoadStartedCallback;
36
37         private readonly WebViewPageLoadSignal pageLoadingSignal;
38         private EventHandler<WebViewPageLoadEventArgs> pageLoadingEventHandler;
39         private WebViewPageLoadCallbackDelegate pageLoadingCallback;
40
41         private readonly WebViewPageLoadSignal pageLoadFinishedSignal;
42         private EventHandler<WebViewPageLoadEventArgs> pageLoadFinishedEventHandler;
43         private WebViewPageLoadCallbackDelegate pageLoadFinishedCallback;
44
45         private readonly WebViewPageLoadErrorSignal pageLoadErrorSignal;
46         private EventHandler<WebViewPageLoadErrorEventArgs> pageLoadErrorEventHandler;
47         private WebViewPageLoadErrorCallbackDelegate pageLoadErrorCallback;
48
49         private readonly WebViewScrollEdgeReachedSignal scrollEdgeReachedSignal;
50         private EventHandler<WebViewScrollEdgeReachedEventArgs> scrollEdgeReachedEventHandler;
51         private WebViewScrollEdgeReachedCallbackDelegate scrollEdgeReachedCallback;
52
53         private readonly WebViewUrlChangedSignal urlChangedSignal;
54         private EventHandler<WebViewUrlChangedEventArgs> urlChangedEventHandler;
55         private WebViewUrlChangedCallbackDelegate urlChangedCallback;
56
57         private readonly WebViewFormRepostDecidedSignal formRepostPolicyDecidedSignal;
58         private EventHandler<WebViewFormRepostPolicyDecidedEventArgs> formRepostPolicyDecidedEventHandler;
59         private WebViewFormRepostPolicyDecidedCallbackDelegate formRepostPolicyDecidedCallback;
60
61         private readonly WebViewFrameRenderedSignal frameRenderedSignal;
62         private EventHandler<EventArgs> frameRenderedEventHandler;
63         private WebViewFrameRenderedCallbackDelegate frameRenderedCallback;
64
65         /// <summary>
66         /// Creates a WebView.
67         /// </summary>
68         [EditorBrowsable(EditorBrowsableState.Never)]
69         public WebView() : this(Interop.WebView.New(), true)
70         {
71             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
72         }
73
74         /// <summary>
75         /// Creates a WebView with local language and time zone.
76         /// <param name="locale">The locale language of Web</param>
77         /// <param name="timezoneId">The time zone Id of Web</param>
78         /// </summary>
79         [EditorBrowsable(EditorBrowsableState.Never)]
80         public WebView(string locale, string timezoneId) : this(Interop.WebView.New2(locale, timezoneId), true)
81         {
82             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
83         }
84
85         /// <summary>
86         /// Creates a WebView with an args list.
87         /// <param name="args">args array. The first value of array must be program's name.</param>
88         /// </summary>
89         [EditorBrowsable(EditorBrowsableState.Never)]
90         public WebView(string[] args) : this(Interop.WebView.New3(args?.Length ?? 0, args), true)
91         {
92             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
93         }
94
95         /// <summary>
96         /// Copy constructor.
97         /// <param name="webView">WebView to copy. The copied WebView will point at the same implementation</param>
98         /// </summary>
99         [EditorBrowsable(EditorBrowsableState.Never)]
100         public WebView(WebView webView) : this(Interop.WebView.NewWebView(WebView.getCPtr(webView)), true)
101         {
102             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
103         }
104
105         internal WebView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.WebView.Upcast(cPtr), cMemoryOwn)
106         {
107             pageLoadStartedSignal = new WebViewPageLoadSignal(Interop.WebView.NewWebViewPageLoadSignalPageLoadStarted(SwigCPtr));
108             pageLoadingSignal = new WebViewPageLoadSignal(Interop.WebView.NewWebViewPageLoadSignalPageLoadInProgress(SwigCPtr));
109             pageLoadFinishedSignal = new WebViewPageLoadSignal(Interop.WebView.NewWebViewPageLoadSignalPageLoadFinished(SwigCPtr));
110             pageLoadErrorSignal = new WebViewPageLoadErrorSignal(Interop.WebView.NewWebViewPageLoadErrorSignalPageLoadError(SwigCPtr));
111             scrollEdgeReachedSignal = new WebViewScrollEdgeReachedSignal(Interop.WebView.NewWebViewScrollEdgeReachedSignalScrollEdgeReached(SwigCPtr));
112             urlChangedSignal = new WebViewUrlChangedSignal(Interop.WebView.NewWebViewUrlChangedSignalUrlChanged(SwigCPtr));
113             formRepostPolicyDecidedSignal = new WebViewFormRepostDecidedSignal(Interop.WebView.NewWebViewFormRepostDecisionSignalFormRepostDecision(SwigCPtr));
114             frameRenderedSignal = new WebViewFrameRenderedSignal(Interop.WebView.WebViewFrameRenderedSignalFrameRenderedGet(SwigCPtr));
115
116             BackForwardList = new WebBackForwardList(Interop.WebView.GetWebBackForwardList(SwigCPtr), false);
117             Context = new WebContext(Interop.WebView.GetWebContext(SwigCPtr), false);
118             CookieManager = new WebCookieManager(Interop.WebView.GetWebCookieManager(SwigCPtr), false);
119             Settings = new WebSettings(Interop.WebView.GetWebSettings(SwigCPtr), false);
120         }
121
122         /// <summary>
123         /// Dispose for IDisposable pattern
124         /// </summary>
125         [EditorBrowsable(EditorBrowsableState.Never)]
126         protected override void Dispose(DisposeTypes type)
127         {
128             if (disposed)
129             {
130                 return;
131             }
132
133             if (type == DisposeTypes.Explicit)
134             {
135                 //Called by User
136                 //Release your own managed resources here.
137                 //You should release all of your own disposable objects here.
138                 pageLoadStartedSignal.Dispose();
139                 pageLoadingSignal.Dispose();
140                 pageLoadFinishedSignal.Dispose();
141                 pageLoadErrorSignal.Dispose();
142                 scrollEdgeReachedSignal.Dispose();
143                 urlChangedSignal.Dispose();
144                 formRepostPolicyDecidedSignal.Dispose();
145                 frameRenderedSignal.Dispose();
146
147                 BackForwardList.Dispose();
148                 Context.Dispose();
149                 CookieManager.Dispose();
150                 Settings.Dispose();
151             }
152
153             base.Dispose(type);
154         }
155
156         /// <summary>
157         /// The callback function that is invoked when the message is received from the script.
158         /// </summary>
159         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
160         [EditorBrowsable(EditorBrowsableState.Never)]
161         public delegate void JavaScriptMessageHandler(string message);
162
163         /// <summary>
164         /// The callback function that is invoked when the message is received from the script.
165         /// </summary>
166         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
167         [EditorBrowsable(EditorBrowsableState.Never)]
168         public delegate void JavaScriptAlertCallback(string message);
169
170         /// <summary>
171         /// The callback function that is invoked when the message is received from the script.
172         /// </summary>
173         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
174         [EditorBrowsable(EditorBrowsableState.Never)]
175         public delegate void JavaScriptConfirmCallback(string message);
176
177         /// <summary>
178         /// The callback function that is invoked when the message is received from the script.
179         /// </summary>
180         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
181         [EditorBrowsable(EditorBrowsableState.Never)]
182         public delegate void JavaScriptPromptCallback(string message1, string message2);
183
184         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
185         private delegate void WebViewPageLoadCallbackDelegate(IntPtr data, string pageUrl);
186
187         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
188         private delegate void WebViewPageLoadErrorCallbackDelegate(IntPtr data, string pageUrl, int errorCode);
189
190         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
191         private delegate void WebViewScrollEdgeReachedCallbackDelegate(IntPtr data, int edge);
192
193         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
194         private delegate void WebViewUrlChangedCallbackDelegate(IntPtr data, string pageUrl);
195
196         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
197         private delegate void WebViewFormRepostPolicyDecidedCallbackDelegate(IntPtr data, IntPtr decision);
198
199         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
200         private delegate void WebViewFrameRenderedCallbackDelegate(IntPtr data);
201
202         /// <summary>
203         /// Event for the PageLoadStarted signal which can be used to subscribe or unsubscribe the event handler.<br />
204         /// This signal is emitted when page loading has started.<br />
205         /// </summary>
206         [EditorBrowsable(EditorBrowsableState.Never)]
207         public event EventHandler<WebViewPageLoadEventArgs> PageLoadStarted
208         {
209             add
210             {
211                 if (pageLoadStartedEventHandler == null)
212                 {
213                     pageLoadStartedCallback = (OnPageLoadStarted);
214                     pageLoadStartedSignal.Connect(pageLoadStartedCallback);
215                 }
216                 pageLoadStartedEventHandler += value;
217             }
218             remove
219             {
220                 pageLoadStartedEventHandler -= value;
221                 if (pageLoadStartedEventHandler == null && pageLoadStartedCallback != null)
222                 {
223                     pageLoadStartedSignal.Disconnect(pageLoadStartedCallback);
224                 }
225             }
226         }
227
228         /// <summary>
229         /// Event for the PageLoading signal which can be used to subscribe or unsubscribe the event handler.<br />
230         /// This signal is emitted when page loading is in progress.<br />
231         /// </summary>
232         [EditorBrowsable(EditorBrowsableState.Never)]
233         public event EventHandler<WebViewPageLoadEventArgs> PageLoading
234         {
235             add
236             {
237                 if (pageLoadingEventHandler == null)
238                 {
239                     pageLoadingCallback = OnPageLoading;
240                     pageLoadingSignal.Connect(pageLoadingCallback);
241                 }
242                 pageLoadingEventHandler += value;
243             }
244             remove
245             {
246                 pageLoadingEventHandler -= value;
247                 if (pageLoadingEventHandler == null && pageLoadingCallback != null)
248                 {
249                     pageLoadingSignal.Disconnect(pageLoadingCallback);
250                 }
251             }
252         }
253
254         /// <summary>
255         /// Event for the PageLoadFinished signal which can be used to subscribe or unsubscribe the event handler.<br />
256         /// This signal is emitted when page loading has finished.<br />
257         /// </summary>
258         [EditorBrowsable(EditorBrowsableState.Never)]
259         public event EventHandler<WebViewPageLoadEventArgs> PageLoadFinished
260         {
261             add
262             {
263                 if (pageLoadFinishedEventHandler == null)
264                 {
265                     pageLoadFinishedCallback = (OnPageLoadFinished);
266                     pageLoadFinishedSignal.Connect(pageLoadFinishedCallback);
267                 }
268                 pageLoadFinishedEventHandler += value;
269             }
270             remove
271             {
272                 pageLoadFinishedEventHandler -= value;
273                 if (pageLoadFinishedEventHandler == null && pageLoadFinishedCallback != null)
274                 {
275                     pageLoadFinishedSignal.Disconnect(pageLoadFinishedCallback);
276                 }
277             }
278         }
279
280         /// <summary>
281         /// Event for the PageLoadError signal which can be used to subscribe or unsubscribe the event handler.<br />
282         /// This signal is emitted when there's an error in page loading.<br />
283         /// </summary>
284         [EditorBrowsable(EditorBrowsableState.Never)]
285         public event EventHandler<WebViewPageLoadErrorEventArgs> PageLoadError
286         {
287             add
288             {
289                 if (pageLoadErrorEventHandler == null)
290                 {
291                     pageLoadErrorCallback = (OnPageLoadError);
292                     pageLoadErrorSignal.Connect(pageLoadErrorCallback);
293                 }
294                 pageLoadErrorEventHandler += value;
295             }
296             remove
297             {
298                 pageLoadErrorEventHandler -= value;
299                 if (pageLoadErrorEventHandler == null && pageLoadErrorCallback != null)
300                 {
301                     pageLoadErrorSignal.Disconnect(pageLoadErrorCallback);
302                 }
303             }
304         }
305
306         /// <summary>
307         /// Event for the ScrollEdgeReached signal which can be used to subscribe or unsubscribe the event handler.<br />
308         /// This signal is emitted when web view is scrolled to edge.<br />
309         /// </summary>
310         [EditorBrowsable(EditorBrowsableState.Never)]
311         public event EventHandler<WebViewScrollEdgeReachedEventArgs> ScrollEdgeReached
312         {
313             add
314             {
315                 if (scrollEdgeReachedEventHandler == null)
316                 {
317                     scrollEdgeReachedCallback = OnScrollEdgeReached;
318                     scrollEdgeReachedSignal.Connect(scrollEdgeReachedCallback);
319                 }
320                 scrollEdgeReachedEventHandler += value;
321             }
322             remove
323             {
324                 scrollEdgeReachedEventHandler -= value;
325                 if (scrollEdgeReachedEventHandler == null && scrollEdgeReachedCallback != null)
326                 {
327                     scrollEdgeReachedSignal.Disconnect(scrollEdgeReachedCallback);
328                 }
329             }
330         }
331
332         /// <summary>
333         /// Event for the UrlChanged signal which can be used to subscribe or unsubscribe the event handler.<br />
334         /// This signal is emitted when url is changed.<br />
335         /// </summary>
336         [EditorBrowsable(EditorBrowsableState.Never)]
337         public event EventHandler<WebViewUrlChangedEventArgs> UrlChanged
338         {
339             add
340             {
341                 if (urlChangedEventHandler == null)
342                 {
343                     urlChangedCallback = OnUrlChanged;
344                     urlChangedSignal.Connect(urlChangedCallback);
345                 }
346                 urlChangedEventHandler += value;
347             }
348             remove
349             {
350                 urlChangedEventHandler -= value;
351                 if (urlChangedEventHandler == null && urlChangedCallback != null)
352                 {
353                     urlChangedSignal.Disconnect(urlChangedCallback);
354                 }
355             }
356         }
357
358         /// <summary>
359         /// Event for the FormRepostDecided signal which can be used to subscribe or unsubscribe the event handler.<br />
360         /// This signal is emitted when form repost policy would be decided.<br />
361         /// </summary>
362         [EditorBrowsable(EditorBrowsableState.Never)]
363         public event EventHandler<WebViewFormRepostPolicyDecidedEventArgs> FormRepostPolicyDecided
364         {
365             add
366             {
367                 if (formRepostPolicyDecidedEventHandler == null)
368                 {
369                     formRepostPolicyDecidedCallback = OnFormRepostPolicyDecided;
370                     formRepostPolicyDecidedSignal.Connect(formRepostPolicyDecidedCallback);
371                 }
372                 formRepostPolicyDecidedEventHandler += value;
373             }
374             remove
375             {
376                 formRepostPolicyDecidedEventHandler -= value;
377                 if (formRepostPolicyDecidedEventHandler == null && formRepostPolicyDecidedCallback != null)
378                 {
379                     formRepostPolicyDecidedSignal.Disconnect(formRepostPolicyDecidedCallback);
380                 }
381             }
382         }
383
384         /// <summary>
385         /// Event for the FrameRendered signal which can be used to subscribe or unsubscribe the event handler.<br />
386         /// This signal is emitted when frame is rendered off-screen.<br />
387         /// </summary>
388         [EditorBrowsable(EditorBrowsableState.Never)]
389         public event EventHandler<EventArgs> FrameRendered
390         {
391             add
392             {
393                 if (frameRenderedEventHandler == null)
394                 {
395                     frameRenderedCallback = OnFrameRendered;
396                     frameRenderedSignal.Connect(frameRenderedCallback);
397                 }
398                 frameRenderedEventHandler += value;
399             }
400             remove
401             {
402                 frameRenderedEventHandler -= value;
403                 if (frameRenderedEventHandler == null && frameRenderedCallback != null)
404                 {
405                     frameRenderedSignal.Disconnect(frameRenderedCallback);
406                 }
407             }
408         }
409
410         /// <summary>
411         /// BackForwardList.
412         /// </summary>
413         [EditorBrowsable(EditorBrowsableState.Never)]
414         public WebBackForwardList BackForwardList { get; }
415
416         /// <summary>
417         /// Context.
418         /// </summary>
419         [EditorBrowsable(EditorBrowsableState.Never)]
420         public WebContext Context { get; }
421
422         /// <summary>
423         /// CookieManager.
424         /// </summary>
425         [EditorBrowsable(EditorBrowsableState.Never)]
426         public WebCookieManager CookieManager { get; }
427
428         /// <summary>
429         /// BackForwardList.
430         /// </summary>
431         [EditorBrowsable(EditorBrowsableState.Never)]
432         public WebSettings Settings { get; }
433
434         /// <summary>
435         /// The url to load.
436         /// </summary>
437         [EditorBrowsable(EditorBrowsableState.Never)]
438         public string Url
439         {
440             get
441             {
442                 return (string)GetValue(UrlProperty);
443             }
444             set
445             {
446                 SetValue(UrlProperty, value);
447                 NotifyPropertyChanged();
448             }
449         }
450
451         /// <summary>
452         /// Deprecated. The cache model of the current WebView.
453         /// </summary>
454         [EditorBrowsable(EditorBrowsableState.Never)]
455         public CacheModel CacheModel
456         {
457             get
458             {
459                 return (CacheModel)Context.CacheModel;
460             }
461             set
462             {
463                 Context.CacheModel = (WebContext.CacheModelType)value;
464             }
465         }
466
467         /// <summary>
468         /// Deprecated. The cookie acceptance policy.
469         /// </summary>
470         [EditorBrowsable(EditorBrowsableState.Never)]
471         public CookieAcceptPolicy CookieAcceptPolicy
472         {
473             get
474             {
475                 return (CookieAcceptPolicy)CookieManager.CookieAcceptPolicy;
476             }
477             set
478             {
479                 CookieManager.CookieAcceptPolicy = (WebCookieManager.CookieAcceptPolicyType)value;
480             }
481         }
482
483         /// <summary>
484         /// The user agent string.
485         /// </summary>
486         [EditorBrowsable(EditorBrowsableState.Never)]
487         public string UserAgent
488         {
489             get
490             {
491                 return (string)GetValue(UserAgentProperty);
492             }
493             set
494             {
495                 SetValue(UserAgentProperty, value);
496                 NotifyPropertyChanged();
497             }
498         }
499
500         /// <summary>
501         /// Deprecated. Whether JavaScript is enabled.
502         /// </summary>
503         [EditorBrowsable(EditorBrowsableState.Never)]
504         public bool EnableJavaScript
505         {
506             get
507             {
508                 return Settings.EnableJavaScript;
509             }
510             set
511             {
512                 Settings.EnableJavaScript = value;
513             }
514         }
515
516         /// <summary>
517         /// Deprecated. Whether images can be loaded automatically.
518         /// </summary>
519         [EditorBrowsable(EditorBrowsableState.Never)]
520         public bool LoadImagesAutomatically
521         {
522             get
523             {
524                 return Settings.AllowImagesLoadAutomatically;
525             }
526             set
527             {
528                 Settings.AllowImagesLoadAutomatically = value;
529             }
530         }
531
532         /// <summary>
533         /// The default text encoding name.<br />
534         /// e.g. "UTF-8"<br />
535         /// </summary>
536         [EditorBrowsable(EditorBrowsableState.Never)]
537         public string DefaultTextEncodingName
538         {
539             get
540             {
541                 return Settings.DefaultTextEncodingName;
542             }
543             set
544             {
545                 Settings.DefaultTextEncodingName = value;
546             }
547         }
548
549         /// <summary>
550         /// The default font size in pixel.
551         /// </summary>
552         [EditorBrowsable(EditorBrowsableState.Never)]
553         public int DefaultFontSize
554         {
555             get
556             {
557                 return Settings.DefaultFontSize;
558             }
559             set
560             {
561                 Settings.DefaultFontSize = value;
562             }
563         }
564
565         /// <summary>
566         /// The position of scroll.
567         /// </summary>
568         [EditorBrowsable(EditorBrowsableState.Never)]
569         public Position ScrollPosition
570         {
571             get
572             {
573                 Vector2 pv = (Vector2)GetValue(ScrollPositionProperty);
574                 return new Position(pv.X, pv.Y);
575             }
576             set
577             {
578                 if (value != null)
579                 {
580                     Position pv = value;
581                     Vector2 vpv = new Vector2(pv.X, pv.Y);
582                     SetValue(ScrollPositionProperty, vpv);
583                     NotifyPropertyChanged();
584                 }
585             }
586         }
587
588         /// <summary>
589         /// The size of scroll, read-only.
590         /// </summary>
591         [EditorBrowsable(EditorBrowsableState.Never)]
592         public Size ScrollSize
593         {
594             get
595             {
596                 Vector2 sv = (Vector2)GetValue(ScrollSizeProperty);
597                 return new Size(sv.Width, sv.Height);
598             }
599         }
600
601         /// <summary>
602         /// The size of content, read-only.
603         /// </summary>
604         [EditorBrowsable(EditorBrowsableState.Never)]
605         public Size ContentSize
606         {
607             get
608             {
609                 Vector2 sv = (Vector2)GetValue(ContentSizeProperty);
610                 return new Size(sv.Width, sv.Height);
611             }
612         }
613
614         /// <summary>
615         /// Whether video hole is enabled or not.
616         /// </summary>
617         [EditorBrowsable(EditorBrowsableState.Never)]
618         public bool VideoHoleEnabled
619         {
620             get
621             {
622                 return (bool)GetValue(VideoHoleEnabledProperty);
623             }
624             set
625             {
626                 SetValue(VideoHoleEnabledProperty, value);
627                 NotifyPropertyChanged();
628             }
629         }
630
631         /// <summary>
632         /// Whether mouse events are enabled or not.
633         /// </summary>
634         [EditorBrowsable(EditorBrowsableState.Never)]
635         public bool MouseEventsEnabled
636         {
637             get
638             {
639                 return (bool)GetValue(MouseEventsEnabledProperty);
640             }
641             set
642             {
643                 SetValue(MouseEventsEnabledProperty, value);
644                 NotifyPropertyChanged();
645             }
646         }
647
648         /// <summary>
649         /// Whether key events are enabled or not.
650         /// </summary>
651         [EditorBrowsable(EditorBrowsableState.Never)]
652         public bool KeyEventsEnabled
653         {
654             get
655             {
656                 return (bool)GetValue(KeyEventsEnabledProperty);
657             }
658             set
659             {
660                 SetValue(KeyEventsEnabledProperty, value);
661                 NotifyPropertyChanged();
662             }
663         }
664
665         /// <summary>
666         /// Gets title of web page.
667         /// </summary>
668         [EditorBrowsable(EditorBrowsableState.Never)]
669         public string Title
670         {
671             get
672             {
673                 return (string)GetValue(TitleProperty);
674             }
675         }
676
677         /// <summary>
678         /// Gets favicon.
679         /// </summary>
680         [EditorBrowsable(EditorBrowsableState.Never)]
681         public ImageView Favicon
682         {
683             get
684             {
685                 global::System.IntPtr imageView = Interop.WebView.GetFavicon(SwigCPtr);
686                 if (NDalicPINVOKE.SWIGPendingException.Pending)
687                     return null;
688                 return new ImageView(imageView, false);
689             }
690         }
691
692         internal static new class Property
693         {
694             internal static readonly int Url = Interop.WebView.UrlGet();
695             internal static readonly int UserAgent = Interop.WebView.UserAgentGet();
696             internal static readonly int ScrollPosition = Interop.WebView.ScrollPositionGet();
697             internal static readonly int ScrollSize = Interop.WebView.ScrollSizeGet();
698             internal static readonly int ContentSize = Interop.WebView.ContentSizeGet();
699             internal static readonly int Title = Interop.WebView.TitleGet();
700             internal static readonly int VideoHoleEnabled = Interop.WebView.VideoHoleEnabledGet();
701             internal static readonly int MouseEventsEnabled = Interop.WebView.MouseEventsEnabledGet();
702             internal static readonly int KeyEventsEnabled = Interop.WebView.KeyEventsEnabledGet();
703         }
704
705         private static readonly BindableProperty UrlProperty = BindableProperty.Create(nameof(Url), typeof(string), typeof(WebView), string.Empty, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
706         {
707             var webview = (WebView)bindable;
708             if (newValue != null)
709             {
710                 Tizen.NUI.Object.SetProperty(webview.SwigCPtr, WebView.Property.Url, new Tizen.NUI.PropertyValue((string)newValue));
711             }
712         }),
713         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
714         {
715             var webview = (WebView)bindable;
716             string temp;
717             Tizen.NUI.Object.GetProperty(webview.SwigCPtr, WebView.Property.Url).Get(out temp);
718             return temp;
719         }));
720
721         private static readonly BindableProperty UserAgentProperty = BindableProperty.Create(nameof(UserAgent), typeof(string), typeof(WebView), string.Empty, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
722         {
723             var webview = (WebView)bindable;
724             if (newValue != null)
725             {
726                 Tizen.NUI.Object.SetProperty((HandleRef)webview.SwigCPtr, WebView.Property.UserAgent, new Tizen.NUI.PropertyValue((string)newValue));
727             }
728         }),
729         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
730         {
731             var webview = (WebView)bindable;
732             string temp;
733             Tizen.NUI.Object.GetProperty((HandleRef)webview.SwigCPtr, WebView.Property.UserAgent).Get(out temp);
734             return temp;
735         }));
736
737         private static readonly BindableProperty ScrollPositionProperty = BindableProperty.Create(nameof(ScrollPosition), typeof(Vector2), typeof(WebView), null, propertyChanged: (bindable, oldValue, newValue) =>
738         {
739             var webview = (WebView)bindable;
740             if (newValue != null)
741             {
742                 Tizen.NUI.Object.SetProperty(webview.SwigCPtr, WebView.Property.ScrollPosition, new Tizen.NUI.PropertyValue((Vector2)newValue));
743             }
744         },
745         defaultValueCreator: (bindable) =>
746         {
747             var webview = (WebView)bindable;
748             Vector2 temp = new Vector2(0.0f, 0.0f);
749             Tizen.NUI.Object.GetProperty(webview.SwigCPtr, WebView.Property.ScrollPosition).Get(temp);
750             return temp;
751         });
752
753         private static readonly BindableProperty ScrollSizeProperty = BindableProperty.Create(nameof(ScrollSize), typeof(Vector2), typeof(WebView), null, defaultValueCreator: (bindable) =>
754         {
755             var webview = (WebView)bindable;
756             Vector2 temp = new Vector2(0.0f, 0.0f);
757             Tizen.NUI.Object.GetProperty(webview.SwigCPtr, WebView.Property.ScrollSize).Get(temp);
758             return temp;
759         });
760
761         private static readonly BindableProperty ContentSizeProperty = BindableProperty.Create(nameof(ContentSize), typeof(Vector2), typeof(WebView), null, defaultValueCreator: (bindable) =>
762         {
763             var webview = (WebView)bindable;
764             Vector2 temp = new Vector2(0.0f, 0.0f);
765             Tizen.NUI.Object.GetProperty(webview.SwigCPtr, WebView.Property.ContentSize).Get(temp);
766             return temp;
767         });
768
769         private static readonly BindableProperty TitleProperty = BindableProperty.Create(nameof(Title), typeof(string), typeof(WebView), null, defaultValueCreator: (bindable) =>
770         {
771             var webview = (WebView)bindable;
772             string title;
773             Tizen.NUI.Object.GetProperty(webview.SwigCPtr, WebView.Property.Title).Get(out title);
774             return title;
775         });
776
777         private static readonly BindableProperty VideoHoleEnabledProperty = BindableProperty.Create(nameof(VideoHoleEnabled), typeof(bool), typeof(WebView), true, propertyChanged: (bindable, oldValue, newValue) =>
778         {
779             var webview = (WebView)bindable;
780             if (newValue != null)
781             {
782                 Tizen.NUI.Object.SetProperty(webview.SwigCPtr, WebView.Property.VideoHoleEnabled, new Tizen.NUI.PropertyValue((bool)newValue));
783             }
784         },
785         defaultValueCreator: (bindable) =>
786         {
787             var webview = (WebView)bindable;
788             bool temp;
789             Tizen.NUI.Object.GetProperty(webview.SwigCPtr, WebView.Property.VideoHoleEnabled).Get(out temp);
790             return temp;
791         });
792
793         private static readonly BindableProperty MouseEventsEnabledProperty = BindableProperty.Create(nameof(MouseEventsEnabled), typeof(bool), typeof(WebView), true, propertyChanged: (bindable, oldValue, newValue) =>
794         {
795             var webview = (WebView)bindable;
796             if (newValue != null)
797             {
798                 Tizen.NUI.Object.SetProperty(webview.SwigCPtr, WebView.Property.MouseEventsEnabled, new Tizen.NUI.PropertyValue((bool)newValue));
799             }
800         },
801         defaultValueCreator: (bindable) =>
802         {
803                 var webview = (WebView)bindable;
804                 bool temp;
805                 Tizen.NUI.Object.GetProperty(webview.SwigCPtr, WebView.Property.MouseEventsEnabled).Get(out temp);
806                 return temp;
807         });
808
809         private static readonly BindableProperty KeyEventsEnabledProperty = BindableProperty.Create(nameof(KeyEventsEnabled), typeof(bool), typeof(WebView), true, propertyChanged: (bindable, oldValue, newValue) =>
810         {
811             var webview = (WebView)bindable;
812             if (newValue != null)
813             {
814                 Tizen.NUI.Object.SetProperty(webview.SwigCPtr, WebView.Property.KeyEventsEnabled, new Tizen.NUI.PropertyValue((bool)newValue));
815             }
816         },
817         defaultValueCreator: (bindable) =>
818         {
819             var webview = (WebView)bindable;
820             bool temp;
821             Tizen.NUI.Object.GetProperty(webview.SwigCPtr, WebView.Property.KeyEventsEnabled).Get(out temp);
822             return temp;
823         });
824
825         // For rooting handlers
826         internal Dictionary<string, JavaScriptMessageHandler> handlerRootMap = new Dictionary<string, JavaScriptMessageHandler>();
827
828         /// <summary>
829         /// Loads a html.
830         /// <param name="url">The path of Web</param>
831         /// </summary>
832         [EditorBrowsable(EditorBrowsableState.Never)]
833         public void LoadUrl(string url)
834         {
835             Interop.WebView.LoadUrl(SwigCPtr, url);
836             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
837         }
838
839         /// <summary>
840         /// Deprecated. Loads a html by string.
841         /// <param name="data">The data of Web</param>
842         /// </summary>
843         [EditorBrowsable(EditorBrowsableState.Never)]
844         public void LoadHTMLString(string data)
845         {
846             Interop.WebView.LoadHtmlString(SwigCPtr, data);
847             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
848         }
849
850         /// <summary>
851         /// Loads a html by string.
852         /// <param name="data">The data of Web</param>
853         /// </summary>
854         [EditorBrowsable(EditorBrowsableState.Never)]
855         public void LoadHtmlString(string data)
856         {
857             Interop.WebView.LoadHtmlString(SwigCPtr, data);
858             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
859         }
860
861         /// <summary>
862         /// Reloads the Web
863         /// </summary>
864         [EditorBrowsable(EditorBrowsableState.Never)]
865         public void Reload()
866         {
867             Interop.WebView.Reload(SwigCPtr);
868             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
869         }
870
871         /// <summary>
872         /// Stops loading the Web
873         /// </summary>
874         [EditorBrowsable(EditorBrowsableState.Never)]
875         public void StopLoading()
876         {
877             Interop.WebView.StopLoading(SwigCPtr);
878             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
879         }
880
881         /// <summary>
882         /// Suspends the operation.
883         /// </summary>
884         [EditorBrowsable(EditorBrowsableState.Never)]
885         public void Suspend()
886         {
887             Interop.WebView.Suspend(SwigCPtr);
888             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
889         }
890
891         /// <summary>
892         /// Resumes the operation after calling Suspend()
893         /// </summary>
894         [EditorBrowsable(EditorBrowsableState.Never)]
895         public void Resume()
896         {
897             Interop.WebView.Resume(SwigCPtr);
898             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
899         }
900
901         /// <summary>
902         /// Scroll web view by deltaX and detlaY.
903         /// <param name="deltaX">The deltaX of scroll</param>
904         /// <param name="deltaY">The deltaY of scroll</param>
905         /// </summary>
906         [EditorBrowsable(EditorBrowsableState.Never)]
907         public void ScrollBy(int deltaX, int deltaY)
908         {
909             Interop.WebView.ScrollBy(SwigCPtr, deltaX, deltaY);
910             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
911         }
912
913         /// <summary>
914         /// Goes to the back
915         /// </summary>
916         [EditorBrowsable(EditorBrowsableState.Never)]
917         public void GoBack()
918         {
919             Interop.WebView.GoBack(SwigCPtr);
920             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
921         }
922
923         /// <summary>
924         /// Goes to the forward
925         /// </summary>
926         [EditorBrowsable(EditorBrowsableState.Never)]
927         public void GoForward()
928         {
929             Interop.WebView.GoForward(SwigCPtr);
930             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
931         }
932
933         /// <summary>
934         /// Returns whether backward is possible.
935         /// <returns>True if backward is possible, false otherwise</returns>
936         /// </summary>
937         [EditorBrowsable(EditorBrowsableState.Never)]
938         public bool CanGoBack()
939         {
940             bool ret = Interop.WebView.CanGoBack(SwigCPtr);
941             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
942             return ret;
943         }
944
945         /// <summary>
946         /// Returns whether forward is possible.
947         /// <returns>True if forward is possible, false otherwise</returns>
948         /// </summary>
949         [EditorBrowsable(EditorBrowsableState.Never)]
950         public bool CanGoForward()
951         {
952             bool ret = Interop.WebView.CanGoForward(SwigCPtr);
953             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
954             return ret;
955         }
956
957         /// <summary>
958         /// Evaluates JavaScript code represented as a string.
959         /// <param name="script">The JavaScript code</param>
960         /// </summary>
961         [EditorBrowsable(EditorBrowsableState.Never)]
962         public void EvaluateJavaScript(string script)
963         {
964             Interop.WebView.EvaluateJavaScript(SwigCPtr, script, new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero));
965             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
966         }
967
968         /// <summary>
969         /// Add a message handler into the WebView.
970         /// <param name="objectName">The name of exposed object</param>
971         /// <param name="handler">The callback function</param>
972         /// </summary>
973         [EditorBrowsable(EditorBrowsableState.Never)]
974         public void AddJavaScriptMessageHandler(string objectName, JavaScriptMessageHandler handler)
975         {
976             if (handlerRootMap.ContainsKey(objectName))
977             {
978                 return;
979             }
980
981             handlerRootMap.Add(objectName, handler);
982
983             System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(handler);
984             Interop.WebView.AddJavaScriptMessageHandler(SwigCPtr, objectName, new System.Runtime.InteropServices.HandleRef(this, ip));
985
986             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
987         }
988
989         /// <summary>
990         /// Add a message handler into the WebView.
991         /// <param name="callback">The callback function</param>
992         /// </summary>
993         [EditorBrowsable(EditorBrowsableState.Never)]
994         public void RegisterJavaScriptAlertCallback(JavaScriptAlertCallback callback)
995         {
996             System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(callback);
997             Interop.WebView.RegisterJavaScriptAlertCallback(SwigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip));
998
999             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1000         }
1001
1002         /// <summary>
1003         /// Reply for alert popup.
1004         /// </summary>
1005         [EditorBrowsable(EditorBrowsableState.Never)]
1006         public void JavaScriptAlertReply()
1007         {
1008             Interop.WebView.JavaScriptAlertReply(SwigCPtr);
1009             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1010         }
1011
1012         /// <summary>
1013         /// Add a message handler into the WebView.
1014         /// <param name="callback">The callback function</param>
1015         /// </summary>
1016         [EditorBrowsable(EditorBrowsableState.Never)]
1017         public void RegisterJavaScriptConfirmCallback(JavaScriptConfirmCallback callback)
1018         {
1019             System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(callback);
1020             Interop.WebView.RegisterJavaScriptConfirmCallback(SwigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip));
1021
1022             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1023         }
1024
1025         /// <summary>
1026         /// Reply for confirm popup.
1027         /// <param name="confirmed">confirmed or not</param>
1028         /// </summary>
1029         [EditorBrowsable(EditorBrowsableState.Never)]
1030         public void JavaScriptConfirmReply(bool confirmed)
1031         {
1032             Interop.WebView.JavaScriptConfirmReply(SwigCPtr, confirmed);
1033             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1034         }
1035
1036         /// <summary>
1037         /// Add a message handler into the WebView.
1038         /// <param name="callback">The callback function</param>
1039         /// </summary>
1040         [EditorBrowsable(EditorBrowsableState.Never)]
1041         public void RegisterJavaScriptPromptCallback(JavaScriptPromptCallback callback)
1042         {
1043             System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(callback);
1044             Interop.WebView.RegisterJavaScriptPromptCallback(SwigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip));
1045
1046             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1047         }
1048
1049         /// <summary>
1050         /// Reply for prompt popup.
1051         /// <param name="result">text in prompt input field.</param>
1052         /// </summary>
1053         [EditorBrowsable(EditorBrowsableState.Never)]
1054         public void JavaScriptPromptReply(string result)
1055         {
1056             Interop.WebView.JavaScriptPromptReply(SwigCPtr, result);
1057             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1058         }
1059
1060         /// <summary>
1061         /// Clears title resources of current WebView.
1062         /// </summary>
1063         [EditorBrowsable(EditorBrowsableState.Never)]
1064         public void ClearAllTilesResources()
1065         {
1066             Interop.WebView.ClearAllTilesResources(SwigCPtr);
1067             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1068         }
1069
1070         /// <summary>
1071         /// Clears the history of current WebView.
1072         /// </summary>
1073         [EditorBrowsable(EditorBrowsableState.Never)]
1074         public void ClearHistory()
1075         {
1076             Interop.WebView.ClearHistory(SwigCPtr);
1077             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1078         }
1079
1080         /// <summary>
1081         /// Deprecated. Clears the cache of current WebView.
1082         /// </summary>
1083         [EditorBrowsable(EditorBrowsableState.Never)]
1084         public void ClearCache()
1085         {
1086             Context.ClearCache();
1087         }
1088
1089         /// <summary>
1090         /// Deprecated. Clears all the cookies of current WebView.
1091         /// </summary>
1092         [EditorBrowsable(EditorBrowsableState.Never)]
1093         public void ClearCookies()
1094         {
1095             CookieManager.ClearCookies();
1096         }
1097
1098         internal static WebView DownCast(BaseHandle handle)
1099         {
1100             WebView ret = new WebView(Interop.WebView.DownCast(BaseHandle.getCPtr(handle)), true);
1101             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1102             return ret;
1103         }
1104
1105         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(WebView obj)
1106         {
1107             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
1108         }
1109
1110         internal WebView Assign(WebView webView)
1111         {
1112             WebView ret = new WebView(Interop.WebView.Assign(SwigCPtr, WebView.getCPtr(webView)), false);
1113             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1114             return ret;
1115         }
1116
1117         /// This will not be public opened.
1118         /// <param name="swigCPtr"></param>
1119         [EditorBrowsable(EditorBrowsableState.Never)]
1120         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
1121         {
1122             Interop.WebView.DeleteWebView(swigCPtr);
1123         }
1124
1125         private void OnPageLoadStarted(IntPtr data, string pageUrl)
1126         {
1127             WebViewPageLoadEventArgs e = new WebViewPageLoadEventArgs();
1128
1129             e.WebView = Registry.GetManagedBaseHandleFromNativePtr(data) as WebView;
1130             e.PageUrl = pageUrl;
1131
1132             pageLoadStartedEventHandler?.Invoke(this, e);
1133         }
1134
1135         private void OnPageLoading(IntPtr data, string pageUrl)
1136         {
1137             pageLoadingEventHandler?.Invoke(this, new WebViewPageLoadEventArgs());
1138         }
1139
1140         private void OnPageLoadFinished(IntPtr data, string pageUrl)
1141         {
1142             WebViewPageLoadEventArgs e = new WebViewPageLoadEventArgs();
1143
1144             e.WebView = Registry.GetManagedBaseHandleFromNativePtr(data) as WebView;
1145             e.PageUrl = pageUrl;
1146
1147             pageLoadFinishedEventHandler?.Invoke(this, e);
1148         }
1149
1150         private void OnPageLoadError(IntPtr data, string pageUrl, int errorCode)
1151         {
1152             WebViewPageLoadErrorEventArgs e = new WebViewPageLoadErrorEventArgs();
1153
1154             e.WebView = Registry.GetManagedBaseHandleFromNativePtr(data) as WebView;
1155             e.PageUrl = pageUrl;
1156             e.ErrorCode = (WebViewPageLoadErrorEventArgs.LoadErrorCode)errorCode;
1157
1158             pageLoadErrorEventHandler?.Invoke(this, e);
1159         }
1160
1161         private void OnScrollEdgeReached(IntPtr data, int edge)
1162         {
1163             WebViewScrollEdgeReachedEventArgs arg = new WebViewScrollEdgeReachedEventArgs((WebViewScrollEdgeReachedEventArgs.Edge)edge);
1164             scrollEdgeReachedEventHandler?.Invoke(this, arg);
1165         }
1166
1167         private void OnUrlChanged(IntPtr data, string pageUrl)
1168         {
1169             urlChangedEventHandler?.Invoke(this, new WebViewUrlChangedEventArgs(pageUrl));
1170         }
1171
1172         private void OnFormRepostPolicyDecided(IntPtr data, IntPtr decision)
1173         {
1174             WebFormRepostPolicyDecisionMaker repostDecision = new WebFormRepostPolicyDecisionMaker(decision, false);
1175             formRepostPolicyDecidedEventHandler?.Invoke(this, new WebViewFormRepostPolicyDecidedEventArgs(repostDecision));
1176             repostDecision.Dispose();
1177         }
1178
1179         private void OnFrameRendered(IntPtr data)
1180         {
1181             frameRenderedEventHandler?.Invoke(this, new EventArgs());
1182         }
1183     }
1184 }