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

Commit cc749dee authored by Ben Murdoch's avatar Ben Murdoch
Browse files

Add a method on the JavaBridge to resolve filenames from content URIs.

Requires an external/webkit change.

Change-Id: I7cc9a1c9c544546ca4fe8a212d3d60183ad99c36
parent 3f21110a
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -16,10 +16,12 @@

package android.webkit;

import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

import java.util.HashMap;
import java.util.Set;

final class JWebCoreJavaBridge extends Handler {
@@ -49,12 +51,15 @@ final class JWebCoreJavaBridge extends Handler {
    /* package */
    static final int REFRESH_PLUGINS = 100;

    private HashMap<String, String> mContentUriToFileNameMap;

    /**
     * Construct a new JWebCoreJavaBridge to interface with
     * WebCore timers and cookies.
     */
    public JWebCoreJavaBridge() {
        nativeConstructor();

    }

    @Override
@@ -267,6 +272,28 @@ final class JWebCoreJavaBridge extends Handler {
        }
    }

    // Called on the WebCore thread through JNI.
    private String resolveFileNameForContentUri(String uri) {
        if (mContentUriToFileNameMap != null) {
            String fileName = mContentUriToFileNameMap.get(uri);
            if (fileName != null) {
                return fileName;
            }
        }

        // Failsafe fallback to just use the last path segment.
        // (See OpenableColumns documentation in the SDK)
        Uri jUri = Uri.parse(uri);
        return jUri.getLastPathSegment();
    }

    public void storeFileNameForContentUri(String fileName, String contentUri) {
        if (mContentUriToFileNameMap == null) {
            mContentUriToFileNameMap = new HashMap<String, String>();
        }
        mContentUriToFileNameMap.put(contentUri, fileName);
    }

    private native void nativeConstructor();
    private native void nativeFinalize();
    private native void sharedTimerFired();
+20 −22
Original line number Diff line number Diff line
@@ -276,34 +276,32 @@ final class WebViewCore {

    /**
     * Called by JNI.  Open a file chooser to upload a file.
     * @return String version of the URI plus the name of the file.
     * FIXME: Just return the URI here, and in FileSystem::pathGetFileName, call
     * into Java to get the filename.
     * @return String version of the URI.
     */
    private String openFileChooser() {
        Uri uri = mCallbackProxy.openFileChooser();
        if (uri == null) return "";
        // Find out the name, and append it to the URI.
        // Webkit will treat the name as the filename, and
        // the URI as the path.  The URI will be used
        // in BrowserFrame to get the actual data.
        if (uri != null) {
            String fileName = "";
            Cursor cursor = mContext.getContentResolver().query(
                    uri,
                    new String[] { OpenableColumns.DISPLAY_NAME },
                null,
                null,
                null);
        String name = "";
                    null, null, null);
            if (cursor != null) {
                try {
                    if (cursor.moveToNext()) {
                    name = cursor.getString(0);
                        fileName = cursor.getString(0);
                    }
                } finally {
                    cursor.close();
                }
            } else {
                fileName = uri.getLastPathSegment();
            }
            String uriString = uri.toString();
            BrowserFrame.sJavaBridge.storeFileNameForContentUri(fileName, uriString);
            return uriString;
        }
        return uri.toString() + "/" + name;
        return "";
    }

    /**