Search in sources :

Example 1 with WindowAndroid

use of org.chromium.ui.base.WindowAndroid in project AndroidChromium by JackyAndroid.

the class LocationSettings method canSitesRequestLocationPermission.

@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);
}
Also used : LocationUtils(org.chromium.components.location.LocationUtils) ContentViewCore(org.chromium.content.browser.ContentViewCore) WindowAndroid(org.chromium.ui.base.WindowAndroid) CalledByNative(org.chromium.base.annotations.CalledByNative)

Example 2 with WindowAndroid

use of org.chromium.ui.base.WindowAndroid in project AndroidChromium by JackyAndroid.

the class PermissionUpdateInfoBarDelegate method requestPermissions.

@CalledByNative
private void requestPermissions() {
    WindowAndroid windowAndroid = mContentViewCore.getWindowAndroid();
    if (windowAndroid == null) {
        nativeOnPermissionResult(mNativePtr, false);
        return;
    }
    boolean canRequestAllPermissions = true;
    for (int i = 0; i < mAndroidPermisisons.length; i++) {
        canRequestAllPermissions &= (windowAndroid.hasPermission(mAndroidPermisisons[i]) || windowAndroid.canRequestPermission(mAndroidPermisisons[i]));
    }
    if (canRequestAllPermissions) {
        windowAndroid.requestPermissions(mAndroidPermisisons, this);
    } else {
        Activity activity = windowAndroid.getActivity().get();
        if (activity == null) {
            nativeOnPermissionResult(mNativePtr, false);
            return;
        }
        mActivityStateListener = new ActivityStateListener() {

            @Override
            public void onActivityStateChange(Activity activity, int newState) {
                if (newState == ActivityState.DESTROYED) {
                    ApplicationStatus.unregisterActivityStateListener(this);
                    mActivityStateListener = null;
                    nativeOnPermissionResult(mNativePtr, false);
                } else if (newState == ActivityState.RESUMED) {
                    ApplicationStatus.unregisterActivityStateListener(this);
                    mActivityStateListener = null;
                    notifyPermissionResult();
                }
            }
        };
        ApplicationStatus.registerStateListenerForActivity(mActivityStateListener, activity);
        Intent settingsIntent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        settingsIntent.setData(Uri.parse("package:" + windowAndroid.getApplicationContext().getPackageName()));
        settingsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        activity.startActivity(settingsIntent);
    }
}
Also used : ActivityStateListener(org.chromium.base.ApplicationStatus.ActivityStateListener) Activity(android.app.Activity) Intent(android.content.Intent) WindowAndroid(org.chromium.ui.base.WindowAndroid) CalledByNative(org.chromium.base.annotations.CalledByNative)

Example 3 with WindowAndroid

use of org.chromium.ui.base.WindowAndroid in project AndroidChromium by JackyAndroid.

the class DomDistillerUIUtils method getActivityFromWebContents.

/**
     * @param webContents The WebContents to get the Activity from.
     * @return The Activity associated with the WebContents.
     */
private static Activity getActivityFromWebContents(WebContents webContents) {
    if (webContents == null)
        return null;
    ContentViewCore contentView = ContentViewCore.fromWebContents(webContents);
    if (contentView == null)
        return null;
    WindowAndroid window = contentView.getWindowAndroid();
    if (window == null)
        return null;
    return window.getActivity().get();
}
Also used : ContentViewCore(org.chromium.content.browser.ContentViewCore) WindowAndroid(org.chromium.ui.base.WindowAndroid)

Example 4 with WindowAndroid

use of org.chromium.ui.base.WindowAndroid in project AndroidChromium by JackyAndroid.

the class ChromeDownloadDelegate method shouldInterceptContextMenuDownload.

/**
     * 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();
    // 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;
}
Also used : PermissionCallback(org.chromium.ui.base.WindowAndroid.PermissionCallback) Uri(android.net.Uri) WindowAndroid(org.chromium.ui.base.WindowAndroid)

Example 5 with WindowAndroid

use of org.chromium.ui.base.WindowAndroid in project AndroidChromium by JackyAndroid.

the class PermissionUpdateInfoBarDelegate method notifyPermissionResult.

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);
}
Also used : WindowAndroid(org.chromium.ui.base.WindowAndroid)

Aggregations

WindowAndroid (org.chromium.ui.base.WindowAndroid)8 ContentViewCore (org.chromium.content.browser.ContentViewCore)4 Activity (android.app.Activity)2 Intent (android.content.Intent)2 CalledByNative (org.chromium.base.annotations.CalledByNative)2 ContentResolver (android.content.ContentResolver)1 PackageManager (android.content.pm.PackageManager)1 Uri (android.net.Uri)1 Nullable (android.support.annotation.Nullable)1 ActivityStateListener (org.chromium.base.ApplicationStatus.ActivityStateListener)1 InstallerDelegate (org.chromium.chrome.browser.banners.InstallerDelegate)1 LocationUtils (org.chromium.components.location.LocationUtils)1 PermissionCallback (org.chromium.ui.base.WindowAndroid.PermissionCallback)1