[epiphany/wip/missing-codecs: 4/8] Remember geolocation permission requests



commit 192582945fa64add29041145e29a1b6667146495
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Sun Nov 6 20:53:27 2016 -0600

    Remember geolocation permission requests
    
    Just like we do notification permission requests

 data/org.gnome.epiphany.host.gschema.xml |    5 ++
 embed/ephy-web-view.c                    |   85 ++++++++++++++++++------------
 lib/ephy-hosts-manager.c                 |   22 ++++++++
 lib/ephy-hosts-manager.h                 |    3 +-
 4 files changed, 80 insertions(+), 35 deletions(-)
---
diff --git a/data/org.gnome.epiphany.host.gschema.xml b/data/org.gnome.epiphany.host.gschema.xml
index 9b5e3f5..4f8813a 100644
--- a/data/org.gnome.epiphany.host.gschema.xml
+++ b/data/org.gnome.epiphany.host.gschema.xml
@@ -6,6 +6,11 @@
   </enum>
 
   <schema id="org.gnome.Epiphany.host" gettext-domain="">
+    <key name="geolocation-permission" enum="org.gnome.Epiphany.host.permissions">
+      <default>"undecided"</default>
+      <summary>Decision to apply when geolocation permission is requested for this host</summary>
+      <description>This option is used to save whether a given host has been given permission to access the 
user's location. The 'undecided' default means the browser needs to ask the user for permission, while 
'allow' and 'deny' tell it to automatically make the decision upon request.</description>
+    </key>
     <key name="notifications-permission" enum="org.gnome.Epiphany.host.permissions">
       <default>"undecided"</default>
       <summary>Decision to apply when notification permission is requested for this host</summary>
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index ed9bf11..e269661 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -1257,6 +1257,8 @@ decide_on_permission_request (GtkWidget               *info_bar,
                               int                      response,
                               PermissionRequestData   *data)
 {
+  const char *address;
+
   switch (response) {
     case GTK_RESPONSE_YES:
       webkit_permission_request_allow (data->request);
@@ -1266,16 +1268,25 @@ decide_on_permission_request (GtkWidget               *info_bar,
       break;
   }
 
-  if (WEBKIT_IS_NOTIFICATION_PERMISSION_REQUEST (data->request) && response != GTK_RESPONSE_NONE) {
-    const char *address = ephy_web_view_get_address (data->web_view);
-    if (ephy_embed_utils_address_has_web_scheme (address)) {
-      EphyHostsManager *hosts_manager = ephy_embed_shell_get_hosts_manager (ephy_embed_shell_get_default ());
-      ephy_hosts_manager_set_permission_for_address (
-        hosts_manager,
-        EPHY_HOST_PERMISSION_TYPE_SHOW_NOTIFICATIONS,
-        address,
-        response == GTK_RESPONSE_YES ? EPHY_HOST_PERMISSION_ALLOW : EPHY_HOST_PERMISSION_DENY);
-    }
+  address = ephy_web_view_get_address (data->web_view);
+
+  if ((WEBKIT_IS_NOTIFICATION_PERMISSION_REQUEST (data->request) ||
+       WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST (data->request)) &&
+      response != GTK_RESPONSE_NONE &&
+      ephy_embed_utils_address_has_web_scheme (address)) {
+    EphyEmbedShell *shell;
+    EphyHostsManager *hosts_manager;
+
+    shell = ephy_embed_shell_get_default ();
+    hosts_manager = ephy_embed_shell_get_hosts_manager (shell);
+
+    ephy_hosts_manager_set_permission_for_address (
+      hosts_manager,
+      WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST (data->request) ? EPHY_HOST_PERMISSION_TYPE_ACCESS_LOCATION
+                                                               : 
EPHY_HOST_PERMISSION_TYPE_SHOW_NOTIFICATIONS,
+      address,
+      response == GTK_RESPONSE_YES ? EPHY_HOST_PERMISSION_ALLOW
+                                   : EPHY_HOST_PERMISSION_DENY);
   }
 
   gtk_widget_destroy (info_bar);
@@ -1294,37 +1305,43 @@ permission_request_cb (WebKitWebView           *web_view,
   PermissionRequestData *data;
   char *message;
   char *host;
+  const char *address;
+  EphyEmbedShell *shell;
+  EphyHostsManager *hosts_manager;
+  EphyHostPermission permission;
+  EphyHostPermissionType permission_type;
 
-  if (!WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST (decision) &&
-      !WEBKIT_IS_NOTIFICATION_PERMISSION_REQUEST (decision))
-    return FALSE;
+  shell = ephy_embed_shell_get_default ();
 
-  if (WEBKIT_IS_NOTIFICATION_PERMISSION_REQUEST (decision)) {
+  if (WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST (decision)) {
+    permission_type = EPHY_HOST_PERMISSION_TYPE_ACCESS_LOCATION;
+  } else if (WEBKIT_IS_NOTIFICATION_PERMISSION_REQUEST (decision)) {
     /* Application mode implies being OK with notifications. */
-    if (ephy_embed_shell_get_mode (ephy_embed_shell_get_default ()) == EPHY_EMBED_SHELL_MODE_APPLICATION) {
+    if (ephy_embed_shell_get_mode (shell) == EPHY_EMBED_SHELL_MODE_APPLICATION) {
       webkit_permission_request_allow (decision);
       return TRUE;
     }
+    permission_type = EPHY_HOST_PERMISSION_TYPE_SHOW_NOTIFICATIONS;
+  } else {
+    return FALSE;
+  }
 
-    {
-      const char *address = ephy_web_view_get_address (EPHY_WEB_VIEW (web_view));
-      EphyHostsManager *hosts_manager = ephy_embed_shell_get_hosts_manager (ephy_embed_shell_get_default ());
-      EphyHostPermission permission = ephy_hosts_manager_get_permission_for_address (hosts_manager,
-                                                                                     
EPHY_HOST_PERMISSION_TYPE_SHOW_NOTIFICATIONS,
-                                                                                     address);
-
-      switch (permission) {
-      case EPHY_HOST_PERMISSION_ALLOW:
-        webkit_permission_request_allow (decision);
-        return TRUE;
-      case EPHY_HOST_PERMISSION_DENY:
-        webkit_permission_request_deny (decision);
-        return TRUE;
-      case EPHY_HOST_PERMISSION_UNDECIDED:
-      default:
-        break;
-      }
-    }
+  address = ephy_web_view_get_address (EPHY_WEB_VIEW (web_view));
+  hosts_manager = ephy_embed_shell_get_hosts_manager (ephy_embed_shell_get_default ());
+  permission = ephy_hosts_manager_get_permission_for_address (hosts_manager,
+                                                              permission_type,
+                                                              address);
+
+  switch (permission) {
+  case EPHY_HOST_PERMISSION_ALLOW:
+    webkit_permission_request_allow (decision);
+    return TRUE;
+  case EPHY_HOST_PERMISSION_DENY:
+    webkit_permission_request_deny (decision);
+    return TRUE;
+  case EPHY_HOST_PERMISSION_UNDECIDED:
+  default:
+    break;
   }
 
   info_bar = gtk_info_bar_new_with_buttons (_("Deny"), GTK_RESPONSE_NO,
diff --git a/lib/ephy-hosts-manager.c b/lib/ephy-hosts-manager.c
index 235ef93..cb3b06b 100644
--- a/lib/ephy-hosts-manager.c
+++ b/lib/ephy-hosts-manager.c
@@ -169,6 +169,23 @@ ephy_hosts_manager_set_save_password_permission_for_address (EphyHostsManager
   g_settings_set_enum (settings, "save-password-permission", permission);
 }
 
+static EphyHostPermission
+ephy_hosts_manager_get_geolocation_permission_for_address (EphyHostsManager *manager,
+                                                           const char       *address)
+{
+  GSettings *settings = ephy_hosts_manager_get_settings_for_address (manager, address);
+  return g_settings_get_enum (settings, "geolocation-permission");
+}
+
+static void
+ephy_hosts_manager_set_geolocation_permission_for_address (EphyHostsManager   *manager,
+                                                           const char         *address,
+                                                           EphyHostPermission  permission)
+{
+  GSettings *settings = ephy_hosts_manager_get_settings_for_address (manager, address);
+  g_settings_set_enum (settings, "geolocation-permission", permission);
+}
+
 EphyHostPermission
 ephy_hosts_manager_get_permission_for_address (EphyHostsManager       *manager,
                                                EphyHostPermissionType  type,
@@ -179,6 +196,8 @@ ephy_hosts_manager_get_permission_for_address (EphyHostsManager       *manager,
     return ephy_hosts_manager_get_notifications_permission_for_address (manager, address);
   case EPHY_HOST_PERMISSION_TYPE_SAVE_PASSWORD:
     return ephy_hosts_manager_get_save_password_permission_for_address (manager, address);
+  case EPHY_HOST_PERMISSION_TYPE_ACCESS_LOCATION:
+    return ephy_hosts_manager_get_geolocation_permission_for_address (manager, address);
   default:
     g_assert_not_reached ();
   }
@@ -197,6 +216,9 @@ ephy_hosts_manager_set_permission_for_address (EphyHostsManager       *manager,
   case EPHY_HOST_PERMISSION_TYPE_SAVE_PASSWORD:
     ephy_hosts_manager_set_save_password_permission_for_address (manager, address, permission);
     break;
+  case EPHY_HOST_PERMISSION_TYPE_ACCESS_LOCATION:
+    ephy_hosts_manager_set_geolocation_permission_for_address (manager, address, permission);
+    break;
   default:
     g_assert_not_reached ();
   }
diff --git a/lib/ephy-hosts-manager.h b/lib/ephy-hosts-manager.h
index 285ed57..0468dee 100644
--- a/lib/ephy-hosts-manager.h
+++ b/lib/ephy-hosts-manager.h
@@ -37,7 +37,8 @@ typedef enum {
 
 typedef enum {
   EPHY_HOST_PERMISSION_TYPE_SHOW_NOTIFICATIONS,
-  EPHY_HOST_PERMISSION_TYPE_SAVE_PASSWORD
+  EPHY_HOST_PERMISSION_TYPE_SAVE_PASSWORD,
+  EPHY_HOST_PERMISSION_TYPE_ACCESS_LOCATION
 } EphyHostPermissionType;
 
 EphyHostsManager*       ephy_hosts_manager_new                                      (void);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]