Search in sources :

Example 1 with ContentBitmapCallback

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);
}
Also used : Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) ContentBitmapCallback(org.chromium.content_public.browser.ContentBitmapCallback)

Example 2 with ContentBitmapCallback

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);
    }
}
Also used : WebContents(org.chromium.content_public.browser.WebContents) Bitmap(android.graphics.Bitmap) ContentBitmapCallback(org.chromium.content_public.browser.ContentBitmapCallback) AsyncInitializationActivity(org.chromium.chrome.browser.init.AsyncInitializationActivity) PrintShareActivity(org.chromium.chrome.browser.printing.PrintShareActivity) Activity(android.app.Activity) Uri(android.net.Uri)

Aggregations

Bitmap (android.graphics.Bitmap)2 ContentBitmapCallback (org.chromium.content_public.browser.ContentBitmapCallback)2 Activity (android.app.Activity)1 Rect (android.graphics.Rect)1 Uri (android.net.Uri)1 AsyncInitializationActivity (org.chromium.chrome.browser.init.AsyncInitializationActivity)1 PrintShareActivity (org.chromium.chrome.browser.printing.PrintShareActivity)1 WebContents (org.chromium.content_public.browser.WebContents)1