Chromium Code Reviews| 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 912d08b443d07e1f35a621605bf54fe1dd90a739..a510dca1359603635f263f9427b7fccfeffcbc65 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/ChromeActivity.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/ChromeActivity.java |
| @@ -241,6 +241,9 @@ public abstract class ChromeActivity extends AsyncInitializationActivity |
| // Chrome delegate that includes functionalities needed by Blimp client. |
| private ChromeBlimpClientContextDelegate mBlimpClientContextDelegate; |
| + // Skips capturing screenshot for testing purpose. |
| + private boolean mScreenshotCaptureSkippedForTesting; |
| + |
| /** |
| * @param The {@link AppMenuHandlerFactory} for creating {@link mAppMenuHandler} |
| */ |
| @@ -993,6 +996,11 @@ public abstract class ChromeActivity extends AsyncInitializationActivity |
| return super.onOptionsItemSelected(item); |
| } |
| + @VisibleForTesting |
| + public void setScreenshotCaptureSkippedForTesting(boolean value) { |
| + mScreenshotCaptureSkippedForTesting = value; |
| + } |
| + |
| /** |
| * Triggered when the share menu item is selected. |
| * This creates and shows a share intent picker dialog or starts a share intent directly. |
| @@ -1000,6 +1008,7 @@ public abstract class ChromeActivity extends AsyncInitializationActivity |
| * recently used to share. |
| * @param isIncognito Whether currentTab is incognito. |
| */ |
| + @VisibleForTesting |
| public void onShareMenuItemSelected(final boolean shareDirectly, final boolean isIncognito) { |
| final Tab currentTab = getActivityTab(); |
| if (currentTab == null) return; |
| @@ -1022,37 +1031,50 @@ public abstract class ChromeActivity extends AsyncInitializationActivity |
| private void triggerShare( |
| final Tab currentTab, final boolean shareDirectly, boolean isIncognito) { |
| final Activity mainActivity = this; |
| + |
| + // Check whether this page is an offline page, and use its online URL if so. |
| + OfflinePageItem offlinePage = currentTab.getOfflinePage(); |
| + String onlineUrl = currentTab.getOriginalUrl(); |
| + RecordHistogram.recordBooleanHistogram( |
| + "OfflinePages.SharedPageWasOffline", offlinePage != null); |
| + boolean canShareOfflinePage = OfflinePageBridge.isPageSharingEnabled(); |
| + // If there is no entry in the offline pages DB for this tab, use the tab's URL directly. |
| + WebContents webContents = currentTab.getWebContents(); |
| + if (isIncognito || webContents == null) { |
| + ShareHelper.share(shareDirectly, true, mainActivity, currentTab.getTitle(), null, |
| + onlineUrl, null, null, null); |
| + return; |
| + } |
| + |
| + // Share an empty uuidUri in place of screenshot file. The file ready notification is sent |
| + // by onScreenshotReady call below when the file is written. |
| + final Uri uuidUri = BlockingFileProvider.generateUriAndBlockAccess(mainActivity); |
| + if (canShareOfflinePage) { |
|
Ted C
2016/08/27 00:22:12
we were previously running this code if "(isIncogn
ssid
2016/09/06 22:25:36
Done.
|
| + // Share the offline page instead of the URL. |
| + boolean isOfflinePage = (offlinePage != null); |
| + OfflinePageUtils.shareOfflinePage(shareDirectly, true, mainActivity, null, onlineUrl, |
| + uuidUri, null, currentTab, isOfflinePage); |
| + } else { |
| + ShareHelper.share(shareDirectly, true, mainActivity, currentTab.getTitle(), null, |
| + onlineUrl, null, uuidUri, null); |
| + if (shareDirectly) { |
| + RecordUserAction.record("MobileMenuDirectShare"); |
| + } else { |
| + RecordUserAction.record("MobileMenuShare"); |
| + } |
| + } |
| + |
| + // Start screenshot capture and notify the provider when it is ready. |
| 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. |
| - OfflinePageItem offlinePage = currentTab.getOfflinePage(); |
| - String onlineUrl = currentTab.getOriginalUrl(); |
| - RecordHistogram.recordBooleanHistogram( |
| - "OfflinePages.SharedPageWasOffline", offlinePage != null); |
| - boolean canShareOfflinePage = OfflinePageBridge.isPageSharingEnabled(); |
| - |
| - if (canShareOfflinePage) { |
| - // Share the offline page instead of the URL. |
| - boolean isOfflinePage = (offlinePage != null); |
| - OfflinePageUtils.shareOfflinePage(shareDirectly, true, mainActivity, null, |
| - onlineUrl, bitmap, null, currentTab, isOfflinePage); |
| - } else { |
| - ShareHelper.share(shareDirectly, true, mainActivity, currentTab.getTitle(), |
| - null, onlineUrl, null, bitmap, null); |
| - if (shareDirectly) { |
| - RecordUserAction.record("MobileMenuDirectShare"); |
| - } else { |
| - RecordUserAction.record("MobileMenuShare"); |
| - } |
| - } |
| + ShareHelper.onScreenshotReady(uuidUri, bitmap, mainActivity); |
| } |
| }; |
| - if (isIncognito || currentTab.getWebContents() == null) { |
| - callback.onFinishGetBitmap(null, ReadbackResponse.SURFACE_UNAVAILABLE); |
| + if (!mScreenshotCaptureSkippedForTesting) { |
| + webContents.getContentBitmapAsync(Bitmap.Config.ARGB_8888, 1.f, EMPTY_RECT, callback); |
| } else { |
| - currentTab.getWebContents().getContentBitmapAsync( |
| - Bitmap.Config.ARGB_8888, 1.f, EMPTY_RECT, callback); |
| + callback.onFinishGetBitmap(null, ReadbackResponse.SURFACE_UNAVAILABLE); |
| } |
| } |