Chromium Code Reviews| 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 5fcad3e7556c5490d9826ae85f0434bf5c183333..d840e46965e9acddc3540104d311f27488330282 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 |
| @@ -17,6 +17,7 @@ import android.content.pm.PackageManager.NameNotFoundException; |
| import android.content.pm.ResolveInfo; |
| import android.graphics.Bitmap; |
| import android.graphics.drawable.Drawable; |
| +import android.net.Uri; |
| import android.os.AsyncTask; |
| import android.preference.PreferenceManager; |
| import android.util.Log; |
| @@ -48,6 +49,7 @@ public class ShareHelper { |
| private static final String PACKAGE_NAME_KEY = "last_shared_package_name"; |
| private static final String CLASS_NAME_KEY = "last_shared_class_name"; |
| + private static final String EXTRA_RAW_FILE_PATH = "raw-file-path"; |
|
Ted C
2015/03/04 00:43:35
unused?
Jaekyun Seok (inactive)
2015/03/04 00:48:13
Done.
|
| /** |
| * Directory name for screenshots. |
| @@ -119,7 +121,7 @@ public class ShareHelper { |
| */ |
| private static void showShareDialog(final Activity activity, final String title, |
| final String url, final Bitmap screenshot) { |
| - Intent intent = getShareIntent(activity, title, url, null); |
| + Intent intent = getShareIntent(title, url, null); |
| PackageManager manager = activity.getPackageManager(); |
| List<ResolveInfo> resolveInfoList = manager.queryIntentActivities(intent, 0); |
| assert resolveInfoList.size() > 0; |
| @@ -166,21 +168,46 @@ public class ShareHelper { |
| private static void makeIntentAndShare(final Activity activity, final String title, |
| final String url, final Bitmap screenshot, final ComponentName component) { |
| if (screenshot == null) { |
| - activity.startActivity( |
| - getDirectShareIntentForComponent(activity, title, url, null, component)); |
| + activity.startActivity(getDirectShareIntentForComponent(title, url, null, component)); |
| } else { |
| - new AsyncTask<Void, Void, Intent>() { |
| + new AsyncTask<Void, Void, File>() { |
| @Override |
| - protected Intent doInBackground(Void... params) { |
| - return getDirectShareIntentForComponent( |
| - activity, title, url, screenshot, component); |
| + protected File doInBackground(Void... params) { |
| + FileOutputStream fOut = null; |
| + try { |
| + File path = new File(UiUtils.getDirectoryForImageCapture(activity), |
| + SCREENSHOT_DIRECTORY_NAME); |
| + if (path.exists() || path.mkdir()) { |
| + File saveFile = File.createTempFile( |
| + String.valueOf(System.currentTimeMillis()), ".jpg", path); |
| + fOut = new FileOutputStream(saveFile); |
| + screenshot.compress(Bitmap.CompressFormat.JPEG, 85, fOut); |
| + fOut.flush(); |
| + fOut.close(); |
| + |
| + return saveFile; |
| + } |
| + } catch (IOException ie) { |
| + if (fOut != null) { |
| + try { |
| + fOut.close(); |
| + } catch (IOException e) { |
| + // Ignore exception. |
| + } |
| + } |
| + } |
| + |
| + return null; |
| } |
| @Override |
| - protected void onPostExecute(Intent intent) { |
| + protected void onPostExecute(File saveFile) { |
| if (ApplicationStatus.getStateForApplication() |
| != ApplicationState.HAS_DESTROYED_ACTIVITIES) { |
| - activity.startActivity(intent); |
| + Uri screenshotUri = saveFile == null |
| + ? null : UiUtils.getUriForImageCaptureFile(activity, saveFile); |
| + activity.startActivity(getDirectShareIntentForComponent( |
| + title, url, screenshotUri, component)); |
| } |
| } |
| }.execute(); |
| @@ -217,47 +244,20 @@ public class ShareHelper { |
| } |
| @VisibleForTesting |
| - public static Intent getShareIntent( |
| - Context context, String title, String url, Bitmap screenshot) { |
| + public static Intent getShareIntent(String title, String url, Uri screenshotUri) { |
| url = DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl(url); |
| Intent intent = new Intent(Intent.ACTION_SEND); |
| intent.addFlags(ApiCompatibilityUtils.getActivityNewDocumentFlag()); |
| intent.setType("text/plain"); |
| intent.putExtra(Intent.EXTRA_SUBJECT, title); |
| intent.putExtra(Intent.EXTRA_TEXT, url); |
| - if (screenshot != null) { |
| - FileOutputStream fOut = null; |
| - try { |
| - File path = new File( |
| - UiUtils.getDirectoryForImageCapture(context), SCREENSHOT_DIRECTORY_NAME); |
| - if (path.exists() || path.mkdir()) { |
| - File saveFile = File.createTempFile( |
| - String.valueOf(System.currentTimeMillis()), ".jpg", path); |
| - fOut = new FileOutputStream(saveFile); |
| - screenshot.compress(Bitmap.CompressFormat.JPEG, 85, fOut); |
| - fOut.flush(); |
| - fOut.close(); |
| - |
| - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
| - intent.putExtra(Intent.EXTRA_STREAM, |
| - UiUtils.getUriForImageCaptureFile(context, saveFile)); |
| - } |
| - } catch (IOException ie) { |
| - if (fOut != null) { |
| - try { |
| - fOut.close(); |
| - } catch (IOException e) { |
| - // Ignore exception. |
| - } |
| - } |
| - } |
| - } |
| + if (screenshotUri != null) intent.putExtra(Intent.EXTRA_STREAM, screenshotUri); |
| return intent; |
| } |
| private static Intent getDirectShareIntentForComponent( |
| - Context context, String title, String url, Bitmap screenshot, ComponentName component) { |
| - Intent intent = getShareIntent(context, title, url, screenshot); |
| + String title, String url, Uri screenshotUri, ComponentName component) { |
| + Intent intent = getShareIntent(title, url, screenshotUri); |
| intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT |
| | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP); |
| intent.setComponent(component); |