2
2
* Copyright © 2005 Adam Hooper
3
* Copyright © 2008 Nuanti Ltd.
4
5
* This program is free software; you can redistribute it and/or modify
5
6
* it under the terms of the GNU General Public License as published by
23
24
#include "ephy-greasemonkey-extension.h"
24
25
#include "greasemonkey-script.h"
25
#include "mozilla-helpers.h"
26
26
#include "ephy-debug.h"
27
27
#include "ephy-file-helpers.h"
29
#include <epiphany/ephy-extension.h>
30
#include <epiphany/ephy-embed.h>
31
#include <epiphany/ephy-embed-container.h>
32
#include <epiphany/ephy-embed-event.h>
33
#include <epiphany/ephy-embed-factory.h>
34
#include <epiphany/ephy-embed-persist.h>
35
#include <epiphany/ephy-shell.h>
36
#include <epiphany/ephy-window.h>
29
#include <epiphany/epiphany.h>
30
#include <webkit/webkit.h>
38
#include <gtk/gtkmessagedialog.h>
39
#include <gtk/gtkuimanager.h>
41
34
#include <glib/gi18n-lib.h>
42
#include <glib/gstdio.h>
43
36
#include <gio/gio.h>
46
38
#include <sys/stat.h>
47
39
#include <sys/types.h>
347
340
LOG ("Installing script at '%s'", url);
349
persist = EPHY_EMBED_PERSIST
350
(ephy_embed_factory_new_object (EPHY_TYPE_EMBED_PERSIST));
342
persist = g_object_new (EPHY_TYPE_EMBED_PERSIST, NULL);
352
344
ephy_embed_persist_set_source (persist, url);
353
345
ephy_embed_persist_set_embed (persist, embed);
369
361
ephy_embed_persist_save (persist);
365
hovering_over_link_cb (WebKitWebView *web_view,
368
EphyGreasemonkeyExtension *extension)
370
WindowData *window_data;
373
window = EPHY_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (web_view)));
374
g_return_if_fail (window != NULL);
376
window_data = (WindowData *) g_object_get_data (G_OBJECT (window),
378
g_return_if_fail (window_data != NULL);
380
g_free (window_data->last_hovered_url);
381
window_data->last_hovered_url = g_strdup (uri);
385
populate_popup_cb (WebKitWebView *web_view,
387
EphyGreasemonkeyExtension *extension)
390
* Set whether or not the action is visible before we display the
393
WindowData *window_data;
397
gboolean show_install;
400
window = EPHY_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (web_view)));
401
g_return_if_fail (window != NULL);
403
window_data = (WindowData *) g_object_get_data (G_OBJECT (window),
405
g_return_if_fail (window_data != NULL);
407
url = window_data->last_hovered_url;
408
show_install = url && g_str_has_suffix (url, ".user.js");
410
action = gtk_action_group_get_action (window_data->action_group,
412
g_return_if_fail (action != NULL);
414
if (show_install == TRUE)
416
g_free (window_data->last_clicked_url);
417
window_data->last_clicked_url = g_strdup (url);
420
gtk_action_set_visible (action, show_install);
422
item = gtk_action_create_menu_item (action);
423
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
373
428
context_menu_cb (EphyEmbed *embed,
374
429
EphyEmbedEvent *event,
427
483
char *script_str;
429
if (greasemonkey_script_applies_to_url (script, data->location))
431
g_object_get (script, "script", &script_str, NULL);
432
mozilla_evaluate_js (data->event, script_str);
485
if (!greasemonkey_script_applies_to_url (script, data->location))
488
g_object_get (script, "script", &script_str, NULL);
489
webkit_web_view_execute_script (data->web_view, script_str);
438
content_loaded_cb (EphyEmbed *embed,
494
window_object_cleared_cb (WebKitWebView *web_view,
495
WebKitWebFrame *web_frame,
497
gpointer window_object,
440
498
EphyGreasemonkeyExtension *extension)
442
500
ApplyScriptCBData *data;
501
const char *location;
445
location = ephy_embed_get_location (embed, FALSE);
503
location = webkit_web_frame_get_uri (web_frame);
446
504
if (location == NULL)
451
509
data = g_new (ApplyScriptCBData, 1);
510
data->web_view = web_view;
452
511
data->location = location;
455
513
g_hash_table_foreach (extension->priv->scripts,
456
514
(GHFunc) maybe_apply_script, data);
555
612
EphyWindow *window,
556
613
EphyEmbed *embed)
615
WebKitWebView *web_view;
558
616
LOG ("impl_attach_tab");
560
618
g_return_if_fail (EPHY_IS_EMBED (embed));
620
web_view = WEBKIT_WEB_VIEW (gtk_bin_get_child (GTK_BIN (gtk_bin_get_child (GTK_BIN (embed)))));
562
623
g_signal_connect (embed, "ge_context_menu",
563
624
G_CALLBACK (context_menu_cb), ext);
564
g_signal_connect (embed, "dom_content_loaded",
565
G_CALLBACK (content_loaded_cb), ext);
627
g_signal_connect (web_view, "hovering_over_link",
628
G_CALLBACK (hovering_over_link_cb), ext);
630
g_signal_connect (web_view, "populate_popup",
631
G_CALLBACK (populate_popup_cb), ext);
633
g_signal_connect (web_view, "window_object_cleared",
634
G_CALLBACK (window_object_cleared_cb), ext);
570
639
EphyWindow *window,
571
640
EphyEmbed *embed)
642
WebKitWebView *web_view;
573
643
LOG ("impl_detach_tab");
575
645
g_return_if_fail (EPHY_IS_EMBED (embed));
647
web_view = WEBKIT_WEB_VIEW (gtk_bin_get_child (GTK_BIN (gtk_bin_get_child (GTK_BIN (embed)))));
577
650
g_signal_handlers_disconnect_by_func
578
651
(embed, G_CALLBACK (context_menu_cb), ext);
579
g_signal_handlers_disconnect_by_func
580
(embed, G_CALLBACK (content_loaded_cb), ext);
654
g_signal_handlers_disconnect_by_func
655
(web_view, G_CALLBACK (hovering_over_link_cb), ext);
657
g_signal_handlers_disconnect_by_func
658
(web_view, G_CALLBACK (populate_popup_cb), ext);
660
g_signal_handlers_disconnect_by_func
661
(web_view, G_CALLBACK (window_object_cleared_cb), ext);