From ae0ca842e501c8410fbb90ef1a8622cea9ba4978 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 2 Jun 2022 15:01:57 +0800 Subject: [PATCH] [v3.6] Don't rename webview& video c++ destuctor to destroy in webview/video.ini, add a 'destroy' method and bind it instead. (#11323) * [v3.6] Don't rename webview& video c++ destuctor to destroy in webview/video.ini, add a 'destroy' method and bind it instead. * VideoPlayer doesn't need to be inherited from RefCounted. * Add final keyword for VideoPlayer & WebView. --- .../cocos/ui/videoplayer/VideoPlayer-ios.mm | 9 ++- .../cocos/ui/videoplayer/VideoPlayer-java.cpp | 17 ++++- native/cocos/ui/videoplayer/VideoPlayer.h | 10 ++- native/cocos/ui/webview/WebView-inl.h | 74 +++++++++++++----- native/cocos/ui/webview/WebView.h | 9 ++- .../cocos/ui/webview/WebViewImpl-android.cpp | 64 +++++++++------- native/cocos/ui/webview/WebViewImpl-ios.h | 12 +-- native/cocos/ui/webview/WebViewImpl-ios.mm | 76 ++++++++++++++++++- native/cocos/ui/webview/WebViewImpl-java.h | 10 ++- native/cocos/ui/webview/WebViewImpl-ohos.cpp | 14 +++- native/tools/tojs/video.ini | 2 +- native/tools/tojs/webview.ini | 2 +- 12 files changed, 231 insertions(+), 68 deletions(-) diff --git a/native/cocos/ui/videoplayer/VideoPlayer-ios.mm b/native/cocos/ui/videoplayer/VideoPlayer-ios.mm index 95a376df75..c655ac202e 100644 --- a/native/cocos/ui/videoplayer/VideoPlayer-ios.mm +++ b/native/cocos/ui/videoplayer/VideoPlayer-ios.mm @@ -298,8 +298,13 @@ VideoPlayer::VideoPlayer() } VideoPlayer::~VideoPlayer() { - if (_videoView) { - [((UIVideoViewWrapperIos *)_videoView) dealloc]; + destroy(); +} + +void VideoPlayer::destroy() { + if (_videoView != nil) { + [((UIVideoViewWrapperIos *)_videoView) release]; + _videoView = nil; } } diff --git a/native/cocos/ui/videoplayer/VideoPlayer-java.cpp b/native/cocos/ui/videoplayer/VideoPlayer-java.cpp index abda6b172d..28457037a2 100644 --- a/native/cocos/ui/videoplayer/VideoPlayer-java.cpp +++ b/native/cocos/ui/videoplayer/VideoPlayer-java.cpp @@ -82,8 +82,21 @@ VideoPlayer::VideoPlayer() } VideoPlayer::~VideoPlayer() { - sAllVideoPlayers.erase(_videoPlayerIndex); - JniHelper::callStaticVoidMethod(VIDEO_HELPER_CLASS_NAME, "removeVideoWidget", _videoPlayerIndex); + destroy(); +} + +void VideoPlayer::destroy() { + if (_videoPlayerIndex != -1) { + auto iter = sAllVideoPlayers.find(_videoPlayerIndex); + if (iter != sAllVideoPlayers.end()) { + sAllVideoPlayers.erase(iter); + } + + JniHelper::callStaticVoidMethod(VIDEO_HELPER_CLASS_NAME, "removeVideoWidget", + _videoPlayerIndex); + + _videoPlayerIndex = -1; + } } void VideoPlayer::setURL(const ccstd::string &videoUrl) { diff --git a/native/cocos/ui/videoplayer/VideoPlayer.h b/native/cocos/ui/videoplayer/VideoPlayer.h index fa34e05286..1f43cc7420 100644 --- a/native/cocos/ui/videoplayer/VideoPlayer.h +++ b/native/cocos/ui/videoplayer/VideoPlayer.h @@ -50,7 +50,7 @@ namespace cc { * It's mean VideoPlayer displays a video file above all graphical elements of cocos2d-x. * @js NA */ -class VideoPlayer : public RefCounted { +class VideoPlayer final { public: /** * Videoplayer play event type. @@ -66,6 +66,12 @@ public: }; VideoPlayer(); + ~VideoPlayer(); + + /** + * Destroy VideoPlayer, remove it from parent + */ + void destroy(); /** * A callback which will be called after specific VideoPlayer event happens. @@ -151,8 +157,6 @@ public: virtual void setFrame(float x, float y, float width, float height); protected: - ~VideoPlayer() override; - enum class Source { FILENAME = 0, URL diff --git a/native/cocos/ui/webview/WebView-inl.h b/native/cocos/ui/webview/WebView-inl.h index 74391e64d5..50e94dba57 100644 --- a/native/cocos/ui/webview/WebView-inl.h +++ b/native/cocos/ui/webview/WebView-inl.h @@ -58,75 +58,115 @@ WebView *WebView::create() { return nullptr; } +void WebView::destroy() { + CC_SAFE_DESTROY(_impl); +} + void WebView::setJavascriptInterfaceScheme(const ccstd::string &scheme) { - _impl->setJavascriptInterfaceScheme(scheme); + if (_impl != nullptr) { + _impl->setJavascriptInterfaceScheme(scheme); + } } void WebView::loadData(const cc::Data &data, const ccstd::string &MIMEType, const ccstd::string &encoding, const ccstd::string &baseURL) { - _impl->loadData(data, MIMEType, encoding, baseURL); + if (_impl != nullptr) { + _impl->loadData(data, MIMEType, encoding, baseURL); + } } void WebView::loadHTMLString(const ccstd::string &string, const ccstd::string &baseURL) { - _impl->loadHTMLString(string, baseURL); + if (_impl != nullptr) { + _impl->loadHTMLString(string, baseURL); + } } void WebView::loadURL(const ccstd::string &url) { - _impl->loadURL(url); + if (_impl != nullptr) { + _impl->loadURL(url); + } } void WebView::loadFile(const ccstd::string &fileName) { - _impl->loadFile(fileName); + if (_impl != nullptr) { + _impl->loadFile(fileName); + } } void WebView::stopLoading() { - _impl->stopLoading(); + if (_impl != nullptr) { + _impl->stopLoading(); + } } void WebView::reload() { - _impl->reload(); + if (_impl != nullptr) { + _impl->reload(); + } } bool WebView::canGoBack() { - return _impl->canGoBack(); + if (_impl != nullptr) { + return _impl->canGoBack(); + } + return false; } bool WebView::canGoForward() { - return _impl->canGoForward(); + if (_impl != nullptr) { + return _impl->canGoForward(); + } + return false; } void WebView::goBack() { - _impl->goBack(); + if (_impl != nullptr) { + _impl->goBack(); + } } void WebView::goForward() { - _impl->goForward(); + if (_impl != nullptr) { + _impl->goForward(); + } } void WebView::evaluateJS(const ccstd::string &js) { - _impl->evaluateJS(js); + if (_impl != nullptr) { + _impl->evaluateJS(js); + } } void WebView::setScalesPageToFit(bool scalesPageToFit) { - _impl->setScalesPageToFit(scalesPageToFit); + if (_impl != nullptr) { + _impl->setScalesPageToFit(scalesPageToFit); + } } void WebView::setVisible(bool visible) { - _impl->setVisible(visible); + if (_impl != nullptr) { + _impl->setVisible(visible); + } } void WebView::setFrame(float x, float y, float width, float height) { - _impl->setFrame(x, y, width, height); + if (_impl != nullptr) { + _impl->setFrame(x, y, width, height); + } } void WebView::setBounces(bool bounces) { - _impl->setBounces(bounces); + if (_impl != nullptr) { + _impl->setBounces(bounces); + } } void WebView::setBackgroundTransparent(bool isTransparent) { - _impl->setBackgroundTransparent(isTransparent); + if (_impl != nullptr) { + _impl->setBackgroundTransparent(isTransparent); + } } void WebView::setOnDidFailLoading(const ccWebViewCallback &callback) { diff --git a/native/cocos/ui/webview/WebView.h b/native/cocos/ui/webview/WebView.h index 4840785388..e550675f04 100644 --- a/native/cocos/ui/webview/WebView.h +++ b/native/cocos/ui/webview/WebView.h @@ -48,13 +48,18 @@ class WebViewImpl; * It's mean WebView displays web pages above all graphical elements of cocos2d-x. * @js NA */ -class WebView : public RefCounted { +class WebView final { public: /** * Allocates and initializes a WebView. */ static WebView *create(); + /** + * Destroy webview, remove it from its parent + */ + void destroy(); + /** * Set javascript interface scheme. * @@ -232,7 +237,7 @@ protected: /** * Default destructor. */ - ~WebView() override; + ~WebView(); private: WebViewImpl *_impl; diff --git a/native/cocos/ui/webview/WebViewImpl-android.cpp b/native/cocos/ui/webview/WebViewImpl-android.cpp index 655e961cf4..62fc15ca52 100644 --- a/native/cocos/ui/webview/WebViewImpl-android.cpp +++ b/native/cocos/ui/webview/WebViewImpl-android.cpp @@ -72,7 +72,7 @@ extern "C" { JNIEXPORT jboolean JNICALL Java_com_cocos_lib_CocosWebViewHelper_shouldStartLoading(JNIEnv *env, jclass, jint index, //NOLINT jstring jurl) { - auto charUrl = env->GetStringUTFChars(jurl, nullptr); + const auto *charUrl = env->GetStringUTFChars(jurl, nullptr); ccstd::string url = charUrl; env->ReleaseStringUTFChars(jurl, charUrl); return cc::WebViewImpl::shouldStartLoading(index, url); @@ -87,7 +87,7 @@ JNIEXPORT void JNICALL Java_com_cocos_lib_CocosWebViewHelper_didFinishLoading(JNIEnv *env, jclass, jint index, //NOLINT jstring jurl) { // LOGD("didFinishLoading"); - auto charUrl = env->GetStringUTFChars(jurl, nullptr); + const auto *charUrl = env->GetStringUTFChars(jurl, nullptr); ccstd::string url = charUrl; env->ReleaseStringUTFChars(jurl, charUrl); cc::WebViewImpl::didFinishLoading(index, url); @@ -102,7 +102,7 @@ JNIEXPORT void JNICALL Java_com_cocos_lib_CocosWebViewHelper_didFailLoading(JNIEnv *env, jclass, jint index, //NOLINT jstring jurl) { // LOGD("didFailLoading"); - auto charUrl = env->GetStringUTFChars(jurl, nullptr); + const auto *charUrl = env->GetStringUTFChars(jurl, nullptr); ccstd::string url = charUrl; env->ReleaseStringUTFChars(jurl, charUrl); cc::WebViewImpl::didFailLoading(index, url); @@ -117,7 +117,7 @@ JNIEXPORT void JNICALL Java_com_cocos_lib_CocosWebViewHelper_onJsCallback(JNIEnv *env, jclass, jint index, //NOLINT jstring jmessage) { // LOGD("jsCallback"); - auto charMessage = env->GetStringUTFChars(jmessage, nullptr); + const auto *charMessage = env->GetStringUTFChars(jmessage, nullptr); ccstd::string message = charMessage; env->ReleaseStringUTFChars(jmessage, charMessage); cc::WebViewImpl::onJsCallback(index, message); @@ -166,65 +166,75 @@ WebViewImpl::WebViewImpl(WebView *webView) : _viewTag(-1), } WebViewImpl::~WebViewImpl() { - JniHelper::callStaticVoidMethod(CLASS_NAME, "removeWebView", _viewTag); - sWebViewImpls.erase(_viewTag); + destroy(); } -void WebViewImpl::loadData(const Data &data, const ccstd::string &mimeType, - const ccstd::string &encoding, const ccstd::string &baseURL) { +void WebViewImpl::destroy() { + if (_viewTag != -1) { + JniHelper::callStaticVoidMethod(CLASS_NAME, "removeWebView", _viewTag); + auto iter = sWebViewImpls.find(_viewTag); + if (iter != sWebViewImpls.end()) { + sWebViewImpls.erase(iter); + } + _viewTag = -1; + } +} + +void WebViewImpl::loadData(const Data &data, const ccstd::string &mimeType, // NOLINT + const ccstd::string &encoding, const ccstd::string &baseURL) { // NOLINT ccstd::string dataString(reinterpret_cast(data.getBytes()), static_cast(data.getSize())); JniHelper::callStaticVoidMethod(CLASS_NAME, "setJavascriptInterfaceScheme", _viewTag, dataString, mimeType, encoding, baseURL); } -void WebViewImpl::loadHTMLString(const ccstd::string &string, const ccstd::string &baseURL) { +void WebViewImpl::loadHTMLString(const ccstd::string &string, const ccstd::string &baseURL) { // NOLINT JniHelper::callStaticVoidMethod(CLASS_NAME, "loadHTMLString", _viewTag, string, baseURL); } -void WebViewImpl::loadURL(const ccstd::string &url) { +void WebViewImpl::loadURL(const ccstd::string &url) { // NOLINT JniHelper::callStaticVoidMethod(CLASS_NAME, "loadUrl", _viewTag, url); } -void WebViewImpl::loadFile(const ccstd::string &fileName) { +void WebViewImpl::loadFile(const ccstd::string &fileName) { // NOLINT auto fullPath = getUrlStringByFileName(fileName); JniHelper::callStaticVoidMethod(CLASS_NAME, "loadFile", _viewTag, fullPath); } -void WebViewImpl::stopLoading() { +void WebViewImpl::stopLoading() { // NOLINT JniHelper::callStaticVoidMethod(CLASS_NAME, "stopLoading", _viewTag); } -void WebViewImpl::reload() { +void WebViewImpl::reload() { // NOLINT JniHelper::callStaticVoidMethod(CLASS_NAME, "reload", _viewTag); } -bool WebViewImpl::canGoBack() { +bool WebViewImpl::canGoBack() { // NOLINT return JniHelper::callStaticBooleanMethod(CLASS_NAME, "canGoBack", _viewTag); } -bool WebViewImpl::canGoForward() { +bool WebViewImpl::canGoForward() { // NOLINT return JniHelper::callStaticBooleanMethod(CLASS_NAME, "canGoForward", _viewTag); } -void WebViewImpl::goBack() { +void WebViewImpl::goBack() { // NOLINT JniHelper::callStaticVoidMethod(CLASS_NAME, "goBack", _viewTag); } -void WebViewImpl::goForward() { +void WebViewImpl::goForward() { // NOLINT JniHelper::callStaticVoidMethod(CLASS_NAME, "goForward", _viewTag); } -void WebViewImpl::setJavascriptInterfaceScheme(const ccstd::string &scheme) { +void WebViewImpl::setJavascriptInterfaceScheme(const ccstd::string &scheme) { // NOLINT JniHelper::callStaticVoidMethod(CLASS_NAME, "setJavascriptInterfaceScheme", _viewTag, scheme); } -void WebViewImpl::evaluateJS(const ccstd::string &js) { +void WebViewImpl::evaluateJS(const ccstd::string &js) { // NOLINT JniHelper::callStaticVoidMethod(CLASS_NAME, "evaluateJS", _viewTag, js); } -void WebViewImpl::setScalesPageToFit(bool scalesPageToFit) { +void WebViewImpl::setScalesPageToFit(bool scalesPageToFit) { // NOLINT JniHelper::callStaticVoidMethod(CLASS_NAME, "setScalesPageToFit", _viewTag, scalesPageToFit); } @@ -232,7 +242,7 @@ bool WebViewImpl::shouldStartLoading(int viewTag, const ccstd::string &url) { bool allowLoad = true; auto it = sWebViewImpls.find(viewTag); if (it != sWebViewImpls.end()) { - auto webView = it->second->_webView; + auto *webView = it->second->_webView; if (webView->_onShouldStartLoading) { allowLoad = webView->_onShouldStartLoading(webView, url); } @@ -243,7 +253,7 @@ bool WebViewImpl::shouldStartLoading(int viewTag, const ccstd::string &url) { void WebViewImpl::didFinishLoading(int viewTag, const ccstd::string &url) { auto it = sWebViewImpls.find(viewTag); if (it != sWebViewImpls.end()) { - auto webView = it->second->_webView; + auto *webView = it->second->_webView; if (webView->_onDidFinishLoading) { webView->_onDidFinishLoading(webView, url); } @@ -253,7 +263,7 @@ void WebViewImpl::didFinishLoading(int viewTag, const ccstd::string &url) { void WebViewImpl::didFailLoading(int viewTag, const ccstd::string &url) { auto it = sWebViewImpls.find(viewTag); if (it != sWebViewImpls.end()) { - auto webView = it->second->_webView; + auto *webView = it->second->_webView; if (webView->_onDidFailLoading) { webView->_onDidFailLoading(webView, url); } @@ -263,18 +273,18 @@ void WebViewImpl::didFailLoading(int viewTag, const ccstd::string &url) { void WebViewImpl::onJsCallback(int viewTag, const ccstd::string &message) { auto it = sWebViewImpls.find(viewTag); if (it != sWebViewImpls.end()) { - auto webView = it->second->_webView; + auto *webView = it->second->_webView; if (webView->_onJSCallback) { webView->_onJSCallback(webView, message); } } } -void WebViewImpl::setVisible(bool visible) { +void WebViewImpl::setVisible(bool visible) { // NOLINT JniHelper::callStaticVoidMethod(CLASS_NAME, "setVisible", _viewTag, visible); } -void WebViewImpl::setFrame(float x, float y, float width, float height) { +void WebViewImpl::setFrame(float x, float y, float width, float height) { // NOLINT JniHelper::callStaticVoidMethod(CLASS_NAME, "setWebViewRect", _viewTag, static_cast(x), static_cast(y), static_cast(width), static_cast(height)); } @@ -283,7 +293,7 @@ void WebViewImpl::setBounces(bool bounces) { // empty function as this was mainly a fix for iOS } -void WebViewImpl::setBackgroundTransparent(bool isTransparent) { +void WebViewImpl::setBackgroundTransparent(bool isTransparent) { // NOLINT JniHelper::callStaticVoidMethod(CLASS_NAME, "setBackgroundTransparent", _viewTag, isTransparent); } diff --git a/native/cocos/ui/webview/WebViewImpl-ios.h b/native/cocos/ui/webview/WebViewImpl-ios.h index 18cf8cf2b3..6f3e03d0d3 100644 --- a/native/cocos/ui/webview/WebViewImpl-ios.h +++ b/native/cocos/ui/webview/WebViewImpl-ios.h @@ -38,11 +38,13 @@ class Data; class WebView; -class WebViewImpl { +class WebViewImpl final { public: - WebViewImpl(WebView *webView); + explicit WebViewImpl(WebView *webView); - virtual ~WebViewImpl(); + ~WebViewImpl(); + + void destroy(); void setJavascriptInterfaceScheme(const ccstd::string &scheme); @@ -73,9 +75,9 @@ public: void setScalesPageToFit(const bool scalesPageToFit); - virtual void setVisible(bool visible); + void setVisible(bool visible); - virtual void setFrame(float x, float y, float width, float height); + void setFrame(float x, float y, float width, float height); void setBounces(bool bounces); diff --git a/native/cocos/ui/webview/WebViewImpl-ios.mm b/native/cocos/ui/webview/WebViewImpl-ios.mm index 32a27539b6..485f511b5c 100644 --- a/native/cocos/ui/webview/WebViewImpl-ios.mm +++ b/native/cocos/ui/webview/WebViewImpl-ios.mm @@ -312,11 +312,21 @@ WebViewImpl::WebViewImpl(WebView *webView) } WebViewImpl::~WebViewImpl() { - [_uiWebViewWrapper release]; - _uiWebViewWrapper = nullptr; + destroy(); +} + +void WebViewImpl::destroy() { + if (_uiWebViewWrapper != nil) { + [_uiWebViewWrapper release]; + _uiWebViewWrapper = nil; + } } void WebViewImpl::setJavascriptInterfaceScheme(const ccstd::string &scheme) { + if (_uiWebViewWrapper == nil) { + return; + } + [_uiWebViewWrapper setJavascriptInterfaceScheme:scheme]; } @@ -324,64 +334,122 @@ void WebViewImpl::loadData(const Data &data, const ccstd::string &MIMEType, const ccstd::string &encoding, const ccstd::string &baseURL) { + if (_uiWebViewWrapper == nil) { + return; + } + ccstd::string dataString(reinterpret_cast(data.getBytes()), static_cast(data.getSize())); [_uiWebViewWrapper loadData:dataString MIMEType:MIMEType textEncodingName:encoding baseURL:baseURL]; } void WebViewImpl::loadHTMLString(const ccstd::string &string, const ccstd::string &baseURL) { + if (_uiWebViewWrapper == nil) { + return; + } + [_uiWebViewWrapper loadHTMLString:string baseURL:baseURL]; } void WebViewImpl::loadURL(const ccstd::string &url) { + if (_uiWebViewWrapper == nil) { + return; + } + [_uiWebViewWrapper loadUrl:url]; } void WebViewImpl::loadFile(const ccstd::string &fileName) { + if (_uiWebViewWrapper == nil) { + return; + } + auto fullPath = cc::FileUtils::getInstance()->fullPathForFilename(fileName); [_uiWebViewWrapper loadFile:fullPath]; } void WebViewImpl::stopLoading() { + if (_uiWebViewWrapper == nil) { + return; + } + [_uiWebViewWrapper stopLoading]; } void WebViewImpl::reload() { + if (_uiWebViewWrapper == nil) { + return; + } + [_uiWebViewWrapper reload]; } bool WebViewImpl::canGoBack() { + if (_uiWebViewWrapper == nil) { + return false; + } return _uiWebViewWrapper.canGoBack; } bool WebViewImpl::canGoForward() { + if (_uiWebViewWrapper == nil) { + return false; + } return _uiWebViewWrapper.canGoForward; } void WebViewImpl::goBack() { + if (_uiWebViewWrapper == nil) { + return; + } + [_uiWebViewWrapper goBack]; } void WebViewImpl::goForward() { + if (_uiWebViewWrapper == nil) { + return; + } + [_uiWebViewWrapper goForward]; } void WebViewImpl::evaluateJS(const ccstd::string &js) { + if (_uiWebViewWrapper == nil) { + return; + } + [_uiWebViewWrapper evaluateJS:js]; } void WebViewImpl::setBounces(bool bounces) { + if (_uiWebViewWrapper == nil) { + return; + } + [_uiWebViewWrapper setBounces:bounces]; } void WebViewImpl::setScalesPageToFit(bool scalesPageToFit) { + if (_uiWebViewWrapper == nil) { + return; + } + [_uiWebViewWrapper setScalesPageToFit:scalesPageToFit]; } void WebViewImpl::setVisible(bool visible) { + if (_uiWebViewWrapper == nil) { + return; + } + [_uiWebViewWrapper setVisible:visible]; } void WebViewImpl::setFrame(float x, float y, float width, float height) { + if (_uiWebViewWrapper == nil) { + return; + } + UIView *view = UIApplication.sharedApplication.delegate.window.rootViewController.view; auto scaleFactor = [view contentScaleFactor]; [_uiWebViewWrapper setFrameWithX:x / scaleFactor @@ -391,6 +459,10 @@ void WebViewImpl::setFrame(float x, float y, float width, float height) { } void WebViewImpl::setBackgroundTransparent(bool isTransparent) { + if (_uiWebViewWrapper == nil) { + return; + } + [_uiWebViewWrapper setBackgroundTransparent:isTransparent]; } } //namespace cc diff --git a/native/cocos/ui/webview/WebViewImpl-java.h b/native/cocos/ui/webview/WebViewImpl-java.h index 310d500251..3147313fb5 100644 --- a/native/cocos/ui/webview/WebViewImpl-java.h +++ b/native/cocos/ui/webview/WebViewImpl-java.h @@ -36,11 +36,13 @@ namespace cc { class WebView; -class WebViewImpl { +class WebViewImpl final { public: explicit WebViewImpl(WebView *webView); - virtual ~WebViewImpl(); + ~WebViewImpl(); + + void destroy(); void setJavascriptInterfaceScheme(const ccstd::string &scheme); @@ -69,9 +71,9 @@ public: void setScalesPageToFit(bool scalesPageToFit); - virtual void setVisible(bool visible); + void setVisible(bool visible); - virtual void setFrame(float x, float y, float width, float height); + void setFrame(float x, float y, float width, float height); void setBounces(bool bounces); diff --git a/native/cocos/ui/webview/WebViewImpl-ohos.cpp b/native/cocos/ui/webview/WebViewImpl-ohos.cpp index 664caaf30f..bc98057178 100644 --- a/native/cocos/ui/webview/WebViewImpl-ohos.cpp +++ b/native/cocos/ui/webview/WebViewImpl-ohos.cpp @@ -168,8 +168,18 @@ WebViewImpl::WebViewImpl(WebView *webView) : _viewTag(-1), } WebViewImpl::~WebViewImpl() { - JniHelper::callStaticVoidMethod(CLASS_NAME, "removeWebView", _viewTag); - sWebViewImpls.erase(_viewTag); + destroy(); +} + +void WebViewImpl::destroy() { + if (_viewTag != -1) { + JniHelper::callStaticVoidMethod(CLASS_NAME, "removeWebView", _viewTag); + auto iter = sWebViewImpls.find(_viewTag); + if (iter != sWebViewImpls.end()) { + sWebViewImpls.erase(iter); + } + _viewTag = -1; + } } void WebViewImpl::loadData(const Data &data, const ccstd::string &mimeType, diff --git a/native/tools/tojs/video.ini b/native/tools/tojs/video.ini index 68c7fc7e41..311a713d25 100644 --- a/native/tools/tojs/video.ini +++ b/native/tools/tojs/video.ini @@ -42,7 +42,7 @@ classes = VideoPlayer skip = -rename_functions = VideoPlayer::[~VideoPlayer=destroy] +rename_functions = rename_classes = diff --git a/native/tools/tojs/webview.ini b/native/tools/tojs/webview.ini index 976b3f1cbd..6d22788ae3 100644 --- a/native/tools/tojs/webview.ini +++ b/native/tools/tojs/webview.ini @@ -41,7 +41,7 @@ classes = WebView skip = -rename_functions = WebView::[~WebView=destroy] +rename_functions = rename_classes =