Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1940)

Unified Diff: android_webview/java/src/org/chromium/android_webview/AwGeolocationPermissions.java

Issue 12211047: Implementing geolocation for the Android Webview (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor style updates Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: android_webview/java/src/org/chromium/android_webview/AwGeolocationPermissions.java
diff --git a/android_webview/java/src/org/chromium/android_webview/AwGeolocationPermissions.java b/android_webview/java/src/org/chromium/android_webview/AwGeolocationPermissions.java
index 133f5970eb5a12a778701aba59b3f329e39941e0..f0afdca89d7c165d5e41375d47e815c8a4de873f 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwGeolocationPermissions.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwGeolocationPermissions.java
@@ -24,10 +24,39 @@ public final class AwGeolocationPermissions {
AwGeolocationPermissions.class.getCanonicalName() + "%";
private final SharedPreferences mSharedPreferences;
+ private static AwGeolocationPermissions sInstance;
joth 2013/02/06 22:09:51 crumbs more statics. I'll make a patch to avoid th
Kristian Monsen 2013/02/08 00:07:44 OK.
+
+ // TODO(kristianm): Make this private once framework is updated to use getInstance
boliu 2013/02/06 20:29:54 Sorry I don't understand this comment. What framew
Kristian Monsen 2013/02/08 00:07:44 Android -> framework/webview. That is where this i
public AwGeolocationPermissions(SharedPreferences sharedPreferences) {
mSharedPreferences = sharedPreferences;
+ sInstance = this;
+ }
+
+ /**
+ * Get the static instance after it has been created
+ */
+ public static synchronized AwGeolocationPermissions getInstance() {
boliu 2013/02/06 20:29:54 Can we use synchronized blocks instead of having t
Kristian Monsen 2013/02/08 00:07:44 Done.
+ if (sInstance == null) {
+ throw new IllegalStateException("This should only be called after creteInstance.");
+ }
+ return sInstance;
+ }
+
+ /**
+ * Create the static instance of this class
+ */
+ public static synchronized AwGeolocationPermissions createInstance(
boliu 2013/02/06 20:29:54 getInstance vs createInstance? I'm confused if thi
Kristian Monsen 2013/02/08 00:07:44 It needs a SharedPreference when creating the stat
+ SharedPreferences sharedPreferences) {
+ if (sInstance != null) {
+ throw new IllegalStateException("This should only be called once.");
+ }
+ sInstance = new AwGeolocationPermissions(sharedPreferences);
boliu 2013/02/06 20:29:54 sInstance is set here and in the constructor, dupl
Kristian Monsen 2013/02/08 00:07:44 Yes, done. I wanted it here, but had to be in the
+ return sInstance;
}
+ /**
+ * Set one origin to be allowed.
+ */
public void allow(String origin) {
String key = getOriginKey(origin);
if (key != null) {
@@ -35,6 +64,9 @@ public final class AwGeolocationPermissions {
}
}
+ /**
+ * Set one origin to be denied.
+ */
public void deny(String origin) {
String key = getOriginKey(origin);
if (key != null) {
@@ -42,6 +74,9 @@ public final class AwGeolocationPermissions {
}
}
+ /**
+ * Clear one origin from being allowed and denied.
+ */
public void clear(String origin) {
String key = getOriginKey(origin);
if (key != null) {
@@ -49,6 +84,9 @@ public final class AwGeolocationPermissions {
}
}
+ /**
+ * Clear all origins set to allowed or denied.
+ */
public void clearAll() {
SharedPreferences.Editor editor = null;
for (String name : mSharedPreferences.getAll().keySet()) {
@@ -64,7 +102,10 @@ public final class AwGeolocationPermissions {
}
}
- public void getAllowed(String origin, final ValueCallback<Boolean> callback) {
+ /**
+ * Sync method to get if an origin set to be allowed.
+ */
+ public boolean getAllowed(String origin) {
joth 2013/02/06 22:09:51 I think isOriginAllowed / isOriginDenied would be
Kristian Monsen 2013/02/08 00:07:44 Done.
boolean allowed = false;
try {
String key = getOriginKey(origin);
@@ -74,7 +115,30 @@ public final class AwGeolocationPermissions {
} catch (ClassCastException e) {
// Want to return false in this case, do nothing here
}
- final boolean finalAllowed = allowed;
+ return allowed;
joth 2013/02/06 22:09:51 AIUI passing key == null to getFoo() is fine so yo
Kristian Monsen 2013/02/08 00:07:44 Done.
+ }
+
+ /**
+ * Sync method to get if an origin set to be denied.
+ */
+ public boolean getDenied(String origin) {
+ boolean allowed = true;
+ try {
+ String key = getOriginKey(origin);
+ if (key != null) {
+ allowed = mSharedPreferences.getBoolean(key, true);
joth 2013/02/06 22:09:51 the 'true' here & above looks very odd. This come
Kristian Monsen 2013/02/08 00:07:44 Updated as it makes the only callsite clearer, but
joth 2013/02/08 02:15:01 agreed. we might as well invent an enum (int const
+ }
+ } catch (ClassCastException e) {
+ // Want to return false in this case, do nothing here
+ }
+ return !allowed;
+ }
+
+ /**
+ * ASync method to get if an origin set to be allowed.
+ */
+ public void getAllowed(String origin, final ValueCallback<Boolean> callback) {
+ final boolean finalAllowed = getAllowed(origin);
boliu 2013/02/06 20:29:54 given this is async, should this be more async tha
Kristian Monsen 2013/02/08 00:07:44 I felt this was better as the result will reflect
joth 2013/02/08 02:15:01 Seems reasonable. Otherwise, calling this sequence
ThreadUtils.postOnUiThread(new Runnable() {
@Override
public void run() {
@@ -83,6 +147,9 @@ public final class AwGeolocationPermissions {
});
}
+ /**
+ * ASync method to get the domains currently allowed or denied.
+ */
public void getOrigins(final ValueCallback<Set<String>> callback) {
final Set<String> origins = new HashSet<String>();
for (String name : mSharedPreferences.getAll().keySet()) {
@@ -98,6 +165,9 @@ public final class AwGeolocationPermissions {
});
}
+ /**
+ * Get the domain of an URL using the GURL library.
+ */
private String getOriginKey(String url) {
String origin = GURLUtils.getOrigin(url);
if (origin.isEmpty()) {

Powered by Google App Engine
This is Rietveld 408576698