Commit 7f256d89 authored by Gayane Petrosyan's avatar Gayane Petrosyan Committed by Commit Bot

[SH-Clank] Use URL from tab for link to text feature.

As url is not set in ShareParams when text is shared, url should be
passed from tab.
If url is passed through ShareParams, it will add first party options
for sharing url and will share text+url.

Bug: 1102382
Change-Id: I83d5e883b6e1f1f05cd9768d7618ceb61396185c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2343295
Commit-Queue: Gayane Petrosyan <gayane@chromium.org>
Reviewed-by: default avatarKyle Milka <kmilka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796481}
parent 1a4de419
...@@ -90,7 +90,7 @@ class ChromeProvidedSharingOptionsProvider { ...@@ -90,7 +90,7 @@ class ChromeProvidedSharingOptionsProvider {
mOrderedFirstPartyOptions = new ArrayList<>(); mOrderedFirstPartyOptions = new ArrayList<>();
initializeFirstPartyOptionsInOrder(); initializeFirstPartyOptionsInOrder();
mChromeOptionShareCallback = chromeOptionShareCallback; mChromeOptionShareCallback = chromeOptionShareCallback;
mUrl = getUrlToShare(shareParams, chromeShareExtras); mUrl = getUrlToShare(shareParams, chromeShareExtras, mTabProvider.get().getUrl().getSpec());
} }
/** /**
...@@ -302,8 +302,7 @@ class ChromeProvidedSharingOptionsProvider { ...@@ -302,8 +302,7 @@ class ChromeProvidedSharingOptionsProvider {
recordTimeToShare(mShareStartTime); recordTimeToShare(mShareStartTime);
LinkToTextCoordinator linkToTextCoordinator = new LinkToTextCoordinator( LinkToTextCoordinator linkToTextCoordinator = new LinkToTextCoordinator(
mActivity, mTabProvider.get().getWindowAndroid(), mActivity, mTabProvider.get().getWindowAndroid(),
mChromeOptionShareCallback, mShareParams.getUrl(), mChromeOptionShareCallback, mUrl, mShareParams.getText());
mShareParams.getText());
mBottomSheetController.hideContent(mBottomSheetContent, true); mBottomSheetController.hideContent(mBottomSheetContent, true);
}); });
return new FirstPartyOption( return new FirstPartyOption(
...@@ -316,13 +315,18 @@ class ChromeProvidedSharingOptionsProvider { ...@@ -316,13 +315,18 @@ class ChromeProvidedSharingOptionsProvider {
* <p>This prioritizes the URL in {@link ShareParams}, but if it does not exist, we look for an * <p>This prioritizes the URL in {@link ShareParams}, but if it does not exist, we look for an
* image source URL from {@link ChromeShareExtras}. The image source URL is not contained in * image source URL from {@link ChromeShareExtras}. The image source URL is not contained in
* {@link ShareParams#getUrl()} because we do not want to share the image URL with the image * {@link ShareParams#getUrl()} because we do not want to share the image URL with the image
* file in third-party app shares. * file in third-party app shares. If both are empty then current tab URL is used. This is
* useful for {@link LinkToTextCoordinator} that needs URL but it cannot be provided through
* {@link ShareParams}.
*/ */
static String getUrlToShare(ShareParams shareParams, ChromeShareExtras chromeShareExtras) { static String getUrlToShare(
ShareParams shareParams, ChromeShareExtras chromeShareExtras, String tabUrl) {
if (!TextUtils.isEmpty(shareParams.getUrl())) { if (!TextUtils.isEmpty(shareParams.getUrl())) {
return shareParams.getUrl(); return shareParams.getUrl();
} else if (!TextUtils.isEmpty(chromeShareExtras.getImageSrcUrl())) {
return chromeShareExtras.getImageSrcUrl();
} }
return chromeShareExtras.getImageSrcUrl(); return tabUrl;
} }
static void recordTimeToShare(long shareStartTime) { static void recordTimeToShare(long shareStartTime) {
......
...@@ -43,6 +43,7 @@ import org.chromium.components.user_prefs.UserPrefsJni; ...@@ -43,6 +43,7 @@ import org.chromium.components.user_prefs.UserPrefsJni;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.modelutil.PropertyModel; import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.test.util.DummyUiActivity; import org.chromium.ui.test.util.DummyUiActivity;
import org.chromium.url.GURL;
import java.util.List; import java.util.List;
...@@ -97,6 +98,7 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -97,6 +98,7 @@ public class ChromeProvidedSharingOptionsProviderTest {
Mockito.when(mUserPrefsNatives.get(mProfile)).thenReturn(mPrefService); Mockito.when(mUserPrefsNatives.get(mProfile)).thenReturn(mPrefService);
Mockito.when(mTabProvider.get()).thenReturn(mTab); Mockito.when(mTabProvider.get()).thenReturn(mTab);
Mockito.when(mTab.getWebContents()).thenReturn(mWebContents); Mockito.when(mTab.getWebContents()).thenReturn(mWebContents);
Mockito.when(mTab.getUrl()).thenReturn(new GURL(URL));
Mockito.when(mWebContents.isIncognito()).thenReturn(false); Mockito.when(mWebContents.isIncognito()).thenReturn(false);
mActivity = mActivityTestRule.getActivity(); mActivity = mActivityTestRule.getActivity();
} }
...@@ -257,7 +259,8 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -257,7 +259,8 @@ public class ChromeProvidedSharingOptionsProviderTest {
new ChromeShareExtras.Builder().setImageSrcUrl(URL).build(); new ChromeShareExtras.Builder().setImageSrcUrl(URL).build();
assertEquals("URL should be imageSrcUrl.", assertEquals("URL should be imageSrcUrl.",
ChromeProvidedSharingOptionsProvider.getUrlToShare(shareParams, chromeShareExtras), ChromeProvidedSharingOptionsProvider.getUrlToShare(
shareParams, chromeShareExtras, ""),
URL); URL);
} }
...@@ -269,7 +272,21 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -269,7 +272,21 @@ public class ChromeProvidedSharingOptionsProviderTest {
new ChromeShareExtras.Builder().setImageSrcUrl("").build(); new ChromeShareExtras.Builder().setImageSrcUrl("").build();
assertEquals("URL should be ShareParams URL.", assertEquals("URL should be ShareParams URL.",
ChromeProvidedSharingOptionsProvider.getUrlToShare(shareParams, chromeShareExtras), ChromeProvidedSharingOptionsProvider.getUrlToShare(
shareParams, chromeShareExtras, ""),
URL);
}
@Test
@MediumTest
public void getUrlToShare_noShareParamsUrl_noImageUrl() {
ShareParams shareParams = new ShareParams.Builder(null, /*title=*/"", /*url=*/"").build();
ChromeShareExtras chromeShareExtras =
new ChromeShareExtras.Builder().setImageSrcUrl("").build();
assertEquals("URL should be ShareParams URL.",
ChromeProvidedSharingOptionsProvider.getUrlToShare(
shareParams, chromeShareExtras, URL),
URL); URL);
} }
......
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