From: huayongxu <49056704+huayongxu@users.noreply.github.com> Date: Tue, 7 Sep 2021 07:33:40 +0000 (+0800) Subject: [NUI] Fix issue that objects are disposed outside callback. (#3514) X-Git-Tag: accepted/tizen/unified/20231205.024657~1504 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4c06932362cf352398ac52d59e5204a7a2f966a9;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI] Fix issue that objects are disposed outside callback. (#3514) --- diff --git a/src/Tizen.NUI/src/internal/WebView/WebContext.cs b/src/Tizen.NUI/src/internal/WebView/WebContext.cs index aa82b1c..829ef2b 100755 --- a/src/Tizen.NUI/src/internal/WebView/WebContext.cs +++ b/src/Tizen.NUI/src/internal/WebView/WebContext.cs @@ -33,12 +33,11 @@ namespace Tizen.NUI private float timeOffset; private ApplicationType applicationType; private WebSecurityOriginList securityOriginList; - private SecurityOriginListAcquiredCallback securityOriginsAcquiredCallback; + private SecurityOriginListAcquiredCallback securityOriginListAcquiredCallback; private readonly WebContextSecurityOriginListAcquiredProxyCallback securityOriginListAcquiredProxyCallback; - private WebPasswordDataList passwordList; + private WebPasswordDataList passwordDataList; private PasswordDataListAcquiredCallback passwordDataListAcquiredCallback; private readonly WebContextPasswordDataListAcquiredProxyCallback passwordDataListAcquiredProxyCallback; - private WebHttpRequestInterceptor httpRequestInterceptor; private HttpRequestInterceptedCallback httpRequestInterceptedCallback; private readonly WebContextHttpRequestInterceptedProxyCallback httpRequestInterceptedProxyCallback; @@ -65,18 +64,14 @@ namespace Tizen.NUI //Called by User //Release your own managed resources here. //You should release all of your own disposable objects here. - if (passwordList != null) + if (passwordDataList != null) { - passwordList.Dispose(); + passwordDataList.Dispose(); } if (securityOriginList != null) { securityOriginList.Dispose(); } - if (httpRequestInterceptor != null) - { - httpRequestInterceptor.Dispose(); - } } base.Dispose(type); @@ -115,7 +110,7 @@ namespace Tizen.NUI /// [UnmanagedFunctionPointer(CallingConvention.StdCall)] [EditorBrowsable(EditorBrowsableState.Never)] - public delegate bool MimeOverriddenCallback(string url, string currentMime, string newMime); + public delegate bool MimeOverriddenCallback(string url, string currentMime, out string newMime); /// /// The callback function that is invoked when http request need be intercepted. @@ -400,7 +395,7 @@ namespace Tizen.NUI [EditorBrowsable(EditorBrowsableState.Never)] public bool GetWebDatabaseOrigins(SecurityOriginListAcquiredCallback callback) { - securityOriginsAcquiredCallback = callback; + securityOriginListAcquiredCallback = callback; IntPtr ip = Marshal.GetFunctionPointerForDelegate(securityOriginListAcquiredProxyCallback); bool result = Interop.WebContext.GetWebDatabaseOrigins(SwigCPtr, new HandleRef(this, ip)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); @@ -426,7 +421,7 @@ namespace Tizen.NUI [EditorBrowsable(EditorBrowsableState.Never)] public bool GetWebStorageOrigins(SecurityOriginListAcquiredCallback callback) { - securityOriginsAcquiredCallback = callback; + securityOriginListAcquiredCallback = callback; IntPtr ip = Marshal.GetFunctionPointerForDelegate(securityOriginListAcquiredProxyCallback); bool result = Interop.WebContext.GetWebStorageOrigins(SwigCPtr, new HandleRef(this, ip)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); @@ -540,7 +535,7 @@ namespace Tizen.NUI /// /// Registers callback for http request interceptor. - /// callback for overriding mime type + /// callback for intercepting http request /// [EditorBrowsable(EditorBrowsableState.Never)] public void RegisterHttpRequestInterceptedCallback(HttpRequestInterceptedCallback callback) @@ -708,32 +703,29 @@ namespace Tizen.NUI { originList.Add(securityOriginList.GetItemAtIndex(i)); } - securityOriginsAcquiredCallback?.Invoke(originList); + securityOriginListAcquiredCallback?.Invoke(originList); } private void OnPasswordDataListAcquired(IntPtr alist) { - if (passwordList != null) + if (passwordDataList != null) { - passwordList.Dispose(); + passwordDataList.Dispose(); } - passwordList = new WebPasswordDataList(alist, true); - List passwordDataList = new List(); - for(uint i = 0; i < passwordList.ItemCount; i++) + passwordDataList = new WebPasswordDataList(alist, true); + List pList = new List(); + for(uint i = 0; i < passwordDataList.ItemCount; i++) { - passwordDataList.Add(passwordList.GetItemAtIndex(i)); + pList.Add(passwordDataList.GetItemAtIndex(i)); } - passwordDataListAcquiredCallback?.Invoke(passwordDataList); + passwordDataListAcquiredCallback?.Invoke(pList); } private void OnHttpRequestIntercepted(IntPtr interceptor) { - if (httpRequestInterceptor != null) - { - httpRequestInterceptor.Dispose(); - } - httpRequestInterceptor = new WebHttpRequestInterceptor(interceptor, true); - httpRequestInterceptedCallback?.Invoke(httpRequestInterceptor); +#pragma warning disable CA2000 // Dispose objects before losing scope + httpRequestInterceptedCallback?.Invoke(new WebHttpRequestInterceptor(interceptor, true)); +#pragma warning restore CA2000 // Dispose objects before losing scope } } } diff --git a/src/Tizen.NUI/src/internal/WebView/WebContextMenuItem.cs b/src/Tizen.NUI/src/internal/WebView/WebContextMenuItem.cs index 4b332c0..0721040 100755 --- a/src/Tizen.NUI/src/internal/WebView/WebContextMenuItem.cs +++ b/src/Tizen.NUI/src/internal/WebView/WebContextMenuItem.cs @@ -41,6 +41,7 @@ namespace Tizen.NUI /// /// Enum that provides the tags of items for the context menu. /// + [EditorBrowsable(EditorBrowsableState.Never)] public enum ItemTag { NoAction = 0, @@ -140,6 +141,7 @@ namespace Tizen.NUI /// /// Enum that defines the types of the items for the context menu. /// + [EditorBrowsable(EditorBrowsableState.Never)] public enum ItemType { Action, diff --git a/src/Tizen.NUI/src/internal/WebView/WebHitTestResult.cs b/src/Tizen.NUI/src/internal/WebView/WebHitTestResult.cs index 87d53f5..ada41d9 100755 --- a/src/Tizen.NUI/src/internal/WebView/WebHitTestResult.cs +++ b/src/Tizen.NUI/src/internal/WebView/WebHitTestResult.cs @@ -226,6 +226,7 @@ namespace Tizen.NUI ImageView image = new ImageView(url.ToString()); image.Size = new Size(pixelData.GetWidth(), pixelData.GetHeight()); pixelData.Dispose(); + url.Dispose(); return image; } } diff --git a/src/Tizen.NUI/src/internal/WebView/WebView.cs b/src/Tizen.NUI/src/internal/WebView/WebView.cs index 51be8a5..e96f3d0 100755 --- a/src/Tizen.NUI/src/internal/WebView/WebView.cs +++ b/src/Tizen.NUI/src/internal/WebView/WebView.cs @@ -2008,9 +2008,9 @@ namespace Tizen.NUI.BaseComponents private void OnScreenshotAcquired(IntPtr data) { - ImageView image = new ImageView(data, true); - screenshotAcquiredCallback?.Invoke(image); - image.Dispose(); +#pragma warning disable CA2000 // Dispose objects before losing scope + screenshotAcquiredCallback?.Invoke(new ImageView(data, true)); +#pragma warning restore CA2000 // Dispose objects before losing scope } private void OnResponsePolicyDecided(IntPtr maker) @@ -2050,9 +2050,9 @@ namespace Tizen.NUI.BaseComponents private void OnHitTestFinished(IntPtr test) { - WebHitTestResult hitTest = new WebHitTestResult(test, true); - hitTestFinishedCallback?.Invoke(hitTest); - hitTest.Dispose(); +#pragma warning disable CA2000 // Dispose objects before losing scope + hitTestFinishedCallback?.Invoke(new WebHitTestResult(test, true)); +#pragma warning restore CA2000 // Dispose objects before losing scope } } } diff --git a/test/Tizen.NUI.WebViewTest/SimpleWebViewApp.cs b/test/Tizen.NUI.WebViewTest/SimpleWebViewApp.cs index 31724d3..9b931bb 100755 --- a/test/Tizen.NUI.WebViewTest/SimpleWebViewApp.cs +++ b/test/Tizen.NUI.WebViewTest/SimpleWebViewApp.cs @@ -328,23 +328,23 @@ namespace Tizen.NUI.WebViewTest FocusManager.Instance.SetCurrentFocusView(simpleWebView); } - //if (args.Touch.GetState(0) == PointStateType.Down && args.Touch.GetMouseButton(0) == MouseButton.Secondary) - //{ - // if (menuView == null && menuPosition == null) - // { - // menuPosition = args.Touch.GetScreenPosition(0); - // } - //} - //else if(args.Touch.GetState(0) == PointStateType.Down && args.Touch.GetMouseButton(0) == MouseButton.Primary) - //{ - // if (menuView != null) - // { - // menuView.HideMenu(); - // GetDefaultWindow().Remove(menuView); - // menuView = null; - // menuPosition = null; - // } - //} + if (args.Touch.GetState(0) == PointStateType.Down && args.Touch.GetMouseButton(0) == MouseButton.Secondary) + { + if (menuView == null && menuPosition == null) + { + menuPosition = args.Touch.GetScreenPosition(0); + } + } + else if (args.Touch.GetState(0) == PointStateType.Down && args.Touch.GetMouseButton(0) == MouseButton.Primary) + { + if (menuView != null) + { + menuView.HideMenu(); + GetDefaultWindow().Remove(menuView); + menuView = null; + menuPosition = null; + } + } return false; } @@ -666,7 +666,7 @@ namespace Tizen.NUI.WebViewTest Log.Info("WebView", $"------------download started, url: {url}-------"); } - private bool OnMimeOverridden(string url, string currentMime, string newMime) + private bool OnMimeOverridden(string url, string currentMime, out string newMime) { Log.Info("WebView", $"------------mime overridden, url: {url}-------"); Log.Info("WebView", $"------------mime overridden, currentMime: {currentMime}-------");