Statistics
| Branch: | Revision:

root / src / android / webkit / WebViewClient.java @ 5d668a55

History | View | Annotate | Download (9 kB)

1
package android.webkit;
2

    
3
import android.graphics.Bitmap;
4
import android.net.http.SslError;
5
import android.os.Message;
6
import android.view.KeyEvent;
7

    
8
public class WebViewClient {
9

    
10
    /**
11
     * Give the host application a chance to take over the control when a new
12
     * url is about to be loaded in the current WebView. If WebViewClient is not
13
     * provided, by default WebView will ask Activity Manager to choose the
14
     * proper handler for the url. If WebViewClient is provided, return true
15
     * means the host application handles the url, while return false means the
16
     * current WebView handles the url.
17
     * 
18
     * @param view The WebView that is initiating the callback.
19
     * @param url The url to be loaded.
20
     * @return True if the host application wants to leave the current WebView
21
     *         and handle the url itself, otherwise return false.
22
     */
23
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
24
        return false;
25
    }
26

    
27
    /**
28
     * Notify the host application that a page has started loading. This method
29
     * is called once for each main frame load so a page with iframes or
30
     * framesets will call onPageStarted one time for the main frame. This also
31
     * means that onPageStarted will not be called when the contents of an
32
     * embedded frame changes, i.e. clicking a link whose target is an iframe.
33
     * 
34
     * @param view The WebView that is initiating the callback.
35
     * @param url The url to be loaded.
36
     * @param favicon The favicon for this page if it already exists in the
37
     *            database.
38
     */
39
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
40
    }
41

    
42
    /**
43
     * Notify the host application that a page has finished loading. This method
44
     * is called only for main frame. When onPageFinished() is called, the
45
     * rendering picture may not be updated yet. To get the notification for the
46
     * new Picture, use {@link WebView.PictureListener#onNewPicture}.
47
     * 
48
     * @param view The WebView that is initiating the callback.
49
     * @param url The url of the page.
50
     */
51
    public void onPageFinished(WebView view, String url) {
52
    }
53

    
54
    /**
55
     * Notify the host application that the WebView will load the resource
56
     * specified by the given url.
57
     * 
58
     * @param view The WebView that is initiating the callback.
59
     * @param url The url of the resource the WebView will load.
60
     */
61
    public void onLoadResource(WebView view, String url) {
62
    }
63

    
64
    /**
65
     * Notify the host application that there have been an excessive number of
66
     * HTTP redirects. As the host application if it would like to continue
67
     * trying to load the resource. The default behavior is to send the cancel
68
     * message.
69
     * 
70
     * @param view The WebView that is initiating the callback.
71
     * @param cancelMsg The message to send if the host wants to cancel
72
     * @param continueMsg The message to send if the host wants to continue
73
     */
74
    public void onTooManyRedirects(WebView view, Message cancelMsg,
75
            Message continueMsg) {
76
        cancelMsg.sendToTarget();
77
    }
78

    
79
    // These ints must match up to the hidden values in EventHandler.
80
    /** Generic error */
81
    public static final int ERROR_UNKNOWN = -1;
82
    /** Server or proxy hostname lookup failed */
83
    public static final int ERROR_HOST_LOOKUP = -2;
84
    /** Unsupported authentication scheme (not basic or digest) */
85
    public static final int ERROR_UNSUPPORTED_AUTH_SCHEME = -3;
86
    /** User authentication failed on server */
87
    public static final int ERROR_AUTHENTICATION = -4;
88
    /** User authentication failed on proxy */
89
    public static final int ERROR_PROXY_AUTHENTICATION = -5;
90
    /** Failed to connect to the server */
91
    public static final int ERROR_CONNECT = -6;
92
    /** Failed to read or write to the server */
93
    public static final int ERROR_IO = -7;
94
    /** Connection timed out */
95
    public static final int ERROR_TIMEOUT = -8;
96
    /** Too many redirects */
97
    public static final int ERROR_REDIRECT_LOOP = -9;
98
    /** Unsupported URI scheme */
99
    public static final int ERROR_UNSUPPORTED_SCHEME = -10;
100
    /** Failed to perform SSL handshake */
101
    public static final int ERROR_FAILED_SSL_HANDSHAKE = -11;
102
    /** Malformed URL */
103
    public static final int ERROR_BAD_URL = -12;
104
    /** Generic file error */
105
    public static final int ERROR_FILE = -13;
106
    /** File not found */
107
    public static final int ERROR_FILE_NOT_FOUND = -14;
108
    /** Too many requests during this load */
109
    public static final int ERROR_TOO_MANY_REQUESTS = -15;
110

    
111
    /**
112
     * Report an error to the host application. These errors are unrecoverable
113
     * (i.e. the main resource is unavailable). The errorCode parameter
114
     * corresponds to one of the ERROR_* constants.
115
     * @param view The WebView that is initiating the callback.
116
     * @param errorCode The error code corresponding to an ERROR_* value.
117
     * @param description A String describing the error.
118
     * @param failingUrl The url that failed to load.
119
     */
120
    public void onReceivedError(WebView view, int errorCode,
121
            String description, String failingUrl) {
122
    }
123

    
124
    /**
125
     * As the host application if the browser should resend data as the
126
     * requested page was a result of a POST. The default is to not resend the
127
     * data.
128
     * 
129
     * @param view The WebView that is initiating the callback.
130
     * @param dontResend The message to send if the browser should not resend
131
     * @param resend The message to send if the browser should resend data
132
     */
133
    public void onFormResubmission(WebView view, Message dontResend,
134
            Message resend) {
135
        dontResend.sendToTarget();
136
    }
137

    
138
    /**
139
     * Notify the host application to update its visited links database.
140
     * 
141
     * @param view The WebView that is initiating the callback.
142
     * @param url The url being visited.
143
     * @param isReload True if this url is being reloaded.
144
     */
145
    public void doUpdateVisitedHistory(WebView view, String url,
146
            boolean isReload) {
147
    }
148

    
149
    /**
150
     * Notify the host application to handle a ssl certificate error request
151
     * (display the error to the user and ask whether to proceed or not). The
152
     * host application has to call either handler.cancel() or handler.proceed()
153
     * as the connection is suspended and waiting for the response. The default
154
     * behavior is to cancel the load.
155
     * 
156
     * @param view The WebView that is initiating the callback.
157
     * @param handler An SslErrorHandler object that will handle the user's
158
     *            response.
159
     * @param error The SSL error object.
160
     * @hide - hide this because it contains a parameter of type SslError,
161
     * which is located in a hidden package.
162
     */
163
    public void onReceivedSslError(WebView view, SslErrorHandler handler,
164
            SslError error) {
165
        handler.cancel();
166
    }
167

    
168
    /**
169
     * Notify the host application to handle an authentication request. The
170
     * default behavior is to cancel the request.
171
     * 
172
     * @param view The WebView that is initiating the callback.
173
     * @param handler The HttpAuthHandler that will handle the user's response.
174
     * @param host The host requiring authentication.
175
     * @param realm A description to help store user credentials for future
176
     *            visits.
177
     */
178
    public void onReceivedHttpAuthRequest(WebView view,
179
            HttpAuthHandler handler, String host, String realm) {
180
        handler.cancel();
181
    }
182

    
183
    /**
184
     * Give the host application a chance to handle the key event synchronously.
185
     * e.g. menu shortcut key events need to be filtered this way. If return
186
     * true, WebView will not handle the key event. If return false, WebView
187
     * will always handle the key event, so none of the super in the view chain
188
     * will see the key event. The default behavior returns false.
189
     * 
190
     * @param view The WebView that is initiating the callback.
191
     * @param event The key event.
192
     * @return True if the host application wants to handle the key event
193
     *         itself, otherwise return false
194
     */
195
    public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {
196
        return false;
197
    }
198

    
199
    /**
200
     * Notify the host application that a key was not handled by the WebView.
201
     * Except system keys, WebView always consumes the keys in the normal flow
202
     * or if shouldOverrideKeyEvent returns true. This is called asynchronously
203
     * from where the key is dispatched. It gives the host application an chance
204
     * to handle the unhandled key events.
205
     * 
206
     * @param view The WebView that is initiating the callback.
207
     * @param event The key event.
208
     */
209
    public void onUnhandledKeyEvent(WebView view, KeyEvent event) {
210
    }
211

    
212
    /**
213
     * Notify the host application that the scale applied to the WebView has
214
     * changed.
215
     * 
216
     * @param view he WebView that is initiating the callback.
217
     * @param oldScale The old scale factor
218
     * @param newScale The new scale factor
219
     */
220
    public void onScaleChanged(WebView view, float oldScale, float newScale) {
221
    }
222
}