5b16b22a891b59fa0e03590ee24916a5187f9f99
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / android / core / src / org / xwalk / core / XWalkUIClient.java
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.
4
5 package org.xwalk.core;
6
7 import android.net.Uri;
8 import android.webkit.ValueCallback;
9
10 import org.xwalk.core.internal.XWalkJavascriptResultInternal;
11 import org.xwalk.core.internal.XWalkUIClientInternal;
12 import org.xwalk.core.internal.XWalkViewInternal;
13
14 /**
15  * This class notifies the embedder UI events/callbacks.
16  */
17 public class XWalkUIClient extends XWalkUIClientInternal {
18
19     /**
20      * Constructor.
21      * @param view the owner XWalkView instance.
22      * @since 1.0
23      */
24     public XWalkUIClient(XWalkView view) {
25         super(view);
26     }
27
28     /**
29      * The type of JavaScript modal dialog.
30      * @since 1.0
31      */
32     public enum JavascriptMessageType {
33         /** JavaScript alert dialog. */
34         JAVASCRIPT_ALERT,
35         /** JavaScript confirm dialog. */
36         JAVASCRIPT_CONFIRM,
37         /** JavaScript prompt dialog. */
38         JAVASCRIPT_PROMPT,
39         /** JavaScript dialog for a window-before-unload notification. */
40         JAVASCRIPT_BEFOREUNLOAD
41     }
42
43     /**
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.
51      * @since 1.0
52      */
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);
61     }
62
63     /**
64      * @hide
65      */
66     @Override
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(
73                     (XWalkView) view,
74                     type, url, message, defaultValue,
75                     new XWalkJavascriptResultHandler(result));
76         }
77
78         return super.onJavascriptModalDialog(
79                 view, typeInternal, url, message, defaultValue, result);
80     }
81
82     /**
83      * Request display and focus for this XWalkView.
84      * @param view the owner XWalkView instance.
85      * @since 1.0
86      */
87     public void onRequestFocus(XWalkView view) {
88         super.onRequestFocus(view);
89     }
90
91     /**
92      * @hide
93      */
94     @Override
95     public void onRequestFocus(XWalkViewInternal view) {
96         if (view instanceof XWalkView) {
97             onRequestFocus((XWalkView) view);
98         } else {
99             super.onRequestFocus(view);
100         }
101     }
102
103     /**
104      * Notify the client to close the given XWalkView.
105      * @param view the owner XWalkView instance.
106      * @since 1.0
107      */
108     public void onJavascriptCloseWindow(XWalkView view) {
109         super.onJavascriptCloseWindow(view);
110     }
111
112     /**
113      * @hide
114      */
115     @Override
116     public void onJavascriptCloseWindow(XWalkViewInternal view) {
117         if (view instanceof XWalkView) {
118             onJavascriptCloseWindow((XWalkView) view);
119         } else {
120             super.onJavascriptCloseWindow(view);
121         }
122     }
123
124     /**
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.
128      * @since 1.0
129      */
130     public void onFullscreenToggled(XWalkView view, boolean enterFullscreen) {
131         super.onFullscreenToggled(view, enterFullscreen);
132     }
133
134     /**
135      * @hide
136      */
137     @Override
138     public void onFullscreenToggled(XWalkViewInternal view, boolean enterFullscreen) {
139         if (view instanceof XWalkView) {
140             onFullscreenToggled((XWalkView) view, enterFullscreen);
141         } else {
142             super.onFullscreenToggled(view, enterFullscreen);
143         }
144     }
145
146     /**
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
156      * @since 1.0
157      */
158     public void openFileChooser(XWalkView view, ValueCallback<Uri> uploadFile,
159             String acceptType, String capture) {
160         super.openFileChooser(view, uploadFile, acceptType, capture);
161     }
162
163     /**
164      * @hide
165      */
166     @Override
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);
171         } else {
172             super.openFileChooser(view, uploadFile, acceptType, capture);
173         }
174     }
175
176     /**
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.
181      * @since 1.0
182      */
183     public void onScaleChanged(XWalkView view, float oldScale, float newScale) {
184         super.onScaleChanged(view, oldScale, newScale);
185     }
186
187     /**
188      * @hide
189      */
190     @Override
191     public void onScaleChanged(XWalkViewInternal view, float oldScale, float newScale) {
192         if (view instanceof XWalkView) {
193             onScaleChanged((XWalkView) view, oldScale, newScale);
194         } else {
195             super.onScaleChanged(view, oldScale, newScale);
196         }
197     }
198 }