Skip to content

Commit 200ff0a

Browse files
author
Steve Block
committed
Remove superfluous synchronized modifier on SslCertLookupTable.getInstance()
Also fixes style in SslCertLookupTable and WebViewcore.reportSslCertError(). Bug: 5287216 Change-Id: I1cd975b1c8cecf1ca1dad0643be8ab62f7a950bc
1 parent cbb62bb commit 200ff0a

2 files changed

Lines changed: 26 additions & 31 deletions

File tree

core/java/android/webkit/BrowserFrame.java

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,51 +1159,49 @@ public boolean suppressDialog() {
11591159
}
11601160

11611161
/**
1162-
* Called by JNI when the native HTTPS stack gets an invalid cert chain.
1162+
* Called by JNI when the Chromium HTTP stack gets an invalid certificate chain.
11631163
*
11641164
* We delegate the request to CallbackProxy, and route its response to
11651165
* {@link #nativeSslCertErrorProceed(int)} or
11661166
* {@link #nativeSslCertErrorCancel(int, int)}.
11671167
*/
1168-
private void reportSslCertError(
1169-
final int handle, final int cert_error, byte cert_der[], String url) {
1170-
final SslError ssl_error;
1168+
private void reportSslCertError(final int handle, final int certError, byte certDER[],
1169+
String url) {
1170+
final SslError sslError;
11711171
try {
1172-
X509Certificate cert = new X509CertImpl(cert_der);
1172+
X509Certificate cert = new X509CertImpl(certDER);
11731173
SslCertificate sslCert = new SslCertificate(cert);
11741174
if (JniUtil.useChromiumHttpStack()) {
1175-
ssl_error = SslError.SslErrorFromChromiumErrorCode(cert_error, sslCert,
1175+
sslError = SslError.SslErrorFromChromiumErrorCode(certError, sslCert,
11761176
new URL(url).getHost());
11771177
} else {
1178-
ssl_error = new SslError(cert_error, cert, url);
1178+
sslError = new SslError(certError, cert, url);
11791179
}
11801180
} catch (IOException e) {
11811181
// Can't get the certificate, not much to do.
11821182
Log.e(LOGTAG, "Can't get the certificate from WebKit, canceling");
1183-
nativeSslCertErrorCancel(handle, cert_error);
1183+
nativeSslCertErrorCancel(handle, certError);
11841184
return;
11851185
}
11861186

1187-
SslErrorHandler handler = new SslErrorHandler() {
1187+
if (SslCertLookupTable.getInstance().isAllowed(sslError)) {
1188+
nativeSslCertErrorProceed(handle);
1189+
return;
1190+
}
11881191

1192+
SslErrorHandler handler = new SslErrorHandler() {
11891193
@Override
11901194
public void proceed() {
1191-
SslCertLookupTable.getInstance().Allow(ssl_error);
1195+
SslCertLookupTable.getInstance().setIsAllowed(sslError, true);
11921196
nativeSslCertErrorProceed(handle);
11931197
}
1194-
11951198
@Override
11961199
public void cancel() {
1197-
SslCertLookupTable.getInstance().Deny(ssl_error);
1198-
nativeSslCertErrorCancel(handle, cert_error);
1200+
SslCertLookupTable.getInstance().setIsAllowed(sslError, false);
1201+
nativeSslCertErrorCancel(handle, certError);
11991202
}
12001203
};
1201-
1202-
if (SslCertLookupTable.getInstance().IsAllowed(ssl_error)) {
1203-
nativeSslCertErrorProceed(handle);
1204-
} else {
1205-
mCallbackProxy.onReceivedSslError(handler, ssl_error);
1206-
}
1204+
mCallbackProxy.onReceivedSslError(handler, sslError);
12071205
}
12081206

12091207
/**
@@ -1416,7 +1414,7 @@ public void stopLoading() {
14161414
private native void nativeAuthenticationCancel(int handle);
14171415

14181416
private native void nativeSslCertErrorProceed(int handle);
1419-
private native void nativeSslCertErrorCancel(int handle, int cert_error);
1417+
private native void nativeSslCertErrorCancel(int handle, int certError);
14201418

14211419
native void nativeSslClientCert(int handle,
14221420
byte[] pkcs8EncodedPrivateKey,

core/java/android/webkit/SslCertLookupTable.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
import android.net.http.SslError;
2121

2222
/**
23-
* A simple class to store the wrong certificates that user is aware but
24-
* chose to proceed.
23+
* Stores the user's decision of whether to allow or deny an invalid certificate.
24+
*
25+
* This class is not threadsafe. It is used only on the WebCore thread.
2526
*/
2627
final class SslCertLookupTable {
2728
private static SslCertLookupTable sTable;
2829
private final Bundle table;
2930

30-
public static synchronized SslCertLookupTable getInstance() {
31+
public static SslCertLookupTable getInstance() {
3132
if (sTable == null) {
3233
sTable = new SslCertLookupTable();
3334
}
@@ -38,15 +39,11 @@ private SslCertLookupTable() {
3839
table = new Bundle();
3940
}
4041

41-
public void Allow(SslError ssl_error) {
42-
table.putBoolean(ssl_error.toString(), true);
43-
}
44-
45-
public void Deny(SslError ssl_error) {
46-
table.putBoolean(ssl_error.toString(), false);
42+
public void setIsAllowed(SslError sslError, boolean allow) {
43+
table.putBoolean(sslError.toString(), allow);
4744
}
4845

49-
public boolean IsAllowed(SslError ssl_error) {
50-
return table.getBoolean(ssl_error.toString());
46+
public boolean isAllowed(SslError sslError) {
47+
return table.getBoolean(sslError.toString());
5148
}
5249
}

0 commit comments

Comments
 (0)