Commit 0da6796f authored by Sophey Dong's avatar Sophey Dong Committed by Commit Bot

[SharingHub] Add ChromeShareExtras.

This will be used alongside ShareParams, and will contain Chrome-specific sharing parameters since ShareParams has now moved to components.browser_ui.

Bug: 1079467
Change-Id: Id48c22e3f1d39d5ef18341871490fee9e69dae12
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2207912Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarKyle Milka <kmilka@chromium.org>
Reviewed-by: default avatarTanya Gupta <tgupta@chromium.org>
Commit-Queue: Sophey Dong <sophey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#773951}
parent bc33c87d
......@@ -1392,6 +1392,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/settings/SettingsActivity.java",
"java/src/org/chromium/chrome/browser/settings/SettingsLauncherImpl.java",
"java/src/org/chromium/chrome/browser/share/ChromeProvidedSharingOptionsProvider.java",
"java/src/org/chromium/chrome/browser/share/ChromeShareExtras.java",
"java/src/org/chromium/chrome/browser/share/LensUtils.java",
"java/src/org/chromium/chrome/browser/share/OptionalShareTargetsManager.java",
"java/src/org/chromium/chrome/browser/share/ShareActivity.java",
......
......@@ -20,6 +20,7 @@ import androidx.appcompat.content.res.AppCompatResources;
import org.chromium.base.Callback;
import org.chromium.base.metrics.RecordUserAction;
import org.chromium.base.supplier.ObservableSupplier;
import org.chromium.chrome.browser.share.ChromeShareExtras;
import org.chromium.chrome.browser.share.ShareDelegate;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabCreationState;
......@@ -257,8 +258,8 @@ public class TabGridDialogMediator {
public void onCancel() {}
})
.build();
mShareDelegateSupplier.get().share(
shareParams, /* shareDirectly */ false, /* saveLastUsed */ true);
mShareDelegateSupplier.get().share(shareParams,
new ChromeShareExtras(/*saveLastUsed=*/true, /*shareDirectly=*/false));
}
};
......
......@@ -41,6 +41,7 @@ import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.search_engines.TemplateUrlServiceFactory;
import org.chromium.chrome.browser.share.ChromeShareExtras;
import org.chromium.chrome.browser.share.LensUtils;
import org.chromium.chrome.browser.share.ShareDelegate;
import org.chromium.chrome.browser.share.ShareHelper;
......@@ -449,8 +450,7 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator {
}
if ((mMode == ContextMenuMode.NORMAL || mMode == ContextMenuMode.CUSTOM_TAB)
&& EphemeralTabCoordinator.isSupported()) {
ContextMenuItem item =
new ChromeContextMenuItem(Item.OPEN_IMAGE_IN_EPHEMERAL_TAB);
ContextMenuItem item = new ChromeContextMenuItem(Item.OPEN_IMAGE_IN_EPHEMERAL_TAB);
if (mShowEphemeralTabNewLabel == null) {
mShowEphemeralTabNewLabel = shouldTriggerEphemeralTabHelpUi();
}
......@@ -469,8 +469,7 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator {
final boolean enableGoogleLensFeature = LensUtils.enableGoogleLensFeature();
if (isSrcDownloadableScheme && templateUrlServiceInstance.isLoaded()
&& templateUrlServiceInstance.isSearchByImageAvailable()
&& templateUrlServiceInstance.getDefaultSearchEngineTemplateUrl()
!= null
&& templateUrlServiceInstance.getDefaultSearchEngineTemplateUrl() != null
&& !LocaleManager.getInstance().needToCheckForSearchEnginePromo()) {
// All behavior relating to Lens integration is gated by Feature Flag.
if (enableGoogleLensFeature
......@@ -650,10 +649,9 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator {
} else if (itemId == R.id.contextmenu_share_link) {
recordContextMenuSelection(params, ContextMenuUma.Action.SHARE_LINK);
ShareParams linkShareParams =
new ShareParams.Builder(getWindow(), params.getUrl(), params.getUrl())
.build();
mShareDelegateSupplier.get().share(
linkShareParams, /* shareDirectly */ false, /* saveLastUsed */ true);
new ShareParams.Builder(getWindow(), params.getUrl(), params.getUrl()).build();
mShareDelegateSupplier.get().share(linkShareParams,
new ChromeShareExtras(/*saveLastUsed=*/true, /*shareDirectly=*/false));
} else if (itemId == R.id.contextmenu_search_with_google_lens) {
recordContextMenuSelection(params, ContextMenuUma.Action.SEARCH_WITH_GOOGLE_LENS);
searchWithGoogleLens(params, renderFrameHost, mDelegate.isIncognito());
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.share;
import org.chromium.components.browser_ui.share.ShareParams;
/**
* A container object for passing share extras not contained in {@link ShareParams} to {@link
* ShareDelegate}.
*
* <p>This class contains extras that are used only by Android Share, and should never be
* componentized. {@link ShareParams} lives in //components and only contains parameters that are
* used in more than one part of the Chromium codebase.
*/
public class ChromeShareExtras {
/**
* Whether to save the chosen activity for future direct sharing.
*/
private final boolean mSaveLastUsed;
/**
* Whether it should share directly with the activity that was most recently used to share. If
* false, the share selection will be saved.
*/
private final boolean mShareDirectly;
public ChromeShareExtras(boolean saveLastUsed, boolean shareDirectly) {
mSaveLastUsed = saveLastUsed;
mShareDirectly = shareDirectly;
}
/**
* @return Whether to save the chosen activity for future direct sharing.
*/
public boolean saveLastUsed() {
return mSaveLastUsed;
}
/**
* @return Whether it should share directly with the activity that was most recently used to
* share.
*/
public boolean shareDirectly() {
return mShareDirectly;
}
}
dtrainor@chromium.org
per-file ChromeProvidedSharingOptionsProvider.java=file://components/send_tab_to_self/OWNERS
per-file ChromeShareExtras.java=file://components/send_tab_to_self/OWNERS
per-file ShareSheet*=file://components/send_tab_to_self/OWNERS
per-file ShareDelegate*=file://components/send_tab_to_self/OWNERS
per-file ShareButtonController*=file://components/send_tab_to_self/OWNERS
......
......@@ -15,10 +15,9 @@ public interface ShareDelegate {
* Initiate a share based on the provided ShareParams.
*
* @param params The share parameters.
* @param shareDirectly If this share should be sent directly to the last used share target.
* @param saveLastUsed If the chosen share target should be saved for future reuse.
* @param chromeShareExtras The extras not contained in {@code params}.
*/
void share(ShareParams params, boolean shareDirectly, boolean saveLastUsed);
void share(ShareParams params, ChromeShareExtras chromeShareExtras);
/**
* Initiate a share for the provided Tab.
......
......@@ -66,12 +66,12 @@ public class ShareDelegateImpl implements ShareDelegate {
// ShareDelegate implementation.
@Override
public void share(ShareParams params, boolean shareDirectly, boolean saveLastUsed) {
public void share(ShareParams params, ChromeShareExtras chromeShareExtras) {
if (mShareStartTime == 0L) {
mShareStartTime = System.currentTimeMillis();
}
mDelegate.share(params, shareDirectly, saveLastUsed, mBottomSheetController,
mActivityTabProvider, mShareStartTime);
mDelegate.share(params, chromeShareExtras, mBottomSheetController, mActivityTabProvider,
mShareStartTime);
mShareStartTime = 0;
}
......@@ -128,7 +128,7 @@ public class ShareDelegateImpl implements ShareDelegate {
OfflinePageUtils.maybeShareOfflinePage(currentTab, (ShareParams p) -> {
if (p != null) {
share(p, /* shareDirectly */ false, /* saveLastUsed */ false);
share(p, new ChromeShareExtras(/*saveLastUsed=*/false, /*shareDirectly=*/false));
} else {
WindowAndroid window = currentTab.getWindowAndroid();
// Could not share as an offline page.
......@@ -165,7 +165,7 @@ public class ShareDelegateImpl implements ShareDelegate {
ShareParams.Builder builder =
new ShareParams.Builder(window, title, getUrlToShare(visibleUrl, canonicalUrl))
.setScreenshotUri(blockingUri);
share(builder.build(), shareDirectly, !shareDirectly);
share(builder.build(), new ChromeShareExtras(!shareDirectly, shareDirectly));
if (shareDirectly) {
RecordUserAction.record("MobileMenuDirectShare");
} else {
......@@ -257,10 +257,10 @@ public class ShareDelegateImpl implements ShareDelegate {
/**
* Trigger the share action for the specified params.
*/
void share(ShareParams params, boolean shareDirectly, boolean saveLastUsed,
void share(ShareParams params, ChromeShareExtras chromeShareExtras,
BottomSheetController controller, ActivityTabProvider tabProvider,
long shareStartTime) {
if (shareDirectly) {
if (chromeShareExtras.shareDirectly()) {
ShareHelper.shareWithLastUsedComponent(params);
} else if (ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_SHARING_HUB)) {
ShareSheetCoordinator coordinator =
......@@ -269,9 +269,10 @@ public class ShareDelegateImpl implements ShareDelegate {
ContextUtils.getApplicationContext().getPackageManager()),
PrefServiceBridge.getInstance());
// TODO(crbug/1009124): open custom share sheet.
coordinator.showShareSheet(params, saveLastUsed, shareStartTime);
coordinator.showShareSheet(
params, chromeShareExtras.saveLastUsed(), shareStartTime);
} else {
ShareHelper.showDefaultShareUi(params, saveLastUsed);
ShareHelper.showDefaultShareUi(params, chromeShareExtras.saveLastUsed());
}
}
}
......
......@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.webshare;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.share.ChromeShareExtras;
import org.chromium.components.browser_ui.share.ShareParams;
import org.chromium.components.browser_ui.webshare.ShareServiceImpl;
import org.chromium.content_public.browser.WebContents;
......@@ -33,8 +34,8 @@ public class ShareServiceImplementationFactory implements InterfaceFactory<Share
public void share(ShareParams params) {
ChromeActivity<?> activity =
(ChromeActivity<?>) params.getWindow().getActivity().get();
activity.getShareDelegateSupplier().get().share(
params, /* shareDirectly */ false, /* saveLastUsed */ false);
activity.getShareDelegateSupplier().get().share(params,
new ChromeShareExtras(/*saveLastUsed=*/false, /*shareDirectly=*/false));
}
};
......
......@@ -114,7 +114,7 @@ public class ShareDelegateImplIntegrationTest {
TestThreadUtils.runOnUiThreadBlocking(() -> {
ShareSheetDelegate delegate = new ShareSheetDelegate() {
@Override
void share(ShareParams params, boolean shareDirectly, boolean saveLastUsed,
void share(ShareParams params, ChromeShareExtras chromeShareParams,
BottomSheetController controller, ActivityTabProvider tabProvider,
long shareStartTime) {
paramsRef.set(params);
......
......@@ -32,6 +32,9 @@ public class ShareParams {
*/
private final String mText;
/** The URL of the page to be shared. */
private final String mUrl;
/** The common MIME type of the files to be shared. A wildcard if they have differing types. */
private final String mFileContentType;
......@@ -50,13 +53,14 @@ public class ShareParams {
*/
private TargetChosenCallback mCallback;
private ShareParams(WindowAndroid window, String title, String text,
private ShareParams(WindowAndroid window, String title, String text, String url,
@Nullable String fileContentType, @Nullable ArrayList<Uri> fileUris,
@Nullable Uri offlineUri, @Nullable Uri screenshotUri,
@Nullable TargetChosenCallback callback) {
mWindow = window;
mTitle = title;
mText = text;
mUrl = url;
mFileContentType = fileContentType;
mFileUris = fileUris;
mOfflineUri = offlineUri;
......@@ -85,6 +89,13 @@ public class ShareParams {
return mText;
}
/**
* @return The URL of the page to be shared.
*/
public String getUrl() {
return mUrl;
}
/**
* @return The MIME type to the arbitrary files to be shared.
*/
......@@ -211,8 +222,8 @@ public class ShareParams {
mText = mUrl;
}
}
return new ShareParams(mWindow, mTitle, mText, mFileContentType, mFileUris, mOfflineUri,
mScreenshotUri, mCallback);
return new ShareParams(mWindow, mTitle, mText, mUrl, mFileContentType, mFileUris,
mOfflineUri, mScreenshotUri, mCallback);
}
}
......
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