aboutsummaryrefslogtreecommitdiffstats
path: root/embed/mozilla/mozilla-embed.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'embed/mozilla/mozilla-embed.cpp')
-rw-r--r--embed/mozilla/mozilla-embed.cpp351
1 files changed, 348 insertions, 3 deletions
diff --git a/embed/mozilla/mozilla-embed.cpp b/embed/mozilla/mozilla-embed.cpp
index f1a45c0c7..399fb3795 100644
--- a/embed/mozilla/mozilla-embed.cpp
+++ b/embed/mozilla/mozilla-embed.cpp
@@ -110,6 +110,13 @@ static void mozilla_embed_favicon_cb (EphyEmbed *embed,
static gboolean mozilla_embed_open_uri_cb (EphyEmbed *embed,
const char *uri,
MozillaEmbed *membed);
+static void mozilla_embed_file_monitor_cancel (MozillaEmbed *embed);
+#if 0
+static guint popup_blocker_n_hidden (MozillaEmbed *embed);
+static gboolean mozilla_embed_get_popups_allowed (MozillaEmbed *embed);
+static void mozilla_embed_set_popups_allowed (MozillaEmbed *embed,
+ gboolean allowed);
+#endif
static void mozilla_embed_file_monitor_cancel (MozillaEmbed *embed);
static void impl_set_typed_address (EphyEmbed *embed,
const char *address,
@@ -127,6 +134,7 @@ typedef enum
MOZILLA_EMBED_LOAD_STOPPED
} MozillaEmbedLoadState;
+#define MAX_HIDDEN_POPUPS 5
#define MAX_TITLE_LENGTH 512 /* characters */
#define RELOAD_DELAY 250 /* ms */
#define RELOAD_DELAY_MAX_TICKS 40 /* RELOAD_DELAY * RELOAD_DELAY_MAX_TICKS = 10 s */
@@ -164,7 +172,10 @@ struct MozillaEmbedPrivate
/* File watch */
GnomeVFSMonitorHandle *monitor;
guint reload_scheduled_id;
- guint reload_delay_ticks;
+ guint reload_delay_ticks;
+
+ GSList *hidden_popups;
+ GSList *shown_popups;
};
#define WINDOWWATCHER_CONTRACTID "@mozilla.org/embedcomp/window-watcher;1"
@@ -174,12 +185,14 @@ enum
PROP_0,
PROP_ADDRESS,
PROP_DOCUMENT_TYPE,
+ PROP_HIDDEN_POPUP_COUNT,
PROP_ICON,
PROP_ICON_ADDRESS,
PROP_LINK_MESSAGE,
PROP_LOAD_PROGRESS,
PROP_LOAD_STATUS,
PROP_NAVIGATION,
+ PROP_POPUPS_ALLOWED,
PROP_SECURITY,
PROP_STATUS_MESSAGE,
PROP_TITLE,
@@ -187,6 +200,13 @@ enum
PROP_ZOOM
};
+typedef struct
+{
+ char *url;
+ char *name;
+ char *features;
+} PopupInfo;
+
static void
impl_manager_do_command (EphyCommandManager *manager,
const char *command)
@@ -294,6 +314,10 @@ mozilla_embed_get_property (GObject *object,
case PROP_DOCUMENT_TYPE:
g_value_set_enum (value, priv->document_type);
break;
+ case PROP_HIDDEN_POPUP_COUNT:
+ g_value_set_int (value, 0);
+ // g_value_set_int (value, popup_blocker_n_hidden (embed));
+ break;
case PROP_ICON:
g_value_set_object (value, priv->icon);
break;
@@ -312,6 +336,10 @@ mozilla_embed_get_property (GObject *object,
case PROP_NAVIGATION:
g_value_set_flags (value, priv->nav_flags);
break;
+ case PROP_POPUPS_ALLOWED:
+ g_value_set_boolean (value, FALSE);
+ // g_value_set_boolean (value, mozilla_embed_get_popups_allowed (embed));
+ break;
case PROP_SECURITY:
g_value_set_enum (value, priv->security_level);
break;
@@ -349,8 +377,12 @@ mozilla_embed_set_property (GObject *object,
impl_set_typed_address (EPHY_EMBED (object), g_value_get_string (value),
EPHY_EMBED_ADDRESS_EXPIRE_NOW);
break;
+ case PROP_POPUPS_ALLOWED:
+ //mozilla_embed_set_popups_allowed (MOZILLA_EMBED (object), g_value_get_boolean (value));
+ break;
case PROP_ADDRESS:
case PROP_DOCUMENT_TYPE:
+ case PROP_HIDDEN_POPUP_COUNT:
case PROP_ICON:
case PROP_LOAD_PROGRESS:
case PROP_LOAD_STATUS:
@@ -400,6 +432,8 @@ mozilla_embed_class_init (MozillaEmbedClass *klass)
g_object_class_override_property (object_class, PROP_LINK_MESSAGE, "link-message");
g_object_class_override_property (object_class, PROP_ICON, "icon");
g_object_class_override_property (object_class, PROP_ICON_ADDRESS, "icon-address");
+ g_object_class_override_property (object_class, PROP_POPUPS_ALLOWED, "popups-allowed");
+ g_object_class_override_property (object_class, PROP_HIDDEN_POPUP_COUNT, "hidden-popup-count");
g_type_class_add_private (object_class, sizeof(MozillaEmbedPrivate));
}
@@ -525,6 +559,10 @@ mozilla_embed_finalize (GObject *object)
embed->priv->icon = NULL;
}
+#if 0
+ popups_manager_reset (embed);
+#endif
+
g_free (embed->priv->icon_address);
g_free (embed->priv->address);
g_free (embed->priv->typed_address);
@@ -538,6 +576,314 @@ mozilla_embed_finalize (GObject *object)
g_object_unref (embed_shell);
}
+#if 0
+static void
+ephy_tab_content_change_cb (EphyEmbed *embed, const char *address, EphyTab *tab)
+{
+ popups_manager_reset (tab);
+ g_object_notify (G_OBJECT (tab), "popups-allowed");
+}
+
+static void
+ephy_tab_new_window_cb (EphyEmbed *embed,
+ EphyEmbed *new_embed,
+ EphyTab *tab)
+{
+ EphyWindow *window;
+
+ g_return_if_fail (new_embed != NULL);
+
+ window = EPHY_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (new_embed)));
+ g_return_if_fail (window != NULL);
+
+ popups_manager_add_window (tab, window);
+}
+
+static void
+ephy_tab_popup_blocked_cb (EphyEmbed *embed,
+ const char *url,
+ const char *name,
+ const char *features,
+ EphyTab *tab)
+{
+ popups_manager_add (tab, url, name, features);
+}
+
+static void
+popups_manager_free_info (PopupInfo *popup)
+{
+ g_free (popup->url);
+ g_free (popup->name);
+ g_free (popup->features);
+ g_free (popup);
+}
+
+static void
+popups_manager_add (MozillaEmbed *embed,
+ const char *url,
+ const char *name,
+ const char *features)
+{
+ MozillaEmbedPrivate *priv = embed->priv;
+ PopupInfo *popup;
+
+ LOG ("popups_manager_add: embed %p, url %s, features %s",
+ embed, url, features);
+
+ popup = g_new0 (PopupInfo, 1);
+
+ popup->url = (url == NULL) ? NULL : g_strdup (url);
+ popup->name = g_strdup (name);
+ popup->features = g_strdup (features);
+
+ priv->hidden_popups = g_slist_prepend (priv->hidden_popups, popup);
+
+ if (popup_blocker_n_hidden (embed) > MAX_HIDDEN_POPUPS) /* bug #160863 */
+ {
+ /* Remove the oldest popup */
+ GSList *l = embed->priv->hidden_popups;
+
+ while (l->next->next != NULL)
+ {
+ l = l->next;
+ }
+
+ popup = (PopupInfo *) l->next->data;
+ popups_manager_free_info (popup);
+
+ l->next = NULL;
+ }
+ else
+ {
+ g_object_notify (G_OBJECT (embed), "hidden-popup-count");
+ }
+}
+
+static gboolean
+popups_manager_remove_window (MozillaEmbed *embed,
+ EphyWindow *window)
+{
+ embed->priv->shown_popups = g_slist_remove (embed->priv->shown_popups,
+ window);
+
+ return FALSE;
+}
+
+static void
+disconnect_popup (EphyWindow *window,
+ MozillaEmbed *embed)
+{
+ g_signal_handlers_disconnect_by_func
+ (window, G_CALLBACK (popups_manager_remove_window), embed);
+}
+
+static void
+popups_manager_add_window (MozillaEmbed *embed,
+ EphyWindow *window)
+{
+ LOG ("popups_manager_add_window: embed %p, window %p", embed, window);
+
+ embed->priv->shown_popups = g_slist_prepend
+ (embed->priv->shown_popups, window);
+
+ g_signal_connect_swapped (window, "destroy",
+ G_CALLBACK (popups_manager_remove_window),
+ embed);
+}
+
+static gboolean
+mozilla_embed_get_popups_allowed (MozillaEmbed *embed)
+{
+ EphyPermissionManager *permission_manager;
+ EphyPermission response;
+ EphyEmbed *embed;
+ char *location;
+ gboolean allow;
+
+ permission_manager = EPHY_PERMISSION_MANAGER
+ (ephy_embed_shell_get_embed_single (embed_shell));
+ g_return_val_if_fail (EPHY_IS_PERMISSION_MANAGER (permission_manager),
+ FALSE);
+
+ location = ephy_embed_get_location (embed, TRUE);
+ if (location == NULL) return FALSE; /* FALSE, TRUE… same thing */
+
+ response = ephy_permission_manager_test_permission
+ (permission_manager, location, EPT_POPUP);
+
+ switch (response)
+ {
+ case EPHY_PERMISSION_ALLOWED:
+ allow = TRUE;
+ break;
+ case EPHY_PERMISSION_DENIED:
+ allow = FALSE;
+ break;
+ case EPHY_PERMISSION_DEFAULT:
+ default:
+ allow = eel_gconf_get_boolean
+ (CONF_SECURITY_ALLOW_POPUPS);
+ break;
+ }
+
+ g_free (location);
+
+ LOG ("mozilla_embed_get_popups_allowed: embed %p, allowed: %d", embed, allow);
+
+ return allow;
+}
+
+static void
+popups_manager_show (PopupInfo *popup,
+ MozillaEmbed *embed)
+{
+ EphyEmbed *embed;
+ EphyEmbedSingle *single;
+
+ /* Only show popup with non NULL url */
+ if (popup->url != NULL)
+ {
+ embed = ephy_embed_get_embed (embed);
+
+ single = EPHY_EMBED_SINGLE
+ (ephy_embed_shell_get_embed_single (embed_shell));
+
+ ephy_embed_single_open_window (single, embed, popup->url,
+ popup->name, popup->features);
+ }
+ popups_manager_free_info (popup);
+}
+
+static void
+popups_manager_show_all (MozillaEmbed *embed)
+{
+ LOG ("popup_blocker_show_all: embed %p", embed);
+
+ g_slist_foreach (embed->priv->hidden_popups,
+ (GFunc) popups_manager_show, embed);
+ g_slist_free (embed->priv->hidden_popups);
+ embed->priv->hidden_popups = NULL;
+
+ g_object_notify (G_OBJECT (embed), "hidden-popup-count");
+}
+
+static char *
+popups_manager_new_window_info (EphyWindow *window)
+{
+ MozillaEmbed *embed;
+ EphyEmbedChrome chrome;
+ gboolean is_popup;
+ char *features;
+
+ g_object_get (window, "chrome", &chrome, "is-popup", &is_popup, NULL);
+ g_return_val_if_fail (is_popup, g_strdup (""));
+
+ embed = ephy_window_get_active_embed (window);
+ g_return_val_if_fail (embed != NULL, g_strdup (""));
+
+ features = g_strdup_printf
+ ("width=%d,height=%d,menubar=%d,status=%d,toolbar=%d",
+ embed->priv->width, embed->priv->height,
+ (chrome & EPHY_EMBED_CHROME_MENUBAR) > 0,
+ (chrome & EPHY_EMBED_CHROME_STATUSBAR) > 0,
+ (chrome & EPHY_EMBED_CHROME_TOOLBAR) > 0);
+
+ return features;
+}
+
+static void
+popups_manager_hide (EphyWindow *window,
+ MozillaEmbed *parent_embed)
+{
+ EphyEmbed *embed;
+ char *location;
+ char *features;
+
+ embed = ephy_window_get_active_embed (window);
+ g_return_if_fail (EPHY_IS_EMBED (embed));
+
+ location = ephy_embed_get_location (embed, TRUE);
+ if (location == NULL) return;
+
+ features = popups_manager_new_window_info (window);
+
+ popups_manager_add (parent_embed, location, "" /* FIXME? maybe _blank? */, features);
+
+ gtk_widget_destroy (GTK_WIDGET (window));
+
+ g_free (location);
+ g_free (features);
+}
+
+static void
+popups_manager_hide_all (MozillaEmbed *embed)
+{
+ LOG ("popup_blocker_hide_all: embed %p", embed);
+
+ g_slist_foreach (embed->priv->shown_popups,
+ (GFunc) popups_manager_hide, embed);
+ g_slist_free (embed->priv->shown_popups);
+ embed->priv->shown_popups = NULL;
+}
+
+static void
+mozilla_embed_set_popups_allowed (MozillaEmbed *embed,
+ gboolean allowed)
+{
+ char *location;
+ EphyEmbed *embed;
+ EphyPermissionManager *manager;
+ EphyPermission permission;
+
+ embed = ephy_embed_get_embed (embed);
+
+ location = ephy_embed_get_location (embed, TRUE);
+ g_return_if_fail (location != NULL);
+
+ manager = EPHY_PERMISSION_MANAGER
+ (ephy_embed_shell_get_embed_single (embed_shell));
+ g_return_if_fail (EPHY_IS_PERMISSION_MANAGER (manager));
+
+ permission = allowed ? EPHY_PERMISSION_ALLOWED
+ : EPHY_PERMISSION_DENIED;
+
+ ephy_permission_manager_add_permission (manager, location, EPT_POPUP, permission);
+
+ if (allowed)
+ {
+ popups_manager_show_all (embed);
+ }
+ else
+ {
+ popups_manager_hide_all (embed);
+ }
+
+ g_free (location);
+}
+
+static guint
+popup_blocker_n_hidden (MozillaEmbed *embed)
+{
+ return g_slist_length (embed->priv->hidden_popups);
+}
+
+static void
+popups_manager_reset (MozillaEmbed *embed)
+{
+ g_slist_foreach (embed->priv->hidden_popups,
+ (GFunc) popups_manager_free_info, NULL);
+ g_slist_free (embed->priv->hidden_popups);
+ embed->priv->hidden_popups = NULL;
+
+ g_slist_foreach (embed->priv->shown_popups,
+ (GFunc) disconnect_popup, embed);
+ g_slist_free (embed->priv->shown_popups);
+ embed->priv->shown_popups = NULL;
+
+ g_object_notify (G_OBJECT (embed), "hidden-popup-count");
+}
+#endif
+
static void
impl_load_url (EphyEmbed *embed,
const char *url)
@@ -1512,7 +1858,7 @@ mozilla_embed_load_icon (MozillaEmbed *embed)
EphyFaviconCache *cache;
if (priv->icon_address == NULL || priv->icon != NULL) return;
-#if 0
+
shell = ephy_embed_shell_get_default ();
cache = EPHY_FAVICON_CACHE (ephy_embed_shell_get_favicon_cache (shell));
@@ -1520,7 +1866,6 @@ mozilla_embed_load_icon (MozillaEmbed *embed)
priv->icon = ephy_favicon_cache_get (cache, priv->icon_address);
g_object_notify (G_OBJECT (embed), "icon");
-#endif
}
static void