Add WebView.removeJavascriptInterface()

Bug: 3234178
Change-Id: I7136f8d76b20f90a7e9e1c55b6755ffe6c35b77b
This commit is contained in:
Steve Block
2010-12-07 18:18:26 +00:00
parent 9aa6ea8386
commit 689a342b0f
4 changed files with 42 additions and 2 deletions

View File

@@ -599,13 +599,20 @@ class BrowserFrame extends Handler {
public void addJavascriptInterface(Object obj, String interfaceName) {
assert obj != null;
removeJavascriptInterface(interfaceName);
if (mJSInterfaceMap == null) {
mJSInterfaceMap = new HashMap<String, Object>();
}
mJSInterfaceMap.put(interfaceName, obj);
}
public void removeJavascriptInterface(String interfaceName) {
if (mJSInterfaceMap == null) {
return;
}
if (mJSInterfaceMap.containsKey(interfaceName)) {
mJSInterfaceMap.remove(interfaceName);
}
mJSInterfaceMap.put(interfaceName, obj);
}
/**

View File

@@ -3523,7 +3523,8 @@ public class WebView extends AbsoluteLayout
* </ul></p>
* @param obj The class instance to bind to Javascript, null instances are
* ignored.
* @param interfaceName The name to used to expose the class in JavaScript.
* @param interfaceName The name to used to expose the instance in
* JavaScript.
*/
public void addJavascriptInterface(Object obj, String interfaceName) {
if (obj == null) {
@@ -3535,6 +3536,16 @@ public class WebView extends AbsoluteLayout
mWebViewCore.sendMessage(EventHub.ADD_JS_INTERFACE, arg);
}
/**
* Removes a previously added JavaScript interface with the given name.
* @param interfaceName The name of the interface to remove.
*/
public void removeJavascriptInterface(String interfaceName) {
WebViewCore.JSInterfaceData arg = new WebViewCore.JSInterfaceData();
arg.mInterfaceName = interfaceName;
mWebViewCore.sendMessage(EventHub.REMOVE_JS_INTERFACE, arg);
}
/**
* Return the WebSettings object used to control the settings for this
* WebView.

View File

@@ -852,6 +852,7 @@ final class WebViewCore {
"VALID_NODE_BOUNDS", // = 146
"SAVE_WEBARCHIVE", // = 147
"WEBKIT_DRAW_LAYERS", // = 148;
"REMOVE_JS_INTERFACE", // = 149;
};
class EventHub {
@@ -925,6 +926,8 @@ final class WebViewCore {
// Update layers
static final int WEBKIT_DRAW_LAYERS = 148;
static final int REMOVE_JS_INTERFACE = 149;
// Network-based messaging
static final int CLEAR_SSL_PREF_TABLE = 150;
@@ -1290,6 +1293,12 @@ final class WebViewCore {
jsData.mInterfaceName);
break;
case REMOVE_JS_INTERFACE:
jsData = (JSInterfaceData) msg.obj;
mBrowserFrame.removeJavascriptInterface(
jsData.mInterfaceName);
break;
case REQUEST_EXT_REPRESENTATION:
mBrowserFrame.externalRepresentation(
(Message) msg.obj);