Skip to content

Commit fe33a75

Browse files
author
Steve Block
committed
Add WebViewClient.onProceededAfterSslError()
This is used to notify the host application that an SSL error occurred while loading a resource, but the WebView but chose to proceed anyway based on a decision retained from a previous response to onReceivedSslError(). Bug: 5403366 Change-Id: I51a25b93d7824b7eb7b6d5a961cba948e37c85db
1 parent 17f2541 commit fe33a75

File tree

3 files changed

+80
-51
lines changed

3 files changed

+80
-51
lines changed

core/java/android/webkit/BrowserFrame.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ private void loadFinished(String url, int loadType, boolean isMainFrame) {
471471

472472
/**
473473
* We have received an SSL certificate for the main top-level page.
474+
* Used by the Android HTTP stack only.
474475
*/
475476
void certificate(SslCertificate certificate) {
476477
if (mIsMainFrame) {
@@ -1178,6 +1179,7 @@ private void reportSslCertError(final int handle, final int certError, byte cert
11781179

11791180
if (SslCertLookupTable.getInstance().isAllowed(sslError)) {
11801181
nativeSslCertErrorProceed(handle);
1182+
mCallbackProxy.onProceededAfterSslError(sslError);
11811183
return;
11821184
}
11831185

@@ -1267,7 +1269,8 @@ private void didFinishLoading() {
12671269
}
12681270

12691271
/**
1270-
* Called by JNI when we load a page over SSL.
1272+
* Called by JNI when we recieve a certificate for the page's main resource.
1273+
* Used by the Chromium HTTP stack only.
12711274
*/
12721275
private void setCertificate(byte cert_der[]) {
12731276
try {

core/java/android/webkit/CallbackProxy.java

Lines changed: 62 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -77,53 +77,54 @@ class CallbackProxy extends Handler {
7777
// Used to call startActivity during url override.
7878
private final Context mContext;
7979

80-
// Message Ids
81-
private static final int PAGE_STARTED = 100;
82-
private static final int RECEIVED_ICON = 101;
83-
private static final int RECEIVED_TITLE = 102;
84-
private static final int OVERRIDE_URL = 103;
85-
private static final int AUTH_REQUEST = 104;
86-
private static final int SSL_ERROR = 105;
87-
private static final int PROGRESS = 106;
88-
private static final int UPDATE_VISITED = 107;
89-
private static final int LOAD_RESOURCE = 108;
90-
private static final int CREATE_WINDOW = 109;
91-
private static final int CLOSE_WINDOW = 110;
92-
private static final int SAVE_PASSWORD = 111;
93-
private static final int JS_ALERT = 112;
94-
private static final int JS_CONFIRM = 113;
95-
private static final int JS_PROMPT = 114;
96-
private static final int JS_UNLOAD = 115;
97-
private static final int ASYNC_KEYEVENTS = 116;
98-
private static final int DOWNLOAD_FILE = 118;
99-
private static final int REPORT_ERROR = 119;
100-
private static final int RESEND_POST_DATA = 120;
101-
private static final int PAGE_FINISHED = 121;
102-
private static final int REQUEST_FOCUS = 122;
103-
private static final int SCALE_CHANGED = 123;
104-
private static final int RECEIVED_CERTIFICATE = 124;
105-
private static final int SWITCH_OUT_HISTORY = 125;
106-
private static final int EXCEEDED_DATABASE_QUOTA = 126;
107-
private static final int REACHED_APPCACHE_MAXSIZE = 127;
108-
private static final int JS_TIMEOUT = 128;
109-
private static final int ADD_MESSAGE_TO_CONSOLE = 129;
110-
private static final int GEOLOCATION_PERMISSIONS_SHOW_PROMPT = 130;
111-
private static final int GEOLOCATION_PERMISSIONS_HIDE_PROMPT = 131;
112-
private static final int RECEIVED_TOUCH_ICON_URL = 132;
113-
private static final int GET_VISITED_HISTORY = 133;
114-
private static final int OPEN_FILE_CHOOSER = 134;
115-
private static final int ADD_HISTORY_ITEM = 135;
116-
private static final int HISTORY_INDEX_CHANGED = 136;
117-
private static final int AUTH_CREDENTIALS = 137;
118-
private static final int SET_INSTALLABLE_WEBAPP = 138;
119-
private static final int NOTIFY_SEARCHBOX_LISTENERS = 139;
120-
private static final int AUTO_LOGIN = 140;
121-
private static final int CLIENT_CERT_REQUEST = 141;
122-
private static final int SEARCHBOX_IS_SUPPORTED_CALLBACK = 142;
123-
private static final int SEARCHBOX_DISPATCH_COMPLETE_CALLBACK= 143;
80+
// Message IDs
81+
private static final int PAGE_STARTED = 100;
82+
private static final int RECEIVED_ICON = 101;
83+
private static final int RECEIVED_TITLE = 102;
84+
private static final int OVERRIDE_URL = 103;
85+
private static final int AUTH_REQUEST = 104;
86+
private static final int SSL_ERROR = 105;
87+
private static final int PROGRESS = 106;
88+
private static final int UPDATE_VISITED = 107;
89+
private static final int LOAD_RESOURCE = 108;
90+
private static final int CREATE_WINDOW = 109;
91+
private static final int CLOSE_WINDOW = 110;
92+
private static final int SAVE_PASSWORD = 111;
93+
private static final int JS_ALERT = 112;
94+
private static final int JS_CONFIRM = 113;
95+
private static final int JS_PROMPT = 114;
96+
private static final int JS_UNLOAD = 115;
97+
private static final int ASYNC_KEYEVENTS = 116;
98+
private static final int DOWNLOAD_FILE = 118;
99+
private static final int REPORT_ERROR = 119;
100+
private static final int RESEND_POST_DATA = 120;
101+
private static final int PAGE_FINISHED = 121;
102+
private static final int REQUEST_FOCUS = 122;
103+
private static final int SCALE_CHANGED = 123;
104+
private static final int RECEIVED_CERTIFICATE = 124;
105+
private static final int SWITCH_OUT_HISTORY = 125;
106+
private static final int EXCEEDED_DATABASE_QUOTA = 126;
107+
private static final int REACHED_APPCACHE_MAXSIZE = 127;
108+
private static final int JS_TIMEOUT = 128;
109+
private static final int ADD_MESSAGE_TO_CONSOLE = 129;
110+
private static final int GEOLOCATION_PERMISSIONS_SHOW_PROMPT = 130;
111+
private static final int GEOLOCATION_PERMISSIONS_HIDE_PROMPT = 131;
112+
private static final int RECEIVED_TOUCH_ICON_URL = 132;
113+
private static final int GET_VISITED_HISTORY = 133;
114+
private static final int OPEN_FILE_CHOOSER = 134;
115+
private static final int ADD_HISTORY_ITEM = 135;
116+
private static final int HISTORY_INDEX_CHANGED = 136;
117+
private static final int AUTH_CREDENTIALS = 137;
118+
private static final int SET_INSTALLABLE_WEBAPP = 138;
119+
private static final int NOTIFY_SEARCHBOX_LISTENERS = 139;
120+
private static final int AUTO_LOGIN = 140;
121+
private static final int CLIENT_CERT_REQUEST = 141;
122+
private static final int SEARCHBOX_IS_SUPPORTED_CALLBACK = 142;
123+
private static final int SEARCHBOX_DISPATCH_COMPLETE_CALLBACK = 143;
124+
private static final int PROCEEDED_AFTER_SSL_ERROR = 144;
124125

125126
// Message triggered by the client to resume execution
126-
private static final int NOTIFY = 200;
127+
private static final int NOTIFY = 200;
127128

128129
// Result transportation object for returning results across thread
129130
// boundaries.
@@ -349,6 +350,13 @@ public void handleMessage(Message msg) {
349350
}
350351
break;
351352

353+
case PROCEEDED_AFTER_SSL_ERROR:
354+
if (mWebViewClient != null) {
355+
mWebViewClient.onProceededAfterSslError(mWebView,
356+
(SslError) msg.obj);
357+
}
358+
break;
359+
352360
case CLIENT_CERT_REQUEST:
353361
if (mWebViewClient != null) {
354362
HashMap<String, Object> map =
@@ -1024,6 +1032,15 @@ public void onReceivedSslError(SslErrorHandler handler, SslError error) {
10241032
sendMessage(msg);
10251033
}
10261034

1035+
public void onProceededAfterSslError(SslError error) {
1036+
if (mWebViewClient == null) {
1037+
return;
1038+
}
1039+
Message msg = obtainMessage(PROCEEDED_AFTER_SSL_ERROR);
1040+
msg.obj = error;
1041+
sendMessage(msg);
1042+
}
1043+
10271044
public void onReceivedClientCertRequest(ClientCertRequestHandler handler, String host_and_port) {
10281045
// Do an unsynchronized quick check to avoid posting if no callback has
10291046
// been set.

core/java/android/webkit/WebViewClient.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ public void doUpdateVisitedHistory(WebView view, String url,
186186
}
187187

188188
/**
189-
* Notify the host application to handle a SSL certificate error request
190-
* (display the error to the user and ask whether to proceed or not). The
191-
* host application has to call either handler.cancel() or handler.proceed()
192-
* as the connection is suspended and waiting for the response. The default
193-
* behavior is to cancel the load.
189+
* Notify the host application that an SSL error occurred while loading a
190+
* resource. The host application must call either handler.cancel() or
191+
* handler.proceed(). Note that the decision may be retained for use in
192+
* response to future SSL errors. The default behavior is to cancel the
193+
* load.
194194
*
195195
* @param view The WebView that is initiating the callback.
196196
* @param handler An SslErrorHandler object that will handle the user's
@@ -202,6 +202,15 @@ public void onReceivedSslError(WebView view, SslErrorHandler handler,
202202
handler.cancel();
203203
}
204204

205+
/**
206+
* Notify the host application that an SSL error occurred while loading a
207+
* resource, but the WebView but chose to proceed anyway based on a
208+
* decision retained from a previous response to onReceivedSslError().
209+
* @hide
210+
*/
211+
public void onProceededAfterSslError(WebView view, SslError error) {
212+
}
213+
205214
/**
206215
* Notify the host application to handle a SSL client certificate
207216
* request (display the request to the user and ask whether to

0 commit comments

Comments
 (0)