/** * 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. * * 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! */ @Override public boolean onJsPrompt(WebView view, String origin, String message, String defaultValue, final JsPromptResult result) { // Unlike the @JavascriptInterface bridge, this method is always called on the UI thread. String handledRet = parentEngine.bridge.promptOnJsPrompt(origin, message, defaultValue); if (handledRet != null) { result.confirm(handledRet); } else { dialogsHelper.showPrompt(message, defaultValue, new CordovaDialogsHelper.Result() { @Override public void gotResult(boolean success, String value) { if (success) { result.confirm(value); } else { result.cancel(); } } }); } return true; }
@Override public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) { Log.i(TAG,"onJsPrompt:"+url+" message:"+message+" d:"+defaultValue+" "); if (mJsCallJavas != null && JsCallJava.isSafeWebViewCallMsg(message)) { JSONObject jsonObject = JsCallJava.getMsgJSONObject(message); String interfacedName = JsCallJava.getInterfacedName(jsonObject); if (interfacedName != null) { JsCallJava jsCallJava = mJsCallJavas.get(interfacedName); if (jsCallJava != null) { result.confirm(jsCallJava.call(view, jsonObject)); } } return true; } else { return false; } }
@Override public boolean onJsPrompt( WebView view, String url, String message, String defaultValue, JsPromptResult result) { // Need to set a result. result.confirm("ok"); // Hard-coded to test performance of prompt. callJS("PromptCallback()"); return true; }
@Override public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) { try { // If incomingMessageHandler is null, it means that we've been cleaned up, but we're // still receiving some final messages from the WebView, so we'll just ignore them. // But we should still return true and "confirm" the JsPromptResult down below. if (incomingMessageHandler != null) { JSONObject messagePack = new JSONObject(decodeURL(message)); Message msg = Message.obtain(incomingMessageHandler, MESSAGE_HANDLE_MESSAGE_FROM_JS, messagePack); incomingMessageHandler.sendMessage(msg); } } catch (JSONException e) { throw new RuntimeException(e); } result.confirm(); return true; }
@Override public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, final JsPromptResult jsPromptResult) { return onMyJsPrompt(WEBViewImpl.toWEBView(view), url, message, defaultValue, new MyJsPromptResult() { @Override public void confirm(String result) { jsPromptResult.confirm(result); } @Override public void cancel() { jsPromptResult.cancel(); } @Override public void confirm() { jsPromptResult.confirm(); } }); }
@Override public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) { if (message != null && message.startsWith(JSINVOKER_PREFIX)) { //invoke java method String javaStatement = message.substring(JSINVOKER_PREFIX.length()); try { Object r = jsInvoker.invoke(javaStatement); if (r != null) { result.confirm(r.toString()); } else { result.confirm(); } } catch (JsInvoker.SyntaxException e) { e.printStackTrace(); result.cancel(); } return true; } return client != null && client.onJsPrompt(view, url, message, defaultValue, result); }
/** * 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; } }
@Override public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, final JsPromptResult result) { final View v = View.inflate(getActivity(), R.layout.dialog_js_prompt_message_layout, null); ((TextView)(v.findViewById(R.id.tv_message))).setText(message); ((EditText)(v.findViewById(R.id.et_content))).setText(defaultValue); Dialog dialog = DialogCreator.createDialog(null, v, getString(R.string.confirm), getString(R.string.cancel)) .setOnButtonClickListener(new BaseDialog.ButtonClickListener() { @Override public void onButtonClick(int button_id) { if (button_id == 0) { result.confirm(((EditText) (v.findViewById(R.id.et_content))).getText().toString()); } else { result.cancel(); } } }); dialog.setCanceledOnTouchOutside(false); dialog.show(); return true; }