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

Commit b48fdbe7 authored by Elliott Slaughter's avatar Elliott Slaughter
Browse files

Browser save page as web archive.

Change-Id: Id34a93b2e9bb6c185338989d1eeb6929d0bd06c5
parent 2707d602
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -204199,6 +204199,36 @@
<parameter name="outState" type="android.os.Bundle">
</parameter>
</method>
<method name="saveWebArchive"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="filename" type="java.lang.String">
</parameter>
</method>
<method name="saveWebArchive"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="basename" type="java.lang.String">
</parameter>
<parameter name="autoname" type="boolean">
</parameter>
<parameter name="callback" type="android.webkit.ValueCallback&lt;java.lang.String&gt;">
</parameter>
</method>
<method name="setCertificate"
 return="void"
 abstract="false"
+14 −0
Original line number Diff line number Diff line
@@ -300,6 +300,18 @@ class BrowserFrame extends Handler {
        mLoadInitFromJava = false;
    }

    /**
     * Saves the contents of the frame as a web archive.
     *
     * @param basename The filename where the archive should be placed.
     * @param autoname If false, takes filename to be a file. If true, filename
     *                 is assumed to be a directory in which a filename will be
     *                 chosen according to the url of the current page.
     */
    /* package */ String saveWebArchive(String basename, boolean autoname) {
        return nativeSaveWebArchive(basename, autoname);
    }

    /**
     * Go back or forward the number of steps given.
     * @param steps A negative or positive number indicating the direction
@@ -1040,5 +1052,7 @@ class BrowserFrame extends Handler {
     */
    private native HashMap getFormTextData();

    private native String nativeSaveWebArchive(String basename, boolean autoname);

    private native void nativeOrientationChanged(int orientation);
}
+1 −0
Original line number Diff line number Diff line
@@ -363,6 +363,7 @@ public class MimeTypeMap {
            sMimeTypeMap.loadEntry("application/x-wais-source", "src");
            sMimeTypeMap.loadEntry("application/x-wingz", "wz");
            sMimeTypeMap.loadEntry("application/x-webarchive", "webarchive");
            sMimeTypeMap.loadEntry("application/x-webarchive-xml", "webarchivexml");
            sMimeTypeMap.loadEntry("application/x-x509-ca-cert", "crt");
            sMimeTypeMap.loadEntry("application/x-x509-user-cert", "crt");
            sMimeTypeMap.loadEntry("application/x-xcf", "xcf");
+49 −1
Original line number Diff line number Diff line
@@ -590,6 +590,7 @@ public class WebView extends AbsoluteLayout
    static final int SET_SCROLLBAR_MODES                = 129;
    static final int SELECTION_STRING_CHANGED           = 130;
    static final int SET_TOUCH_HIGHLIGHT_RECTS          = 131;
    static final int SAVE_WEBARCHIVE_FINISHED           = 132;

    private static final int FIRST_PACKAGE_MSG_ID = SCROLL_TO_MSG_ID;
    private static final int LAST_PACKAGE_MSG_ID = SET_TOUCH_HIGHLIGHT_RECTS;
@@ -638,7 +639,8 @@ public class WebView extends AbsoluteLayout
        "REQUEST_KEYBOARD_WITH_SELECTION_MSG_ID", // = 128;
        "SET_SCROLLBAR_MODES", //            = 129;
        "SELECTION_STRING_CHANGED", //       = 130;
        "SET_TOUCH_HIGHLIGHT_RECTS" //       = 131;
        "SET_TOUCH_HIGHLIGHT_RECTS", //      = 131;
        "SAVE_WEBARCHIVE_FINISHED" //        = 132;
    };

    // If the site doesn't use the viewport meta tag to specify the viewport,
@@ -1519,6 +1521,45 @@ public class WebView extends AbsoluteLayout
        clearTextEntry(false);
    }

    /**
     * Saves the current view as a web archive.
     *
     * @param filename The filename where the archive should be placed.
     */
    public void saveWebArchive(String filename) {
        saveWebArchive(filename, false, null);
    }

    /* package */ static class SaveWebArchiveMessage {
        SaveWebArchiveMessage (String basename, boolean autoname, ValueCallback<String> callback) {
            mBasename = basename;
            mAutoname = autoname;
            mCallback = callback;
        }

        /* package */ final String mBasename;
        /* package */ final boolean mAutoname;
        /* package */ final ValueCallback<String> mCallback;
        /* package */ String mResultFile;
    }

    /**
     * Saves the current view as a web archive.
     *
     * @param basename The filename where the archive should be placed.
     * @param autoname If false, takes basename to be a file. If true, basename
     *                 is assumed to be a directory in which a filename will be
     *                 chosen according to the url of the current page.
     * @param callback Called after the web archive has been saved. The
     *                 parameter for onReceiveValue will either be the filename
     *                 under which the file was saved, or null if saving the
     *                 file failed.
     */
    public void saveWebArchive(String basename, boolean autoname, ValueCallback<String> callback) {
        mWebViewCore.sendMessage(EventHub.SAVE_WEBARCHIVE,
            new SaveWebArchiveMessage(basename, autoname, callback));
    }

    /**
     * Stop the current load.
     */
@@ -6435,6 +6476,13 @@ public class WebView extends AbsoluteLayout
                    }
                    break;

                case SAVE_WEBARCHIVE_FINISHED:
                    SaveWebArchiveMessage saveMessage = (SaveWebArchiveMessage)msg.obj;
                    if (saveMessage.mCallback != null) {
                        saveMessage.mCallback.onReceiveValue(saveMessage.mResultFile);
                    }
                    break;

                default:
                    super.handleMessage(msg);
                    break;
+20 −0
Original line number Diff line number Diff line
@@ -774,6 +774,7 @@ final class WebViewCore {
            "ON_RESUME",    // = 144
            "FREE_MEMORY",  // = 145
            "VALID_NODE_BOUNDS", // = 146
            "SAVE_WEBARCHIVE", // = 147
        };

    class EventHub {
@@ -840,6 +841,9 @@ final class WebViewCore {
        static final int FREE_MEMORY = 145;
        static final int VALID_NODE_BOUNDS = 146;

        // Load and save web archives
        static final int SAVE_WEBARCHIVE = 147;

        // Network-based messaging
        static final int CLEAR_SSL_PREF_TABLE = 150;

@@ -1300,6 +1304,15 @@ final class WebViewCore {
                            nativeSetJsFlags((String)msg.obj);
                            break;

                        case SAVE_WEBARCHIVE:
                            WebView.SaveWebArchiveMessage saveMessage =
                                (WebView.SaveWebArchiveMessage)msg.obj;
                            saveMessage.mResultFile =
                                saveWebArchive(saveMessage.mBasename, saveMessage.mAutoname);
                            mWebView.mPrivateHandler.obtainMessage(
                                WebView.SAVE_WEBARCHIVE_FINISHED, saveMessage).sendToTarget();
                            break;

                        case GEOLOCATION_PERMISSIONS_PROVIDE:
                            GeolocationPermissionsData data =
                                    (GeolocationPermissionsData) msg.obj;
@@ -1601,6 +1614,13 @@ final class WebViewCore {
        mBrowserFrame.loadUrl(url, extraHeaders);
    }

    private String saveWebArchive(String filename, boolean autoname) {
        if (DebugFlags.WEB_VIEW_CORE) {
            Log.v(LOGTAG, " CORE saveWebArchive " + filename + " " + autoname);
        }
        return mBrowserFrame.saveWebArchive(filename, autoname);
    }

    private void key(KeyEvent evt, boolean isDown) {
        if (DebugFlags.WEB_VIEW_CORE) {
            Log.v(LOGTAG, "CORE key at " + System.currentTimeMillis() + ", "