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

Commit 6262ae5c authored by Ben Murdoch's avatar Ben Murdoch
Browse files

Implement handling of console messages from WebCore. Default implementation in...

Implement handling of console messages from WebCore. Default implementation in WebChromeClient is to do nothing.
parent 79525264
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@ class CallbackProxy extends Handler {
    private static final int SWITCH_OUT_HISTORY        = 125;
    private static final int EXCEEDED_DATABASE_QUOTA   = 126;
    private static final int JS_TIMEOUT                = 127;
    private static final int ADD_MESSAGE_TO_CONSOLE    = 128;

    // Message triggered by the client to resume execution
    private static final int NOTIFY                    = 200;
@@ -581,6 +582,13 @@ class CallbackProxy extends Handler {
            case SWITCH_OUT_HISTORY:
                mWebView.switchOutDrawHistory();
                break;

            case ADD_MESSAGE_TO_CONSOLE:
                String message = msg.getData().getString("message");
                String sourceID = msg.getData().getString("sourceID");
                int lineNumber = msg.getData().getInt("lineNumber");
                mWebChromeClient.addMessageToConsole(message, lineNumber, sourceID);
                break;
        }
    }

@@ -1086,6 +1094,28 @@ class CallbackProxy extends Handler {
        sendMessage(exceededQuota);
    }

    /**
     * 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.
     * @param message The message to add to the console.
     * @param lineNumber The lineNumber of the source file on which the error
     *     occurred.
     * @param sourceID The filename of the source file in which the error
     *     occurred.
     * @hide pending API counsel.
     */
    public void addMessageToConsole(String message, int lineNumber, String sourceID) {
        if (mWebChromeClient == null) {
            return;
        }

        Message msg = obtainMessage(ADD_MESSAGE_TO_CONSOLE);
        msg.getData().putString("message", message);
        msg.getData().putString("sourceID", sourceID);
        msg.getData().putInt("lineNumber", lineNumber);
        sendMessage(msg);
    }

    /**
     * @hide pending API council approval
     */
+11 −0
Original line number Diff line number Diff line
@@ -189,4 +189,15 @@ public class WebChromeClient {
    public boolean onJsTimeout() {
        return true;
    }

    /**
     * Add a JavaScript error message to the console. Clients should override
     * this to process the log message as they see fit.
     * @param message The error message to report.
     * @param lineNumber The line number of the error.
     * @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) {
    }
}
+10 −0
Original line number Diff line number Diff line
@@ -226,6 +226,16 @@ final class WebViewCore {
        return mSettings;
    }

    /**
     * Add an error message to the client's console.
     * @param message The message to add
     * @param lineNumber the line on which the error occurred
     * @param sourceID the filename of the source that caused the error.
     */
    protected void addMessageToConsole(String message, int lineNumber, String sourceID) {
        mCallbackProxy.addMessageToConsole(message, lineNumber, sourceID);
    }

    /**
     * Invoke a javascript alert.
     * @param message The message displayed in the alert.