| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.contextmenu; | 5 package org.chromium.chrome.browser.contextmenu; |
| 6 | 6 |
| 7 import android.text.TextUtils; | 7 import android.text.TextUtils; |
| 8 | 8 |
| 9 import org.chromium.base.CalledByNative; | 9 import org.chromium.base.CalledByNative; |
| 10 import org.chromium.base.JNINamespace; | 10 import org.chromium.base.JNINamespace; |
| 11 import org.chromium.content_public.Referrer; |
| 11 | 12 |
| 12 import java.util.ArrayList; | 13 import java.util.ArrayList; |
| 13 | 14 |
| 14 /** | 15 /** |
| 15 * A list of parameters that explain what kind of context menu to show the user.
This data is | 16 * A list of parameters that explain what kind of context menu to show the user.
This data is |
| 16 * generated from content/public/common/context_menu_params.h. | 17 * generated from content/public/common/context_menu_params.h. |
| 17 */ | 18 */ |
| 18 @JNINamespace("ContextMenuParamsAndroid") | 19 @JNINamespace("ContextMenuParamsAndroid") |
| 19 public class ContextMenuParams { | 20 public class ContextMenuParams { |
| 20 /** Must correspond to the MediaType enum in WebKit/chromium/public/WebConte
xtMenuData.h */ | 21 /** Must correspond to the MediaType enum in WebKit/chromium/public/WebConte
xtMenuData.h */ |
| (...skipping 15 matching lines...) Expand all Loading... |
| 36 this.label = label; | 37 this.label = label; |
| 37 this.action = action; | 38 this.action = action; |
| 38 } | 39 } |
| 39 } | 40 } |
| 40 | 41 |
| 41 private final String mLinkUrl; | 42 private final String mLinkUrl; |
| 42 private final String mLinkText; | 43 private final String mLinkText; |
| 43 private final String mUnfilteredLinkUrl; | 44 private final String mUnfilteredLinkUrl; |
| 44 private final String mSrcUrl; | 45 private final String mSrcUrl; |
| 45 private final boolean mIsEditable; | 46 private final boolean mIsEditable; |
| 47 private final Referrer mReferrer; |
| 46 | 48 |
| 47 private final boolean mIsAnchor; | 49 private final boolean mIsAnchor; |
| 48 private final boolean mIsSelectedText; | 50 private final boolean mIsSelectedText; |
| 49 private final boolean mIsImage; | 51 private final boolean mIsImage; |
| 50 private final boolean mIsVideo; | 52 private final boolean mIsVideo; |
| 51 | 53 |
| 52 private final ArrayList<CustomMenuItem> mCustomMenuItems = new ArrayList<Cus
tomMenuItem>(); | 54 private final ArrayList<CustomMenuItem> mCustomMenuItems = new ArrayList<Cus
tomMenuItem>(); |
| 53 | 55 |
| 54 /** | 56 /** |
| 55 * @return Whether or not the context menu should consist of custom items. | 57 * @return Whether or not the context menu should consist of custom items. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 } | 116 } |
| 115 | 117 |
| 116 /** | 118 /** |
| 117 * @return Whether or not the context menu is being shown for an editable pi
ece of content. | 119 * @return Whether or not the context menu is being shown for an editable pi
ece of content. |
| 118 */ | 120 */ |
| 119 public boolean isEditable() { | 121 public boolean isEditable() { |
| 120 return mIsEditable; | 122 return mIsEditable; |
| 121 } | 123 } |
| 122 | 124 |
| 123 /** | 125 /** |
| 126 * @return the referrer associated with the frame on which the menu is invok
ed |
| 127 */ |
| 128 public Referrer getReferrer() { |
| 129 return mReferrer; |
| 130 } |
| 131 |
| 132 /** |
| 124 * @return Whether or not the context menu is being shown for an anchor. | 133 * @return Whether or not the context menu is being shown for an anchor. |
| 125 */ | 134 */ |
| 126 public boolean isAnchor() { | 135 public boolean isAnchor() { |
| 127 return mIsAnchor; | 136 return mIsAnchor; |
| 128 } | 137 } |
| 129 | 138 |
| 130 /** | 139 /** |
| 131 * @return Whether or not the context menu is being shown for selected text. | 140 * @return Whether or not the context menu is being shown for selected text. |
| 132 */ | 141 */ |
| 133 public boolean isSelectedText() { | 142 public boolean isSelectedText() { |
| 134 return mIsSelectedText; | 143 return mIsSelectedText; |
| 135 } | 144 } |
| 136 | 145 |
| 137 /** | 146 /** |
| 138 * @return Whether or not the context menu is being shown for an image. | 147 * @return Whether or not the context menu is being shown for an image. |
| 139 */ | 148 */ |
| 140 public boolean isImage() { | 149 public boolean isImage() { |
| 141 return mIsImage; | 150 return mIsImage; |
| 142 } | 151 } |
| 143 | 152 |
| 144 /** | 153 /** |
| 145 * @return Whether or not the context menu is being shown for a video. | 154 * @return Whether or not the context menu is being shown for a video. |
| 146 */ | 155 */ |
| 147 public boolean isVideo() { | 156 public boolean isVideo() { |
| 148 return mIsVideo; | 157 return mIsVideo; |
| 149 } | 158 } |
| 150 | 159 |
| 151 private ContextMenuParams(int mediaType, String linkUrl, String linkText, | 160 private ContextMenuParams(int mediaType, String linkUrl, String linkText, |
| 152 String unfilteredLinkUrl, String srcUrl, String selectionText, boole
an isEditable) { | 161 String unfilteredLinkUrl, String srcUrl, String selectionText, boole
an isEditable, |
| 162 Referrer referrer) { |
| 153 mLinkUrl = linkUrl; | 163 mLinkUrl = linkUrl; |
| 154 mLinkText = linkText; | 164 mLinkText = linkText; |
| 155 mUnfilteredLinkUrl = unfilteredLinkUrl; | 165 mUnfilteredLinkUrl = unfilteredLinkUrl; |
| 156 mSrcUrl = srcUrl; | 166 mSrcUrl = srcUrl; |
| 157 mIsEditable = isEditable; | 167 mIsEditable = isEditable; |
| 168 mReferrer = referrer; |
| 158 | 169 |
| 159 mIsAnchor = !TextUtils.isEmpty(linkUrl); | 170 mIsAnchor = !TextUtils.isEmpty(linkUrl); |
| 160 mIsSelectedText = !TextUtils.isEmpty(selectionText); | 171 mIsSelectedText = !TextUtils.isEmpty(selectionText); |
| 161 mIsImage = mediaType == MediaType.MEDIA_TYPE_IMAGE; | 172 mIsImage = mediaType == MediaType.MEDIA_TYPE_IMAGE; |
| 162 mIsVideo = mediaType == MediaType.MEDIA_TYPE_VIDEO; | 173 mIsVideo = mediaType == MediaType.MEDIA_TYPE_VIDEO; |
| 163 } | 174 } |
| 164 | 175 |
| 165 @CalledByNative | 176 @CalledByNative |
| 166 private static ContextMenuParams create(int mediaType, String linkUrl, Strin
g linkText, | 177 private static ContextMenuParams create(int mediaType, String linkUrl, Strin
g linkText, |
| 167 String unfilteredLinkUrl, String srcUrl, String selectionText, boole
an isEditable) { | 178 String unfilteredLinkUrl, String srcUrl, String selectionText, boole
an isEditable, |
| 179 String sanitizedReferrer, int referrerPolicy) { |
| 180 Referrer referrer = TextUtils.isEmpty(sanitizedReferrer) ? |
| 181 null : new Referrer(sanitizedReferrer, referrerPolicy); |
| 168 return new ContextMenuParams(mediaType, linkUrl, linkText, unfilteredLin
kUrl, srcUrl, | 182 return new ContextMenuParams(mediaType, linkUrl, linkText, unfilteredLin
kUrl, srcUrl, |
| 169 selectionText, isEditable); | 183 selectionText, isEditable, referrer); |
| 170 } | 184 } |
| 171 | 185 |
| 172 @CalledByNative | 186 @CalledByNative |
| 173 private void addCustomItem(String label, int action) { | 187 private void addCustomItem(String label, int action) { |
| 174 mCustomMenuItems.add(new CustomMenuItem(label, action)); | 188 mCustomMenuItems.add(new CustomMenuItem(label, action)); |
| 175 } | 189 } |
| 176 } | 190 } |
| OLD | NEW |