use of org.chromium.content_public.browser.ContentBitmapCallback in project AndroidChromium by JackyAndroid.
the class CustomTabObserver method captureNavigationInfo.
private void captureNavigationInfo(final Tab tab) {
if (mCustomTabsConnection == null)
return;
if (!mCustomTabsConnection.shouldSendNavigationInfoForSession(mSession))
return;
final ContentBitmapCallback callback = new ContentBitmapCallback() {
@Override
public void onFinishGetBitmap(Bitmap bitmap, int response) {
if (TextUtils.isEmpty(tab.getTitle()) && bitmap == null)
return;
mCustomTabsConnection.sendNavigationInfo(mSession, tab.getUrl(), tab.getTitle(), bitmap);
}
};
// Delay screenshot capture since the page might be doing post load tasks. And this also
// gives time to get rid of any redirects and avoid capturing screenshots for those.
ThreadUtils.postOnUiThreadDelayed(new Runnable() {
@Override
public void run() {
if (!tab.isHidden() && mCurrentState != STATE_RESET)
return;
if (tab.getWebContents() == null)
return;
tab.getWebContents().getContentBitmapAsync(Bitmap.Config.ARGB_8888, mScaleForNavigationInfo, new Rect(), callback);
mScreenshotTakenForCurrentNavigation = true;
}
}, 1000);
}
use of org.chromium.content_public.browser.ContentBitmapCallback in project AndroidChromium by JackyAndroid.
the class ChromeActivity method triggerShare.
private void triggerShare(final Tab currentTab, final boolean shareDirectly, boolean isIncognito) {
final Activity mainActivity = this;
WebContents webContents = currentTab.getWebContents();
RecordHistogram.recordBooleanHistogram("OfflinePages.SharedPageWasOffline", currentTab.isOfflinePage());
boolean canShareOfflinePage = OfflinePageBridge.isPageSharingEnabled();
// Share an empty blockingUri in place of screenshot file. The file ready notification is
// sent by onScreenshotReady call below when the file is written.
final Uri blockingUri = (isIncognito || webContents == null) ? null : ChromeFileProvider.generateUriAndBlockAccess(mainActivity);
if (canShareOfflinePage) {
OfflinePageUtils.shareOfflinePage(shareDirectly, true, mainActivity, null, blockingUri, null, currentTab);
} else {
ShareHelper.share(shareDirectly, true, mainActivity, currentTab.getTitle(), null, currentTab.getUrl(), null, blockingUri, null);
if (shareDirectly) {
RecordUserAction.record("MobileMenuDirectShare");
} else {
RecordUserAction.record("MobileMenuShare");
}
}
if (blockingUri == null)
return;
// Start screenshot capture and notify the provider when it is ready.
ContentBitmapCallback callback = new ContentBitmapCallback() {
@Override
public void onFinishGetBitmap(Bitmap bitmap, int response) {
ShareHelper.saveScreenshotToDisk(bitmap, mainActivity, new Callback<Uri>() {
@Override
public void onResult(Uri result) {
// Unblock the file once it is saved to disk.
ChromeFileProvider.notifyFileReady(blockingUri, result);
}
});
}
};
if (!mScreenshotCaptureSkippedForTesting) {
webContents.getContentBitmapAsync(Bitmap.Config.ARGB_8888, 1.f, EMPTY_RECT, callback);
} else {
callback.onFinishGetBitmap(null, ReadbackResponse.SURFACE_UNAVAILABLE);
}
}
Aggregations