author | Jan Henning <jh+bugzilla@buttercookie.de> |
Sat, 12 May 2018 23:17:38 +0200 | |
changeset 803596 | cffc3091e60c1c103755925afa362e542f8c84a5 |
parent 803595 | f6464ef0686ed9328c58dcc4a0852b2f6dc0ea3e |
child 803597 | ce464e1f8dfe459789161f77a13cd2840283ca5a |
push id | 112161 |
push user | mozilla@buttercookie.de |
push date | Mon, 04 Jun 2018 18:00:37 +0000 |
reviewers | jchen |
bugs | 1450449 |
milestone | 62.0a1 |
mobile/android/base/java/org/mozilla/gecko/widget/GeckoActionProvider.java | file | annotate | diff | comparison | revisions |
--- a/mobile/android/base/java/org/mozilla/gecko/widget/GeckoActionProvider.java +++ b/mobile/android/base/java/org/mozilla/gecko/widget/GeckoActionProvider.java @@ -3,19 +3,21 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package org.mozilla.gecko.widget; import android.app.Activity; import android.net.Uri; import android.support.design.widget.Snackbar; +import android.support.v4.content.FileProvider; import android.util.Base64; import android.view.Menu; +import org.mozilla.gecko.AppConstants; import org.mozilla.gecko.GeckoApp; import org.mozilla.gecko.R; import org.mozilla.gecko.SnackbarBuilder; import org.mozilla.gecko.Telemetry; import org.mozilla.gecko.TelemetryContract; import org.mozilla.gecko.overlays.ui.ShareDialog; import org.mozilla.gecko.menu.MenuItemSwitcherLayout; import org.mozilla.gecko.util.IOUtils; @@ -323,17 +325,17 @@ public class GeckoActionProvider { final File imageFile = File.createTempFile("image", "." + extension, dir); os = new FileOutputStream(imageFile); byte[] buf = Base64.decode(src.substring(dataStart + 1), Base64.DEFAULT); os.write(buf); // Only alter the intent when we're sure everything has worked - intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(imageFile)); + addFileExtra(intent, imageFile); } else { InputStream is = null; try { final byte[] buf = new byte[2048]; final URL url = new URL(src); final String filename = URLUtil.guessFileName(src, null, type); is = url.openStream(); @@ -341,20 +343,31 @@ public class GeckoActionProvider { os = new FileOutputStream(imageFile); int length; while ((length = is.read(buf)) != -1) { os.write(buf, 0, length); } // Only alter the intent when we're sure everything has worked - intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(imageFile)); + addFileExtra(intent, imageFile); } finally { IOUtils.safeStreamClose(is); } } } catch (IOException ex) { // If something went wrong, we'll just leave the intent un-changed } finally { IOUtils.safeStreamClose(os); } } + + private void addFileExtra(final Intent intent, final File file) { + if (AppConstants.Versions.preN) { + intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); + } else { + Uri contentUri = FileProvider.getUriForFile(mContext, + AppConstants.MOZ_FILE_PROVIDER_AUTHORITY, file); + intent.putExtra(Intent.EXTRA_STREAM, contentUri); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + } + } }