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

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

Issue 2143133002: Do screenshot capture async for share intents. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix packagename Created 4 years, 5 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/ChromeActivity.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ChromeActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/ChromeActivity.java
index 8d95ad3e75f9c5cde4349f2a6334b641040fcf05..e8e03b1127d0a602744c381f9d1df9c25fda5256 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ChromeActivity.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ChromeActivity.java
@@ -18,6 +18,7 @@ import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
+import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Looper;
@@ -123,7 +124,6 @@ import org.chromium.content.common.ContentSwitches;
import org.chromium.content_public.browser.ContentBitmapCallback;
import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.content_public.browser.WebContents;
-import org.chromium.content_public.browser.readback_types.ReadbackResponse;
import org.chromium.policy.CombinedPolicyProvider.PolicyChangeListener;
import org.chromium.printing.PrintManagerDelegateImpl;
import org.chromium.printing.PrintingController;
@@ -959,32 +959,42 @@ public abstract class ChromeActivity extends AsyncInitializationActivity
if (currentTab == null) return;
final Activity mainActivity = this;
- ContentBitmapCallback callback = new ContentBitmapCallback() {
- @Override
- public void onFinishGetBitmap(Bitmap bitmap, int response) {
- // Check whether this page is an offline page, and use its online URL if so.
- String url = currentTab.getOfflinePageOriginalUrl();
- RecordHistogram.recordBooleanHistogram(
- "OfflinePages.SharedPageWasOffline", url != null);
-
- // If there is no entry in the offline pages DB for this tab, use the tab's
- // URL directly.
- if (url == null) url = currentTab.getUrl();
-
- ShareHelper.share(
- shareDirectly, mainActivity, currentTab.getTitle(), url, bitmap);
- if (shareDirectly) {
- RecordUserAction.record("MobileMenuDirectShare");
- } else {
- RecordUserAction.record("MobileMenuShare");
- }
- }
- };
+
+ // Check whether this page is an offline page, and use its online URL if so.
+ String url = currentTab.getOfflinePageOriginalUrl();
+ RecordHistogram.recordBooleanHistogram("OfflinePages.SharedPageWasOffline", url != null);
+ // If there is no entry in the offline pages DB for this tab, use the tab's URL directly.
+ if (url == null) url = currentTab.getUrl();
+
+ if (shareDirectly) {
+ RecordUserAction.record("MobileMenuDirectShare");
+ } else {
+ RecordUserAction.record("MobileMenuShare");
+ }
+
if (isIncognito || currentTab.getWebContents() == null) {
- callback.onFinishGetBitmap(null, ReadbackResponse.SURFACE_UNAVAILABLE);
+ ShareHelper.share(shareDirectly, mainActivity, currentTab.getTitle(), url, null);
} else {
- currentTab.getWebContents().getContentBitmapAsync(
- Bitmap.Config.ARGB_8888, 1.f, EMPTY_RECT, callback);
+ // Share an empty uuid in place of screenshot file.
+ final String fileName = String.valueOf(System.currentTimeMillis());
nyquist 2016/07/14 17:36:32 Will the user ever see this filename? If not, mayb
ssid 2016/07/19 18:32:57 The uri wouldn't overlap with anything because the
nyquist 2016/07/29 23:45:27 That'd be OK too. I was just thinking about if you
ssid 2016/08/03 22:33:40 The description says it returns the difference bet
+ final Uri uuid = BlockingFileProvider.getContentUriForFile(mainActivity, fileName);
+ ShareHelper.share(shareDirectly, mainActivity, currentTab.getTitle(), url, uuid);
+
+ // Start screenshot capture async and notify the provider when it is ready.
+ final ContentBitmapCallback callback = new ContentBitmapCallback() {
+ @Override
+ public void onFinishGetBitmap(Bitmap bitmap, int response) {
+ ShareHelper.onScreenshotReady(fileName, bitmap, mainActivity);
nyquist 2016/07/14 17:36:32 Is mainActivity guaranteed to be alive here, or wi
ssid 2016/07/19 18:32:57 The check at the end of onScreenshotready should t
+ }
+ };
+ new AsyncTask<Void, Void, Void>() {
+ @Override
+ protected Void doInBackground(Void... params) {
+ currentTab.getWebContents().getContentBitmapAsync(
nyquist 2016/07/14 17:36:32 Is it guaranteed that getWebContents() does not re
ssid 2016/07/19 18:32:57 added a check
+ Bitmap.Config.ARGB_8888, 1.f, EMPTY_RECT, callback);
+ return null;
+ }
+ }.execute();
}
}

Powered by Google App Engine
This is Rietveld 408576698