Changed EphyHistoryWindow to use the new backend, some things still remain (selected_...
[ephy-soc.git] / embed / ephy-adblock-manager.c
blobfdcd191ca10e7ef029467adab44d2f41a9605fe5
1 /*
2 * Copyright © 2003 Marco Pesenti Gritti
3 * Copyright © 2003 Christian Persch
4 * Copyright © 2005 Jean-François Rameau
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * $Id: ephy-adblock-manager.c 6952 2007-03-11 19:42:02Z chpe $
23 #include "config.h"
24 #include "ephy-debug.h"
26 #include "ephy-adblock-manager.h"
27 #include "ephy-adblock.h"
29 struct _EphyAdBlockManagerPrivate
31 EphyAdBlock *blocker;
34 G_DEFINE_TYPE (EphyAdBlockManager, ephy_adblock_manager, G_TYPE_OBJECT);
36 #define EPHY_ADBLOCK_MANAGER_GET_PRIVATE(object) \
37 (G_TYPE_INSTANCE_GET_PRIVATE ((object), \
38 EPHY_TYPE_ADBLOCK_MANAGER, EphyAdBlockManagerPrivate))
41 /**
42 * ephy_adblock_manager_set_blocker:
43 * @shell: a #EphyAdBlockManager
44 * @blocker: the new blocker or NULL
46 * Set a new ad blocker. If #blocker is %NULL,
47 * ad blocking is toggled off.
49 **/
50 void
51 ephy_adblock_manager_set_blocker (EphyAdBlockManager *self,
52 EphyAdBlock *blocker)
54 self->priv->blocker = blocker;
57 /**
58 * ephy_adblock_manager_should_load:
59 * @shell: a #EphyAdBlockManager
60 * @url: the target url to be loaded or not
61 * @AdUriCheckType: what check to be applied (image, script, ...)
63 * Check if an url is to be loaded or not
65 * ReturnValue: TRUE if the url is to be loaded
66 **/
67 gboolean
68 ephy_adblock_manager_should_load (EphyAdBlockManager *self,
69 EphyEmbed *embed,
70 const char *url,
71 AdUriCheckType check_type)
73 if (self->priv->blocker != NULL)
75 return ephy_adblock_should_load (self->priv->blocker,
76 embed,
77 url,
78 check_type);
81 /* default: let's process any url */
82 return TRUE;
85 static void
86 ephy_adblock_manager_init (EphyAdBlockManager *self)
88 EphyAdBlockManagerPrivate *priv;
90 LOG ("ephy_adblock_manager_init");
92 priv = EPHY_ADBLOCK_MANAGER_GET_PRIVATE(self);
93 priv->blocker = NULL;
94 self->priv = priv;
97 static void
98 ephy_adblock_manager_class_init (EphyAdBlockManagerClass *klass)
100 GObjectClass *object_class = G_OBJECT_CLASS (klass);
102 g_signal_new ("rules_changed",
103 G_OBJECT_CLASS_TYPE (object_class),
104 G_SIGNAL_RUN_FIRST,
105 G_STRUCT_OFFSET (EphyAdBlockManagerClass, rules_changed),
106 NULL, NULL,
107 g_cclosure_marshal_VOID__VOID,
108 G_TYPE_NONE,
112 g_type_class_add_private (object_class, sizeof (EphyAdBlockManagerPrivate));
116 * ephy_adblock_manager_edit_rule:
117 * @shell: a #EphyAdBlockManager
118 * @url: the target url on which the rule is based
119 * @allowed: TRUE if the url has to be blocked.
121 * Ask to the blocker a new rule based on @url.
124 void
125 ephy_adblock_manager_edit_rule (EphyAdBlockManager *self,
126 const char *url,
127 gboolean allowed)
129 if (self->priv->blocker != NULL)
131 ephy_adblock_edit_rule (self->priv->blocker,
132 url,
133 allowed);
138 * ephy_adblock_manager_has_blocker:
139 * @shell: a #EphyAdBlockManager
141 * Check if Epiphany has currently an active blocker
143 * ReturnValue: TRUE if an active blocker is running
145 gboolean
146 ephy_adblock_manager_has_blocker (EphyAdBlockManager *self)
148 return self->priv->blocker != NULL;