1 // Copyright (c) 2014 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.xwalk.core;
7 import android.net.Uri;
8 import android.webkit.ValueCallback;
10 import org.xwalk.core.internal.XWalkJavascriptResultInternal;
11 import org.xwalk.core.internal.XWalkUIClientInternal;
12 import org.xwalk.core.internal.XWalkViewInternal;
15 * This class notifies the embedder UI events/callbacks.
17 public class XWalkUIClient extends XWalkUIClientInternal {
21 * @param view the owner XWalkView instance.
24 public XWalkUIClient(XWalkView view) {
29 * The type of JavaScript modal dialog.
32 public enum JavascriptMessageType {
33 /** JavaScript alert dialog. */
35 /** JavaScript confirm dialog. */
37 /** JavaScript prompt dialog. */
39 /** JavaScript dialog for a window-before-unload notification. */
40 JAVASCRIPT_BEFOREUNLOAD
44 * Tell the client to display a prompt dialog to the user.
45 * @param view the owner XWalkView instance.
46 * @param type the type of JavaScript modal dialog.
47 * @param url the url of the web page which wants to show this dialog.
48 * @param message the message to be shown.
49 * @param defaultValue the default value string. Only valid for Prompt dialog.
50 * @param result the callback to handle the result from caller.
53 public boolean onJavascriptModalDialog(XWalkView view, JavascriptMessageType type,
54 String url, String message, String defaultValue, XWalkJavascriptResult result) {
55 XWalkJavascriptResultInternal resultInternal =
56 ((XWalkJavascriptResultHandler) result).getInternal();
57 JavascriptMessageTypeInternal typeInternal =
58 JavascriptMessageTypeInternal.valueOf(type.toString());
59 return super.onJavascriptModalDialog(
60 view, typeInternal, url, message, defaultValue, resultInternal);
67 public boolean onJavascriptModalDialog(XWalkViewInternal view,
68 JavascriptMessageTypeInternal typeInternal,
69 String url, String message, String defaultValue, XWalkJavascriptResultInternal result) {
70 JavascriptMessageType type = JavascriptMessageType.valueOf(typeInternal.toString());
71 if (view instanceof XWalkView) {
72 return onJavascriptModalDialog(
74 type, url, message, defaultValue,
75 new XWalkJavascriptResultHandler(result));
78 return super.onJavascriptModalDialog(
79 view, typeInternal, url, message, defaultValue, result);
83 * Request display and focus for this XWalkView.
84 * @param view the owner XWalkView instance.
87 public void onRequestFocus(XWalkView view) {
88 super.onRequestFocus(view);
95 public void onRequestFocus(XWalkViewInternal view) {
96 if (view instanceof XWalkView) {
97 onRequestFocus((XWalkView) view);
99 super.onRequestFocus(view);
104 * Notify the client to close the given XWalkView.
105 * @param view the owner XWalkView instance.
108 public void onJavascriptCloseWindow(XWalkView view) {
109 super.onJavascriptCloseWindow(view);
116 public void onJavascriptCloseWindow(XWalkViewInternal view) {
117 if (view instanceof XWalkView) {
118 onJavascriptCloseWindow((XWalkView) view);
120 super.onJavascriptCloseWindow(view);
125 * Tell the client to toggle fullscreen mode.
126 * @param view the owner XWalkView instance.
127 * @param enterFullscreen true if it has entered fullscreen mode.
130 public void onFullscreenToggled(XWalkView view, boolean enterFullscreen) {
131 super.onFullscreenToggled(view, enterFullscreen);
138 public void onFullscreenToggled(XWalkViewInternal view, boolean enterFullscreen) {
139 if (view instanceof XWalkView) {
140 onFullscreenToggled((XWalkView) view, enterFullscreen);
142 super.onFullscreenToggled(view, enterFullscreen);
147 * Tell the client to open a file chooser.
148 * @param view the owner XWalkView instance.
149 * @param uploadFile the callback class to handle the result from caller. It MUST
150 * be invoked in all cases. Leave it not invoked will block all following
151 * requests to open file chooser.
152 * @param acceptType value of the 'accept' attribute of the input tag associated
153 * with this file picker.
154 * @param capture value of the 'capture' attribute of the input tag associated
155 * with this file picker
158 public void openFileChooser(XWalkView view, ValueCallback<Uri> uploadFile,
159 String acceptType, String capture) {
160 super.openFileChooser(view, uploadFile, acceptType, capture);
167 public void openFileChooser(XWalkViewInternal view, ValueCallback<Uri> uploadFile,
168 String acceptType, String capture) {
169 if (view instanceof XWalkView) {
170 openFileChooser((XWalkView) view, uploadFile, acceptType, capture);
172 super.openFileChooser(view, uploadFile, acceptType, capture);
177 * Notify the client that the scale applied to the XWalkView has changed.
178 * @param view the owner XWalkView instance.
179 * @param oldScale the old scale before scaling.
180 * @param newScale the current scale factor after scaling.
183 public void onScaleChanged(XWalkView view, float oldScale, float newScale) {
184 super.onScaleChanged(view, oldScale, newScale);
191 public void onScaleChanged(XWalkViewInternal view, float oldScale, float newScale) {
192 if (view instanceof XWalkView) {
193 onScaleChanged((XWalkView) view, oldScale, newScale);
195 super.onScaleChanged(view, oldScale, newScale);