зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1727151 - Don't pass all text to intent if it is large. r=geckoview-reviewers,agi
Although we set all selected text to intent that is text processing, it may cause `RemoteException` since binder cannot handle large data. So we should truncate the text if it is more than 100K. This value is same as Blink's limitation (https://crbug.com/1077599). Differential Revision: https://phabricator.services.mozilla.com/D123410
This commit is contained in:
Родитель
66d9cbefd5
Коммит
74eb4491ae
|
@ -15,9 +15,11 @@ import android.graphics.Matrix;
|
|||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.os.Build;
|
||||
import android.os.TransactionTooLargeException;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.UiThread;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.ActionMode;
|
||||
import android.view.Menu;
|
||||
|
@ -55,6 +57,9 @@ public class BasicSelectionActionDelegate implements ActionMode.Callback,
|
|||
ACTION_SELECT_ALL, ACTION_CUT, ACTION_COPY, ACTION_PASTE
|
||||
};
|
||||
|
||||
// This is limitation of intent text.
|
||||
private static final int MAX_INTENT_TEXT_LENGTH = 100000;
|
||||
|
||||
protected final @NonNull Activity mActivity;
|
||||
protected final boolean mUseFloatingToolbar;
|
||||
protected final @NonNull Matrix mTempMatrix = new Matrix();
|
||||
|
@ -267,11 +272,24 @@ public class BasicSelectionActionDelegate implements ActionMode.Callback,
|
|||
}
|
||||
}
|
||||
|
||||
private String getSelectedText(final int maxLength) {
|
||||
if (mSelection == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(mSelection.text) || mSelection.text.length() < maxLength) {
|
||||
return mSelection.text;
|
||||
}
|
||||
|
||||
return mSelection.text.substring(0, maxLength);
|
||||
}
|
||||
|
||||
private Intent getProcessTextIntent() {
|
||||
final Intent intent = new Intent(Intent.ACTION_PROCESS_TEXT);
|
||||
intent.addCategory(Intent.CATEGORY_DEFAULT);
|
||||
intent.setType("text/plain");
|
||||
intent.putExtra(Intent.EXTRA_PROCESS_TEXT, mSelection.text);
|
||||
// If using large text, anything intent may throw RemoteException.
|
||||
intent.putExtra(Intent.EXTRA_PROCESS_TEXT, getSelectedText(MAX_INTENT_TEXT_LENGTH));
|
||||
// TODO: implement ability to replace text in Gecko for editable selection (bug 1453137).
|
||||
intent.putExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, true);
|
||||
return intent;
|
||||
|
@ -311,11 +329,20 @@ public class BasicSelectionActionDelegate implements ActionMode.Callback,
|
|||
|
||||
if (ACTION_PROCESS_TEXT.equals(actionId)) {
|
||||
if (mExternalActionsEnabled && !mSelection.text.isEmpty()) {
|
||||
menu.addIntentOptions(menuId, menuId, menuId,
|
||||
mActivity.getComponentName(),
|
||||
/* specifiec */ null, getProcessTextIntent(),
|
||||
/* flags */ 0, /* items */ null);
|
||||
changed = true;
|
||||
try {
|
||||
menu.addIntentOptions(menuId, menuId, menuId,
|
||||
mActivity.getComponentName(),
|
||||
/* specifiec */ null, getProcessTextIntent(),
|
||||
/* flags */ 0, /* items */ null);
|
||||
changed = true;
|
||||
} catch (final RuntimeException e) {
|
||||
if (e.getCause() instanceof TransactionTooLargeException) {
|
||||
// Binder size error. MAX_INTENT_TEXT_LENGTH is still large?
|
||||
Log.e(LOGTAG, "Cannot add intent option", e);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
} else if (menu.findItem(menuId) != null) {
|
||||
menu.removeGroup(menuId);
|
||||
changed = true;
|
||||
|
|
Загрузка…
Ссылка в новой задаче