Skip to content

Commit 4198627

Browse files
Steve BlockAndroid (Google) Code Review
authored andcommitted
Merge changes I447cd196,I0c6cdae4
* changes: SSL-related cleanup in BrowserFrame and SslCertLookupTable Clean up SslErrorHandlerImpl
2 parents 7897fdd + bf52c0e commit 4198627

File tree

3 files changed

+40
-41
lines changed

3 files changed

+40
-41
lines changed

core/java/android/webkit/BrowserFrame.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,6 @@ 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-
*
475-
* !!!Called from the network thread!!!
476474
*/
477475
void certificate(SslCertificate certificate) {
478476
if (mIsMainFrame) {
@@ -1186,12 +1184,11 @@ private void reportSslCertError(final int handle, final int certError, byte cert
11861184
SslErrorHandler handler = new SslErrorHandler() {
11871185
@Override
11881186
public void proceed() {
1189-
SslCertLookupTable.getInstance().setIsAllowed(sslError, true);
1187+
SslCertLookupTable.getInstance().setIsAllowed(sslError);
11901188
nativeSslCertErrorProceed(handle);
11911189
}
11921190
@Override
11931191
public void cancel() {
1194-
SslCertLookupTable.getInstance().setIsAllowed(sslError, false);
11951192
nativeSslCertErrorCancel(handle, certError);
11961193
}
11971194
};

core/java/android/webkit/SslCertLookupTable.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
/**
2626
* Stores the user's decision of whether to allow or deny an invalid certificate.
2727
*
28-
* This class is not threadsafe. It is used only on the WebCore thread.
28+
* This class is not threadsafe. It is used only on the WebCore thread. Also, it
29+
* is used only by the Chromium HTTP stack.
2930
*/
3031
final class SslCertLookupTable {
3132
private static SslCertLookupTable sTable;
@@ -42,11 +43,11 @@ private SslCertLookupTable() {
4243
table = new Bundle();
4344
}
4445

45-
public void setIsAllowed(SslError sslError, boolean allow) {
46+
public void setIsAllowed(SslError sslError) {
4647
// TODO: We should key on just the host. See http://b/5409251.
4748
String errorString = sslErrorToString(sslError);
4849
if (errorString != null) {
49-
table.putBoolean(errorString, allow);
50+
table.putBoolean(errorString, true);
5051
}
5152
}
5253

core/java/android/webkit/SslErrorHandlerImpl.java

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package android.webkit;
1818

19-
import junit.framework.Assert;
20-
2119
import android.net.http.SslError;
2220
import android.os.Bundle;
2321
import android.os.Handler;
@@ -54,7 +52,7 @@ class SslErrorHandlerImpl extends SslErrorHandler {
5452
private final SslErrorHandler mOriginHandler;
5553
private final LoadListener mLoadListener;
5654

57-
// Message id for handling the response
55+
// Message id for handling the response from the client.
5856
private static final int HANDLE_RESPONSE = 100;
5957

6058
@Override
@@ -130,7 +128,9 @@ private SslErrorHandlerImpl(SslErrorHandler origin, LoadListener listener) {
130128
}
131129

132130
/**
133-
* Handles SSL error(s) on the way up to the user.
131+
* Handles requests from the network stack about whether to proceed with a
132+
* load given an SSL error(s). We may ask the client what to do, or use a
133+
* cached response.
134134
*/
135135
/* package */ synchronized void handleSslErrorRequest(LoadListener loader) {
136136
if (DebugFlags.SSL_ERROR_HANDLER) {
@@ -147,30 +147,33 @@ private SslErrorHandlerImpl(SslErrorHandler origin, LoadListener listener) {
147147
}
148148

149149
/**
150-
* Check the preference table for a ssl error that has already been shown
151-
* to the user.
150+
* Check the preference table to see if we already have a 'proceed' decision
151+
* from the client for this host and for an error of equal or greater
152+
* severity than the supplied error. If so, instruct the loader to proceed
153+
* and return true. Otherwise return false.
152154
*/
153155
/* package */ synchronized boolean checkSslPrefTable(LoadListener loader,
154156
SslError error) {
155157
final String host = loader.host();
156158
final int primary = error.getPrimaryError();
157159

158160
if (DebugFlags.SSL_ERROR_HANDLER) {
159-
Assert.assertTrue(host != null && primary != 0);
161+
assert host != null;
162+
assert primary != 0;
160163
}
161164

162-
if (mSslPrefTable.containsKey(host)) {
163-
if (primary <= mSslPrefTable.getInt(host)) {
164-
handleSslErrorResponse(loader, error, true);
165-
return true;
165+
if (mSslPrefTable.containsKey(host) && primary <= mSslPrefTable.getInt(host)) {
166+
if (!loader.cancelled()) {
167+
loader.handleSslErrorResponse(true);
166168
}
169+
return true;
167170
}
168171
return false;
169172
}
170173

171174
/**
172175
* Processes queued SSL-error confirmation requests in
173-
* a tight loop while there is no need to ask the user.
176+
* a tight loop while there is no need to ask the client.
174177
*/
175178
/* package */void fastProcessQueuedSslErrors() {
176179
while (processNextLoader());
@@ -195,19 +198,18 @@ private synchronized boolean processNextLoader() {
195198
SslError error = loader.sslError();
196199

197200
if (DebugFlags.SSL_ERROR_HANDLER) {
198-
Assert.assertNotNull(error);
201+
assert error != null;
199202
}
200203

201-
// checkSslPrefTable will handle the ssl error response if the
202-
// answer is available. It does not remove the loader from the
203-
// queue.
204+
// checkSslPrefTable() will instruct the loader to proceed if we
205+
// have a cached 'proceed' decision. It does not remove the loader
206+
// from the queue.
204207
if (checkSslPrefTable(loader, error)) {
205208
mLoaderQueue.remove(loader);
206209
return true;
207210
}
208211

209-
// if we do not have information on record, ask
210-
// the user (display a dialog)
212+
// If we can not proceed based on a cached decision, ask the client.
211213
CallbackProxy proxy = loader.getFrame().getCallbackProxy();
212214
proxy.onReceivedSslError(new SslErrorHandlerImpl(this, loader), error);
213215
}
@@ -217,32 +219,31 @@ private synchronized boolean processNextLoader() {
217219
}
218220

219221
/**
220-
* Proceed with the SSL certificate.
222+
* Proceed with this load.
221223
*/
222224
public void proceed() {
223-
mOriginHandler.sendMessage(
224-
mOriginHandler.obtainMessage(
225-
HANDLE_RESPONSE, 1, 0, mLoadListener));
225+
mOriginHandler.sendMessage(mOriginHandler.obtainMessage(
226+
HANDLE_RESPONSE, 1, 0, mLoadListener));
226227
}
227228

228229
/**
229-
* Cancel this request and all pending requests for the WebView that had
230-
* the error.
230+
* Cancel this load and all pending loads for the WebView that had the
231+
* error.
231232
*/
232233
public void cancel() {
233-
mOriginHandler.sendMessage(
234-
mOriginHandler.obtainMessage(
235-
HANDLE_RESPONSE, 0, 0, mLoadListener));
234+
mOriginHandler.sendMessage(mOriginHandler.obtainMessage(
235+
HANDLE_RESPONSE, 0, 0, mLoadListener));
236236
}
237237

238238
/**
239-
* Handles SSL error(s) on the way down from the user.
239+
* Handles the response from the client about whether to proceed with this
240+
* load. We save the response to be re-used in the future.
240241
*/
241242
/* package */ synchronized void handleSslErrorResponse(LoadListener loader,
242243
SslError error, boolean proceed) {
243244
if (DebugFlags.SSL_ERROR_HANDLER) {
244-
Assert.assertNotNull(loader);
245-
Assert.assertNotNull(error);
245+
assert loader != null;
246+
assert error != null;
246247
}
247248

248249
if (DebugFlags.SSL_ERROR_HANDLER) {
@@ -253,16 +254,16 @@ public void cancel() {
253254

254255
if (!loader.cancelled()) {
255256
if (proceed) {
256-
// update the user's SSL error preference table
257+
// Update the SSL error preference table
257258
int primary = error.getPrimaryError();
258259
String host = loader.host();
259260

260261
if (DebugFlags.SSL_ERROR_HANDLER) {
261-
Assert.assertTrue(host != null && primary != 0);
262+
assert host != null;
263+
assert primary != 0;
262264
}
263265
boolean hasKey = mSslPrefTable.containsKey(host);
264-
if (!hasKey ||
265-
primary > mSslPrefTable.getInt(host)) {
266+
if (!hasKey || primary > mSslPrefTable.getInt(host)) {
266267
mSslPrefTable.putInt(host, primary);
267268
}
268269
}

0 commit comments

Comments
 (0)