Open Bug 1875732 Opened 8 months ago Updated 1 month ago

Uri cannot be used

Categories

(GeckoView :: General, defect)

Firefox 122
All
Android
defect

Tracking

(Not tracked)

UNCONFIRMED

People

(Reporter: webdev_support, Unassigned)

Details

User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Steps to reproduce:

when i open android system file selector, the uri is
content://com.android.providers.media.documents/document/image%3A764691,
getFile() is null


      public @NonNull PromptResponse confirm(
          @NonNull final Context context, @NonNull final Uri[] uris) {
        if (Type.SINGLE == type && (uris == null || uris.length != 1)) {
          throw new IllegalArgumentException();
        }

        final String[] paths = new String[uris != null ? uris.length : 0];
        for (int i = 0; i < paths.length; i++) {
          paths[i] = getFile(context, uris[i]);
          if (paths[i] == null) {
            Log.e(LOGTAG, "Only file URIs are supported: " + uris[i]);
          }
        }
        ensureResult().putStringArray("files", paths);

        return super.confirm();
      }

(In reply to jackyzy823 from comment #1)

The getFile method is not work under newer Android.

Ref: https://stackoverflow.com/questions/61809732/android-data-does-not-exist-on-getcontentresolver

So Geckoview do not have ability to read file content from "content://" scheme , you need to convert to file Uri .

sample code: https://searchfox.org/mozilla-mobile/rev/8bb7243d894ea3c434c2d4372a4c67091f75bff0/firefox-android/android-components/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/prompt/GeckoPromptDelegate.kt#468 and https://searchfox.org/mozilla-mobile/rev/8bb7243d894ea3c434c2d4372a4c67091f75bff0/firefox-android/android-components/components/support/ktx/src/main/java/mozilla/components/support/ktx/android/net/Uri.kt#140

and don't forget to clean up the copied file in cache folder.

(In reply to jackyzy823 from comment #1)

The getFile method is not work under newer Android.

Ref: https://stackoverflow.com/questions/61809732/android-data-does-not-exist-on-getcontentresolver

So Geckoview do not have ability to read file content from "content://" scheme , you need to convert to file Uri .

sample code: https://searchfox.org/mozilla-mobile/rev/8bb7243d894ea3c434c2d4372a4c67091f75bff0/firefox-android/android-components/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/prompt/GeckoPromptDelegate.kt#468 and https://searchfox.org/mozilla-mobile/rev/8bb7243d894ea3c434c2d4372a4c67091f75bff0/firefox-android/android-components/components/support/ktx/src/main/java/mozilla/components/support/ktx/android/net/Uri.kt#140

and don't forget to clean up the copied file in cache folder.

If you click the input select files, mobile will be display a file selector, PromptResponse.confirm call getFile(), so PromptResponse.confirm will be get null . It's a bug ? If it's not a bug, how do I do workeraround?

(In reply to jackyzy823 from comment #1)

The getFile method is not work under newer Android.

Ref: https://stackoverflow.com/questions/61809732/android-data-does-not-exist-on-getcontentresolver

So Geckoview do not have ability to read file content from "content://" scheme , you need to convert to file Uri .

sample code: https://searchfox.org/mozilla-mobile/rev/8bb7243d894ea3c434c2d4372a4c67091f75bff0/firefox-android/android-components/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/prompt/GeckoPromptDelegate.kt#468 and https://searchfox.org/mozilla-mobile/rev/8bb7243d894ea3c434c2d4372a4c67091f75bff0/firefox-android/android-components/components/support/ktx/src/main/java/mozilla/components/support/ktx/android/net/Uri.kt#140

and don't forget to clean up the copied file in cache folder.

If you click the input select files, mobile will be display a file selector, PromptResponse.confirm call getFile(), so PromptResponse.confirm will be get null . It's a bug ? If it's not a bug, how do I do workaround?

Just pass file:// scheme uri to getFile

(In reply to jackyzy823 from comment #4)

Just pass file:// scheme uri to getFile

Could you tell me why , Isn't Android WebView like this?

What I know is that Android WebView does not rely on file selection_ The data field can be any URI. But GeckoView is strange? Can you tell me why this is?

WebView or Chromium implement some methods to read content:// scheme file via ContentResolver.openFileDescriptor

GeckoView haven't implement that yet. So you need to do openFileDescriptor manually as i linked

(In reply to jackyzy823 from comment #7)

WebView or Chromium implement some methods to read content:// scheme file via ContentResolver.openFileDescriptor

GeckoView haven't implement that yet. So you need to do openFileDescriptor manually as i linked

Will we consider fixing this issue later?

The severity field is not set for this bug.
:owlish, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(bugzeeeeee)

(In reply to jackyzy823 from comment #1)

So Geckoview do not have ability to read file content from "content://" scheme , you need to convert to file Uri .

We do have that ability, but for PDF files only, IIRC

What exactly is your use case? Are you using GV to write an app?

Flags: needinfo?(webdev_support)
Flags: needinfo?(webdev-support)
Severity: -- → S3
Flags: needinfo?(bugzeeeeee)

We do have that ability, but for PDF files only, IIRC

Quite similar but not the same , content uri for PDF is opened as nsIInputStream . but i guess file picker require it to be nsIFile

Clear needinfos that are pending on inactive users.

Inactive users most likely will not respond; if the missing information is essential and cannot be collected another way, the bug maybe should be closed as INCOMPLETE.

For more information, please visit BugBot documentation.

Flags: needinfo?(webdev_support)
Flags: needinfo?(webdev-support)
You need to log in before you can comment on or make changes to this bug.