diff options
-rw-r--r-- | doc/reference/tmpl/ephy-permission-manager.sgml | 16 | ||||
-rw-r--r-- | embed/ephy-permission-manager.c | 22 | ||||
-rw-r--r-- | embed/ephy-permission-manager.h | 29 | ||||
-rw-r--r-- | embed/mozilla/EphySingle.cpp | 21 | ||||
-rw-r--r-- | embed/mozilla/mozilla-embed-single.cpp | 30 |
5 files changed, 48 insertions, 70 deletions
diff --git a/doc/reference/tmpl/ephy-permission-manager.sgml b/doc/reference/tmpl/ephy-permission-manager.sgml index f62bd4de1..93abf486c 100644 --- a/doc/reference/tmpl/ephy-permission-manager.sgml +++ b/doc/reference/tmpl/ephy-permission-manager.sgml @@ -28,6 +28,10 @@ network.cookie.cookieBehavior preference. For images, the default is determined by Mozilla's network.image.imageBehavior preference. </para> <para> +The predefined permission types are EPT_COOKIE ("cookie"), EPT_IMAGE ("image") +and EPT_POPUP ("popup"). You can also make up your own type string. +</para> +<para> Though the word "host" is used in many function descriptions, Mozilla does not act as one would expect. Always pass a URL to any functions which need have a "host" parameter. However, the "host" in an @@ -48,18 +52,6 @@ Details a specific permission of a specific website. @type: An #EphyPermissionType. @permission: An #EphyPermission (either allow or deny). -<!-- ##### ENUM EphyPermissionType ##### --> -<para> -Determines what permission we're dealing with. -</para> - -@EPT_COOKIE: - Permission for the website to store cookies on the user's computer. -@EPT_IMAGE: - Permission for the website to show images to the user. -@EPT_POPUP: - Permission for the website to open popup windows (using JavaScript). - <!-- ##### ENUM EphyPermission ##### --> <para> Determines whether the website is allowed or denied access. diff --git a/embed/ephy-permission-manager.c b/embed/ephy-permission-manager.c index db841296d..7d7626cb7 100644 --- a/embed/ephy-permission-manager.c +++ b/embed/ephy-permission-manager.c @@ -54,13 +54,13 @@ ephy_permission_info_get_type (void) **/ EphyPermissionInfo * ephy_permission_info_new (const char *host, - EphyPermissionType type, + const char *type, EphyPermission permission) { EphyPermissionInfo *info = g_new0 (EphyPermissionInfo, 1); info->host = g_strdup (host); - info->type = type; + info->qtype = g_quark_from_string (type); info->permission = permission; return info; @@ -78,7 +78,7 @@ ephy_permission_info_copy (const EphyPermissionInfo *info) EphyPermissionInfo *copy = g_new0 (EphyPermissionInfo, 1); copy->host = g_strdup (info->host); - copy->type = info->type; + copy->qtype = info->qtype; copy->permission = info->permission; return copy; @@ -212,7 +212,7 @@ ephy_permission_manager_base_init (gpointer g_class) * ephy_permission_manager_add: * @manager: the #EphyPermissionManager * @host: a website URL - * @type: an #EphyPermissionType + * @type: a string to identify the type of the permission * @permission: either %EPHY_PERMISSION_ALLOWED or %EPHY_PERMISSION_DENIED * * Adds the specified permission to the permissions database. @@ -220,7 +220,7 @@ ephy_permission_manager_base_init (gpointer g_class) void ephy_permission_manager_add (EphyPermissionManager *manager, const char *host, - EphyPermissionType type, + const char *type, EphyPermission permission) { EphyPermissionManagerIface *iface = EPHY_PERMISSION_MANAGER_GET_IFACE (manager); @@ -231,7 +231,7 @@ ephy_permission_manager_add (EphyPermissionManager *manager, * ephy_permission_manager_remove: * @manager: the #EphyPermissionManager * @host: a website URL - * @type: an #EphyPermissionType + * @type: a string to identify the type of the permission * * Removes the specified permission from the permissions database. This implies * that the browser should use defaults when next visiting the specified @@ -240,7 +240,7 @@ ephy_permission_manager_add (EphyPermissionManager *manager, void ephy_permission_manager_remove (EphyPermissionManager *manager, const char *host, - EphyPermissionType type) + const char *type) { EphyPermissionManagerIface *iface = EPHY_PERMISSION_MANAGER_GET_IFACE (manager); iface->remove (manager, host, type); @@ -263,7 +263,7 @@ ephy_permission_manager_clear (EphyPermissionManager *manager) * ephy_permission_manager_test: * @manager: the #EphyPermissionManager * @host: a website URL - * @type: an #EphyPermissionType + * @type: a string to identify the type of the permission * * Retrieves an #EphyPermissionType from the permissions database. If there is * no entry for this @type and @host, it will return %EPHY_PERMISSION_DEFAULT. @@ -275,7 +275,7 @@ ephy_permission_manager_clear (EphyPermissionManager *manager) EphyPermission ephy_permission_manager_test (EphyPermissionManager *manager, const char *host, - EphyPermissionType type) + const char *type) { EphyPermissionManagerIface *iface = EPHY_PERMISSION_MANAGER_GET_IFACE (manager); return iface->test (manager, host, type); @@ -284,7 +284,7 @@ ephy_permission_manager_test (EphyPermissionManager *manager, /** * ephy_permission_manager_list: * @manager: the #EphyPermissionManager - * @type: an #EphyPermissionType + * @type: a string to identify the type of the permission * * Lists all permission entries of type @type in the permissions database, each * as its own #EphyPermissionInfo. These entries must be freed using @@ -294,7 +294,7 @@ ephy_permission_manager_test (EphyPermissionManager *manager, **/ GList * ephy_permission_manager_list (EphyPermissionManager *manager, - EphyPermissionType type) + const char *type) { EphyPermissionManagerIface *iface = EPHY_PERMISSION_MANAGER_GET_IFACE (manager); return iface->list (manager, type); diff --git a/embed/ephy-permission-manager.h b/embed/ephy-permission-manager.h index 4d85accdf..8ada417f2 100644 --- a/embed/ephy-permission-manager.h +++ b/embed/ephy-permission-manager.h @@ -36,12 +36,9 @@ G_BEGIN_DECLS #define EPHY_TYPE_PERMISSION_INFO (ephy_permission_info_get_type ()) -typedef enum -{ - EPT_COOKIE, - EPT_IMAGE, - EPT_POPUP -} EphyPermissionType; +#define EPT_COOKIE "cookie" +#define EPT_IMAGE "image" +#define EPT_POPUP "popup" typedef enum { @@ -58,7 +55,7 @@ typedef struct EphyPermissionManagerIface EphyPermissionManagerIface; struct _EphyPermissionInfo { char *host; - EphyPermissionType type; + GQuark qtype; EphyPermission permission; }; @@ -78,17 +75,17 @@ struct EphyPermissionManagerIface /* Methods */ void (* add) (EphyPermissionManager *manager, const char *host, - EphyPermissionType type, + const char *type, EphyPermission permission); void (* remove) (EphyPermissionManager *manager, const char *host, - EphyPermissionType type); + const char *type); void (* clear) (EphyPermissionManager *manager); EphyPermission (* test) (EphyPermissionManager *manager, const char *host, - EphyPermissionType type); + const char *type); GList * (* list) (EphyPermissionManager *manager, - EphyPermissionType type); + const char *type); }; /* EphyPermissionInfo */ @@ -96,7 +93,7 @@ struct EphyPermissionManagerIface GType ephy_permission_info_get_type (void); EphyPermissionInfo *ephy_permission_info_new (const char *host, - EphyPermissionType type, + const char *type, EphyPermission permission); EphyPermissionInfo *ephy_permission_info_copy (const EphyPermissionInfo *info); @@ -109,21 +106,21 @@ GType ephy_permission_manager_get_type (void); void ephy_permission_manager_add (EphyPermissionManager *manager, const char *host, - EphyPermissionType type, + const char *type, EphyPermission permission); void ephy_permission_manager_remove (EphyPermissionManager *manager, const char *host, - EphyPermissionType type); + const char *type); void ephy_permission_manager_clear (EphyPermissionManager *manager); EphyPermission ephy_permission_manager_test (EphyPermissionManager *manager, const char *host, - EphyPermissionType type); + const char *type); GList * ephy_permission_manager_list (EphyPermissionManager *manager, - EphyPermissionType type); + const char *type); G_END_DECLS diff --git a/embed/mozilla/EphySingle.cpp b/embed/mozilla/EphySingle.cpp index 1a3791b43..b667c16d1 100644 --- a/embed/mozilla/EphySingle.cpp +++ b/embed/mozilla/EphySingle.cpp @@ -263,26 +263,11 @@ mozilla_cookie_to_ephy_cookie (nsICookie *cookie) EphyPermissionInfo * mozilla_permission_to_ephy_permission (nsIPermission *perm) { - EphyPermissionType type = (EphyPermissionType) 0; - nsresult result; - nsEmbedCString str; - result = perm->GetType(str); + nsEmbedCString type; + result = perm->GetType(type); NS_ENSURE_SUCCESS (result, NULL); - if (strcmp (str.get(), "cookie") == 0) - { - type = EPT_COOKIE; - } - else if (strcmp (str.get(), "image")) - { - type = EPT_IMAGE; - } - else if (strcmp (str.get(), "popup")) - { - type = EPT_POPUP; - } - PRUint32 cap; perm->GetCapability(&cap); EphyPermission permission; @@ -303,5 +288,5 @@ mozilla_permission_to_ephy_permission (nsIPermission *perm) nsEmbedCString host; perm->GetHost(host); - return ephy_permission_info_new (host.get(), type, permission); + return ephy_permission_info_new (host.get(), type.get(), permission); } diff --git a/embed/mozilla/mozilla-embed-single.cpp b/embed/mozilla/mozilla-embed-single.cpp index 6513c8095..7b48f03f6 100644 --- a/embed/mozilla/mozilla-embed-single.cpp +++ b/embed/mozilla/mozilla-embed-single.cpp @@ -718,11 +718,12 @@ static const char *permission_type_string [] = void impl_permission_manager_add (EphyPermissionManager *manager, const char *host, - EphyPermissionType type, + const char *type, EphyPermission permission) { /* can only set allow or deny */ g_return_if_fail (permission != EPHY_PERMISSION_DEFAULT); + g_return_if_fail (type != NULL && type[0] != '\0'); nsCOMPtr<nsIPermissionManager> pm (do_GetService (NS_PERMISSIONMANAGER_CONTRACTID)); @@ -734,8 +735,7 @@ impl_permission_manager_add (EphyPermissionManager *manager, gboolean allow = (permission == EPHY_PERMISSION_ALLOWED); - pm->Add (uri, - permission_type_string [type], + pm->Add (uri, type, allow ? (PRUint32) nsIPermissionManager::ALLOW_ACTION : (PRUint32) nsIPermissionManager::DENY_ACTION); } @@ -743,13 +743,13 @@ impl_permission_manager_add (EphyPermissionManager *manager, void impl_permission_manager_remove (EphyPermissionManager *manager, const char *host, - EphyPermissionType type) + const char *type) { nsCOMPtr<nsIPermissionManager> pm (do_GetService (NS_PERMISSIONMANAGER_CONTRACTID)); if (!pm) return; - pm->Remove (nsEmbedCString (host), permission_type_string [type]); + pm->Remove (nsEmbedCString (host), type); } void @@ -765,8 +765,10 @@ impl_permission_manager_clear (EphyPermissionManager *manager) EphyPermission impl_permission_manager_test (EphyPermissionManager *manager, const char *host, - EphyPermissionType type) + const char *type) { + g_return_val_if_fail (type != NULL && type[0] != '\0', EPHY_PERMISSION_DEFAULT); + nsCOMPtr<nsIPermissionManager> pm (do_GetService (NS_PERMISSIONMANAGER_CONTRACTID)); if (!pm) return EPHY_PERMISSION_DEFAULT; @@ -777,7 +779,7 @@ impl_permission_manager_test (EphyPermissionManager *manager, nsresult rv; PRUint32 action; - rv = pm->TestPermission (uri, permission_type_string [type], &action); + rv = pm->TestPermission (uri, type, &action); NS_ENSURE_SUCCESS (rv, EPHY_PERMISSION_DEFAULT); EphyPermission permission; @@ -801,7 +803,7 @@ impl_permission_manager_test (EphyPermissionManager *manager, GList * impl_permission_manager_list (EphyPermissionManager *manager, - EphyPermissionType type) + const char *type) { GList *list = NULL; @@ -813,11 +815,13 @@ impl_permission_manager_list (EphyPermissionManager *manager, pm->GetEnumerator(getter_AddRefs(pe)); NS_ENSURE_TRUE (pe, NULL); - PRBool more; - for (pe->HasMoreElements (&more); more == PR_TRUE; pe->HasMoreElements (&more)) + PRBool hasMore; + while (NS_SUCCEEDED (pe->HasMoreElements (&hasMore)) && hasMore) { - nsCOMPtr<nsIPermission> perm; - pe->GetNext(getter_AddRefs(perm)); + nsCOMPtr<nsISupports> element; + pe->GetNext (getter_AddRefs (element)); + + nsCOMPtr<nsIPermission> perm (do_QueryInterface (element)); if (!perm) continue; nsresult rv; @@ -825,7 +829,7 @@ impl_permission_manager_list (EphyPermissionManager *manager, rv = perm->GetType(str); if (NS_FAILED (rv)) continue; - if (strcmp (str.get(), permission_type_string[type]) == 0) + if (strcmp (str.get(), type) == 0) { EphyPermissionInfo *info = mozilla_permission_to_ephy_permission (perm); |