Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Tizen.NUI/src/internal/Interop/Interop.WebView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,21 @@ internal static partial class WebView

[DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_SetVideoHole")]
public static extern void SetVideoHole(HandleRef webViewRef, bool enable, bool isWaylandWindow);

[DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_RegisterPlaybackVideoReadyCallback")]
public static extern void RegisterPlaybackVideoReadyCallback(HandleRef webViewRef, IntPtr callbackRef);

[DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_RegisterPlaybackVideoStartedCallback")]
public static extern void RegisterPlaybackVideoStartedCallback(HandleRef webViewRef, IntPtr callbackRef);

[DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_RegisterPlaybackVideoFinishedCallback")]
public static extern void RegisterPlaybackVideoFinishedCallback(HandleRef webViewRef, IntPtr callbackRef);

[DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_RegisterPlaybackVideoStoppedCallback")]
public static extern void RegisterPlaybackVideoStoppedCallback(HandleRef webViewRef, IntPtr callbackRef);

[DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_RegisterPlaybackVideoPausedCallback")]
public static extern void RegisterPlaybackVideoPausedCallback(HandleRef webViewRef, IntPtr callbackRef);
}
}
}
173 changes: 173 additions & 0 deletions src/Tizen.NUI/src/public/WebView/WebView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,24 @@ protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef
public delegate void WebViewDeviceListGetCallback(WebDeviceList list, int size);
private WebViewDeviceListGetCallback deviceListGetCallbackForUser;

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void WebViewPlaybackVideoCallback();

private EventHandler playbackVideoReadyEventHandler;
private WebViewPlaybackVideoCallback playbackVideoReadyCallback;

private EventHandler playbackVideoStartedEventHandler;
private WebViewPlaybackVideoCallback playbackVideoStartedCallback;

private EventHandler playbackVideoFinishedEventHandler;
private WebViewPlaybackVideoCallback playbackVideoFinishedCallback;

private EventHandler playbackVideoStoppedEventHandler;
private WebViewPlaybackVideoCallback playbackVideoStoppedCallback;

private EventHandler playbackVideoPausedEventHandler;
private WebViewPlaybackVideoCallback playbackVideoPausedCallback;

/// <summary>
/// Event for the PageLoadStarted signal which can be used to subscribe or unsubscribe the event handler.<br />
/// This signal is emitted when page loading has started.<br />
Expand Down Expand Up @@ -3374,5 +3392,160 @@ private void OnDeviceConnectionChanged(int deviceType)
deviceConnectionChangedEventHandler?.Invoke(this, new WebViewDeviceConnectionChangedEventArgs(deviceType));
}

/// <summary>
/// Event for the PlaybackVideoReady signal which can be used to subscribe or unsubscribe the event handler.
/// This signal is emitted when playback video is ready.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public event EventHandler PlaybackVideoReady
{
add
{
if (playbackVideoReadyEventHandler == null)
{
playbackVideoReadyCallback = OnPlaybackVideoReady;
Interop.WebView.RegisterPlaybackVideoReadyCallback(SwigCPtr, Marshal.GetFunctionPointerForDelegate(playbackVideoReadyCallback));
}
playbackVideoReadyEventHandler += value;
}
remove
{
playbackVideoReadyEventHandler -= value;
if (playbackVideoReadyEventHandler == null)
{
Interop.WebView.RegisterPlaybackVideoReadyCallback(SwigCPtr, IntPtr.Zero);
}
}
}

/// <summary>
/// Event for the PlaybackVideoStarted signal which can be used to subscribe or unsubscribe the event handler.
/// This signal is emitted when playback video is started.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public event EventHandler PlaybackVideoStarted
{
add
{
if (playbackVideoStartedEventHandler == null)
{
playbackVideoStartedCallback = OnPlaybackVideoStarted;
Interop.WebView.RegisterPlaybackVideoStartedCallback(SwigCPtr, Marshal.GetFunctionPointerForDelegate(playbackVideoStartedCallback));
}
playbackVideoStartedEventHandler += value;
}
remove
{
playbackVideoStartedEventHandler -= value;
if (playbackVideoStartedEventHandler == null)
{
Interop.WebView.RegisterPlaybackVideoStartedCallback(SwigCPtr, IntPtr.Zero);
}
}
}

/// <summary>
/// Event for the PlaybackVideoFinished signal which can be used to subscribe or unsubscribe the event handler.
/// This signal is emitted when playback video is finished.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public event EventHandler PlaybackVideoFinished
{
add
{
if (playbackVideoFinishedEventHandler == null)
{
playbackVideoFinishedCallback = OnPlaybackVideoFinished;
Interop.WebView.RegisterPlaybackVideoFinishedCallback(SwigCPtr, Marshal.GetFunctionPointerForDelegate(playbackVideoFinishedCallback));
}
playbackVideoFinishedEventHandler += value;
}
remove
{
playbackVideoFinishedEventHandler -= value;
if (playbackVideoFinishedEventHandler == null)
{
Interop.WebView.RegisterPlaybackVideoFinishedCallback(SwigCPtr, IntPtr.Zero);
}
}
}

/// <summary>
/// Event for the PlaybackVideoStopped signal which can be used to subscribe or unsubscribe the event handler.
/// This signal is emitted when playback video is stopped.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public event EventHandler PlaybackVideoStopped
{
add
{
if (playbackVideoStoppedEventHandler == null)
{
playbackVideoStoppedCallback = OnPlaybackVideoStopped;
Interop.WebView.RegisterPlaybackVideoStoppedCallback(SwigCPtr, Marshal.GetFunctionPointerForDelegate(playbackVideoStoppedCallback));
}
playbackVideoStoppedEventHandler += value;
}
remove
{
playbackVideoStoppedEventHandler -= value;
if (playbackVideoStoppedEventHandler == null)
{
Interop.WebView.RegisterPlaybackVideoStoppedCallback(SwigCPtr, IntPtr.Zero);
}
}
}

/// <summary>
/// Event for the PlaybackVideoPaused signal which can be used to subscribe or unsubscribe the event handler.
/// This signal is emitted when playback video is paused.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public event EventHandler PlaybackVideoPaused
{
add
{
if (playbackVideoPausedEventHandler == null)
{
playbackVideoPausedCallback = OnPlaybackVideoPaused;
Interop.WebView.RegisterPlaybackVideoPausedCallback(SwigCPtr, Marshal.GetFunctionPointerForDelegate(playbackVideoPausedCallback));
}
playbackVideoPausedEventHandler += value;
}
remove
{
playbackVideoPausedEventHandler -= value;
if (playbackVideoPausedEventHandler == null)
{
Interop.WebView.RegisterPlaybackVideoPausedCallback(SwigCPtr, IntPtr.Zero);
}
}
}

private void OnPlaybackVideoReady()
{
playbackVideoReadyEventHandler?.Invoke(this, new EventArgs());
}

private void OnPlaybackVideoStarted()
{
playbackVideoStartedEventHandler?.Invoke(this, new EventArgs());
}

private void OnPlaybackVideoFinished()
{
playbackVideoFinishedEventHandler?.Invoke(this, new EventArgs());
}

private void OnPlaybackVideoStopped()
{
playbackVideoStoppedEventHandler?.Invoke(this, new EventArgs());
}

private void OnPlaybackVideoPaused()
{
playbackVideoPausedEventHandler?.Invoke(this, new EventArgs());
}
Comment on lines +3525 to +3548

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using new EventArgs() allocates a new instance of EventArgs every time the event is raised. Since video playback events can be triggered frequently, it is highly recommended to use the cached singleton EventArgs.Empty instead to avoid unnecessary memory allocations and reduce garbage collection pressure.

        private void OnPlaybackVideoReady()
        {
            playbackVideoReadyEventHandler?.Invoke(this, EventArgs.Empty);
        }

        private void OnPlaybackVideoStarted()
        {
            playbackVideoStartedEventHandler?.Invoke(this, EventArgs.Empty);
        }

        private void OnPlaybackVideoFinished()
        {
            playbackVideoFinishedEventHandler?.Invoke(this, EventArgs.Empty);
        }

        private void OnPlaybackVideoStopped()
        {
            playbackVideoStoppedEventHandler?.Invoke(this, EventArgs.Empty);
        }

        private void OnPlaybackVideoPaused()
        {
            playbackVideoPausedEventHandler?.Invoke(this, EventArgs.Empty);
        }


}
}
Loading