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

Commit 85a50ff4 authored by Patrick Scott's avatar Patrick Scott
Browse files

Pass the auto login header information to the app.

Add a new callback to handle auto login requests.

Bug: 3367381
Change-Id: I2ee8038cdf8a4ff9d1d3de0c871a0c60f1769655
parent 102930a0
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -244856,6 +244856,25 @@
<parameter name="realm" type="java.lang.String">
</parameter>
</method>
<method name="onReceivedLoginRequest"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="view" type="android.webkit.WebView">
</parameter>
<parameter name="realm" type="java.lang.String">
</parameter>
<parameter name="account" type="java.lang.String">
</parameter>
<parameter name="args" type="java.lang.String">
</parameter>
</method>
<method name="onReceivedSslError"
 return="void"
 abstract="false"
+7 −1
Original line number Diff line number Diff line
@@ -1237,11 +1237,17 @@ class BrowserFrame extends Handler {
        }
    }


    /*package*/ SearchBox getSearchBox() {
        return mSearchBox;
    }

    /**
     * Called by JNI when processing the X-Auto-Login header.
     */
    private void autoLogin(String realm, String account, String args) {
        mCallbackProxy.onReceivedLoginRequest(realm, account, args);
    }

    //==========================================================================
    // native functions
    //==========================================================================
+28 −1
Original line number Diff line number Diff line
@@ -117,6 +117,7 @@ class CallbackProxy extends Handler {
    private static final int AUTH_CREDENTIALS                    = 137;
    private static final int SET_INSTALLABLE_WEBAPP              = 138;
    private static final int NOTIFY_SEARCHBOX_LISTENERS          = 139;
    private static final int AUTO_LOGIN                          = 140;

    // Message triggered by the client to resume execution
    private static final int NOTIFY                              = 200;
@@ -770,7 +771,7 @@ class CallbackProxy extends Handler {
                            (WebHistoryItem) msg.obj, msg.arg1);
                }
                break;
            case AUTH_CREDENTIALS:
            case AUTH_CREDENTIALS: {
                String host = msg.getData().getString("host");
                String realm = msg.getData().getString("realm");
                username = msg.getData().getString("username");
@@ -778,6 +779,7 @@ class CallbackProxy extends Handler {
                mWebView.setHttpAuthUsernamePassword(
                        host, realm, username, password);
                break;
            }
            case SET_INSTALLABLE_WEBAPP:
                if (mWebChromeClient != null) {
                    mWebChromeClient.setInstallableWebApp();
@@ -789,6 +791,17 @@ class CallbackProxy extends Handler {
                @SuppressWarnings("unchecked")
                List<String> suggestions = (List<String>) msg.obj;
                searchBox.handleSuggestions(msg.getData().getString("query"), suggestions);
                break;
            case AUTO_LOGIN: {
                if (mWebViewClient != null) {
                    String realm = msg.getData().getString("realm");
                    String account = msg.getData().getString("account");
                    String args = msg.getData().getString("args");
                    mWebViewClient.onReceivedLoginRequest(mWebView, realm,
                            account, args);
                }
                break;
            }
        }
    }

@@ -1051,6 +1064,20 @@ class CallbackProxy extends Handler {
        sendMessage(msg);
    }

    void onReceivedLoginRequest(String realm, String account, String args) {
        // Do an unsynchronized quick check to avoid posting if no callback has
        // been set.
        if (mWebViewClient == null) {
            return;
        }
        Message msg = obtainMessage(AUTO_LOGIN);
        Bundle bundle = msg.getData();
        bundle.putString("realm", realm);
        bundle.putString("account", account);
        bundle.putString("args", args);
        sendMessage(msg);
    }

    //--------------------------------------------------------------------------
    // DownloadListener functions.
    //--------------------------------------------------------------------------
+14 −0
Original line number Diff line number Diff line
@@ -256,4 +256,18 @@ public class WebViewClient {
     */
    public void onScaleChanged(WebView view, float oldScale, float newScale) {
    }

    /**
     * Notify the host application that a request to automatically log in the
     * user has been processed.
     * @param view The WebView requesting the login.
     * @param realm The account realm used to look up accounts.
     * @param account An optional account. If not null, the account should be
     *                checked against accounts on the device. If it is a valid
     *                account, it should be used to log in the user.
     * @param args Authenticator specific arguments used to log in the user.
     */
    public void onReceivedLoginRequest(WebView view, String realm,
            String account, String args) {
    }
}