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

Commit 4faee09c authored by Steve Block's avatar Steve Block
Browse files

Adds the Java side of the system to show the Geolocation permissions prompt.

parent 0ac031b3
Loading
Loading
Loading
Loading
+90 −31
Original line number Diff line number Diff line
@@ -102,6 +102,8 @@ class CallbackProxy extends Handler {
    private static final int REACHED_APPCACHE_MAXSIZE            = 127;
    private static final int JS_TIMEOUT                          = 128;
    private static final int ADD_MESSAGE_TO_CONSOLE              = 129;
    private static final int GEOLOCATION_PERMISSIONS_SHOW_PROMPT = 130;
    private static final int GEOLOCATION_PERMISSIONS_HIDE_PROMPT = 131;

    // Message triggered by the client to resume execution
    private static final int NOTIFY                              = 200;
@@ -438,6 +440,25 @@ class CallbackProxy extends Handler {
                }
                break;

            case GEOLOCATION_PERMISSIONS_SHOW_PROMPT:
                if (mWebChromeClient != null) {
                    HashMap<String, Object> map =
                            (HashMap<String, Object>) msg.obj;
                    String origin = (String) map.get("origin");
                    GeolocationPermissions.Callback callback =
                            (GeolocationPermissions.Callback)
                            map.get("callback");
                    mWebChromeClient.onGeolocationPermissionsShowPrompt(origin,
                            callback);
                }
                break;

            case GEOLOCATION_PERMISSIONS_HIDE_PROMPT:
                if (mWebChromeClient != null) {
                    mWebChromeClient.onGeolocationPermissionsHidePrompt();
                }
                break;

            case JS_ALERT:
                if (mWebChromeClient != null) {
                    final JsResult res = (JsResult) msg.obj;
@@ -1191,6 +1212,44 @@ class CallbackProxy extends Handler {
        sendMessage(msg);
    }

    /**
     * Called by WebViewCore to instruct the browser to display a prompt to ask
     * the user to set the Geolocation permission state for the given origin.
     * @param origin The origin requesting Geolocation permsissions.
     * @param callback The callback to call once a permission state has been
     *     obtained.
     * @hide pending API council review.
     */
    public void onGeolocationPermissionsShowPrompt(String origin,
            GeolocationPermissions.Callback callback) {
        if (mWebChromeClient == null) {
            return;
        }

        Message showMessage =
                obtainMessage(GEOLOCATION_PERMISSIONS_SHOW_PROMPT);
        HashMap<String, Object> map = new HashMap();
        map.put("origin", origin);
        map.put("callback", callback);
        showMessage.obj = map;
        sendMessage(showMessage);
    }

    /**
     * Called by WebViewCore to instruct the browser to hide the Geolocation
     * permissions prompt.
     * origin.
     * @hide pending API council review.
     */
    public void onGeolocationPermissionsHidePrompt() {
        if (mWebChromeClient == null) {
            return;
        }

        Message hideMessage = obtainMessage(GEOLOCATION_PERMISSIONS_HIDE_PROMPT);
        sendMessage(hideMessage);
    }

    /**
     * Called by WebViewCore when we have a message to be added to the JavaScript
     * error console. Sends a message to the Java side with the details.
+8 −0
Original line number Diff line number Diff line
@@ -31,6 +31,14 @@ import java.util.Set;
 * @hide
 */
public final class GeolocationPermissions {
    /**
     * Callback interface used by the browser to report a Geolocation permission
     * state set by the user in response to a permissions prompt.
     */
    public interface Callback {
        public void invoke(String origin, boolean allow, boolean remember);
    };

    // Log tag
    private static final String TAG = "geolocationPermissions";

+15 −2
Original line number Diff line number Diff line
@@ -226,6 +226,20 @@ public class WebChromeClient {
        quotaUpdater.updateQuota(0);
    }

    /**
     * Instructs the client to show a prompt to ask the user to set the
     * Geolocation permission state for the specified origin.
     * @hide pending API council approval.
     */
    public void onGeolocationPermissionsShowPrompt(String origin,
            GeolocationPermissions.Callback callback) {}

    /**
     * Instructs the client to hide the Geolocation permissions prompt.
     * @hide pending API council approval.
     */
    public void onGeolocationPermissionsHidePrompt() {}

    /**
     * Tell the client that a JavaScript execution timeout has occured. And the
     * client may decide whether or not to interrupt the execution. If the
@@ -249,6 +263,5 @@ public class WebChromeClient {
     * @param sourceID The name of the source file that caused the error.
     * @hide pending API council.
     */
    public void addMessageToConsole(String message, int lineNumber, String sourceID) {
    }
    public void addMessageToConsole(String message, int lineNumber, String sourceID) {}
}
+51 −0
Original line number Diff line number Diff line
@@ -284,6 +284,33 @@ final class WebViewCore {
                });
    }

    /**
     * Shows a prompt to ask the user to set the Geolocation permission state
     * for the given origin.
     * @param origin The origin for which Geolocation permissions are
     *     requested.
     */
    protected void geolocationPermissionsShowPrompt(String origin) {
        mCallbackProxy.onGeolocationPermissionsShowPrompt(origin,
                new GeolocationPermissions.Callback() {
          public void invoke(String origin, boolean allow, boolean remember) {
            GeolocationPermissionsData data = new GeolocationPermissionsData();
            data.mOrigin = origin;
            data.mAllow = allow;
            data.mRemember = remember;
            // Marshall to WebCore thread.
            sendMessage(EventHub.GEOLOCATION_PERMISSIONS_PROVIDE, data);
          }
        });
    }

    /**
     * Hides the Geolocation permissions prompt.
     */
    protected void geolocationPermissionsHidePrompt() {
        mCallbackProxy.onGeolocationPermissionsHidePrompt();
    }

    /**
     * Invoke a javascript confirm dialog.
     * @param message The message displayed in the dialog.
@@ -465,6 +492,16 @@ final class WebViewCore {

    private native void nativeUpdatePluginState(int framePtr, int nodePtr, int state);

    /**
     * Provide WebCore with a Geolocation permission state for the specified
     * origin.
     * @param origin The origin for which Geolocation permissions are provided.
     * @param allow Whether Geolocation permissions are allowed.
     * @param remember Whether this decision should be remembered beyond the
     *     life of the current page.
     */
    private native void nativeGeolocationPermissionsProvide(String origin, boolean allow, boolean remember);

    // EventHub for processing messages
    private final EventHub mEventHub;
    // WebCore thread handler
@@ -608,6 +645,12 @@ final class WebViewCore {
        int mState;
    }

    static class GeolocationPermissionsData {
        String mOrigin;
        boolean mAllow;
        boolean mRemember;
    }

        static final String[] HandlerDebugString = {
            "SCROLL_TEXT_INPUT", // = 99
            "LOAD_URL", // = 100;
@@ -733,6 +776,8 @@ final class WebViewCore {
        static final int DUMP_NAVTREE = 172;

        static final int SET_JS_FLAGS = 173;
        // Geolocation
        static final int GEOLOCATION_PERMISSIONS_PROVIDE = 180;

        // private message ids
        private static final int DESTROY =     200;
@@ -1119,6 +1164,12 @@ final class WebViewCore {

                        case SET_JS_FLAGS:
                            nativeSetJsFlags((String)msg.obj);

                        case GEOLOCATION_PERMISSIONS_PROVIDE:
                            GeolocationPermissionsData data =
                                    (GeolocationPermissionsData) msg.obj;
                            nativeGeolocationPermissionsProvide(data.mOrigin,
                                    data.mAllow, data.mRemember);
                            break;

                        case SYNC_SCROLL: