Skip to content

Commit

Permalink
Bug 1522228 - [1.0] Add baseUri to ContextElement and enforce absolut…
Browse files Browse the repository at this point in the history
…e URI for linkUri. r=snorp,geckoview-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D17567

--HG--
extra : moz-landing-system : lando
  • Loading branch information
Eugen Sawin committed Jan 28, 2019
1 parent 0de6e5d commit effaab9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
12 changes: 11 additions & 1 deletion mobile/android/chrome/geckoview/GeckoViewContentChild.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,17 @@ class GeckoViewContentChild extends GeckoViewChildModule {
return aNode && aNode.getAttribute && aNode.getAttribute(aAttribute);
}

function createAbsoluteUri(aBaseUri, aUri) {
if (!aUri || !aBaseUri || !aBaseUri.displaySpec) {
return null;
}
return Services.io.newURI(aUri, null, aBaseUri).displaySpec;
}

const node = aEvent.composedTarget;
const uri = nearestParentAttribute(node, "href");
const baseUri = node.ownerDocument.baseURIObject;
const uri = createAbsoluteUri(baseUri,
nearestParentAttribute(node, "href"));
const title = nearestParentAttribute(node, "title");
const alt = nearestParentAttribute(node, "alt");
const elementType = ChromeUtils.getClassName(node);
Expand All @@ -279,6 +288,7 @@ class GeckoViewContentChild extends GeckoViewChildModule {
type: "GeckoView:ContextMenu",
screenX: aEvent.screenX,
screenY: aEvent.screenY,
baseUri: (baseUri && baseUri.displaySpec) || null,
uri,
title,
alt,
Expand Down
3 changes: 2 additions & 1 deletion mobile/android/geckoview/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,13 @@ package org.mozilla.geckoview {
}

public static class GeckoSession.ContentDelegate.ContextElement {
ctor protected ContextElement(@android.support.annotation.Nullable java.lang.String, @android.support.annotation.Nullable java.lang.String, @android.support.annotation.Nullable java.lang.String, @android.support.annotation.NonNull java.lang.String, @android.support.annotation.Nullable java.lang.String);
ctor protected ContextElement(@android.support.annotation.Nullable java.lang.String, @android.support.annotation.Nullable java.lang.String, @android.support.annotation.Nullable java.lang.String, @android.support.annotation.Nullable java.lang.String, @android.support.annotation.NonNull java.lang.String, @android.support.annotation.Nullable java.lang.String);
field public static final int TYPE_AUDIO = 3;
field public static final int TYPE_IMAGE = 1;
field public static final int TYPE_NONE = 0;
field public static final int TYPE_VIDEO = 2;
field @android.support.annotation.Nullable public final java.lang.String altText;
field @android.support.annotation.Nullable public final java.lang.String baseUri;
field @android.support.annotation.Nullable public final java.lang.String linkUri;
field @android.support.annotation.Nullable public final java.lang.String srcUri;
field @android.support.annotation.Nullable public final java.lang.String title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ public void handleMessage(final ContentDelegate delegate,
} else if ("GeckoView:ContextMenu".equals(event)) {
final ContentDelegate.ContextElement elem =
new ContentDelegate.ContextElement(
message.getString("baseUri"),
message.getString("uri"),
message.getString("title"),
message.getString("alt"),
Expand Down Expand Up @@ -2650,7 +2651,12 @@ public static class ContextElement {
public static final int TYPE_AUDIO = 3;

/**
* The link URI (href) of the element.
* The base URI of the element's document.
*/
public final @Nullable String baseUri;

/**
* The absolute link URI (href) of the element.
*/
public final @Nullable String linkUri;

Expand All @@ -2677,11 +2683,13 @@ public static class ContextElement {
public final @Nullable String srcUri;

protected ContextElement(
final @Nullable String baseUri,
final @Nullable String linkUri,
final @Nullable String title,
final @Nullable String altText,
final @NonNull String typeStr,
final @Nullable String srcUri) {
this.baseUri = baseUri;
this.linkUri = linkUri;
this.title = title;
this.altText = altText;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ description: GeckoView API Changelog.
<h1> GeckoView API Changelog. </h1>

## v66
- Added `baseUri` to [`ContentDelegate.ContextElement`][65.21] and changed
`linkUri` to absolute form.

- Removed redundant field `GeckoSession.ProgressDelegate.SecurityInformation.trackingMode`.
Use `GeckoSession.TrackingProtectionDelegate.onTrackerBlocked` for
notification of blocked elements during page load.
Expand Down Expand Up @@ -115,4 +118,4 @@ description: GeckoView API Changelog.
[65.24]: ../CrashReporter.html#sendCrashReport-android.content.Context-android.os.Bundle-java.lang.String-
[65.25]: ../GeckoResult.html

[api-version]: 45d1d8774e913a3077d7c489274184fd301f14fc
[api-version]: 8b68d674a0ddb2498df59e0cf8b2edad6f0b3a8e

0 comments on commit effaab9

Please sign in to comment.