summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Garcia Campos <cgarcia@igalia.com>2022-12-16 15:52:07 +0100
committerCarlos Garcia Campos <cgarcia@igalia.com>2023-02-10 14:45:41 +0100
commitb3a3316713afe5b4a7458eb14c59ed8a5fbeb5d1 (patch)
tree297c7cebb60efd358f18dc1edc0cdfeccd90b60d
parentf0c790cfd345fb8dfa9bb1be2ee31a28c114db92 (diff)
downloadepiphany-carlosgc/permission-state-query.tar.gz
embed: implement permission state query APIcarlosgc/permission-state-query
Use new WebKit API added in https://github.com/WebKit/WebKit/pull/6852
-rw-r--r--embed/ephy-web-view.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 3aa6af238..30bf2fe2c 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -2900,6 +2900,49 @@ scale_factor_changed_cb (EphyWebView *web_view,
_ephy_web_view_update_icon (web_view);
}
+static gboolean
+query_permission_state_cb (EphyWebView *web_view,
+ WebKitPermissionStateQuery *query)
+{
+ const char *name = webkit_permission_state_query_get_name (query);
+ EphyPermissionType permission_type;
+ EphyPermissionsManager *permissions_manager;
+ WebKitSecurityOrigin *security_origin;
+ g_autofree char *origin = NULL;
+
+ /* See https://w3c.github.io/permissions and https://github.com/w3c/webappsec-permissions-policy/blob/main/features.md */
+ if (g_strcmp0 (name, "notifications") == 0)
+ permission_type = EPHY_PERMISSION_TYPE_SHOW_NOTIFICATIONS;
+ else if (g_strcmp0 (name, "geolocation") == 0)
+ permission_type = EPHY_PERMISSION_TYPE_ACCESS_LOCATION;
+ else if (g_strcmp0 (name, "microphone") == 0)
+ permission_type = EPHY_PERMISSION_TYPE_ACCESS_MICROPHONE;
+ else if (g_strcmp0 (name, "camera") == 0)
+ permission_type = EPHY_PERMISSION_TYPE_ACCESS_WEBCAM;
+ else if (g_strcmp0 (name, "autoplay") == 0)
+ permission_type = EPHY_PERMISSION_TYPE_AUTOPLAY_POLICY;
+ else
+ return FALSE;
+
+ security_origin = webkit_permission_state_query_get_security_origin (query);
+ origin = webkit_security_origin_to_string (security_origin);
+
+ permissions_manager = ephy_embed_shell_get_permissions_manager (ephy_embed_shell_get_default ());
+ switch (ephy_permissions_manager_get_permission (permissions_manager, permission_type, origin)) {
+ case EPHY_PERMISSION_UNDECIDED:
+ webkit_permission_state_query_finish (query, WEBKIT_PERMISSION_STATE_PROMPT);
+ break;
+ case EPHY_PERMISSION_DENY:
+ webkit_permission_state_query_finish (query, WEBKIT_PERMISSION_STATE_DENIED);
+ break;
+ case EPHY_PERMISSION_PERMIT:
+ webkit_permission_state_query_finish (query, WEBKIT_PERMISSION_STATE_GRANTED);
+ break;
+ }
+
+ return TRUE;
+}
+
/**
* ephy_web_view_load_request:
* @view: the #EphyWebView in which to load the request
@@ -4120,6 +4163,10 @@ ephy_web_view_init (EphyWebView *web_view)
G_CALLBACK (scale_factor_changed_cb),
NULL);
+ g_signal_connect (web_view, "query-permission-state",
+ G_CALLBACK (query_permission_state_cb),
+ NULL);
+
g_signal_connect_object (shell, "password-form-focused",
G_CALLBACK (password_form_focused_cb),
web_view, 0);