This source file includes following definitions.
- JNINamespace
- SuppressWarnings
- isCustomMenu
- getCustomMenuSize
- getCustomLabelAt
- getCustomActionAt
- getLinkUrl
- getLinkText
- getUnfilteredLinkUrl
- getSrcUrl
- isEditable
- getReferrer
- isAnchor
- isSelectedText
- isImage
- isVideo
- create
- addCustomItem
package org.chromium.chrome.browser.contextmenu;
import android.text.TextUtils;
import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
import org.chromium.content_public.Referrer;
import java.util.ArrayList;
@JNINamespace("ContextMenuParamsAndroid")
public class ContextMenuParams {
@SuppressWarnings("unused")
private static interface MediaType {
public static final int MEDIA_TYPE_NONE = 0;
public static final int MEDIA_TYPE_IMAGE = 1;
public static final int MEDIA_TYPE_VIDEO = 2;
public static final int MEDIA_TYPE_AUDIO = 3;
public static final int MEDIA_TYPE_FILE = 4;
public static final int MEDIA_TYPE_PLUGIN = 5;
}
private static class CustomMenuItem {
public final String label;
public final int action;
public CustomMenuItem(String label, int action) {
this.label = label;
this.action = action;
}
}
private final String mLinkUrl;
private final String mLinkText;
private final String mUnfilteredLinkUrl;
private final String mSrcUrl;
private final boolean mIsEditable;
private final Referrer mReferrer;
private final boolean mIsAnchor;
private final boolean mIsSelectedText;
private final boolean mIsImage;
private final boolean mIsVideo;
private final ArrayList<CustomMenuItem> mCustomMenuItems = new ArrayList<CustomMenuItem>();
public boolean isCustomMenu() {
return !mCustomMenuItems.isEmpty();
}
public int getCustomMenuSize() {
return mCustomMenuItems.size();
}
public String getCustomLabelAt(int index) {
assert index >= 0 && index < mCustomMenuItems.size();
return mCustomMenuItems.get(index).label;
}
public int getCustomActionAt(int index) {
assert index >= 0 && index < mCustomMenuItems.size();
return mCustomMenuItems.get(index).action;
}
public String getLinkUrl() {
return mLinkUrl;
}
public String getLinkText() {
return mLinkText;
}
public String getUnfilteredLinkUrl() {
return mUnfilteredLinkUrl;
}
public String getSrcUrl() {
return mSrcUrl;
}
public boolean isEditable() {
return mIsEditable;
}
public Referrer getReferrer() {
return mReferrer;
}
public boolean isAnchor() {
return mIsAnchor;
}
public boolean isSelectedText() {
return mIsSelectedText;
}
public boolean isImage() {
return mIsImage;
}
public boolean isVideo() {
return mIsVideo;
}
private ContextMenuParams(int mediaType, String linkUrl, String linkText,
String unfilteredLinkUrl, String srcUrl, String selectionText, boolean isEditable,
Referrer referrer) {
mLinkUrl = linkUrl;
mLinkText = linkText;
mUnfilteredLinkUrl = unfilteredLinkUrl;
mSrcUrl = srcUrl;
mIsEditable = isEditable;
mReferrer = referrer;
mIsAnchor = !TextUtils.isEmpty(linkUrl);
mIsSelectedText = !TextUtils.isEmpty(selectionText);
mIsImage = mediaType == MediaType.MEDIA_TYPE_IMAGE;
mIsVideo = mediaType == MediaType.MEDIA_TYPE_VIDEO;
}
@CalledByNative
private static ContextMenuParams create(int mediaType, String linkUrl, String linkText,
String unfilteredLinkUrl, String srcUrl, String selectionText, boolean isEditable,
String sanitizedReferrer, int referrerPolicy) {
Referrer referrer = TextUtils.isEmpty(sanitizedReferrer) ?
null : new Referrer(sanitizedReferrer, referrerPolicy);
return new ContextMenuParams(mediaType, linkUrl, linkText, unfilteredLinkUrl, srcUrl,
selectionText, isEditable, referrer);
}
@CalledByNative
private void addCustomItem(String label, int action) {
mCustomMenuItems.add(new CustomMenuItem(label, action));
}
}