Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NUI][API10] Unregister callbacks when passed argument is null. #5616

Merged
merged 1 commit into from
Oct 12, 2023
Merged
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
12 changes: 10 additions & 2 deletions src/Tizen.NUI/src/internal/WebView/WebContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,11 @@ public void GetFormPasswordList(PasswordDataListAcquiredCallback callback)
[EditorBrowsable(EditorBrowsableState.Never)]
public void RegisterDownloadStartedCallback(DownloadStartedCallback callback)
{
IntPtr ip = Marshal.GetFunctionPointerForDelegate(callback);
IntPtr ip = IntPtr.Zero;
if (callback != null)
{
ip = Marshal.GetFunctionPointerForDelegate(callback);
}
Interop.WebContext.RegisterDownloadStartedCallback(SwigCPtr, new HandleRef(this, ip));
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
Expand All @@ -530,7 +534,11 @@ public void RegisterDownloadStartedCallback(DownloadStartedCallback callback)
[EditorBrowsable(EditorBrowsableState.Never)]
public void RegisterMimeOverriddenCallback(MimeOverriddenCallback callback)
{
IntPtr ip = Marshal.GetFunctionPointerForDelegate(callback);
IntPtr ip = IntPtr.Zero;
if (callback != null)
{
ip = Marshal.GetFunctionPointerForDelegate(callback);
}
Interop.WebContext.RegisterMimeOverriddenCallback(SwigCPtr, new HandleRef(this, ip));
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
Expand Down
5 changes: 5 additions & 0 deletions src/Tizen.NUI/src/internal/WebView/WebCookieManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public event EventHandler<EventArgs> CookieChanged
remove
{
cookieChangedEventHandler -= value;
if (cookieChangedEventHandler == null)
{
IntPtr ip = IntPtr.Zero;
Interop.WebCookieManager.CookieChangedCallback(SwigCPtr, new HandleRef(this, ip));
}
}
}

Expand Down
106 changes: 100 additions & 6 deletions src/Tizen.NUI/src/public/WebView/WebView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@
remove
{
pageLoadStartedEventHandler -= value;
if (pageLoadStartedEventHandler == null)
{
IntPtr ip = IntPtr.Zero;
Interop.WebView.RegisterPageLoadStartedCallback(SwigCPtr, new HandleRef(this, ip));
}
}
}

Expand All @@ -328,6 +333,11 @@
remove
{
pageLoadingEventHandler -= value;
if (pageLoadingEventHandler == null)
{
IntPtr ip = IntPtr.Zero;
Interop.WebView.RegisterPageLoadInProgressCallback(SwigCPtr, new HandleRef(this, ip));
}
}
}

Expand All @@ -351,6 +361,11 @@
remove
{
pageLoadFinishedEventHandler -= value;
if (pageLoadFinishedEventHandler == null)
{
IntPtr ip = IntPtr.Zero;
Interop.WebView.RegisterPageLoadFinishedCallback(SwigCPtr, new HandleRef(this, ip));
}
}
}

Expand All @@ -374,6 +389,11 @@
remove
{
pageLoadErrorEventHandler -= value;
if (pageLoadErrorEventHandler == null)
{
IntPtr ip = IntPtr.Zero;
Interop.WebView.RegisterPageLoadErrorCallback(SwigCPtr, new HandleRef(this, ip));
}
}
}

Expand All @@ -397,6 +417,11 @@
remove
{
scrollEdgeReachedEventHandler -= value;
if (scrollEdgeReachedEventHandler == null)
{
IntPtr ip = IntPtr.Zero;
Interop.WebView.RegisterScrollEdgeReachedCallback(SwigCPtr, new HandleRef(this, ip));
}
}
}

Expand All @@ -420,6 +445,11 @@
remove
{
urlChangedEventHandler -= value;
if (urlChangedEventHandler == null)
{
IntPtr ip = IntPtr.Zero;
Interop.WebView.RegisterUrlChangedCallback(SwigCPtr, new HandleRef(this, ip));
}
}
}

Expand All @@ -443,6 +473,11 @@
remove
{
formRepostPolicyDecidedEventHandler -= value;
if (formRepostPolicyDecidedEventHandler == null)
{
IntPtr ip = IntPtr.Zero;
Interop.WebView.RegisterFormRepostDecidedCallback(SwigCPtr, new HandleRef(this, ip));
}
}
}

Expand All @@ -466,6 +501,11 @@
remove
{
frameRenderedEventHandler -= value;
if (frameRenderedEventHandler == null)
{
IntPtr ip = IntPtr.Zero;
Interop.WebView.RegisterFrameRenderedCallback(SwigCPtr, new HandleRef(this, ip));
}
}
}

Expand All @@ -489,6 +529,11 @@
remove
{
responsePolicyDecidedEventHandler -= value;
if (responsePolicyDecidedEventHandler == null)
{
IntPtr ip = IntPtr.Zero;
Interop.WebView.RegisterResponsePolicyDecidedCallback(SwigCPtr, new HandleRef(this, ip));
}
}
}

Expand All @@ -512,6 +557,11 @@
remove
{
navigationPolicyDecidedEventHandler -= value;
if (navigationPolicyDecidedEventHandler == null)
{
IntPtr ip = IntPtr.Zero;
Interop.WebView.RegisterNavigationPolicyDecidedCallback(SwigCPtr, new HandleRef(this, ip));
}
}
}

Expand All @@ -520,7 +570,7 @@
/// This signal is emitted when a new window would be created.<br />
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public event EventHandlerWithReturnType<object, EventArgs, WebView> NewWindowCreated

Check warning on line 573 in src/Tizen.NUI/src/public/WebView/WebView.cs

View workflow job for this annotation

GitHub Actions / build

Rename EventHandlerWithReturnType to end in 'EventHandler'.
{
add
{
Expand All @@ -535,6 +585,11 @@
remove
{
newWindowCreatedEventHandler -= value;
if (newWindowCreatedEventHandler == null)
{
IntPtr ip = IntPtr.Zero;
Interop.WebView.RegisterNewWindowCreatedCallback(SwigCPtr, new HandleRef(this, ip));
}
}
}

Expand All @@ -558,6 +613,11 @@
remove
{
certificateConfirmedEventHandler -= value;
if (certificateConfirmedEventHandler == null)
{
IntPtr ip = IntPtr.Zero;
Interop.WebView.RegisterCertificateConfirmedCallback(SwigCPtr, new HandleRef(this, ip));
}
}
}

Expand All @@ -581,6 +641,11 @@
remove
{
sslCertificateChangedEventHandler -= value;
if (sslCertificateChangedEventHandler == null)
{
IntPtr ip = IntPtr.Zero;
Interop.WebView.RegisterSslCertificateChangedCallback(SwigCPtr, new HandleRef(this, ip));
}
}
}

Expand All @@ -604,6 +669,11 @@
remove
{
httpAuthRequestedEventHandler -= value;
if (httpAuthRequestedEventHandler == null)
{
IntPtr ip = IntPtr.Zero;
Interop.WebView.RegisterHttpAuthHandlerCallback(SwigCPtr, new HandleRef(this, ip));
}
}
}

Expand All @@ -627,6 +697,11 @@
remove
{
consoleMessageReceivedEventHandler -= value;
if (consoleMessageReceivedEventHandler == null)
{
IntPtr ip = IntPtr.Zero;
Interop.WebView.RegisterConsoleMessageReceivedCallback(SwigCPtr, new HandleRef(this, ip));
}
}
}

Expand All @@ -650,6 +725,11 @@
remove
{
contextMenuShownEventHandler -= value;
if (contextMenuShownEventHandler == null)
{
IntPtr ip = IntPtr.Zero;
Interop.WebView.RegisterContextMenuShownCallback(SwigCPtr, new HandleRef(this, ip));
}
}
}

Expand All @@ -673,6 +753,11 @@
remove
{
contextMenuHiddenEventHandler -= value;
if (contextMenuHiddenEventHandler == null)
{
IntPtr ip = IntPtr.Zero;
Interop.WebView.RegisterContextMenuHiddenCallback(SwigCPtr, new HandleRef(this, ip));
}
}
}

Expand Down Expand Up @@ -1029,7 +1114,7 @@
if (value != null)
{
Position pv = value;
Vector2 vpv = new Vector2(pv.X, pv.Y);

Check warning on line 1117 in src/Tizen.NUI/src/public/WebView/WebView.cs

View workflow job for this annotation

GitHub Actions / build

Use recommended dispose pattern to ensure that object created by 'new Vector2(pv.X, pv.Y)' is disposed on all paths. If possible, wrap the creation within a 'using' statement or a 'using' declaration. Otherwise, use a try-finally pattern, with a dedicated local variable declared before the try region and an unconditional Dispose invocation on non-null value in the 'finally' region, say 'x?.Dispose()'. If the object is explicitly disposed within the try region or the dispose ownership is transfered to another object or method, assign 'null' to the local variable just after such an operation to prevent double dispose in 'finally'.
SetValue(ScrollPositionProperty, vpv);
NotifyPropertyChanged();
}
Expand Down Expand Up @@ -1844,9 +1929,12 @@
[EditorBrowsable(EditorBrowsableState.Never)]
public void RegisterJavaScriptAlertCallback(JavaScriptAlertCallback callback)
{
System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(callback);
IntPtr ip = IntPtr.Zero;
if (callback != null)
{
ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(callback);
}
Interop.WebView.RegisterJavaScriptAlertCallback(SwigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip));

if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}

Expand All @@ -1867,9 +1955,12 @@
[EditorBrowsable(EditorBrowsableState.Never)]
public void RegisterJavaScriptConfirmCallback(JavaScriptConfirmCallback callback)
{
System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(callback);
IntPtr ip = IntPtr.Zero;
if (callback != null)
{
ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(callback);
}
Interop.WebView.RegisterJavaScriptConfirmCallback(SwigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip));

if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}

Expand All @@ -1891,9 +1982,12 @@
[EditorBrowsable(EditorBrowsableState.Never)]
public void RegisterJavaScriptPromptCallback(JavaScriptPromptCallback callback)
{
System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(callback);
IntPtr ip = IntPtr.Zero;
if (callback != null)
{
ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(callback);
}
Interop.WebView.RegisterJavaScriptPromptCallback(SwigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip));

if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}

Expand Down
Loading