Commit 9603793b authored by Pete Williamson's avatar Pete Williamson Committed by Commit Bot

Fix crash that can occur when sharing temporary offline pages

Sometimes when sharing temporary offline pages, we fail to create the
content URI.  If we do, fall back to sharing by URL with the URL of the page.

Bug: 871697
Change-Id: Ie2e895fd708fdf4e5e992ebc2317ee49fd5bcee3
Reviewed-on: https://chromium-review.googlesource.com/1168587Reviewed-by: default avatarYafei Duan <romax@chromium.org>
Commit-Queue: Peter Williamson <petewil@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582389}
parent fff9a68b
......@@ -399,6 +399,8 @@ public class OfflinePageUtils {
if (webContents == null) return false;
OfflinePageItem offlinePage = offlinePageBridge.getOfflinePage(webContents);
if (offlinePage == null) return false;
String offlinePath = offlinePage.getFilePath();
final String pageUrl = tab.getUrl();
......@@ -407,9 +409,16 @@ public class OfflinePageUtils {
Uri uri;
boolean isPageUserRequested = offlinePageBridge.isUserRequestedDownloadNamespace(
offlinePage.getClientId().getNamespace());
if (!isPageUserRequested) {
File file = new File(offlinePage.getFilePath());
uri = (new FileProviderHelper()).getContentUriFromFile(file);
// Ensure that we have a file path that is longer than just "/".
if (!isPageUserRequested && offlinePath.length() > 1) {
File file = new File(offlinePath);
// We might get an exception if chrome does not have sharing roots configured. If so,
// just share by URL of the original page instead of sharing the offline page.
try {
uri = (new FileProviderHelper()).getContentUriFromFile(file);
} catch (Exception e) {
uri = Uri.parse(pageUrl);
}
} else {
uri = Uri.parse(pageUrl);
}
......
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