From: dongsug.song Date: Mon, 23 Dec 2024 05:51:15 +0000 (+0900) Subject: [NUI] Add WebView DeviceListGet,SetDefaultAudio X-Git-Tag: submit/tizen_9.0/20241223.075537~1^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2cf3079b8c64d99e6056d9f656deac2e3da78d68;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI] Add WebView DeviceListGet,SetDefaultAudio --- diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.WebDeviceList.cs b/src/Tizen.NUI/src/internal/Interop/Interop.WebDeviceList.cs new file mode 100755 index 000000000..c5dbf5e99 --- /dev/null +++ b/src/Tizen.NUI/src/internal/Interop/Interop.WebDeviceList.cs @@ -0,0 +1,38 @@ +/* + * Copyright(c) 2024 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 global::System.Runtime.InteropServices; + +namespace Tizen.NUI +{ + internal static partial class Interop + { + internal static partial class WebDeviceList + { + [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_delete_DeviceListGet")] + public static extern void Delete(HandleRef obj); + + [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DeviceListGet_GetTypeAndConnect")] + public static extern void GetTypeAndConnect(HandleRef obj, out int type, out bool connect, int idx); + + [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DeviceListGet_GetDeviceId")] + public static extern string GetDeviceId(HandleRef obj, int idx); + + [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DeviceListGet_GetDeviceLabel")] + public static extern string GetDeviceLabel(HandleRef obj, int idx); + } + } +} diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.WebSettings.cs b/src/Tizen.NUI/src/internal/Interop/Interop.WebSettings.cs index 6599ead16..c3dc9b6f7 100755 --- a/src/Tizen.NUI/src/internal/Interop/Interop.WebSettings.cs +++ b/src/Tizen.NUI/src/internal/Interop/Interop.WebSettings.cs @@ -187,6 +187,9 @@ namespace Tizen.NUI [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebSettings_IsExtraFeatureEnabled")] [return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)] public static extern bool IsExtraFeatureEnabled(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebSettings_SetDefaultAudioInputDevice")] + public static extern void SetDefaultAudioInputDevice(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2); } } } diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.WebView.cs b/src/Tizen.NUI/src/internal/Interop/Interop.WebView.cs index 7c2a7a7d1..afe48bf36 100755 --- a/src/Tizen.NUI/src/internal/Interop/Interop.WebView.cs +++ b/src/Tizen.NUI/src/internal/Interop/Interop.WebView.cs @@ -358,6 +358,12 @@ namespace Tizen.NUI [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_FeedMouseWheel")] public static extern void FeedMouseWheel(global::System.Runtime.InteropServices.HandleRef webViewRef, bool yDirection, int step, int x, int y); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_RegisterDeviceConnectionChangedCallback")] + public static extern void RegisterDeviceConnectionChangedCallback(global::System.Runtime.InteropServices.HandleRef webViewRef, global::System.Runtime.InteropServices.HandleRef callbackRef); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_RegisterDeviceListGetCallback")] + public static extern void RegisterDeviceListGetCallback(global::System.Runtime.InteropServices.HandleRef webViewRef, global::System.Runtime.InteropServices.HandleRef callbackRef); } } } diff --git a/src/Tizen.NUI/src/internal/WebView/WebDeviceList.cs b/src/Tizen.NUI/src/internal/WebView/WebDeviceList.cs new file mode 100755 index 000000000..27977cc0f --- /dev/null +++ b/src/Tizen.NUI/src/internal/WebView/WebDeviceList.cs @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2024 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.ComponentModel; +using System.Collections.Generic; + +namespace Tizen.NUI +{ + /// + /// WebDeviceList. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public class WebDeviceList : Disposable + { + internal WebDeviceList(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) + { + } + + /// This will not be public opened. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr) + { + Interop.WebDeviceList.Delete(swigCPtr); + } + + [EditorBrowsable(EditorBrowsableState.Never)] + internal void GetTypeAndConnect(out int type, out bool connect, int idx) + { + Interop.WebDeviceList.GetTypeAndConnect(SwigCPtr, out type, out connect, idx); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + [EditorBrowsable(EditorBrowsableState.Never)] + internal string GetDeviceId(int idx) + { + string ret = Interop.WebDeviceList.GetDeviceId(SwigCPtr, idx); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + [EditorBrowsable(EditorBrowsableState.Never)] + internal string GetDeviceLabel(int idx) + { + string ret = Interop.WebDeviceList.GetDeviceLabel(SwigCPtr, idx); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + [EditorBrowsable(EditorBrowsableState.Never)] + public List Get(int size) + { + List ret = new List(); + + for (int i = 0; i < size; i++) + { + WebDeviceListItem item = new WebDeviceListItem(); + item.Id = GetDeviceId(i); + item.Label = GetDeviceLabel(i); + + int type = -1; + bool connect = false; + GetTypeAndConnect(out type, out connect, i); + item.Type = (WebMediaDeviceType)type; + item.Connected = connect; + Tizen.Log.Fatal("NT", $"@@@ [{i}] id={item.Id}, label={item.Label}, type={item.Type}, conn={item.Connected}"); + ret.Add(item); + } + + Tizen.Log.Fatal("NT", $"list size={ret.Count}"); + return ret; + } + } + + [EditorBrowsable(EditorBrowsableState.Never)] + public struct WebDeviceListItem + { + public string Id; + public string Label; + public WebMediaDeviceType Type; + public bool Connected; + } + + [EditorBrowsable(EditorBrowsableState.Never)] + public enum WebMediaDeviceType + { + Unknown = -1, + AudioInput = 0, + VideoInput, + AudioOutput, + } +} diff --git a/src/Tizen.NUI/src/internal/WebView/WebSettings.cs b/src/Tizen.NUI/src/internal/WebView/WebSettings.cs index b9eceb112..526da505e 100755 --- a/src/Tizen.NUI/src/internal/WebView/WebSettings.cs +++ b/src/Tizen.NUI/src/internal/WebView/WebSettings.cs @@ -571,5 +571,12 @@ namespace Tizen.NUI if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } + + [EditorBrowsable(EditorBrowsableState.Never)] + public void SetDefaultAudioInputDevice(string deviceId) + { + Interop.WebSettings.SetDefaultAudioInputDevice(SwigCPtr, deviceId); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } } } diff --git a/src/Tizen.NUI/src/internal/WebView/WebViewDeviceConnectionChangedEventArgs.cs b/src/Tizen.NUI/src/internal/WebView/WebViewDeviceConnectionChangedEventArgs.cs new file mode 100755 index 000000000..c20b8f8c5 --- /dev/null +++ b/src/Tizen.NUI/src/internal/WebView/WebViewDeviceConnectionChangedEventArgs.cs @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 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.ComponentModel; + +namespace Tizen.NUI +{ + /// + /// Event arguments that DeviceConnectionChanged. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public class WebViewDeviceConnectionChangedEventArgs : EventArgs + { + internal WebViewDeviceConnectionChangedEventArgs(int deviceType) + { + DeviceType = deviceType; + } + + /// + /// Gets Device Type. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public int DeviceType { get; } + } +} diff --git a/src/Tizen.NUI/src/public/WebView/WebView.cs b/src/Tizen.NUI/src/public/WebView/WebView.cs index 96bb4601d..7706b475c 100755 --- a/src/Tizen.NUI/src/public/WebView/WebView.cs +++ b/src/Tizen.NUI/src/public/WebView/WebView.cs @@ -170,6 +170,9 @@ namespace Tizen.NUI.BaseComponents private WebContext webContext = null; private WebCookieManager webCookieManager = null; + private EventHandler deviceConnectionChangedEventHandler; + private webViewDeviceConnectionChangedCallback deviceConnectionChangedCallback; + /// /// Default constructor to create a WebView. /// @@ -439,6 +442,15 @@ namespace Tizen.NUI.BaseComponents [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void WebViewUserMediaPermissionRequestCallback(IntPtr permission, string message); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void webViewDeviceConnectionChangedCallback(int deviceType); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void internalWebViewDeviceListGetCallback(IntPtr list, int size); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void WebViewDeviceListGetCallback(WebDeviceList list, int size); + private WebViewDeviceListGetCallback deviceListGetCallbackForUser; /// /// Event for the PageLoadStarted signal which can be used to subscribe or unsubscribe the event handler.
@@ -1110,6 +1122,44 @@ namespace Tizen.NUI.BaseComponents } } + [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler DeviceConnectionChanged + { + add + { + if (deviceConnectionChangedEventHandler == null) + { + deviceConnectionChangedCallback = OnDeviceConnectionChanged; + IntPtr ip = Marshal.GetFunctionPointerForDelegate(deviceConnectionChangedCallback); + Interop.WebView.RegisterDeviceConnectionChangedCallback(SwigCPtr, new HandleRef(this, ip)); + } + deviceConnectionChangedEventHandler += value; + } + remove + { + deviceConnectionChangedEventHandler -= value; + if (deviceConnectionChangedEventHandler == null) + { + IntPtr ip = IntPtr.Zero; + Interop.WebView.RegisterUserMediaPermissionRequestCallback(SwigCPtr, new HandleRef(this, ip)); + } + } + } + + [EditorBrowsable(EditorBrowsableState.Never)] + public void SetDeviceListGetCallback(WebViewDeviceListGetCallback callback) + { + deviceListGetCallbackForUser = callback; + + internalWebViewDeviceListGetCallback cb = deviceListGet; + IntPtr ip = Marshal.GetFunctionPointerForDelegate(cb); + Interop.WebView.RegisterDeviceListGetCallback(SwigCPtr, new HandleRef(this, ip)); + } + + private void deviceListGet(IntPtr list, int size) + { + deviceListGetCallbackForUser?.Invoke(new WebDeviceList(list, true), size); + } /// /// Options for searching texts. @@ -3265,5 +3315,10 @@ namespace Tizen.NUI.BaseComponents userMediaPermissionRequestEventHandler?.Invoke(this, new WebViewUserMediaPermissionRequestEventArgs(new WebUserMediaPermissionRequest(permission, true), message)); } + private void OnDeviceConnectionChanged(int deviceType) + { + deviceConnectionChangedEventHandler?.Invoke(this, new WebViewDeviceConnectionChangedEventArgs(deviceType)); + } + } }