OSDN Git Service

Adds a method to allow Geolocation permissions for an origin.
authorSteve Block <steveblock@google.com>
Fri, 21 Aug 2009 09:56:56 +0000 (10:56 +0100)
committerSteve Block <steveblock@google.com>
Wed, 26 Aug 2009 11:26:11 +0000 (12:26 +0100)
WebKit/android/WebCoreSupport/GeolocationPermissions.cpp
WebKit/android/WebCoreSupport/GeolocationPermissions.h
WebKit/android/jni/GeolocationPermissionsBridge.cpp

index dfce970..a0b234b 100755 (executable)
@@ -79,19 +79,20 @@ void GeolocationPermissions::queryPermissionState(Frame* frame)
         return;
     }
 
-    // See if we have a record for this origin in the temporary permissions for
-    // this tab. These take precedence over permanent permissions.
-    PermissionsMap::const_iterator iter = m_temporaryPermissions.find(originString);
-    PermissionsMap::const_iterator end = m_temporaryPermissions.end();
+    // See if we have a record for this origin in the permanent permissions.
+    // These take precedence over temporary permissions so that changes made
+    // from the browser settings work as intended.
+    PermissionsMap::const_iterator iter = s_permanentPermissions.find(originString);
+    PermissionsMap::const_iterator end = s_permanentPermissions.end();
     if (iter != end) {
         bool allow = iter->second;
         makeAsynchronousCallbackToGeolocation(originString, allow);
         return;
     }
 
-    // Check the permanent permisions.
-    iter = s_permanentPermissions.find(originString);
-    end = s_permanentPermissions.end();
+    // Check the temporary permisions.
+    iter = m_temporaryPermissions.find(originString);
+    end = m_temporaryPermissions.end();
     if (iter != end) {
         bool allow = iter->second;
         makeAsynchronousCallbackToGeolocation(originString, allow);
@@ -158,9 +159,6 @@ void GeolocationPermissions::recordPermissionState(String origin, bool allow, bo
 {
     if (remember) {
         s_permanentPermissions.set(m_originInProgress, allow);
-        // If we already have a temporary permission for this origin, remove it,
-        // so that later clearing the permanent permission works as expected.
-        m_temporaryPermissions.remove(origin);
     } else {
         // It's possible that another tab recorded a permanent permission for
         // this origin while our request was in progress, but we record it
@@ -258,6 +256,14 @@ void GeolocationPermissions::clear(String origin)
     maybeStorePermanentPermissions();
 }
 
+void GeolocationPermissions::allow(String origin)
+{
+    maybeLoadPermanentPermissions();
+    // We replace any existing permanent permission.
+    s_permanentPermissions.set(origin, true);
+    maybeStorePermanentPermissions();
+}
+
 void GeolocationPermissions::clearAll()
 {
     maybeLoadPermanentPermissions();
index 30d3be4..b0ba3ec 100755 (executable)
@@ -80,11 +80,13 @@ namespace android {
         void resetTemporaryPermissionStates();
 
         // Static methods for use from Java. These are used to interact with the
-        // browser settings menu.
+        // browser settings menu and to update the permanent permissions when
+        // system settings are changed.
         typedef HashSet<WebCore::String> OriginSet;
         static OriginSet getOrigins();
         static bool getAllowed(WebCore::String origin);
         static void clear(WebCore::String origin);
+        static void allow(WebCore::String origin);
         static void clearAll();
         static void setAlwaysDeny(bool deny);
 
index ddcca5d..0eeab3a 100755 (executable)
@@ -69,6 +69,12 @@ static void clear(JNIEnv* env, jobject obj, jstring origin)
     GeolocationPermissions::clear(originString);
 }
 
+static void allow(JNIEnv* env, jobject obj, jstring origin)
+{
+    WebCore::String originString = to_string(env, origin);
+    GeolocationPermissions::allow(originString);
+}
+
 static void clearAll(JNIEnv* env, jobject obj)
 {
     GeolocationPermissions::clearAll();
@@ -84,6 +90,8 @@ static JNINativeMethod gGeolocationPermissionsMethods[] = {
         (void*) getAllowed },
     { "nativeClear", "(Ljava/lang/String;)V",
         (void*) clear },
+    { "nativeAllow", "(Ljava/lang/String;)V",
+        (void*) allow },
     { "nativeClearAll", "()V",
         (void*) clearAll }
 };