summaryrefslogtreecommitdiffstats
path: root/core/java/android
diff options
context:
space:
mode:
authorAndrei Popescu <andreip@google.com>2009-09-03 13:56:07 +0100
committerAndrei Popescu <andreip@google.com>2009-09-03 22:31:55 +0100
commit4950b2b6951bbdc2b0023130bfbaca2a4044044f (patch)
tree5c90e85eab5236bf702a60307e9261f10365833e /core/java/android
parente131b7466c8b817896a618efe4b34eed5d3e51f9 (diff)
downloadframeworks_base-4950b2b6951bbdc2b0023130bfbaca2a4044044f.zip
frameworks_base-4950b2b6951bbdc2b0023130bfbaca2a4044044f.tar.gz
frameworks_base-4950b2b6951bbdc2b0023130bfbaca2a4044044f.tar.bz2
Fix appcache layout test that was timing out due to race condition in WebView::addJavascriptInterface.
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/webkit/BrowserFrame.java8
-rw-r--r--core/java/android/webkit/WebView.java20
-rw-r--r--core/java/android/webkit/WebViewCore.java12
3 files changed, 34 insertions, 6 deletions
diff --git a/core/java/android/webkit/BrowserFrame.java b/core/java/android/webkit/BrowserFrame.java
index 599c6b0..e96ba11 100644
--- a/core/java/android/webkit/BrowserFrame.java
+++ b/core/java/android/webkit/BrowserFrame.java
@@ -31,6 +31,7 @@ import junit.framework.Assert;
import java.net.URLEncoder;
import java.util.HashMap;
+import java.util.Map;
import java.util.Iterator;
class BrowserFrame extends Handler {
@@ -59,7 +60,7 @@ class BrowserFrame extends Handler {
private boolean mIsMainFrame;
// Attached Javascript interfaces
- private HashMap mJSInterfaceMap;
+ private Map<String, Object> mJSInterfaceMap;
// message ids
// a message posted when a frame loading is completed
@@ -98,7 +99,7 @@ class BrowserFrame extends Handler {
* XXX: Called by WebCore thread.
*/
public BrowserFrame(Context context, WebViewCore w, CallbackProxy proxy,
- WebSettings settings) {
+ WebSettings settings, Map<String, Object> javascriptInterfaces) {
// Create a global JWebCoreJavaBridge to handle timers and
// cookies in the WebCore thread.
if (sJavaBridge == null) {
@@ -112,6 +113,7 @@ class BrowserFrame extends Handler {
// create PluginManager with current Context
PluginManager.getInstance(context);
}
+ mJSInterfaceMap = javascriptInterfaces;
mSettings = settings;
mContext = context;
@@ -453,6 +455,8 @@ class BrowserFrame extends Handler {
mJSInterfaceMap.remove(interfaceName);
}
mJSInterfaceMap.put(interfaceName, obj);
+ nativeAddJavascriptInterface(0, mJSInterfaceMap.get(interfaceName),
+ interfaceName);
}
/**
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 611681f..cbf9fd5 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -81,6 +81,7 @@ import java.io.IOException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
/**
* <p>A View that displays web pages. This class is the basis upon which you
@@ -721,11 +722,28 @@ public class WebView extends AbsoluteLayout
* @param defStyle The default style resource ID.
*/
public WebView(Context context, AttributeSet attrs, int defStyle) {
+ this(context, attrs, defStyle, null);
+ }
+
+ /**
+ * Construct a new WebView with layout parameters, a default style and a set
+ * of custom Javscript interfaces to be added to the WebView at initialization
+ * time. This guraratees that these interfaces will be available when the JS
+ * context is initialized.
+ * @param context A Context object used to access application assets.
+ * @param attrs An AttributeSet passed to our parent.
+ * @param defStyle The default style resource ID.
+ * @param javascriptInterfaces is a Map of intareface names, as keys, and
+ * object implementing those interfaces, as values.
+ * @hide pending API council approval.
+ */
+ protected WebView(Context context, AttributeSet attrs, int defStyle,
+ Map<String, Object> javascriptInterfaces) {
super(context, attrs, defStyle);
init();
mCallbackProxy = new CallbackProxy(context, this);
- mWebViewCore = new WebViewCore(context, this, mCallbackProxy);
+ mWebViewCore = new WebViewCore(context, this, mCallbackProxy, javascriptInterfaces);
mDatabase = WebViewDatabase.getInstance(context);
mScroller = new Scroller(context);
diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java
index 081250b..2ff2824 100644
--- a/core/java/android/webkit/WebViewCore.java
+++ b/core/java/android/webkit/WebViewCore.java
@@ -36,6 +36,8 @@ import android.view.SurfaceHolder;
import android.view.SurfaceView;
import java.util.ArrayList;
+import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import junit.framework.Assert;
@@ -67,7 +69,8 @@ final class WebViewCore {
private int mNativeClass;
// The BrowserFrame is an interface to the native Frame component.
private BrowserFrame mBrowserFrame;
-
+ // Custom JS interfaces to add during the initialization.
+ private Map<String, Object> mJavascriptInterfaces;
/*
* range is from 200 to 10,000. 0 is a special value means device-width. -1
* means undefined.
@@ -113,10 +116,12 @@ final class WebViewCore {
// debugging other classes that require operation within the WebCore thread.
/* package */ static final String THREAD_NAME = "WebViewCoreThread";
- public WebViewCore(Context context, WebView w, CallbackProxy proxy) {
+ public WebViewCore(Context context, WebView w, CallbackProxy proxy,
+ Map<String, Object> javascriptInterfaces) {
// No need to assign this in the WebCore thread.
mCallbackProxy = proxy;
mWebView = w;
+ mJavascriptInterfaces = javascriptInterfaces;
// This context object is used to initialize the WebViewCore during
// subwindow creation.
mContext = context;
@@ -164,7 +169,8 @@ final class WebViewCore {
* in turn creates a C level FrameView and attaches it to the frame.
*/
mBrowserFrame = new BrowserFrame(mContext, this, mCallbackProxy,
- mSettings);
+ mSettings, mJavascriptInterfaces);
+ mJavascriptInterfaces = null;
// Sync the native settings and also create the WebCore thread handler.
mSettings.syncSettingsAndCreateHandler(mBrowserFrame);
// Create the handler and transfer messages for the IconDatabase