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

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: Adjustments according to Filip's comments Created 4 years, 4 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..d10ceb95cd4fa1fad1a2d2647eac897e6d994e89 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
@@ -180,13 +180,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 +258,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 +282,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 +297,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 +313,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 +356,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 +377,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,21 +436,29 @@ 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.addFlags(ApiCompatibilityUtils.getActivityNewDocumentFlag());
intent.setType("text/plain");
+ intent.addFlags(ApiCompatibilityUtils.getActivityNewDocumentFlag());
intent.putExtra(Intent.EXTRA_SUBJECT, title);
intent.putExtra(Intent.EXTRA_TEXT, url);
- if (screenshotUri != null) {
+
+ if (screenshotUri != null || offlineUri != 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
+ }
+ if (screenshotUri != null) {
+ // 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);
}
+ if (offlineUri != null) {
+ intent.setType("multipart/related");
+ intent.putExtra(Intent.EXTRA_STREAM, offlineUri);
+ }
return intent;
}
@@ -462,8 +472,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