Search in sources :

Example 1 with PermissionCallback

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

the class WebsiteSettingsPopup method onClick.

@Override
public void onClick(View view) {
    if (view == mSiteSettingsButton) {
        // Delay while the WebsiteSettingsPopup closes.
        runAfterDismiss(new Runnable() {

            @Override
            public void run() {
                recordAction(WebsiteSettingsAction.WEBSITE_SETTINGS_SITE_SETTINGS_OPENED);
                Bundle fragmentArguments = SingleWebsitePreferences.createFragmentArgsForSite(mFullUrl);
                fragmentArguments.putParcelable(SingleWebsitePreferences.EXTRA_WEB_CONTENTS, mWebContents);
                Intent preferencesIntent = PreferencesLauncher.createIntentForSettingsPage(mContext, SingleWebsitePreferences.class.getName());
                preferencesIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArguments);
                mContext.startActivity(preferencesIntent);
            }
        });
    } else if (view == mInstantAppButton) {
        try {
            mContext.startActivity(mInstantAppIntent);
            RecordUserAction.record("Android.InstantApps.LaunchedFromWebsiteSettingsPopup");
        } catch (ActivityNotFoundException e) {
            mInstantAppButton.setEnabled(false);
        }
    } else if (view == mUrlTitle) {
        // Expand/collapse the displayed URL title.
        mUrlTitle.toggleTruncation();
    } else if (view == mUrlConnectionMessage) {
        runAfterDismiss(new Runnable() {

            @Override
            public void run() {
                if (!mWebContents.isDestroyed()) {
                    recordAction(WebsiteSettingsAction.WEBSITE_SETTINGS_SECURITY_DETAILS_OPENED);
                    ConnectionInfoPopup.show(mContext, mWebContents);
                }
            }
        });
    } else if (view.getId() == R.id.website_settings_permission_row) {
        final Object intentOverride = view.getTag(R.id.permission_intent_override);
        if (intentOverride == null && mWindowAndroid != null) {
            // Try and immediately request missing Android permissions where possible.
            final String permissionType = (String) view.getTag(R.id.permission_type);
            if (mWindowAndroid.canRequestPermission(permissionType)) {
                final String[] permissionRequest = new String[] { permissionType };
                mWindowAndroid.requestPermissions(permissionRequest, new PermissionCallback() {

                    @Override
                    public void onRequestPermissionsResult(String[] permissions, int[] grantResults) {
                        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                            updatePermissionDisplay();
                        }
                    }
                });
                return;
            }
        }
        runAfterDismiss(new Runnable() {

            @Override
            public void run() {
                Intent settingsIntent;
                if (intentOverride != null) {
                    settingsIntent = (Intent) intentOverride;
                } else {
                    settingsIntent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                    settingsIntent.setData(Uri.parse("package:" + mContext.getPackageName()));
                }
                settingsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                mContext.startActivity(settingsIntent);
            }
        });
    }
}
Also used : PermissionCallback(org.chromium.ui.base.WindowAndroid.PermissionCallback) ActivityNotFoundException(android.content.ActivityNotFoundException) Bundle(android.os.Bundle) Intent(android.content.Intent) SpannableString(android.text.SpannableString)

Example 2 with PermissionCallback

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

the class ExternalNavigationDelegateImpl method startFileIntent.

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

Example 3 with PermissionCallback

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

the class ChromeDownloadDelegate method requestFileAccess.

@CalledByNative
private void requestFileAccess(final long callbackId) {
    if (mTab == null || mTab.getWindowAndroid() == null) {
        // TODO(tedchoc): Show toast (only when activity is alive).
        DownloadController.getInstance().onRequestFileAccessResult(callbackId, false);
        return;
    }
    final String storagePermission = android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
    final Activity activity = mTab.getWindowAndroid().getActivity().get();
    if (activity == null) {
        DownloadController.getInstance().onRequestFileAccessResult(callbackId, false);
    } else if (mTab.getWindowAndroid().canRequestPermission(storagePermission)) {
        View view = activity.getLayoutInflater().inflate(R.layout.update_permissions_dialog, null);
        TextView dialogText = (TextView) view.findViewById(R.id.text);
        dialogText.setText(R.string.missing_storage_permission_download_education_text);
        final PermissionCallback permissionCallback = new PermissionCallback() {

            @Override
            public void onRequestPermissionsResult(String[] permissions, int[] grantResults) {
                DownloadController.getInstance().onRequestFileAccessResult(callbackId, grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED);
            }
        };
        AlertDialog.Builder builder = new AlertDialog.Builder(activity, R.style.AlertDialogTheme).setView(view).setPositiveButton(R.string.infobar_update_permissions_button_text, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int id) {
                if (mTab == null) {
                    dialog.cancel();
                    return;
                }
                mTab.getWindowAndroid().requestPermissions(new String[] { storagePermission }, permissionCallback);
            }
        }).setOnCancelListener(new DialogInterface.OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                DownloadController.getInstance().onRequestFileAccessResult(callbackId, false);
            }
        });
        builder.create().show();
    } else if (!mTab.getWindowAndroid().isPermissionRevokedByPolicy(storagePermission)) {
        nativeLaunchPermissionUpdateInfoBar(mTab, storagePermission, callbackId);
    } else {
        // TODO(tedchoc): Show toast.
        DownloadController.getInstance().onRequestFileAccessResult(callbackId, false);
    }
}
Also used : DialogInterface(android.content.DialogInterface) ChromeActivity(org.chromium.chrome.browser.ChromeActivity) Activity(android.app.Activity) View(android.view.View) TextView(android.widget.TextView) PermissionCallback(org.chromium.ui.base.WindowAndroid.PermissionCallback) TextView(android.widget.TextView) CalledByNative(org.chromium.base.annotations.CalledByNative)

Example 4 with PermissionCallback

use of org.chromium.ui.base.WindowAndroid.PermissionCallback 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 PermissionCallback

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

the class PermissionInfoBar method requestAndroidPermissions.

private void requestAndroidPermissions() {
    PermissionCallback callback = new PermissionCallback() {

        @Override
        public void onRequestPermissionsResult(String[] permissions, int[] grantResults) {
            int deniedCount = 0;
            int requestableCount = 0;
            int deniedStringId = R.string.infobar_missing_multiple_permissions_text;
            for (int i = 0; i < grantResults.length; i++) {
                if (grantResults[i] == PackageManager.PERMISSION_DENIED) {
                    deniedCount++;
                    if (deniedCount > 1) {
                        deniedStringId = R.string.infobar_missing_multiple_permissions_text;
                    } else {
                        deniedStringId = getDeniedPermissionResourceId(permissions[i]);
                    }
                    if (mWindowAndroid.canRequestPermission(permissions[i])) {
                        requestableCount++;
                    }
                }
            }
            Activity activity = mWindowAndroid.getActivity().get();
            if (deniedCount > 0 && requestableCount > 0 && activity != null) {
                View view = activity.getLayoutInflater().inflate(R.layout.update_permissions_dialog, null);
                TextView dialogText = (TextView) view.findViewById(R.id.text);
                dialogText.setText(deniedStringId);
                AlertDialog.Builder builder = new AlertDialog.Builder(activity, R.style.AlertDialogTheme).setView(view).setPositiveButton(R.string.infobar_update_permissions_button_text, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        requestAndroidPermissions();
                    }
                }).setOnCancelListener(new DialogInterface.OnCancelListener() {

                    @Override
                    public void onCancel(DialogInterface dialog) {
                        onCloseButtonClicked();
                    }
                });
                builder.create().show();
            } else if (deniedCount > 0) {
                onCloseButtonClicked();
            } else {
                onButtonClickedInternal(true);
            }
        }
    };
    String[] permissionsToRequest = new String[mContentSettingsToPermissionsMap.size()];
    for (int i = 0; i < mContentSettingsToPermissionsMap.size(); i++) {
        permissionsToRequest[i] = mContentSettingsToPermissionsMap.valueAt(i);
    }
    mWindowAndroid.requestPermissions(permissionsToRequest, callback);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) Activity(android.app.Activity) TextView(android.widget.TextView) View(android.view.View) PermissionCallback(org.chromium.ui.base.WindowAndroid.PermissionCallback) TextView(android.widget.TextView)

Aggregations

PermissionCallback (org.chromium.ui.base.WindowAndroid.PermissionCallback)5 Activity (android.app.Activity)2 DialogInterface (android.content.DialogInterface)2 View (android.view.View)2 TextView (android.widget.TextView)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 AlertDialog (android.support.v7.app.AlertDialog)1 SpannableString (android.text.SpannableString)1 CalledByNative (org.chromium.base.annotations.CalledByNative)1 ChromeActivity (org.chromium.chrome.browser.ChromeActivity)1 WindowAndroid (org.chromium.ui.base.WindowAndroid)1