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:
@@ -31,6 +31,7 @@ import junit.framework.Assert;
|
|||||||
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
class BrowserFrame extends Handler {
|
class BrowserFrame extends Handler {
|
||||||
@@ -59,7 +60,7 @@ class BrowserFrame extends Handler {
|
|||||||
private boolean mIsMainFrame;
|
private boolean mIsMainFrame;
|
||||||
|
|
||||||
// Attached Javascript interfaces
|
// Attached Javascript interfaces
|
||||||
private HashMap mJSInterfaceMap;
|
private Map<String, Object> mJSInterfaceMap;
|
||||||
|
|
||||||
// message ids
|
// message ids
|
||||||
// a message posted when a frame loading is completed
|
// a message posted when a frame loading is completed
|
||||||
@@ -98,7 +99,7 @@ class BrowserFrame extends Handler {
|
|||||||
* XXX: Called by WebCore thread.
|
* XXX: Called by WebCore thread.
|
||||||
*/
|
*/
|
||||||
public BrowserFrame(Context context, WebViewCore w, CallbackProxy proxy,
|
public BrowserFrame(Context context, WebViewCore w, CallbackProxy proxy,
|
||||||
WebSettings settings) {
|
WebSettings settings, Map<String, Object> javascriptInterfaces) {
|
||||||
// Create a global JWebCoreJavaBridge to handle timers and
|
// Create a global JWebCoreJavaBridge to handle timers and
|
||||||
// cookies in the WebCore thread.
|
// cookies in the WebCore thread.
|
||||||
if (sJavaBridge == null) {
|
if (sJavaBridge == null) {
|
||||||
@@ -112,6 +113,7 @@ class BrowserFrame extends Handler {
|
|||||||
// create PluginManager with current Context
|
// create PluginManager with current Context
|
||||||
PluginManager.getInstance(context);
|
PluginManager.getInstance(context);
|
||||||
}
|
}
|
||||||
|
mJSInterfaceMap = javascriptInterfaces;
|
||||||
|
|
||||||
mSettings = settings;
|
mSettings = settings;
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@@ -453,6 +455,8 @@ class BrowserFrame extends Handler {
|
|||||||
mJSInterfaceMap.remove(interfaceName);
|
mJSInterfaceMap.remove(interfaceName);
|
||||||
}
|
}
|
||||||
mJSInterfaceMap.put(interfaceName, obj);
|
mJSInterfaceMap.put(interfaceName, obj);
|
||||||
|
nativeAddJavascriptInterface(0, mJSInterfaceMap.get(interfaceName),
|
||||||
|
interfaceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ import java.io.IOException;
|
|||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>A View that displays web pages. This class is the basis upon which you
|
* <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.
|
* @param defStyle The default style resource ID.
|
||||||
*/
|
*/
|
||||||
public WebView(Context context, AttributeSet attrs, int defStyle) {
|
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);
|
super(context, attrs, defStyle);
|
||||||
init();
|
init();
|
||||||
|
|
||||||
mCallbackProxy = new CallbackProxy(context, this);
|
mCallbackProxy = new CallbackProxy(context, this);
|
||||||
mWebViewCore = new WebViewCore(context, this, mCallbackProxy);
|
mWebViewCore = new WebViewCore(context, this, mCallbackProxy, javascriptInterfaces);
|
||||||
mDatabase = WebViewDatabase.getInstance(context);
|
mDatabase = WebViewDatabase.getInstance(context);
|
||||||
mScroller = new Scroller(context);
|
mScroller = new Scroller(context);
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ import android.view.SurfaceHolder;
|
|||||||
import android.view.SurfaceView;
|
import android.view.SurfaceView;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
@@ -67,7 +69,8 @@ final class WebViewCore {
|
|||||||
private int mNativeClass;
|
private int mNativeClass;
|
||||||
// The BrowserFrame is an interface to the native Frame component.
|
// The BrowserFrame is an interface to the native Frame component.
|
||||||
private BrowserFrame mBrowserFrame;
|
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
|
* range is from 200 to 10,000. 0 is a special value means device-width. -1
|
||||||
* means undefined.
|
* means undefined.
|
||||||
@@ -113,10 +116,12 @@ final class WebViewCore {
|
|||||||
// debugging other classes that require operation within the WebCore thread.
|
// debugging other classes that require operation within the WebCore thread.
|
||||||
/* package */ static final String THREAD_NAME = "WebViewCoreThread";
|
/* 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.
|
// No need to assign this in the WebCore thread.
|
||||||
mCallbackProxy = proxy;
|
mCallbackProxy = proxy;
|
||||||
mWebView = w;
|
mWebView = w;
|
||||||
|
mJavascriptInterfaces = javascriptInterfaces;
|
||||||
// This context object is used to initialize the WebViewCore during
|
// This context object is used to initialize the WebViewCore during
|
||||||
// subwindow creation.
|
// subwindow creation.
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@@ -164,7 +169,8 @@ final class WebViewCore {
|
|||||||
* in turn creates a C level FrameView and attaches it to the frame.
|
* in turn creates a C level FrameView and attaches it to the frame.
|
||||||
*/
|
*/
|
||||||
mBrowserFrame = new BrowserFrame(mContext, this, mCallbackProxy,
|
mBrowserFrame = new BrowserFrame(mContext, this, mCallbackProxy,
|
||||||
mSettings);
|
mSettings, mJavascriptInterfaces);
|
||||||
|
mJavascriptInterfaces = null;
|
||||||
// Sync the native settings and also create the WebCore thread handler.
|
// Sync the native settings and also create the WebCore thread handler.
|
||||||
mSettings.syncSettingsAndCreateHandler(mBrowserFrame);
|
mSettings.syncSettingsAndCreateHandler(mBrowserFrame);
|
||||||
// Create the handler and transfer messages for the IconDatabase
|
// Create the handler and transfer messages for the IconDatabase
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package com.android.dumprendertree;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.DialogInterface.OnClickListener;
|
import android.content.DialogInterface.OnClickListener;
|
||||||
@@ -47,6 +48,8 @@ import java.io.FileReader;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
public class TestShellActivity extends Activity implements LayoutTestController {
|
public class TestShellActivity extends Activity implements LayoutTestController {
|
||||||
@@ -107,6 +110,8 @@ public class TestShellActivity extends Activity implements LayoutTestController
|
|||||||
mEventSender = new WebViewEventSender(mWebView);
|
mEventSender = new WebViewEventSender(mWebView);
|
||||||
mCallbackProxy = new CallbackProxy(mEventSender, this);
|
mCallbackProxy = new CallbackProxy(mEventSender, this);
|
||||||
|
|
||||||
|
mWebView.addJavascriptInterface(mCallbackProxy, "layoutTestController");
|
||||||
|
mWebView.addJavascriptInterface(mCallbackProxy, "eventSender");
|
||||||
setupWebViewForLayoutTests(mWebView, mCallbackProxy);
|
setupWebViewForLayoutTests(mWebView, mCallbackProxy);
|
||||||
|
|
||||||
contentView.addView(mWebView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, 0.0f));
|
contentView.addView(mWebView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, 0.0f));
|
||||||
@@ -620,7 +625,10 @@ public class TestShellActivity extends Activity implements LayoutTestController
|
|||||||
// allow it's content to execute and be recorded by the test
|
// allow it's content to execute and be recorded by the test
|
||||||
// runner.
|
// runner.
|
||||||
|
|
||||||
WebView newWindowView = new WebView(TestShellActivity.this);
|
HashMap<String, Object> jsIfaces = new HashMap<String, Object>();
|
||||||
|
jsIfaces.put("layoutTestController", mCallbackProxy);
|
||||||
|
jsIfaces.put("eventSender", mCallbackProxy);
|
||||||
|
WebView newWindowView = new NewWindowWebView(TestShellActivity.this, jsIfaces);
|
||||||
setupWebViewForLayoutTests(newWindowView, mCallbackProxy);
|
setupWebViewForLayoutTests(newWindowView, mCallbackProxy);
|
||||||
WebView.WebViewTransport transport =
|
WebView.WebViewTransport transport =
|
||||||
(WebView.WebViewTransport) resultMsg.obj;
|
(WebView.WebViewTransport) resultMsg.obj;
|
||||||
@@ -630,6 +638,12 @@ public class TestShellActivity extends Activity implements LayoutTestController
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static class NewWindowWebView extends WebView {
|
||||||
|
public NewWindowWebView(Context context, Map<String, Object> jsIfaces) {
|
||||||
|
super(context, null, 0, jsIfaces);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void resetTestStatus() {
|
private void resetTestStatus() {
|
||||||
mWaitUntilDone = false;
|
mWaitUntilDone = false;
|
||||||
mDumpDataType = mDefaultDumpDataType;
|
mDumpDataType = mDefaultDumpDataType;
|
||||||
@@ -659,9 +673,6 @@ public class TestShellActivity extends Activity implements LayoutTestController
|
|||||||
settings.setDomStorageEnabled(true);
|
settings.setDomStorageEnabled(true);
|
||||||
settings.setWorkersEnabled(false);
|
settings.setWorkersEnabled(false);
|
||||||
|
|
||||||
webview.addJavascriptInterface(callbackProxy, "layoutTestController");
|
|
||||||
webview.addJavascriptInterface(callbackProxy, "eventSender");
|
|
||||||
|
|
||||||
webview.setWebChromeClient(mChromeClient);
|
webview.setWebChromeClient(mChromeClient);
|
||||||
webview.setWebViewClient(mViewClient);
|
webview.setWebViewClient(mViewClient);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user