Java Code Examples for org.chromium.chrome.browser.offlinepages.OfflinePageBridge#isPageSharingEnabled()

The following examples show how to use org.chromium.chrome.browser.offlinepages.OfflinePageBridge#isPageSharingEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChromeActivity.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
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);
    }
}
 
Example 2
Source File: ChromeActivity.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private void triggerShare(
        final Tab currentTab, final boolean shareDirectly, boolean isIncognito) {
    final Activity mainActivity = this;
    WebContents webContents = currentTab.getWebContents();

    RecordHistogram.recordBooleanHistogram(
            "OfflinePages.SharedPageWasOffline", OfflinePageUtils.isOfflinePage(currentTab));
    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) {
        callback.onFinishGetBitmap(null, ReadbackResponse.SURFACE_UNAVAILABLE);
    } else {
        webContents.getContentBitmapAsync(0, 0, callback);
    }
}