2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 using System.Runtime.InteropServices;
20 using Tizen.NUI.BaseComponents;
27 internal class WebViewLite : View
29 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
31 internal WebViewLite(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.WebViewLite_SWIGUpcast(cPtr), cMemoryOwn) {
32 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
35 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(WebViewLite obj) {
36 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
40 /// To make Button instance be disposed.
42 protected override void Dispose(DisposeTypes type)
49 if (type == DisposeTypes.Explicit)
52 //Release your own managed resources here.
53 //You should release all of your own disposable objects here.
57 //Release your own unmanaged resources here.
58 //You should not access any managed member here except static instance.
59 //because the execution order of Finalizes is non-deterministic.
61 DisConnectFromSignals();
63 if (swigCPtr.Handle != global::System.IntPtr.Zero)
68 NDalicPINVOKE.delete_WebViewLite(swigCPtr);
70 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
76 private void DisConnectFromSignals()
79 global::System.Runtime.InteropServices.HandleRef currentCPtr = swigCPtr;
81 // Use BaseHandle CPtr as current might have been deleted already in derived classes.
82 swigCPtr = GetBaseHandleCPtrHandleRef;
84 if (_loadingFinishedEventCallback != null)
86 FinishedSignal().Disconnect(_loadingFinishedEventCallback);
89 // BaseHandle CPtr is used in Registry and there is danger of deletion if we keep using it here.
90 // Restore current CPtr.
91 swigCPtr = currentCPtr;
94 private LoadingFinishedCallbackType _loadingFinishedEventCallback;
95 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
96 private delegate void LoadingFinishedCallbackType(global::System.IntPtr data);
97 private EventHandler _loadingFinishedEventHandler;
100 /// Web View loading finished event.
102 public event EventHandler LoadingFinished
106 if (_loadingFinishedEventHandler == null)
108 NUILog.Debug("[add before]FinishedSignal().Empty=" + FinishedSignal().Empty() + " GetConnectionCount=" + FinishedSignal().GetConnectionCount());
109 _loadingFinishedEventCallback = OnFinished;
110 FinishedSignal().Connect(_loadingFinishedEventCallback);
111 NUILog.Debug("[add after]FinishedSignal().Empty=" + FinishedSignal().Empty() + " GetConnectionCount=" + FinishedSignal().GetConnectionCount());
113 _loadingFinishedEventHandler += value;
117 _loadingFinishedEventHandler -= value;
119 if (_loadingFinishedEventHandler == null && FinishedSignal().Empty() == false)
121 NUILog.Debug("[remove before]FinishedSignal().Empty=" + FinishedSignal().Empty() + " GetConnectionCount=" + FinishedSignal().GetConnectionCount());
122 FinishedSignal().Disconnect(_loadingFinishedEventCallback);
123 NUILog.Debug("[remove after]FinishedSignal().Empty=" + FinishedSignal().Empty() + " GetConnectionCount=" + FinishedSignal().GetConnectionCount());
127 private void OnFinished(IntPtr data)
129 if (_loadingFinishedEventHandler != null)
131 //here we send all data to user event handlers
132 _loadingFinishedEventHandler(this, null);
137 /// Creates an uninitialized WebViewLite.
139 public WebViewLite () : this (NDalicPINVOKE.WebViewLite_New(), true) {
140 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
145 /// Copy constructor.
146 /// <param name="webViewLite">WebViewLite to copy. The copied WebViewLite will point at the same implementation</param>
148 public WebViewLite(WebViewLite webViewLite) : this(NDalicPINVOKE.new_WebViewLite__SWIG_1(WebViewLite.getCPtr(webViewLite)), true) {
149 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
152 internal WebViewLite Assign(WebViewLite webViewLite) {
153 WebViewLite ret = new WebViewLite(NDalicPINVOKE.WebViewLite_Assign(swigCPtr, WebViewLite.getCPtr(webViewLite)), false);
154 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
158 internal new static WebViewLite DownCast(BaseHandle handle) {
159 WebViewLite ret = new WebViewLite(NDalicPINVOKE.WebViewLite_DownCast(BaseHandle.getCPtr(handle)), true);
160 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
165 /// Creates an internal web view instance (e.g. minimized web engine instance).
166 /// <param name="width">The width of Web</param>
167 /// <param name="height">The height of Web</param>
168 /// <param name="windowX">The x position of window</param>
169 /// <param name="windowY">The y position of window</param>
170 /// <param name="locale">The locale of Web</param>
171 /// <param name="timezoneID">The timezoneID of Web</param>
173 public void CreateInstance(int width, int height, int windowX, int windowY, string locale, string timezoneID) {
174 NDalicPINVOKE.WebViewLite_CreateInstance(swigCPtr, width, height, windowX, windowY, locale, timezoneID);
175 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
179 /// Destroys an internal web view instance (e.g. minimized web engine instance).
181 public void DestroyInstance() {
182 NDalicPINVOKE.WebViewLite_DestroyInstance(swigCPtr);
183 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
187 /// Loads a html file.
188 /// <param name="path">The path of Web</param>
190 public void LoadHtml(string path) {
191 NDalicPINVOKE.WebViewLite_LoadHtml(swigCPtr, path);
192 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
195 internal WebViewLiteSignal FinishedSignal() {
196 WebViewLiteSignal ret = new WebViewLiteSignal(NDalicPINVOKE.WebViewLite_FinishedSignal(swigCPtr), false);
197 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();