Commit 501af0e3 authored by Dominic Mazzoni's avatar Dominic Mazzoni Committed by Commit Bot

Add the target url as a bundle property for Android links and images.

Any AccessibilityNodeInfo can include extra information in a Bundle of
key/value pairs. Some external developers requested that we expose the
target url for a link or image, so we can just include it in the bundle
of extras without needing a formal API for it.

Bug: 961865
Change-Id: I0edb75bc8320a5ee3bf166072a0a061e46786600
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1862862
Commit-Queue: Dominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarAkihiro Ota <akihiroota@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707415}
parent 92b0a064
......@@ -1656,6 +1656,13 @@ bool BrowserAccessibilityAndroid::HasFocusableNonOptionChild() const {
return false;
}
base::string16 BrowserAccessibilityAndroid::GetTargetUrl() const {
if (ui::IsImage(GetRole()) || ui::IsLink(GetRole()))
return GetString16Attribute(ax::mojom::StringAttribute::kUrl);
return {};
}
bool BrowserAccessibilityAndroid::HasNonEmptyValue() const {
return IsEditableText() && !GetValue().empty();
}
......
......@@ -151,6 +151,9 @@ class CONTENT_EXPORT BrowserAccessibilityAndroid : public BrowserAccessibility {
std::vector<int32_t>* word_ends,
int offset);
// Return the target of a link or the source of an image.
base::string16 GetTargetUrl() const;
// Used to keep track of when to stop reporting content_invalid.
// Timer only applies if node has focus.
void ResetContentInvalidTimer();
......
......@@ -736,7 +736,8 @@ jboolean WebContentsAccessibilityAndroid::PopulateAccessibilityNodeInfo(
base::android::ConvertUTF16ToJavaString(env, node->GetHint()),
node->GetIntAttribute(ax::mojom::IntAttribute::kTextSelStart),
node->GetIntAttribute(ax::mojom::IntAttribute::kTextSelEnd),
node->HasImage(), node->IsContentInvalid());
node->HasImage(), node->IsContentInvalid(),
base::android::ConvertUTF16ToJavaString(env, node->GetTargetUrl()));
Java_WebContentsAccessibilityImpl_setAccessibilityNodeInfoLollipopAttributes(
env, obj, info, node->CanOpenPopup(), node->IsContentInvalid(),
......
......@@ -37,11 +37,14 @@ public class KitKatWebContentsAccessibility extends WebContentsAccessibilityImpl
protected void setAccessibilityNodeInfoKitKatAttributes(AccessibilityNodeInfo node,
boolean isRoot, boolean isEditableText, String role, String roleDescription,
String hint, int selectionStartIndex, int selectionEndIndex, boolean hasImage,
boolean contentInvalid) {
boolean contentInvalid, String targetUrl) {
Bundle bundle = node.getExtras();
bundle.putCharSequence("AccessibilityNodeInfo.chromeRole", role);
bundle.putCharSequence("AccessibilityNodeInfo.roleDescription", roleDescription);
bundle.putCharSequence("AccessibilityNodeInfo.hint", hint);
if (!targetUrl.isEmpty()) {
bundle.putCharSequence("AccessibilityNodeInfo.targetUrl", targetUrl);
}
if (hasImage) bundle.putCharSequence("AccessibilityNodeInfo.hasImage", "true");
if (isRoot) {
bundle.putCharSequence(
......
......@@ -42,10 +42,10 @@ public class OWebContentsAccessibility extends LollipopWebContentsAccessibility
protected void setAccessibilityNodeInfoKitKatAttributes(AccessibilityNodeInfo node,
boolean isRoot, boolean isEditableText, String role, String roleDescription,
String hint, int selectionStartIndex, int selectionEndIndex, boolean hasImage,
boolean contentInvalid) {
boolean contentInvalid, String targetUrl) {
super.setAccessibilityNodeInfoKitKatAttributes(node, isRoot, isEditableText, role,
roleDescription, hint, selectionStartIndex, selectionEndIndex, hasImage,
contentInvalid);
contentInvalid, targetUrl);
node.setHintText(hint);
}
......
......@@ -1282,7 +1282,7 @@ public class WebContentsAccessibilityImpl extends AccessibilityNodeProvider
protected void setAccessibilityNodeInfoKitKatAttributes(AccessibilityNodeInfo node,
boolean isRoot, boolean isEditableText, String role, String roleDescription,
String hint, int selectionStartIndex, int selectionEndIndex, boolean hasImage,
boolean contentInvalid) {
boolean contentInvalid, String targetUrl) {
// Requires KitKat or higher.
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment