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

Android InAppBrowser workaround for destructive PROMPT bridge problems

    XMLWordPrintableJSON

Details

    Description

      We encountered the same problem as CB-4005 when running the manual mobile-spec tests.

      Please consider the following modified InAppBrowser code as a workaround to this issue.

      Observations:

      • If InAppBrowser uses Cordova API at all then the cordova.js falls back to using the PROMPT bridge because there is no _cordovaNative defined by InAppBrowser.
      • The InAppBrowser’s onJsPrompt method (current implementation) is not capable of handling the PROMPT bridge messages (eg "gap:", "gap_poll:" etc)

      The combination of the above causes the huge number of prompts which results in the application non-responsiveness issues already described by CB-4005 and elsewhere.

      Solution:

      Change the IAB onJsPrompt to simply ignore those unhandled messages from Cordova PROMPT bridge.

      • Since there is no ability for IAB to run the API calls anyway [Ref 3] no functionality is lost.
      • Now the mobile-spec tests for InAppBrowser can run OK without suffering the unresponsive problems reported by CB-4005 and CB-3665

      Perhaps this is not be a true "fix", but it is certainly more forgiving than the current implementation which just hangs.

      Here is my suggested modification for InAppBrowser.onJsPrompt()

      @Override
      public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) {
          if (defaultValue != null) { 
      
              // See if the prompt string uses the 'gap-iab' protocol. If so, the remainder should be the id of a callback to execute.
              if (defaultValue.startsWith("gap-iab://")) {            	
                  ...
                  // blah blah same code as before 
                  ...
              }
      
              /*
               * IAP does not support ability to execute Cordova API calls so just gobble them up
               * and log a warning.
               */
              if (defaultValue.startsWith("gap")) {		
                  if (!defaultValue.equals("gap_poll:")) {
                      LOG.w(LOG_TAG, "InAppBrowser does not support Cordova API calls: " + url + " " + defaultValue);	
                  }		
                  result.cancel();
                  return true;
              }
          
          }
      
          return false;
      }
      

      Please try it. Works for me

      Related to:
      [1] CB-4005
      [2] CB-3665
      [3] PG Forum https://groups.google.com/forum/#!topic/phonegap/wyOezp7B-iI

      Attachments

        Activity

          People

            bowserj Joey Robert Bowser
            dinglemouse Peter
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: