Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-5021

Make InAppBrowser "close" more robust - avoid NPE if no matching "open"

    Details

      Description

      We have an Android application which implements an embedded WebView "container" in which it executes customer Cordova apps.

      Under certain conditions our container needs to terminate the customer app, and during this termination it attempts to do some resource cleanup. For example, to cleanup any possible lurking InAppBrowser resources it does (equivalent of a IAB.close) the following:

      cwv.pluginManager.exec("InAppBrowser", "close", null, "[]");
      

      Unfortunately, we don't really know if user app was actually using InAppBrowser or not.

      • If it was using IAB, then the above exec works.
      • If it wasn’t using IAB, the above exec results in NPE (inAppWebView is null) since current InAppBrowser.java code assumes "close" won't be called without matching "open".

      Proposed improvement below is to make the InAppBrowser’s "close" more robust, so if it gets called in an unusual scenario (e.g. without a prior "open") then it is just a harmless NOP.

      For example,

      Before:

      else if (action.equals("close")) {
          closeDialog();
          this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
      }
      

      After:

      else if (action.equals("close")) {
          if (inAppWebView != null) {
              closeDialog();
              this.callbackContext.success();
          }
      }
      

        Attachments

          Activity

            People

            • Assignee:
              agrieve Andrew Grieve
              Reporter:
              dinglemouse Peter
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: