~l3on/ubuntu/precise/epiphany-extensions/new-release

« back to all changes in this revision

Viewing changes to extensions/greasemonkey/ephy-greasemonkey-extension.c

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2009-09-18 14:08:05 UTC
  • mfrom: (1.1.36 upstream)
  • Revision ID: james.westby@ubuntu.com-20090918140805-fa8kka5uo6u5l5io
Tags: 2.27.92-0ubuntu1
* new upstream 2.27.92 ships ships epiphany-webkit extensions only
  - update debian/control - move from epiphany-browser to -webkit
  - update debian/rules - drop link creation that tried to support -browser
    and -webkit parts and run dh_pysupport on epiphany-webkit dir
  - update debian/rules - use really-all extensions
  - add debian/patches/02_greasemonkey_web_view.patch - fix greasemonkey
    extension being broken by bad web_view lookup - bgo 595814

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *  Copyright © 2005 Adam Hooper
 
3
 *  Copyright © 2008 Nuanti Ltd.
3
4
 *
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
22
23
 
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"
28
28
 
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>
37
31
 
38
 
#include <gtk/gtkmessagedialog.h>
39
 
#include <gtk/gtkuimanager.h>
 
32
#include <gtk/gtk.h>
40
33
 
41
34
#include <glib/gi18n-lib.h>
42
 
#include <glib/gstdio.h>
 
35
#include <glib.h>
43
36
#include <gio/gio.h>
44
 
#include <gmodule.h>
45
37
 
46
38
#include <sys/stat.h>
47
39
#include <sys/types.h>
67
59
        GList *pending_downloads;
68
60
        guint ui_id;
69
61
        char *last_clicked_url;
 
62
        char *last_hovered_url;
70
63
} WindowData;
71
64
 
72
65
typedef struct
73
66
{
 
67
        WebKitWebView *web_view;
74
68
        const char *location;
75
 
        gpointer event;
76
69
} ApplyScriptCBData;
77
70
 
78
71
static void ephy_greasemonkey_extension_install_cb (GtkAction *action,
346
339
 
347
340
        LOG ("Installing script at '%s'", url);
348
341
 
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);
351
343
 
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);
370
362
}
371
363
 
 
364
static void
 
365
hovering_over_link_cb (WebKitWebView *web_view,
 
366
                 const gchar *title,
 
367
                 const gchar *uri,
 
368
                 EphyGreasemonkeyExtension *extension)
 
369
{
 
370
        WindowData *window_data;
 
371
        EphyWindow *window;
 
372
 
 
373
        window = EPHY_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (web_view)));
 
374
        g_return_if_fail (window != NULL);
 
375
 
 
376
        window_data = (WindowData *) g_object_get_data (G_OBJECT (window),
 
377
                                                        WINDOW_DATA_KEY);
 
378
        g_return_if_fail (window_data != NULL);
 
379
 
 
380
        g_free (window_data->last_hovered_url);
 
381
        window_data->last_hovered_url = g_strdup (uri);
 
382
}
 
383
 
 
384
static void
 
385
populate_popup_cb (WebKitWebView *web_view,
 
386
                 GtkMenu *menu,
 
387
                 EphyGreasemonkeyExtension *extension)
 
388
{
 
389
        /*
 
390
         * Set whether or not the action is visible before we display the
 
391
         * context popup menu
 
392
         */
 
393
        WindowData *window_data;
 
394
        EphyWindow *window;
 
395
        GtkAction *action;
 
396
        const char *url;
 
397
        gboolean show_install;
 
398
        GtkWidget *item;
 
399
 
 
400
        window = EPHY_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (web_view)));
 
401
        g_return_if_fail (window != NULL);
 
402
 
 
403
        window_data = (WindowData *) g_object_get_data (G_OBJECT (window),
 
404
                                                        WINDOW_DATA_KEY);
 
405
        g_return_if_fail (window_data != NULL);
 
406
 
 
407
        url = window_data->last_hovered_url;
 
408
        show_install = url && g_str_has_suffix (url, ".user.js");
 
409
 
 
410
        action = gtk_action_group_get_action (window_data->action_group,
 
411
                                              ACTION_NAME);
 
412
        g_return_if_fail (action != NULL);
 
413
 
 
414
        if (show_install == TRUE)
 
415
        {
 
416
                g_free (window_data->last_clicked_url);
 
417
                window_data->last_clicked_url = g_strdup (url);
 
418
        }
 
419
 
 
420
        gtk_action_set_visible (action, show_install);
 
421
 
 
422
        item = gtk_action_create_menu_item (action);
 
423
        gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
 
424
}
 
425
 
 
426
#if 0
372
427
static gboolean
373
428
context_menu_cb (EphyEmbed *embed,
374
429
                 EphyEmbedEvent *event,
418
473
 
419
474
        return FALSE;
420
475
}
 
476
#endif
421
477
 
422
478
static void
423
479
maybe_apply_script (const char *basename,
426
482
{
427
483
        char *script_str;
428
484
 
429
 
        if (greasemonkey_script_applies_to_url (script, data->location))
430
 
        {
431
 
                g_object_get (script, "script", &script_str, NULL);
432
 
                mozilla_evaluate_js (data->event, script_str);
433
 
                g_free (script_str);
434
 
        }
 
485
        if (!greasemonkey_script_applies_to_url (script, data->location))
 
486
            return;
 
487
 
 
488
        g_object_get (script, "script", &script_str, NULL);
 
489
        webkit_web_view_execute_script (data->web_view, script_str);
 
490
        g_free (script_str);
435
491
}
436
492
 
437
493
static void
438
 
content_loaded_cb (EphyEmbed *embed,
439
 
                   gpointer event,
 
494
window_object_cleared_cb (WebKitWebView *web_view,
 
495
                   WebKitWebFrame *web_frame,
 
496
                   gpointer context,
 
497
                   gpointer window_object,
440
498
                   EphyGreasemonkeyExtension *extension)
441
499
{
442
500
        ApplyScriptCBData *data;
443
 
        char *location;
 
501
        const char *location;
444
502
 
445
 
        location = ephy_embed_get_location (embed, FALSE);
 
503
        location = webkit_web_frame_get_uri (web_frame);
446
504
        if (location == NULL)
447
505
        {
448
506
                return;
449
507
        }
450
508
 
451
509
        data = g_new (ApplyScriptCBData, 1);
 
510
        data->web_view = web_view;
452
511
        data->location = location;
453
 
        data->event = event;
454
512
 
455
513
        g_hash_table_foreach (extension->priv->scripts,
456
514
                              (GHFunc) maybe_apply_script, data);
457
515
 
458
 
        g_free (location);
459
516
        g_free (data);
460
517
}
461
518
 
555
612
                 EphyWindow *window,
556
613
                 EphyEmbed *embed)
557
614
{
 
615
        WebKitWebView *web_view;
558
616
        LOG ("impl_attach_tab");
559
617
 
560
618
        g_return_if_fail (EPHY_IS_EMBED (embed));
561
619
 
 
620
        web_view = WEBKIT_WEB_VIEW (gtk_bin_get_child (GTK_BIN (gtk_bin_get_child (GTK_BIN (embed)))));
 
621
 
 
622
#if 0
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);
 
625
#endif
 
626
 
 
627
        g_signal_connect (web_view, "hovering_over_link",
 
628
                          G_CALLBACK (hovering_over_link_cb), ext);
 
629
 
 
630
        g_signal_connect (web_view, "populate_popup",
 
631
                          G_CALLBACK (populate_popup_cb), ext);
 
632
 
 
633
        g_signal_connect (web_view, "window_object_cleared",
 
634
                          G_CALLBACK (window_object_cleared_cb), ext);
566
635
}
567
636
 
568
637
static void
570
639
                 EphyWindow *window,
571
640
                 EphyEmbed *embed)
572
641
{
 
642
        WebKitWebView *web_view;
573
643
        LOG ("impl_detach_tab");
574
644
 
575
645
        g_return_if_fail (EPHY_IS_EMBED (embed));
576
646
 
 
647
        web_view = WEBKIT_WEB_VIEW (gtk_bin_get_child (GTK_BIN (gtk_bin_get_child (GTK_BIN (embed)))));
 
648
 
 
649
#if 0
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);
 
652
#endif
 
653
 
 
654
        g_signal_handlers_disconnect_by_func
 
655
                (web_view, G_CALLBACK (hovering_over_link_cb), ext);
 
656
 
 
657
        g_signal_handlers_disconnect_by_func
 
658
                (web_view, G_CALLBACK (populate_popup_cb), ext);
 
659
 
 
660
        g_signal_handlers_disconnect_by_func
 
661
                (web_view, G_CALLBACK (window_object_cleared_cb), ext);
581
662
}
582
663
 
583
664
static void