Java Code Examples for org.chromium.ui.base.WindowAndroid#hasPermission()

The following examples show how to use org.chromium.ui.base.WindowAndroid#hasPermission() . 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: AndroidPermissionRequester.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private static SparseArray<String[]> generatePermissionsMapping(
        WindowAndroid windowAndroid, int[] contentSettingsTypes) {
    SparseArray<String[]> permissionsToRequest = new SparseArray<>();
    for (int i = 0; i < contentSettingsTypes.length; i++) {
        String[] permissions = PrefServiceBridge.getAndroidPermissionsForContentSetting(
                contentSettingsTypes[i]);
        if (permissions == null) continue;
        List<String> missingPermissions = new ArrayList<>();
        for (int j = 0; j < permissions.length; j++) {
            String permission = permissions[j];
            if (!windowAndroid.hasPermission(permission)) missingPermissions.add(permission);
        }
        if (!missingPermissions.isEmpty()) {
            permissionsToRequest.append(contentSettingsTypes[i],
                    missingPermissions.toArray(new String[missingPermissions.size()]));
        }
    }
    return permissionsToRequest;
}
 
Example 2
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 3
Source File: AndroidPermissionRequester.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private static SparseArray<String> generatePermissionsMapping(
        WindowAndroid windowAndroid, int[] contentSettingsTypes) {
    SparseArray<String> permissionsToRequest = new SparseArray<String>();
    for (int i = 0; i < contentSettingsTypes.length; i++) {
        String permission = PrefServiceBridge.getAndroidPermissionForContentSetting(
                contentSettingsTypes[i]);
        if (permission != null && !windowAndroid.hasPermission(permission)) {
            permissionsToRequest.append(contentSettingsTypes[i], permission);
        }
    }
    return permissionsToRequest;
}
 
Example 4
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 5
Source File: PermissionUpdateInfoBarDelegate.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private void notifyPermissionResult() {
    boolean hasAllPermissions = true;
    WindowAndroid windowAndroid = mContentViewCore.getWindowAndroid();
    if (windowAndroid == null) {
        hasAllPermissions = false;
    } else {
        for (int i = 0; i < mAndroidPermisisons.length; i++) {
            hasAllPermissions &= windowAndroid.hasPermission(mAndroidPermisisons[i]);
        }
    }
    if (mNativePtr != 0) nativeOnPermissionResult(mNativePtr, hasAllPermissions);
}
 
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: PermissionUpdateInfoBarDelegate.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void notifyPermissionResult() {
    boolean hasAllPermissions = true;
    WindowAndroid windowAndroid = mContentViewCore.getWindowAndroid();
    if (windowAndroid == null) {
        hasAllPermissions = false;
    } else {
        for (int i = 0; i < mAndroidPermisisons.length; i++) {
            hasAllPermissions &= windowAndroid.hasPermission(mAndroidPermisisons[i]);
        }
    }
    if (mNativePtr != 0) nativeOnPermissionResult(mNativePtr, hasAllPermissions);
}
 
Example 8
Source File: DownloadController.java    From delion with Apache License 2.0 2 votes vote down vote up
/**
 * Returns whether file access is allowed.
 *
 * @param windowAndroid WindowAndroid to access file system.
 * @return true if allowed, or false otherwise.
 */
@CalledByNative
private boolean hasFileAccess(WindowAndroid windowAndroid) {
    return windowAndroid.hasPermission(permission.WRITE_EXTERNAL_STORAGE);
}
 
Example 9
Source File: DownloadController.java    From AndroidChromium with Apache License 2.0 2 votes vote down vote up
/**
 * Returns whether file access is allowed.
 *
 * @param windowAndroid WindowAndroid to access file system.
 * @return true if allowed, or false otherwise.
 */
@CalledByNative
private boolean hasFileAccess(WindowAndroid windowAndroid) {
    return windowAndroid.hasPermission(permission.WRITE_EXTERNAL_STORAGE);
}