Add C# binding for web view lite. 72/150072/2
authorFeng Jin <feng16.jin@samsung.com>
Thu, 14 Sep 2017 15:39:16 +0000 (23:39 +0800)
committerFeng Jin <feng16.jin@samsung.com>
Thu, 14 Sep 2017 16:25:23 +0000 (00:25 +0800)
Change-Id: I8c03f8f97cce52f44b20449c4c668aa7be1b49ff
Signed-off-by: Feng Jin <feng16.jin@samsung.com>
Tizen.NUI/src/internal/NDalicPINVOKE.cs
Tizen.NUI/src/internal/WebViewLiteSignal.cs [new file with mode: 0755]
Tizen.NUI/src/public/WebViewLite.cs [new file with mode: 0755]

index e6c72b6..ada713d 100755 (executable)
@@ -11223,6 +11223,60 @@ class NDalicPINVOKE {
 
   [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_AsyncImageLoader_SWIGUpcast")]
   public static extern global::System.IntPtr AsyncImageLoader_SWIGUpcast(global::System.IntPtr jarg1);
+
+  [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_WebViewLite_New")]
+  public static extern global::System.IntPtr WebViewLite_New();
+
+  [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_new_WebViewLite__SWIG_0")]
+  public static extern global::System.IntPtr new_WebViewLite__SWIG_0();
+
+  [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_delete_WebViewLite")]
+  public static extern void delete_WebViewLite(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+  [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_new_WebViewLite__SWIG_1")]
+  public static extern global::System.IntPtr new_WebViewLite__SWIG_1(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+  [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_WebViewLite_Assign")]
+  public static extern global::System.IntPtr WebViewLite_Assign(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
+  [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_WebViewLite_DownCast")]
+  public static extern global::System.IntPtr WebViewLite_DownCast(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+  [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_WebViewLite_CreateInstance")]
+  public static extern void WebViewLite_CreateInstance(global::System.Runtime.InteropServices.HandleRef jarg1, int jarg2, int jarg3, int jarg4, int jarg5, string jarg6, string jarg7);
+
+  [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_WebViewLite_DestroyInstance")]
+  public static extern void WebViewLite_DestroyInstance(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+  [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_WebViewLite_LoadHtml")]
+  public static extern void WebViewLite_LoadHtml(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2);
+
+  [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_WebViewLite_FinishedSignal")]
+  public static extern global::System.IntPtr WebViewLite_FinishedSignal(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+  [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_WebViewLiteSignal_Empty")]
+  public static extern bool WebViewLiteSignal_Empty(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+  [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_WebViewLiteSignal_GetConnectionCount")]
+  public static extern uint WebViewLiteSignal_GetConnectionCount(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+  [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_WebViewLiteSignal_Connect")]
+  public static extern void WebViewLiteSignal_Connect(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
+  [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_WebViewLiteSignal_Disconnect")]
+  public static extern void WebViewLiteSignal_Disconnect(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
+  [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_WebViewLiteSignal_Emit")]
+  public static extern void WebViewLiteSignal_Emit(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
+  [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_new_WebViewLiteSignal")]
+  public static extern global::System.IntPtr new_WebViewLiteSignal();
+
+  [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_delete_WebViewLiteSignal")]
+  public static extern void delete_WebViewLiteSignal(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+  [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_WebViewLite_SWIGUpcast")]
+  public static extern global::System.IntPtr WebViewLite_SWIGUpcast(global::System.IntPtr jarg1);
 }
 
 }
diff --git a/Tizen.NUI/src/internal/WebViewLiteSignal.cs b/Tizen.NUI/src/internal/WebViewLiteSignal.cs
new file mode 100755 (executable)
index 0000000..aaf1918
--- /dev/null
@@ -0,0 +1,137 @@
+/** Copyright (c) 2017 Samsung Electronics Co., Ltd.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+namespace Tizen.NUI {
+
+public class WebViewLiteSignal : global::System.IDisposable {
+  private global::System.Runtime.InteropServices.HandleRef swigCPtr;
+  protected bool swigCMemOwn;
+
+  internal WebViewLiteSignal(global::System.IntPtr cPtr, bool cMemoryOwn) {
+    swigCMemOwn = cMemoryOwn;
+    swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
+  }
+
+  internal static global::System.Runtime.InteropServices.HandleRef getCPtr(WebViewLiteSignal obj) {
+    return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
+  }
+
+  //A Flag to check who called Dispose(). (By User or DisposeQueue)
+  private bool isDisposeQueued = false;
+  //A Flat to check if it is already disposed.
+  protected bool disposed = false;
+
+  ~WebViewLiteSignal()
+  {
+      if (!isDisposeQueued)
+      {
+          isDisposeQueued = true;
+          DisposeQueue.Instance.Add(this);
+      }
+  }
+
+  public void Dispose()
+  {
+      //Throw excpetion if Dispose() is called in separate thread.
+      if (!Window.IsInstalled())
+      {
+          throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
+      }
+
+      if (isDisposeQueued)
+      {
+          Dispose(DisposeTypes.Implicit);
+      }
+      else
+      {
+          Dispose(DisposeTypes.Explicit);
+          System.GC.SuppressFinalize(this);
+      }
+  }
+
+  protected virtual void Dispose(DisposeTypes type)
+  {
+      if (disposed)
+      {
+          return;
+      }
+
+      if (type == DisposeTypes.Explicit)
+      {
+          //Called by User
+          //Release your own managed resources here.
+          //You should release all of your own disposable objects here.
+
+      }
+
+      //Release your own unmanaged resources here.
+      //You should not access any managed member here except static instance.
+      //because the execution order of Finalizes is non-deterministic.
+
+      if (swigCPtr.Handle != global::System.IntPtr.Zero)
+      {
+          if (swigCMemOwn)
+          {
+              swigCMemOwn = false;
+              NDalicPINVOKE.delete_WebViewLiteSignal(swigCPtr);
+          }
+          swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+      }
+
+      disposed = true;
+  }
+
+
+  public bool Empty() {
+    bool ret = NDalicPINVOKE.WebViewLiteSignal_Empty(swigCPtr);
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+    return ret;
+  }
+
+  public uint GetConnectionCount() {
+    uint ret = NDalicPINVOKE.WebViewLiteSignal_GetConnectionCount(swigCPtr);
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+    return ret;
+  }
+
+  public void Connect(System.Delegate func) {
+System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(func);
+    {
+      NDalicPINVOKE.WebViewLiteSignal_Connect(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip));
+      if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+    }
+  }
+
+  public void Disconnect(System.Delegate func) {
+System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(func);
+    {
+      NDalicPINVOKE.WebViewLiteSignal_Disconnect(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip));
+      if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+    }
+  }
+
+  public void Emit(WebViewLite arg) {
+    NDalicPINVOKE.WebViewLiteSignal_Emit(swigCPtr, WebViewLite.getCPtr(arg));
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+  }
+
+  public WebViewLiteSignal() : this(NDalicPINVOKE.new_WebViewLiteSignal(), true) {
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+  }
+
+}
+
+}
diff --git a/Tizen.NUI/src/public/WebViewLite.cs b/Tizen.NUI/src/public/WebViewLite.cs
new file mode 100755 (executable)
index 0000000..1049aad
--- /dev/null
@@ -0,0 +1,195 @@
+/** Copyright (c) 2017 Samsung Electronics Co., Ltd.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+using System;
+using System.Runtime.InteropServices;
+using Tizen.NUI.BaseComponents;
+
+namespace Tizen.NUI {
+
+public class WebViewLite : View
+{
+  private global::System.Runtime.InteropServices.HandleRef swigCPtr;
+
+  internal WebViewLite(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.WebViewLite_SWIGUpcast(cPtr), cMemoryOwn) {
+    swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
+  }
+
+  internal static global::System.Runtime.InteropServices.HandleRef getCPtr(WebViewLite obj) {
+    return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
+  }
+
+  /// <summary>
+  /// To make Button instance be disposed.
+  /// </summary>
+  protected override void Dispose(DisposeTypes type)
+  {
+      if (disposed)
+      {
+          return;
+      }
+
+      if (type == DisposeTypes.Explicit)
+      {
+          //Called by User
+          //Release your own managed resources here.
+          //You should release all of your own disposable objects here.
+
+      }
+
+      //Release your own unmanaged resources here.
+      //You should not access any managed member here except static instance.
+      //because the execution order of Finalizes is non-deterministic.
+
+      DisConnectFromSignals();
+
+      if (swigCPtr.Handle != global::System.IntPtr.Zero)
+      {
+          if (swigCMemOwn)
+          {
+              swigCMemOwn = false;
+              NDalicPINVOKE.delete_WebViewLite(swigCPtr);
+          }
+          swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+      }
+
+      base.Dispose(type);
+  }
+
+  private void DisConnectFromSignals()
+  {
+      // Save current CPtr.
+      global::System.Runtime.InteropServices.HandleRef currentCPtr = swigCPtr;
+
+      // Use BaseHandle CPtr as current might have been deleted already in derived classes.
+      swigCPtr = GetBaseHandleCPtrHandleRef;
+
+      if (_loadingFinishedEventCallback != null)
+      {
+          FinishedSignal().Disconnect(_loadingFinishedEventCallback);
+      }
+
+      // BaseHandle CPtr is used in Registry and there is danger of deletion if we keep using it here.
+      // Restore current CPtr.
+      swigCPtr = currentCPtr;
+  }
+
+  private LoadingFinishedCallbackType _loadingFinishedEventCallback;
+  [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+  private delegate void LoadingFinishedCallbackType(global::System.IntPtr data);
+  private EventHandler _loadingFinishedEventHandler;
+
+  public event EventHandler LoadingFinished
+  {
+      add
+      {
+          if (_loadingFinishedEventHandler == null)
+          {
+              NUILog.Debug("[add before]FinishedSignal().Empty=" + FinishedSignal().Empty() + " GetConnectionCount=" + FinishedSignal().GetConnectionCount());
+              _loadingFinishedEventCallback = OnFinished;
+              FinishedSignal().Connect(_loadingFinishedEventCallback);
+              NUILog.Debug("[add after]FinishedSignal().Empty=" + FinishedSignal().Empty() + " GetConnectionCount=" + FinishedSignal().GetConnectionCount());
+          }
+          _loadingFinishedEventHandler += value;
+      }
+      remove
+      {
+          _loadingFinishedEventHandler -= value;
+
+          if (_loadingFinishedEventHandler == null && FinishedSignal().Empty() == false)
+          {
+              NUILog.Debug("[remove before]FinishedSignal().Empty=" + FinishedSignal().Empty() + " GetConnectionCount=" + FinishedSignal().GetConnectionCount());
+              FinishedSignal().Disconnect(_loadingFinishedEventCallback);
+              NUILog.Debug("[remove after]FinishedSignal().Empty=" + FinishedSignal().Empty() + " GetConnectionCount=" + FinishedSignal().GetConnectionCount());
+          }
+      }
+  }
+  private void OnFinished(IntPtr data)
+  {
+      if (_loadingFinishedEventHandler != null)
+      {
+          //here we send all data to user event handlers
+          _loadingFinishedEventHandler(this, null);
+      }
+  }
+
+  /// <summary>
+  /// Creates an uninitialized WebViewLite.
+  /// </summary>
+  public WebViewLite () : this (NDalicPINVOKE.WebViewLite_New(), true) {
+      if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+
+  }
+
+  /// <summary>
+  /// Copy constructor.
+  /// <param name="webViewLite">WebViewLite to copy. The copied WebViewLite will point at the same implementation</param>
+  /// </summary>
+  public WebViewLite(WebViewLite webViewLite) : this(NDalicPINVOKE.new_WebViewLite__SWIG_1(WebViewLite.getCPtr(webViewLite)), true) {
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+  }
+
+  internal WebViewLite Assign(WebViewLite webViewLite) {
+    WebViewLite ret = new WebViewLite(NDalicPINVOKE.WebViewLite_Assign(swigCPtr, WebViewLite.getCPtr(webViewLite)), false);
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+    return ret;
+  }
+
+  internal new static WebViewLite DownCast(BaseHandle handle) {
+    WebViewLite ret = new WebViewLite(NDalicPINVOKE.WebViewLite_DownCast(BaseHandle.getCPtr(handle)), true);
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+    return ret;
+  }
+
+  /// <summary>
+  /// Creates an internal web view instance (e.g. minimized web engine instance).
+  /// <param name="width">The width of Web</param>
+  /// <param name="height">The height of Web</param>
+  /// <param name="windowX">The x position of window</param>
+  /// <param name="windowY">The y position of window</param>
+  /// <param name="locale">The locale of Web</param>
+  /// <param name="timezoneID">The timezoneID of Web</param>
+  /// </summary>
+  public void CreateInstance(int width, int height, int windowX, int windowY, string locale, string timezoneID) {
+    NDalicPINVOKE.WebViewLite_CreateInstance(swigCPtr, width, height, windowX, windowY, locale, timezoneID);
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+  }
+
+  /// <summary>
+  /// Destroys an internal web view instance (e.g. minimized web engine instance).
+  /// </summary>
+  public void DestroyInstance() {
+    NDalicPINVOKE.WebViewLite_DestroyInstance(swigCPtr);
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+  }
+
+  /// <summary>
+  /// Loads a html file.
+  /// <param name="path">The path of Web</param>
+  /// </summary>
+  public void LoadHtml(string path) {
+    NDalicPINVOKE.WebViewLite_LoadHtml(swigCPtr, path);
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+  }
+
+  internal WebViewLiteSignal FinishedSignal() {
+    WebViewLiteSignal ret = new WebViewLiteSignal(NDalicPINVOKE.WebViewLite_FinishedSignal(swigCPtr), false);
+    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+    return ret;
+  }
+
+}
+
+}