Merge "Use a static variable and methods for the current WebView."
This commit is contained in:
committed by
Android (Google) Code Review
commit
243efd2c57
@@ -21,6 +21,7 @@ import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -46,7 +47,8 @@ final class JWebCoreJavaBridge extends Handler {
|
||||
|
||||
// keep track of the main WebView attached to the current window so that we
|
||||
// can get the proper Context.
|
||||
private WebView mCurrentMainWebView;
|
||||
private static WeakReference<WebView> sCurrentMainWebView =
|
||||
new WeakReference<WebView>(null);
|
||||
|
||||
/* package */
|
||||
static final int REFRESH_PLUGINS = 100;
|
||||
@@ -67,20 +69,20 @@ final class JWebCoreJavaBridge extends Handler {
|
||||
nativeFinalize();
|
||||
}
|
||||
|
||||
synchronized void setActiveWebView(WebView webview) {
|
||||
if (mCurrentMainWebView != null) {
|
||||
static synchronized void setActiveWebView(WebView webview) {
|
||||
if (sCurrentMainWebView.get() != null) {
|
||||
// it is possible if there is a sub-WebView. Do nothing.
|
||||
return;
|
||||
}
|
||||
mCurrentMainWebView = webview;
|
||||
sCurrentMainWebView = new WeakReference<WebView>(webview);
|
||||
}
|
||||
|
||||
synchronized void removeActiveWebView(WebView webview) {
|
||||
if (mCurrentMainWebView != webview) {
|
||||
static synchronized void removeActiveWebView(WebView webview) {
|
||||
if (sCurrentMainWebView.get() != webview) {
|
||||
// it is possible if there is a sub-WebView. Do nothing.
|
||||
return;
|
||||
}
|
||||
mCurrentMainWebView = null;
|
||||
sCurrentMainWebView.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -261,11 +263,12 @@ final class JWebCoreJavaBridge extends Handler {
|
||||
|
||||
synchronized private String getSignedPublicKey(int index, String challenge,
|
||||
String url) {
|
||||
if (mCurrentMainWebView != null) {
|
||||
WebView current = sCurrentMainWebView.get();
|
||||
if (current != null) {
|
||||
// generateKeyPair expects organizations which we don't have. Ignore
|
||||
// url.
|
||||
return CertTool.getSignedPublicKey(
|
||||
mCurrentMainWebView.getContext(), index, challenge);
|
||||
current.getContext(), index, challenge);
|
||||
} else {
|
||||
Log.e(LOGTAG, "There is no active WebView for getSignedPublicKey");
|
||||
return "";
|
||||
|
||||
@@ -4257,9 +4257,9 @@ public class WebView extends AbsoluteLayout
|
||||
public void onWindowFocusChanged(boolean hasWindowFocus) {
|
||||
setActive(hasWindowFocus);
|
||||
if (hasWindowFocus) {
|
||||
BrowserFrame.sJavaBridge.setActiveWebView(this);
|
||||
JWebCoreJavaBridge.setActiveWebView(this);
|
||||
} else {
|
||||
BrowserFrame.sJavaBridge.removeActiveWebView(this);
|
||||
JWebCoreJavaBridge.removeActiveWebView(this);
|
||||
}
|
||||
super.onWindowFocusChanged(hasWindowFocus);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user