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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-inappbrowser",
"version": "5.0.0",
"version": "5.0.1-dev",
"description": "Cordova InAppBrowser Plugin",
"types": "./types/index.d.ts",
"cordova": {
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-plugin-inappbrowser"
version="5.0.0">
version="5.0.1-dev">

<name>InAppBrowser</name>
<description>Cordova InAppBrowser Plugin</description>
Expand Down
10 changes: 10 additions & 0 deletions src/android/InAppBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,16 @@ public void onPageFinished(WebView view, String url) {
dialog.dismiss();
dialog = null;
}

// Fix for webView window not being destroyed correctly causing memory leak
// (https://github.com/apache/cordova-plugin-inappbrowser/issues/290)
if (url.equals(new String("about:blank"))) {
inAppWebView.onPause();
inAppWebView.removeAllViews();
inAppWebView.destroyDrawingCache();
inAppWebView.destroy();
inAppWebView = null;
}
Comment on lines +540 to +546

Choose a reason for hiding this comment

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

high

이 코드는 몇 가지 잠재적인 문제를 가지고 있습니다.

  1. new String("about:blank")는 호출될 때마다 불필요한 새 문자열 객체를 생성합니다. 문자열 리터럴 "about:blank"를 직접 사용하는 것이 더 효율적입니다.
  2. url.equals(...)urlnull일 경우 NullPointerException을 발생시킬 수 있습니다. "about:blank".equals(url)과 같이 리터럴에 대해 equals를 호출하는 것이 더 안전합니다.
  3. onPageFinished 콜백 내에서 인스턴스 변수인 inAppWebView를 직접 사용하면 경합 상태(race condition)가 발생할 수 있습니다. 예를 들어, 이 WebView가 닫히기 전에 다른 InAppBrowser가 열리면 inAppWebView는 새 WebView를 가리키게 되어, 결국 잘못된 WebView를 닫게 될 수 있습니다. 콜백의 view 파라미터를 사용하여 올바른 WebView 인스턴스를 조작해야 합니다.
                        if ("about:blank".equals(url)) {
                            view.onPause();
                            view.removeAllViews();
                            view.destroyDrawingCache();
                            view.destroy();
                            if (inAppWebView == view) {
                                inAppWebView = null;
                            }
                        }

}
});
// NB: From SDK 19: "If you call methods on WebView from any thread
Expand Down
5 changes: 3 additions & 2 deletions src/ios/CDVWKInAppBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,9 @@ - (void)webView:(WKWebView *)theWebView decidePolicyForNavigationAction:(WKNavig
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
}

//if is an app store link, let the system handle it, otherwise it fails to load it
if ([[ url scheme] isEqualToString:@"itms-appss"] || [[ url scheme] isEqualToString:@"itms-apps"]) {
//if is an app store, tel, sms, mailto or geo link, let the system handle it, otherwise it fails to load it
NSArray * allowedSchemes = @[@"itms-appss", @"itms-apps", @"tel", @"sms", @"mailto", @"geo"];
if ([allowedSchemes containsObject:[url scheme]]) {
Comment on lines +543 to +544

Choose a reason for hiding this comment

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

medium

decidePolicyForNavigationAction: 델리게이트 메서드는 페이지 로딩 중에 자주 호출될 수 있습니다. allowedSchemes 배열을 매번 새로 생성하는 것은 비효율적입니다.
이 배열을 static const로 선언하여 앱의 생명주기 동안 한 번만 생성되도록 하는 것이 좋습니다. 이렇게 하면 불필요한 객체 할당을 줄여 성능을 향상시킬 수 있습니다.

Suggested change
NSArray * allowedSchemes = @[@"itms-appss", @"itms-apps", @"tel", @"sms", @"mailto", @"geo"];
if ([allowedSchemes containsObject:[url scheme]]) {
static NSArray * const allowedSchemes = @[@"itms-appss", @"itms-apps", @"tel", @"sms", @"mailto", @"geo"];
if ([allowedSchemes containsObject:[url scheme]]) {

[theWebView stopLoading];
[self openInSystem:url];
shouldStart = NO;
Expand Down
2 changes: 1 addition & 1 deletion tests/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-inappbrowser-tests",
"version": "5.0.0",
"version": "5.0.1-dev",
"description": "",
"cordova": {
"id": "cordova-plugin-inappbrowser-tests",
Expand Down
2 changes: 1 addition & 1 deletion tests/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-plugin-inappbrowser-tests"
version="5.0.0">
version="5.0.1-dev">
<name>Cordova InAppBrowser Plugin Tests</name>
<license>Apache 2.0</license>

Expand Down