Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(553)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/share/ShareHelper.java

Issue 2081153005: [Offline Page] Offline page sharing implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix typo Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/share/ShareHelper.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/share/ShareHelper.java b/chrome/android/java/src/org/chromium/chrome/browser/share/ShareHelper.java
index 9f0590a64eaaa24ec6345cea8b28e4da7fa34e56..7d3290d20295bd27a3694fe956c7e7ab889de35b 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/share/ShareHelper.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/share/ShareHelper.java
@@ -46,6 +46,7 @@ import org.chromium.ui.UiUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutionException;
@@ -180,13 +181,13 @@ public class ShareHelper {
* @param screenshot Screenshot of the page to be shared.
*/
public static void share(boolean shareDirectly, Activity activity, String title, String url,
- Bitmap screenshot) {
+ Uri offlineUri, Bitmap screenshot) {
if (shareDirectly) {
- shareWithLastUsed(activity, title, url, screenshot);
+ shareWithLastUsed(activity, title, url, offlineUri, screenshot);
} else if (TargetChosenReceiver.isSupported()) {
- makeIntentAndShare(activity, title, url, screenshot, null);
+ makeIntentAndShare(activity, title, url, offlineUri, screenshot, null);
} else {
- showShareDialog(activity, title, url, screenshot);
+ showShareDialog(activity, title, url, offlineUri, screenshot);
}
}
@@ -258,8 +259,8 @@ public class ShareHelper {
* @param screenshot Screenshot of the page to be shared.
*/
private static void showShareDialog(final Activity activity, final String title,
- final String url, final Bitmap screenshot) {
- Intent intent = getShareIntent(title, url, null);
+ final String url, final Uri offlineUri, final Bitmap screenshot) {
+ Intent intent = getShareIntent(title, url, null, null);
PackageManager manager = activity.getPackageManager();
List<ResolveInfo> resolveInfoList = manager.queryIntentActivities(intent, 0);
assert resolveInfoList.size() > 0;
@@ -282,7 +283,7 @@ public class ShareHelper {
ComponentName component =
new ComponentName(ai.applicationInfo.packageName, ai.name);
setLastShareComponentName(activity, component);
- makeIntentAndShare(activity, title, url, screenshot, component);
+ makeIntentAndShare(activity, title, url, offlineUri, screenshot, component);
dialog.dismiss();
}
});
@@ -297,10 +298,10 @@ public class ShareHelper {
* @param screenshot Screenshot of the page to be shared.
*/
private static void shareWithLastUsed(
- Activity activity, String title, String url, Bitmap screenshot) {
+ Activity activity, String title, String url, Uri offlineUri, Bitmap screenshot) {
ComponentName component = getLastShareComponentName(activity);
if (component == null) return;
- makeIntentAndShare(activity, title, url, screenshot, component);
+ makeIntentAndShare(activity, title, url, offlineUri, screenshot, component);
}
private static void shareIntent(Activity activity, Intent sharingIntent) {
@@ -313,9 +314,11 @@ public class ShareHelper {
}
private static void makeIntentAndShare(final Activity activity, final String title,
- final String url, final Bitmap screenshot, final ComponentName component) {
+ final String url, final Uri offlineUri, final Bitmap screenshot,
+ final ComponentName component) {
if (screenshot == null) {
- shareIntent(activity, getDirectShareIntentForComponent(title, url, null, component));
+ shareIntent(activity,
+ getDirectShareIntentForComponent(title, url, offlineUri, null, component));
} else {
new AsyncTask<Void, Void, File>() {
@Override
@@ -354,8 +357,8 @@ public class ShareHelper {
!= ApplicationState.HAS_DESTROYED_ACTIVITIES) {
Uri screenshotUri = saveFile == null
? null : UiUtils.getUriForImageCaptureFile(activity, saveFile);
- shareIntent(activity, getDirectShareIntentForComponent(
- title, url, screenshotUri, component));
+ shareIntent(activity, getDirectShareIntentForComponent(title, url,
+ offlineUri, screenshotUri, component));
}
}
}.execute();
@@ -375,7 +378,7 @@ public class ShareHelper {
final ComponentName component = getLastShareComponentName(activity);
boolean isComponentValid = false;
if (component != null) {
- Intent intent = getShareIntent("", "", null);
+ Intent intent = getShareIntent("", "", null, null);
intent.setPackage(component.getPackageName());
PackageManager manager = activity.getPackageManager();
List<ResolveInfo> resolveInfoList = manager.queryIntentActivities(intent, 0);
@@ -434,20 +437,32 @@ public class ShareHelper {
}
@VisibleForTesting
- public static Intent getShareIntent(String title, String url, Uri screenshotUri) {
+ public static Intent getShareIntent(
+ String title, String url, Uri offlineUri, Uri screenshotUri) {
url = DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl(url);
- Intent intent = new Intent(Intent.ACTION_SEND);
+ Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.addFlags(ApiCompatibilityUtils.getActivityNewDocumentFlag());
- intent.setType("text/plain");
+ if (offlineUri != null) {
+ intent.setType("multipart/related");
+ } else {
+ intent.setType("text/plain");
+ }
intent.putExtra(Intent.EXTRA_SUBJECT, title);
intent.putExtra(Intent.EXTRA_TEXT, url);
+ ArrayList<Uri> uris = new ArrayList<Uri>();
if (screenshotUri != null) {
- intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
// To give read access to an Intent target, we need to put |screenshotUri| in clipData
// because adding Intent.FLAG_GRANT_READ_URI_PERMISSION doesn't work for
// EXTRA_SHARE_SCREENSHOT_AS_STREAM.
intent.setClipData(ClipData.newRawUri("", screenshotUri));
- intent.putExtra(EXTRA_SHARE_SCREENSHOT_AS_STREAM, screenshotUri);
+ uris.add(screenshotUri);
+ }
+ if (offlineUri != null) {
+ uris.add(offlineUri);
+ }
+ if (screenshotUri != null || offlineUri != null) {
+ intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
}
return intent;
}
@@ -462,8 +477,8 @@ public class ShareHelper {
}
private static Intent getDirectShareIntentForComponent(
- String title, String url, Uri screenshotUri, ComponentName component) {
- Intent intent = getShareIntent(title, url, screenshotUri);
+ String title, String url, Uri offlineUri, Uri screenshotUri, ComponentName component) {
+ Intent intent = getShareIntent(title, url, offlineUri, screenshotUri);
intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT
| Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
intent.setComponent(component);

Powered by Google App Engine
This is Rietveld 408576698