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

The following examples show how to use org.chromium.ui.base.WindowAndroid#canRequestPermission() . 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: BluetoothChooserDialog.java    From delion with Apache License 2.0 6 votes vote down vote up
@CalledByNative
private static BluetoothChooserDialog create(WindowAndroid windowAndroid, String origin,
        int securityLevel, long nativeBluetoothChooserDialogPtr) {
    if (!LocationUtils.getInstance().hasAndroidLocationPermission(
                windowAndroid.getActivity().get())
            && !windowAndroid.canRequestPermission(
                       Manifest.permission.ACCESS_COARSE_LOCATION)) {
        // If we can't even ask for enough permission to scan for Bluetooth devices, don't open
        // the dialog.
        return null;
    }
    BluetoothChooserDialog dialog = new BluetoothChooserDialog(
            windowAndroid, origin, securityLevel, nativeBluetoothChooserDialogPtr);
    dialog.show();
    return dialog;
}
 
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: LocationSettings.java    From delion with Apache License 2.0 5 votes vote down vote up
@CalledByNative
private static boolean canSitesRequestLocationPermission(WebContents webContents) {
    ContentViewCore cvc = ContentViewCore.fromWebContents(webContents);
    if (cvc == null) return false;
    WindowAndroid windowAndroid = cvc.getWindowAndroid();
    if (windowAndroid == null) return false;
    Context context = windowAndroid.getApplicationContext();

    LocationUtils locationUtils = LocationUtils.getInstance();
    if (!locationUtils.isSystemLocationSettingEnabled(context)) return false;

    return locationUtils.hasAndroidLocationPermission(context)
            || windowAndroid.canRequestPermission(Manifest.permission.ACCESS_FINE_LOCATION);
}
 
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: BluetoothChooserDialog.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@CalledByNative
private static BluetoothChooserDialog create(WindowAndroid windowAndroid, String origin,
        int securityLevel, long nativeBluetoothChooserDialogPtr) {
    if (!LocationUtils.getInstance().hasAndroidLocationPermission()
            && !windowAndroid.canRequestPermission(
                       Manifest.permission.ACCESS_COARSE_LOCATION)) {
        // If we can't even ask for enough permission to scan for Bluetooth devices, don't open
        // the dialog.
        return null;
    }
    BluetoothChooserDialog dialog = new BluetoothChooserDialog(
            windowAndroid, origin, securityLevel, nativeBluetoothChooserDialogPtr);
    dialog.show();
    return dialog;
}
 
Example 6
Source File: LocationSettings.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@CalledByNative
private static boolean canSitesRequestLocationPermission(WebContents webContents) {
    ContentViewCore cvc = ContentViewCore.fromWebContents(webContents);
    if (cvc == null) return false;
    WindowAndroid windowAndroid = cvc.getWindowAndroid();
    if (windowAndroid == null) return false;

    LocationUtils locationUtils = LocationUtils.getInstance();
    if (!locationUtils.isSystemLocationSettingEnabled()) return false;

    return locationUtils.hasAndroidLocationPermission()
            || windowAndroid.canRequestPermission(Manifest.permission.ACCESS_FINE_LOCATION);
}
 
Example 7
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 8
Source File: BluetoothChooserDialog.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@CalledByNative
private static BluetoothChooserDialog create(WindowAndroid windowAndroid, String origin,
        int securityLevel, long nativeBluetoothChooserDialogPtr) {
    if (!LocationUtils.getInstance().hasAndroidLocationPermission()
            && !windowAndroid.canRequestPermission(
                       Manifest.permission.ACCESS_COARSE_LOCATION)) {
        // If we can't even ask for enough permission to scan for Bluetooth devices, don't open
        // the dialog.
        return null;
    }
    BluetoothChooserDialog dialog = new BluetoothChooserDialog(
            windowAndroid, origin, securityLevel, nativeBluetoothChooserDialogPtr);
    dialog.show();
    return dialog;
}
 
Example 9
Source File: LocationSettings.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@CalledByNative
private static boolean canPromptForAndroidLocationPermission(WebContents webContents) {
    WindowAndroid windowAndroid = webContents.getTopLevelNativeWindow();
    if (windowAndroid == null) return false;

    return windowAndroid.canRequestPermission(Manifest.permission.ACCESS_FINE_LOCATION);
}