Commit ecda4196 authored by Bo Liu's avatar Bo Liu Committed by Commit Bot

weblayer: Add srcUrl to ContextMenuParams

Requested by internal client.
Note the API is added in 82, so there is currently no backward
compatibility requirements.

Bug: 1035469
Change-Id: I471da6a83a2aa156aa8441e5d033478d8416840f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2095877
Commit-Queue: Bo <boliu@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748867}
parent 4bd395e2
...@@ -137,6 +137,36 @@ public class TabCallbackTest { ...@@ -137,6 +137,36 @@ public class TabCallbackTest {
Assert.assertEquals("anchor text", params[0].linkText); Assert.assertEquals("anchor text", params[0].linkText);
} }
// Requires implementation M82.
@Test
@SmallTest
public void testShowContextMenuImg() throws TimeoutException {
String pageUrl = mActivityTestRule.getTestDataURL("img.html");
InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl(pageUrl);
ContextMenuParams params[] = new ContextMenuParams[1];
CallbackHelper callbackHelper = new CallbackHelper();
TestThreadUtils.runOnUiThreadBlocking(() -> {
Tab tab = activity.getTab();
TabCallback callback = new TabCallback() {
@Override
public void showContextMenu(ContextMenuParams param) {
params[0] = param;
callbackHelper.notifyCalled();
}
};
tab.registerTabCallback(callback);
});
TestTouchUtils.longClickView(
InstrumentationRegistry.getInstrumentation(), activity.getWindow().getDecorView());
callbackHelper.waitForFirst();
Assert.assertEquals(Uri.parse(pageUrl), params[0].pageUri);
Assert.assertEquals(
Uri.parse(mActivityTestRule.getTestDataURL("notfound.png")), params[0].srcUri);
Assert.assertEquals("alt_text", params[0].titleOrAltText);
}
@Test @Test
@SmallTest @SmallTest
public void testTabModalOverlay() throws TimeoutException { public void testTabModalOverlay() throws TimeoutException {
......
...@@ -562,7 +562,8 @@ public final class TabImpl extends ITab.Stub { ...@@ -562,7 +562,8 @@ public final class TabImpl extends ITab.Stub {
mClient.showContextMenu(ObjectWrapper.wrap(params.getPageUrl()), mClient.showContextMenu(ObjectWrapper.wrap(params.getPageUrl()),
ObjectWrapper.wrap(nonEmptyOrNull(params.getLinkUrl())), ObjectWrapper.wrap(nonEmptyOrNull(params.getLinkUrl())),
ObjectWrapper.wrap(nonEmptyOrNull(params.getLinkText())), ObjectWrapper.wrap(nonEmptyOrNull(params.getLinkText())),
ObjectWrapper.wrap(nonEmptyOrNull(params.getTitleText()))); ObjectWrapper.wrap(nonEmptyOrNull(params.getTitleText())),
ObjectWrapper.wrap(nonEmptyOrNull(params.getSrcUrl())));
} }
private void onBrowserControlsStateUpdated(int state) { private void onBrowserControlsStateUpdated(int state) {
......
...@@ -21,7 +21,8 @@ interface ITabClient { ...@@ -21,7 +21,8 @@ interface ITabClient {
// Added in M82. // Added in M82.
void showContextMenu(in IObjectWrapper pageUrl, in IObjectWrapper linkUrl, void showContextMenu(in IObjectWrapper pageUrl, in IObjectWrapper linkUrl,
in IObjectWrapper linkText, in IObjectWrapper titleOrAltText) = 4; in IObjectWrapper linkText, in IObjectWrapper titleOrAltText,
in IObjectWrapper srcUrl) = 4;
// Added in M82. // Added in M82.
void onTabModalStateChanged(in boolean isTabModalShowing) = 5; void onTabModalStateChanged(in boolean isTabModalShowing) = 5;
......
...@@ -37,10 +37,20 @@ public class ContextMenuParams { ...@@ -37,10 +37,20 @@ public class ContextMenuParams {
@Nullable @Nullable
public final String titleOrAltText; public final String titleOrAltText;
public ContextMenuParams(Uri pageUri, Uri linkUri, String linkText, String titleOrAltText) { /**
* This is the source Uri for the element that the context menu was
* invoked on. Example of elements with source URLs are img, audio, and
* video.
*/
@Nullable
public final Uri srcUri;
public ContextMenuParams(
Uri pageUri, Uri linkUri, String linkText, String titleOrAltText, Uri srcUri) {
this.pageUri = pageUri; this.pageUri = pageUri;
this.linkUri = linkUri; this.linkUri = linkUri;
this.linkText = linkText; this.linkText = linkText;
this.titleOrAltText = titleOrAltText; this.titleOrAltText = titleOrAltText;
this.srcUri = srcUri;
} }
} }
...@@ -368,14 +368,16 @@ public class Tab { ...@@ -368,14 +368,16 @@ public class Tab {
@Override @Override
public void showContextMenu(IObjectWrapper pageUrl, IObjectWrapper linkUrl, public void showContextMenu(IObjectWrapper pageUrl, IObjectWrapper linkUrl,
IObjectWrapper linkText, IObjectWrapper titleOrAltText) { IObjectWrapper linkText, IObjectWrapper titleOrAltText, IObjectWrapper srcUrl) {
StrictModeWorkaround.apply(); StrictModeWorkaround.apply();
String pageUrlString = ObjectWrapper.unwrap(pageUrl, String.class); String pageUrlString = ObjectWrapper.unwrap(pageUrl, String.class);
String linkUrlString = ObjectWrapper.unwrap(linkUrl, String.class); String linkUrlString = ObjectWrapper.unwrap(linkUrl, String.class);
String srcUrlString = ObjectWrapper.unwrap(srcUrl, String.class);
ContextMenuParams params = new ContextMenuParams(Uri.parse(pageUrlString), ContextMenuParams params = new ContextMenuParams(Uri.parse(pageUrlString),
linkUrlString != null ? Uri.parse(linkUrlString) : null, linkUrlString != null ? Uri.parse(linkUrlString) : null,
ObjectWrapper.unwrap(linkText, String.class), ObjectWrapper.unwrap(linkText, String.class),
ObjectWrapper.unwrap(titleOrAltText, String.class)); ObjectWrapper.unwrap(titleOrAltText, String.class),
srcUrlString != null ? Uri.parse(srcUrlString) : null);
for (TabCallback callback : mCallbacks) { for (TabCallback callback : mCallbacks) {
callback.showContextMenu(params); callback.showContextMenu(params);
} }
......
<html>
<head>
<style>
body, html {
height: 100%;
}
img {
display: block;
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<img src="notfound.png" alt="alt_text" />
</body>
</html>
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