Bug 1355389 - Added one extra parameter to the message from the emitted event, parameter which indicates if the input element has multiple attribute. r=mcomella

MozReview-Commit-ID: CpRfgaYvV5y

--HG--
extra : rebase_source : 63f62e70ca994e0fcd3744b131b8af10d93cd939
This commit is contained in:
Andrei Lazar 2018-04-13 18:09:23 +03:00
Родитель b31fdd70ba
Коммит 58e362a83d
2 изменённых файлов: 25 добавлений и 16 удалений

Просмотреть файл

@ -4,7 +4,6 @@
package org.mozilla.gecko;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.permissions.PermissionBlock;
import org.mozilla.gecko.permissions.Permissions;
import org.mozilla.gecko.util.BundleEventListener;
@ -18,10 +17,8 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Environment;
import android.os.Parcelable;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.Log;
@ -35,10 +32,12 @@ import java.util.List;
public class FilePicker implements BundleEventListener {
private static final String LOGTAG = "GeckoFilePicker";
private static FilePicker sFilePicker;
private static final int MODE_OPEN_MULTIPLE_ATTRIBUTE_VALUE = 3;
private static final int MODE_OPEN_SINGLE_ATTRIBUTE_VALUE = 0;
private final Context context;
public interface ResultHandler {
public void gotFile(String filename);
void gotFile(String filename);
}
public static void init(Context context) {
@ -60,6 +59,8 @@ public class FilePicker implements BundleEventListener {
final String mode = message.getString("mode", "");
final int tabId = message.getInt("tabId", -1);
final String title = message.getString("title", "");
final boolean isModeOpenMultiple = message.getInt("modeOpenAttribute", MODE_OPEN_SINGLE_ATTRIBUTE_VALUE)
== MODE_OPEN_MULTIPLE_ATTRIBUTE_VALUE;
if ("mimeType".equals(mode)) {
mimeType = message.getString("mimeType", "");
@ -89,7 +90,7 @@ public class FilePicker implements BundleEventListener {
// TODO: Figure out which permissions have been denied and use that
// knowledge for availPermissions. For now we assume we don't have any
// permissions at all (bug 1411014).
showFilePickerAsync(title, "*/*", new String[0], new ResultHandler() {
showFilePickerAsync(title, "*/*", new String[0], isModeOpenMultiple, new ResultHandler() {
@Override
public void gotFile(final String filename) {
callback.sendSuccess(filename);
@ -100,7 +101,7 @@ public class FilePicker implements BundleEventListener {
.run(new Runnable() {
@Override
public void run() {
showFilePickerAsync(title, finalMimeType, requiredPermission, new ResultHandler() {
showFilePickerAsync(title, finalMimeType, requiredPermission, isModeOpenMultiple, new ResultHandler() {
@Override
public void gotFile(final String filename) {
callback.sendSuccess(filename);
@ -149,6 +150,7 @@ public class FilePicker implements BundleEventListener {
private List<Intent> getIntentsForFilePicker(final @NonNull String mimeType,
final @NonNull String[] availPermissions,
final boolean isModeOpenMultiple,
final FilePickerResultHandler fileHandler) {
// The base intent to use for the file picker. Even if this is an implicit intent, Android will
// still show a list of Activities that match this action/type.
@ -159,20 +161,21 @@ public class FilePicker implements BundleEventListener {
// A list of other activities to show in the picker (and the intents to launch them).
HashMap<String, Intent> intents = new HashMap<String, Intent> ();
if (mimeType.startsWith("audio/")) {
baseIntent = getIntent(mimeType);
addActivities(baseIntent, baseIntents, null);
baseIntent = getIntent(mimeType);
if (isModeOpenMultiple) {
baseIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
}
if (mimeType.startsWith("audio/")) {
addActivities(baseIntent, baseIntents, null);
if (mimeType.equals("audio/*") &&
hasPermissionsForMimeType(mimeType, availPermissions)) {
// We also add a capture intent
Intent intent = IntentHelper.getAudioCaptureIntent();
addActivities(intent, intents, baseIntents);
}
} else if (mimeType.startsWith("image/")) {
baseIntent = getIntent(mimeType);
} else if (mimeType.startsWith("image/") ) {
addActivities(baseIntent, baseIntents, null);
if (mimeType.equals("image/*") &&
hasPermissionsForMimeType(mimeType, availPermissions)) {
// We also add a capture intent
@ -182,9 +185,7 @@ public class FilePicker implements BundleEventListener {
addActivities(intent, intents, baseIntents);
}
} else if (mimeType.startsWith("video/")) {
baseIntent = getIntent(mimeType);
addActivities(baseIntent, baseIntents, null);
if (mimeType.equals("video/*") &&
hasPermissionsForMimeType(mimeType, availPermissions)) {
// We also add a capture intent
@ -193,6 +194,9 @@ public class FilePicker implements BundleEventListener {
}
} else {
baseIntent = getIntent("*/*");
if (isModeOpenMultiple) {
baseIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
}
addActivities(baseIntent, baseIntents, null);
Intent intent;
@ -245,8 +249,9 @@ public class FilePicker implements BundleEventListener {
private Intent getFilePickerIntent(String title,
final @NonNull String mimeType,
final @NonNull String[] availPermissions,
final boolean isModeOpenMultiple,
final FilePickerResultHandler fileHandler) {
final List<Intent> intents = getIntentsForFilePicker(mimeType, availPermissions, fileHandler);
final List<Intent> intents = getIntentsForFilePicker(mimeType, availPermissions, isModeOpenMultiple, fileHandler);
if (intents.size() == 0) {
Log.i(LOGTAG, "no activities for the file picker!");
@ -274,10 +279,11 @@ public class FilePicker implements BundleEventListener {
*/
protected void showFilePickerAsync(final String title, final @NonNull String mimeType,
final @NonNull String[] availPermissions,
final boolean isModeOpenMultiple,
final ResultHandler handler, final int tabId) {
final FilePickerResultHandler fileHandler =
new FilePickerResultHandler(handler, context, tabId);
final Intent intent = getFilePickerIntent(title, mimeType, availPermissions, fileHandler);
final Intent intent = getFilePickerIntent(title, mimeType, availPermissions, isModeOpenMultiple, fileHandler);
final Activity currentActivity =
GeckoActivityMonitor.getInstance().getCurrentActivity();

Просмотреть файл

@ -222,6 +222,9 @@ FilePicker.prototype = {
msg.mode = "mimeType";
msg.mimeType = this._mimeTypeFilter;
}
if (this._mode) {
msg.modeOpenAttribute = this._mode;
}
EventDispatcher.instance.sendRequestForResult(msg).then(file => {
this._filePath = file || null;