This source file includes following definitions.
- allow
- deny
- clear
- clearAll
- isOriginAllowed
- hasOrigin
- getAllowed
- getOrigins
- getOriginKey
package org.chromium.android_webview;
import android.content.SharedPreferences;
import android.webkit.ValueCallback;
import org.chromium.base.ThreadUtils;
import org.chromium.net.GURLUtils;
import java.util.HashSet;
import java.util.Set;
public final class AwGeolocationPermissions {
private static final String PREF_PREFIX =
"AwGeolocationPermissions%";
private final SharedPreferences mSharedPreferences;
public AwGeolocationPermissions(SharedPreferences sharedPreferences) {
mSharedPreferences = sharedPreferences;
}
public void allow(String origin) {
String key = getOriginKey(origin);
if (key != null) {
mSharedPreferences.edit().putBoolean(key, true).apply();
}
}
public void deny(String origin) {
String key = getOriginKey(origin);
if (key != null) {
mSharedPreferences.edit().putBoolean(key, false).apply();
}
}
public void clear(String origin) {
String key = getOriginKey(origin);
if (key != null) {
mSharedPreferences.edit().remove(key).apply();
}
}
public void clearAll() {
SharedPreferences.Editor editor = null;
for (String name : mSharedPreferences.getAll().keySet()) {
if (name.startsWith(PREF_PREFIX)) {
if (editor == null) {
editor = mSharedPreferences.edit();
}
editor.remove(name);
}
}
if (editor != null) {
editor.apply();
}
}
public boolean isOriginAllowed(String origin) {
return mSharedPreferences.getBoolean(getOriginKey(origin), false);
}
public boolean hasOrigin(String origin) {
return mSharedPreferences.contains(getOriginKey(origin));
}
public void getAllowed(String origin, final ValueCallback<Boolean> callback) {
final boolean finalAllowed = isOriginAllowed(origin);
ThreadUtils.postOnUiThread(new Runnable() {
@Override
public void run() {
callback.onReceiveValue(finalAllowed);
}
});
}
public void getOrigins(final ValueCallback<Set<String>> callback) {
final Set<String> origins = new HashSet<String>();
for (String name : mSharedPreferences.getAll().keySet()) {
if (name.startsWith(PREF_PREFIX)) {
origins.add(name.substring(PREF_PREFIX.length()));
}
}
ThreadUtils.postOnUiThread(new Runnable() {
@Override
public void run() {
callback.onReceiveValue(origins);
}
});
}
private String getOriginKey(String url) {
String origin = GURLUtils.getOrigin(url);
if (origin.isEmpty()) {
return null;
}
return PREF_PREFIX + origin;
}
}