Merge change 23804 into eclair

* changes:
  Fix appcache layout test that was timing out due to race condition in WebView::addJavascriptInterface.
This commit is contained in:
Android (Google) Code Review
2009-09-04 03:27:47 -07:00
4 changed files with 49 additions and 10 deletions

View File

@@ -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);
}
/**

View File

@@ -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);

View File

@@ -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