org.chromium.ui.base.WindowAndroid.PermissionCallback Java Examples

The following examples show how to use org.chromium.ui.base.WindowAndroid.PermissionCallback. 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: ExternalNavigationDelegateImpl.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void startFileIntent(final Intent intent, final String referrerUrl, final Tab tab,
        final boolean needsToCloseTab) {
    PermissionCallback permissionCallback = new PermissionCallback() {
        @Override
        public void onRequestPermissionsResult(String[] permissions, int[] grantResults) {
            if (grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                loadIntent(intent, referrerUrl, null, tab, needsToCloseTab, tab.isIncognito());
            } else {
                // TODO(tedchoc): Show an indication to the user that the navigation failed
                //                instead of silently dropping it on the floor.
                if (needsToCloseTab) {
                    // If the access was not granted, then close the tab if necessary.
                    closeTab(tab);
                }
            }
        }
    };
    tab.getWindowAndroid().requestPermissions(
            new String[] {permission.WRITE_EXTERNAL_STORAGE}, permissionCallback);
}
 
Example #2
Source File: ExternalNavigationDelegateImpl.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void startFileIntent(final Intent intent, final String referrerUrl, final Tab tab,
        final boolean needsToCloseTab) {
    PermissionCallback permissionCallback = new PermissionCallback() {
        @Override
        public void onRequestPermissionsResult(String[] permissions, int[] grantResults) {
            if (grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                loadIntent(intent, referrerUrl, null, tab, needsToCloseTab, tab.isIncognito());
            } else {
                // TODO(tedchoc): Show an indication to the user that the navigation failed
                //                instead of silently dropping it on the floor.
                if (needsToCloseTab) {
                    // If the access was not granted, then close the tab if necessary.
                    closeTab(tab);
                }
            }
        }
    };
    tab.getWindowAndroid().requestPermissions(
            new String[] {permission.WRITE_EXTERNAL_STORAGE}, permissionCallback);
}
 
Example #3
Source File: ExternalNavigationDelegateImpl.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void startFileIntent(final Intent intent, final String referrerUrl, final Tab tab,
        final boolean needsToCloseTab) {
    PermissionCallback permissionCallback = new PermissionCallback() {
        @Override
        public void onRequestPermissionsResult(String[] permissions, int[] grantResults) {
            if (grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                loadIntent(intent, referrerUrl, null, tab, needsToCloseTab, tab.isIncognito());
            } else {
                // TODO(tedchoc): Show an indication to the user that the navigation failed
                //                instead of silently dropping it on the floor.
                if (needsToCloseTab) {
                    // If the access was not granted, then close the tab if necessary.
                    closeTab(tab);
                }
            }
        }
    };
    tab.getWindowAndroid().requestPermissions(
            new String[] {permission.READ_EXTERNAL_STORAGE}, permissionCallback);
}
 
Example #4
Source File: ChromeDownloadDelegate.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * For certain download types(OMA for example), android DownloadManager should
 * handle them. Call this function to intercept those downloads.
 *
 * @param url URL to be downloaded.
 * @return whether the DownloadManager should intercept the download.
 */
public boolean shouldInterceptContextMenuDownload(String url) {
    Uri uri = Uri.parse(url);
    String scheme = uri.normalizeScheme().getScheme();
    if (!"http".equals(scheme) && !"https".equals(scheme)) return false;
    String path = uri.getPath();
    // OMA downloads have extension "dm" or "dd". For the latter, it
    // can be handled when native download completes.
    if (path != null && (path.endsWith(".dm"))) {
        if (mTab == null) return true;
        String fileName = URLUtil.guessFileName(
                url, null, OMADownloadHandler.OMA_DRM_MESSAGE_MIME);
        final DownloadInfo downloadInfo =
                new DownloadInfo.Builder().setUrl(url).setFileName(fileName).build();
        WindowAndroid window = mTab.getWindowAndroid();
        if (window.hasPermission(permission.WRITE_EXTERNAL_STORAGE)) {
            onDownloadStartNoStream(downloadInfo);
        } else if (window.canRequestPermission(permission.WRITE_EXTERNAL_STORAGE)) {
            PermissionCallback permissionCallback = new PermissionCallback() {
                @Override
                public void onRequestPermissionsResult(
                        String[] permissions, int[] grantResults) {
                    if (grantResults.length > 0
                            && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                        onDownloadStartNoStream(downloadInfo);
                    }
                }
            };
            window.requestPermissions(
                    new String[] {permission.WRITE_EXTERNAL_STORAGE}, permissionCallback);
        }
        return true;
    }
    return false;
}
 
Example #5
Source File: ChromeDownloadDelegate.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * For certain download types(OMA for example), android DownloadManager should
 * handle them. Call this function to intercept those downloads.
 *
 * @param url URL to be downloaded.
 * @return whether the DownloadManager should intercept the download.
 */
public boolean shouldInterceptContextMenuDownload(String url) {
    Uri uri = Uri.parse(url);
    String scheme = uri.normalizeScheme().getScheme();
    if (!"http".equals(scheme) && !"https".equals(scheme)) return false;
    String path = uri.getPath();
    // OMA downloads have extension "dm" or "dd". For the latter, it
    // can be handled when native download completes.
    if (path == null || !path.endsWith(".dm")) return false;
    if (mTab == null) return true;
    String fileName = URLUtil.guessFileName(
            url, null, OMADownloadHandler.OMA_DRM_MESSAGE_MIME);
    final DownloadInfo downloadInfo =
            new DownloadInfo.Builder().setUrl(url).setFileName(fileName).build();
    WindowAndroid window = mTab.getWindowAndroid();
    if (window.hasPermission(permission.WRITE_EXTERNAL_STORAGE)) {
        onDownloadStartNoStream(downloadInfo);
    } else if (window.canRequestPermission(permission.WRITE_EXTERNAL_STORAGE)) {
        PermissionCallback permissionCallback = new PermissionCallback() {
            @Override
            public void onRequestPermissionsResult(
                    String[] permissions, int[] grantResults) {
                if (grantResults.length > 0
                        && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    onDownloadStartNoStream(downloadInfo);
                }
            }
        };
        window.requestPermissions(
                new String[] {permission.WRITE_EXTERNAL_STORAGE}, permissionCallback);
    }
    return true;
}
 
Example #6
Source File: ChromeDownloadDelegate.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * For certain download types(OMA for example), android DownloadManager should
 * handle them. Call this function to intercept those downloads.
 *
 * @param url URL to be downloaded.
 * @return whether the DownloadManager should intercept the download.
 */
public boolean shouldInterceptContextMenuDownload(String url) {
    Uri uri = Uri.parse(url);
    String scheme = uri.normalizeScheme().getScheme();
    if (!UrlConstants.HTTP_SCHEME.equals(scheme) && !UrlConstants.HTTPS_SCHEME.equals(scheme)) {
        return false;
    }
    String path = uri.getPath();
    if (!OMADownloadHandler.isOMAFile(path)) return false;
    if (mTab == null) return true;
    String fileName = URLUtil.guessFileName(
            url, null, OMADownloadHandler.OMA_DRM_MESSAGE_MIME);
    final DownloadInfo downloadInfo =
            new DownloadInfo.Builder().setUrl(url).setFileName(fileName).build();
    WindowAndroid window = mTab.getWindowAndroid();
    if (window.hasPermission(permission.WRITE_EXTERNAL_STORAGE)) {
        onDownloadStartNoStream(downloadInfo);
    } else if (window.canRequestPermission(permission.WRITE_EXTERNAL_STORAGE)) {
        PermissionCallback permissionCallback = new PermissionCallback() {
            @Override
            public void onRequestPermissionsResult(
                    String[] permissions, int[] grantResults) {
                if (grantResults.length > 0
                        && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    onDownloadStartNoStream(downloadInfo);
                }
            }
        };
        window.requestPermissions(
                new String[] {permission.WRITE_EXTERNAL_STORAGE}, permissionCallback);
    }
    return true;
}
 
Example #7
Source File: AndroidPermissionDelegate.java    From 365browser with Apache License 2.0 2 votes vote down vote up
/**
 * Requests the specified permissions are granted for further use.
 * @param permissions The list of permissions to request access to.
 * @param callback The callback to be notified whether the permissions were granted.
 */
void requestPermissions(String[] permissions, PermissionCallback callback);