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);
}
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);
}
}
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();
}
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;
}
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);
}
Aggregations