Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 689a342b authored by Steve Block's avatar Steve Block
Browse files

Add WebView.removeJavascriptInterface()

Bug: 3234178
Change-Id: I7136f8d76b20f90a7e9e1c55b6755ffe6c35b77b
parent 9aa6ea83
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -227783,6 +227783,19 @@
 visibility="public"
>
</method>
<method name="removeJavascriptInterface"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="interfaceName" type="java.lang.String">
</parameter>
</method>
<method name="requestFocusNodeHref"
 return="void"
 abstract="false"
+8 −1
Original line number Diff line number Diff line
@@ -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);
    }

    /**
+12 −1
Original line number Diff line number Diff line
@@ -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.
+9 −0
Original line number Diff line number Diff line
@@ -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);