コード例 #1
0
 /**
  * Tell the client to display a prompt dialog to the user. If the client returns true, WebView
  * will assume that the client will handle the prompt dialog and call the appropriate
  * JsPromptResult method.
  *
  * <p>The prompt bridge provided for the InAppBrowser is capable of executing any oustanding
  * callback belonging to the InAppBrowser plugin. Care has been taken that other callbacks cannot
  * be triggered, and that no other code execution is possible.
  *
  * <p>To trigger the bridge, the prompt default value should be of the form:
  *
  * <p>gap-iab://<callbackId>
  *
  * <p>where <callbackId> is the string id of the callback to trigger (something like
  * "InAppBrowser0123456789")
  *
  * <p>If present, the prompt message is expected to be a JSON-encoded value to pass to the
  * callback. A JSON_EXCEPTION is returned if the JSON is invalid.
  *
  * @param view
  * @param url
  * @param message
  * @param defaultValue
  * @param result
  */
 @Override
 public boolean onJsPrompt(
     WebView view, String url, String message, String defaultValue, JsPromptResult result) {
   // 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 != null && defaultValue.startsWith("gap")) {
     if (defaultValue.startsWith("gap-iab://")) {
       PluginResult scriptResult;
       String scriptCallbackId = defaultValue.substring(10);
       if (scriptCallbackId.startsWith("InAppBrowser")) {
         if (message == null || message.length() == 0) {
           scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray());
         } else {
           try {
             scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray(message));
           } catch (JSONException e) {
             scriptResult = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage());
           }
         }
         this.webView.sendPluginResult(scriptResult, scriptCallbackId);
         result.confirm("");
         return true;
       }
     } else {
       // Anything else with a gap: prefix should get this message
       LOG.w(
           LOG_TAG,
           "InAppBrowser does not support Cordova API calls: " + url + " " + defaultValue);
       result.cancel();
       return true;
     }
   }
   return false;
 }
 @Override
 public void onJsResultComplete(JsResult result) {
   if (mChromePromptResultReceiver != null) {
     if (mPromptResult.getResult()) {
       mChromePromptResultReceiver.confirm(mPromptResult.getStringResult());
     } else {
       mChromePromptResultReceiver.cancel();
     }
   } else {
     if (mPromptResult.getResult()) {
       mChromeResultReceiver.confirm();
     } else {
       mChromeResultReceiver.cancel();
     }
   }
 }
コード例 #3
0
  @Override
  public boolean onJsPrompt(
      WebView view, String url, String message, String defaultValue, JsPromptResult r) {
    if (message != null && message.startsWith("calabash:")) {
      r.confirm("CALABASH_ACK");
      System.out.println("onJsPrompt: " + message);
      result.message = message.replace("calabash:", "");
      eventHandled.open();

      return true;
    } else {
      if (mWebChromeClient == null) {
        r.confirm("CALABASH_ERROR");
        return true;
      } else {
        return mWebChromeClient.onJsPrompt(view, url, message, defaultValue, r);
      }
    }
  }
コード例 #4
0
 @Override
 public boolean onJsPrompt(
     WebView view, String url, String message, String defaultValue, JsPromptResult result) {
   try {
     JSONObject messagePack = new JSONObject(URLDecoder.decode(message, "utf-8"));
     Message msg =
         Message.obtain(incomingMessageHandler, MESSAGE_HANDLE_MESSAGE_FROM_JS, messagePack);
     incomingMessageHandler.sendMessage(msg);
     result.confirm();
   } catch (JSONException e) {
     throw new RuntimeException(e);
   } catch (UnsupportedEncodingException e) {
     throw new RuntimeException(e);
   }
   return true;
 }
コード例 #5
0
 @Override
 public boolean onJsPrompt(
     final WebView view,
     final String url,
     final String message,
     final String defaultValue,
     final JsPromptResult result) {
   final BWebHost webHost = webView.getWebHost();
   if (webHost != null) {
     Pair<String, String> pair = new Pair<String, String>(message, defaultValue);
     Object r = webHost.exec(BConstants.MSG_PAGE_JS_CALL, 0, pair);
     if (r != null) {
       result.confirm(r.toString());
       return true;
     }
   }
   final FragmentActivity activity = webHost.getHost();
   if (activity != null) {
     final JsPromptResult res = result;
     AlertDialog.Builder dlg = new AlertDialog.Builder(activity);
     dlg.setMessage(message);
     final EditText input = new EditText(activity);
     if (defaultValue != null) {
       input.setText(defaultValue);
     }
     dlg.setView(input);
     dlg.setCancelable(false);
     dlg.setPositiveButton(
         android.R.string.ok,
         new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int which) {
             String usertext = input.getText().toString();
             res.confirm(usertext);
           }
         });
     dlg.setNegativeButton(
         android.R.string.cancel,
         new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int which) {
             res.cancel();
           }
         });
     dlg.show();
   }
   return true;
 }
コード例 #6
0
  /**
   * Overrides onJsPrompt in order to create {@code WebElement} objects based on the web elements
   * attributes prompted by the injections of JavaScript
   */
  @Override
  public boolean onJsPrompt(
      WebView view, String url, String message, String defaultValue, JsPromptResult r) {

    if (message != null && (message.contains(";,") || message.contains("robotium-finished"))) {

      if (message.equals("robotium-finished")) {
        webElementCreator.setFinished(true);
      } else {
        webElementCreator.createWebElementAndAddInList(message, view);
      }
      r.confirm();
      return true;
    } else {
      if (originalWebChromeClient != null) {
        return originalWebChromeClient.onJsPrompt(view, url, message, defaultValue, r);
      }
      return true;
    }
  }
コード例 #7
0
 public boolean onJsPrompt(
     WebView paramWebView,
     final String paramString1,
     String paramString2,
     String paramString3,
     final JsPromptResult paramJsPromptResult) {
   paramWebView = appView.bridge.promptOnJsPrompt(paramString1, paramString2, paramString3);
   if (paramWebView != null) {
     paramJsPromptResult.confirm(paramWebView);
   }
   for (; ; ) {
     return true;
     paramWebView = new AlertDialog.Builder(cordova.getActivity());
     paramWebView.setMessage(paramString2);
     paramString1 = new EditText(cordova.getActivity());
     if (paramString3 != null) {
       paramString1.setText(paramString3);
     }
     paramWebView.setView(paramString1);
     paramWebView.setCancelable(false);
     paramWebView.setPositiveButton(
         17039370,
         new DialogInterface.OnClickListener() {
           public void onClick(
               DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt) {
             paramAnonymousDialogInterface = paramString1.getText().toString();
             paramJsPromptResult.confirm(paramAnonymousDialogInterface);
           }
         });
     paramWebView.setNegativeButton(
         17039360,
         new DialogInterface.OnClickListener() {
           public void onClick(
               DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt) {
             paramJsPromptResult.cancel();
           }
         });
     paramWebView.show();
   }
 }
コード例 #8
0
  /**
   * Tell the client to display a prompt dialog to the user. If the client returns true, WebView
   * will assume that the client will handle the prompt dialog and call the appropriate
   * JsPromptResult method.
   *
   * <p>Since we are hacking prompts for our own purposes, we should not be using them for this
   * purpose, perhaps we should hack console.log to do this instead!
   *
   * @param view
   * @param url
   * @param message
   * @param defaultValue
   * @param result
   */
  @Override
  public boolean onJsPrompt(
      WebView view, String url, String message, String defaultValue, JsPromptResult result) {

    // Security check to make sure any requests are coming from the page initially
    // loaded in webview and not another loaded in an iframe.
    boolean reqOk = false;
    if (url.startsWith("file://")
        || url.indexOf(this.ctx.baseUrl) == 0
        || ctx.isUrlWhiteListed(url)) {
      reqOk = true;
    }

    // Calling PluginManager.exec() to call a native service using
    // prompt(this.stringify(args), "gap:"+this.stringify([service, action, callbackId, true]));
    if (reqOk
        && defaultValue != null
        && defaultValue.length() > 3
        && defaultValue.substring(0, 4).equals("gap:")) {
      JSONArray array;
      try {
        array = new JSONArray(defaultValue.substring(4));
        String service = array.getString(0);
        String action = array.getString(1);
        String callbackId = array.getString(2);
        boolean async = array.getBoolean(3);
        String r = ctx.pluginManager.exec(service, action, callbackId, message, async);
        result.confirm(r);
      } catch (JSONException e) {
        e.printStackTrace();
      }
    }

    // Polling for JavaScript messages
    else if (reqOk && defaultValue != null && defaultValue.equals("gap_poll:")) {
      String r = ctx.callbackServer.getJavascript();
      result.confirm(r);
    }

    // Calling into CallbackServer
    else if (reqOk && defaultValue != null && defaultValue.equals("gap_callbackServer:")) {
      String r = "";
      if (message.equals("usePolling")) {
        r = "" + ctx.callbackServer.usePolling();
      } else if (message.equals("restartServer")) {
        ctx.callbackServer.restartServer();
      } else if (message.equals("getPort")) {
        r = Integer.toString(ctx.callbackServer.getPort());
      } else if (message.equals("getToken")) {
        r = ctx.callbackServer.getToken();
      }
      result.confirm(r);
    }

    // Cordova JS has initialized, so show webview
    // (This solves white flash seen when rendering HTML)
    else if (reqOk && defaultValue != null && defaultValue.equals("gap_init:")) {
      ctx.appView.setVisibility(View.VISIBLE);
      ctx.spinnerStop();
      result.confirm("OK");
    }

    // Show dialog
    else {
      final JsPromptResult res = result;
      AlertDialog.Builder dlg = new AlertDialog.Builder(this.ctx);
      dlg.setMessage(message);
      final EditText input = new EditText(this.ctx);
      if (defaultValue != null) {
        input.setText(defaultValue);
      }
      dlg.setView(input);
      dlg.setCancelable(false);
      dlg.setPositiveButton(
          android.R.string.ok,
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
              String usertext = input.getText().toString();
              res.confirm(usertext);
            }
          });
      dlg.setNegativeButton(
          android.R.string.cancel,
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
              res.cancel();
            }
          });
      dlg.create();
      dlg.show();
    }
    return true;
  }
コード例 #9
0
  /**
   * Tell the client to display a prompt dialog to the user. If the client returns true, WebView
   * will assume that the client will handle the prompt dialog and call the appropriate
   * JsPromptResult method.
   *
   * <p>Since we are hacking prompts for our own purposes, we should not be using them for this
   * purpose, perhaps we should hack console.log to do this instead!
   *
   * @param view
   * @param url
   * @param message
   * @param defaultValue
   * @param result
   */
  @Override
  public boolean onJsPrompt(
      WebView view, String url, String message, String defaultValue, JsPromptResult result) {

    // Security check to make sure any requests are coming from the page initially
    // loaded in webview and not another loaded in an iframe.
    boolean reqOk = false;
    if (url.startsWith("file://") || Config.isUrlWhiteListed(url)) {
      reqOk = true;
    }

    // Calling PluginManager.exec() to call a native service using
    // prompt(this.stringify(args), "gap:"+this.stringify([service, action, callbackId, true]));
    if (reqOk
        && defaultValue != null
        && defaultValue.length() > 3
        && defaultValue.substring(0, 4).equals("gap:")) {
      JSONArray array;
      try {
        array = new JSONArray(defaultValue.substring(4));
        String service = array.getString(0);
        String action = array.getString(1);
        String callbackId = array.getString(2);
        String r = this.appView.exposedJsApi.exec(service, action, callbackId, message);
        result.confirm(r == null ? "" : r);
      } catch (JSONException e) {
        e.printStackTrace();
        return false;
      }
    }

    // Sets the native->JS bridge mode.
    else if (reqOk && defaultValue != null && defaultValue.equals("gap_bridge_mode:")) {
      try {
        this.appView.exposedJsApi.setNativeToJsBridgeMode(Integer.parseInt(message));
        result.confirm("");
      } catch (NumberFormatException e) {
        result.confirm("");
        e.printStackTrace();
      }
    }

    // Polling for JavaScript messages
    else if (reqOk && defaultValue != null && defaultValue.equals("gap_poll:")) {
      String r = this.appView.exposedJsApi.retrieveJsMessages("1".equals(message));
      result.confirm(r == null ? "" : r);
    }

    // Do NO-OP so older code doesn't display dialog
    else if (defaultValue != null && defaultValue.equals("gap_init:")) {
      result.confirm("OK");
    }

    // Show dialog
    else {
      final JsPromptResult res = result;
      AlertDialog.Builder dlg = new AlertDialog.Builder(this.cordova.getActivity());
      dlg.setMessage(message);
      final EditText input = new EditText(this.cordova.getActivity());
      if (defaultValue != null) {
        input.setText(defaultValue);
      }
      dlg.setView(input);
      dlg.setCancelable(false);
      dlg.setPositiveButton(
          android.R.string.ok,
          new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
              String usertext = input.getText().toString();
              res.confirm(usertext);
            }
          });
      dlg.setNegativeButton(
          android.R.string.cancel,
          new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
              res.cancel();
            }
          });
      dlg.show();
    }
    return true;
  }