~midori/midori/trunk

« back to all changes in this revision

Viewing changes to midori/midori-view.c

  • Committer: Tarmac
  • Author(s): Christian Dywan
  • Date: 2013-06-19 21:00:46 UTC
  • mfrom: (6216.1.10 midori.butcher)
  • Revision ID: tarmac-20130619210046-i3yv8cnkyjuafubb
Bump WebKit requirement to 1.8.3 and drop support for earlier versions

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
    #include <sys/utsname.h>
57
57
#endif
58
58
 
59
 
#if !WEBKIT_CHECK_VERSION (1, 4, 3)
60
 
/* This is unstable API, so we need to declare it */
61
 
gchar*
62
 
webkit_web_view_get_selected_text (WebKitWebView* web_view);
63
 
#endif
64
 
 
65
59
static void
66
60
midori_view_item_meta_data_changed (KatzeItem*   item,
67
61
                                    const gchar* key,
492
486
    g_object_unref (icon);
493
487
}
494
488
 
495
 
#if !WEBKIT_CHECK_VERSION (1, 3, 13)
496
 
static GdkPixbuf*
497
 
katze_pixbuf_new_from_buffer (const guchar* buffer,
498
 
                              gsize         length,
499
 
                              const gchar*  mime_type,
500
 
                              GError**      error)
501
 
{
502
 
    /* Proposed for inclusion in GdkPixbuf
503
 
       See http://bugzilla.gnome.org/show_bug.cgi?id=74291 */
504
 
    GdkPixbufLoader* loader;
505
 
    GdkPixbuf* pixbuf;
506
 
 
507
 
    g_return_val_if_fail (buffer != NULL, NULL);
508
 
    g_return_val_if_fail (length > 0, NULL);
509
 
 
510
 
    if (mime_type)
511
 
    {
512
 
        loader = gdk_pixbuf_loader_new_with_mime_type (mime_type, error);
513
 
        if (!loader)
514
 
            return NULL;
515
 
    }
516
 
    else
517
 
        loader = gdk_pixbuf_loader_new ();
518
 
    if (!gdk_pixbuf_loader_write (loader, buffer, length, error))
519
 
    {
520
 
        g_object_unref (loader);
521
 
        return NULL;
522
 
    }
523
 
    if (!gdk_pixbuf_loader_close (loader, error))
524
 
    {
525
 
        g_object_unref (loader);
526
 
        return NULL;
527
 
    }
528
 
 
529
 
    pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
530
 
    g_object_ref (pixbuf);
531
 
    g_object_unref (loader);
532
 
    return pixbuf;
533
 
}
534
 
 
535
 
static void
536
 
katze_net_object_maybe_unref (gpointer object)
537
 
{
538
 
    if (object)
539
 
        g_object_unref (object);
540
 
}
541
 
 
542
 
static GHashTable*
543
 
midori_view_get_memory (void)
544
 
{
545
 
    static GHashTable* memory = NULL;
546
 
    if (!memory)
547
 
        memory = g_hash_table_new_full (g_str_hash, g_str_equal,
548
 
            g_free, katze_net_object_maybe_unref);
549
 
    return (memory);
550
 
}
551
 
 
552
 
static gboolean
553
 
katze_net_icon_status_cb (KatzeNetRequest*  request,
554
 
                          MidoriView*       view)
555
 
{
556
 
    switch (request->status)
557
 
    {
558
 
        case KATZE_NET_VERIFIED:
559
 
            if (request->mime_type && strncmp (request->mime_type, "image/", 6))
560
 
            {
561
 
                return FALSE;
562
 
            }
563
 
            break;
564
 
        case KATZE_NET_MOVED:
565
 
            break;
566
 
        default:
567
 
            return FALSE;
568
 
    }
569
 
    return TRUE;
570
 
}
571
 
 
572
 
static void
573
 
katze_net_icon_transfer_cb (KatzeNetRequest*  request,
574
 
                            MidoriView*       view)
575
 
{
576
 
    GdkPixbuf* pixbuf;
577
 
    FILE* fp;
578
 
    GdkPixbuf* pixbuf_scaled;
579
 
    gint icon_width, icon_height;
580
 
    size_t ret;
581
 
    GtkSettings* settings;
582
 
 
583
 
    if (request->status == KATZE_NET_MOVED)
584
 
        return;
585
 
 
586
 
    pixbuf = NULL;
587
 
    if (request->data)
588
 
    {
589
 
        gchar* icon_file = katze_net_get_cached_path (NULL, view->icon_uri, "icons");
590
 
        if (icon_file && (fp = fopen (icon_file, "wb")))
591
 
        {
592
 
            ret = fwrite (request->data, 1, request->length, fp);
593
 
            fclose (fp);
594
 
            if ((ret - request->length != 0))
595
 
                g_warning ("Error writing to file %s in %s", icon_file, G_STRFUNC);
596
 
        }
597
 
        g_free (icon_file);
598
 
 
599
 
        pixbuf = katze_pixbuf_new_from_buffer ((guchar*)request->data,
600
 
                            request->length, request->mime_type, NULL);
601
 
 
602
 
    }
603
 
 
604
 
    if (!pixbuf)
605
 
    {
606
 
        midori_view_unset_icon (view);
607
 
        return;
608
 
    }
609
 
 
610
 
    g_hash_table_insert (midori_view_get_memory (), g_strdup (view->icon_uri), pixbuf);
611
 
    settings = gtk_widget_get_settings (view->web_view);
612
 
    gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &icon_width, &icon_height);
613
 
    pixbuf_scaled = gdk_pixbuf_scale_simple (pixbuf, icon_width, icon_height, GDK_INTERP_BILINEAR);
614
 
    midori_view_apply_icon (view, pixbuf_scaled, view->icon_uri);
615
 
}
616
 
#endif
617
 
 
618
489
static void
619
490
_midori_web_view_load_icon (MidoriView* view)
620
491
{
634
505
        g_object_unref (pixbuf);
635
506
        midori_view_apply_icon (view, pixbuf_scaled, view->icon_uri);
636
507
    }
637
 
    #elif WEBKIT_CHECK_VERSION (1, 8, 0)
 
508
    #else
638
509
    if ((pixbuf = webkit_web_view_try_get_favicon_pixbuf (
639
510
        WEBKIT_WEB_VIEW (view->web_view), icon_width, icon_height)))
640
511
        midori_view_apply_icon (view, pixbuf, view->icon_uri);
641
 
    #elif WEBKIT_CHECK_VERSION (1, 3, 13)
642
 
    if ((pixbuf = webkit_web_view_get_icon_pixbuf (
643
 
        WEBKIT_WEB_VIEW (view->web_view))))
644
 
    {
645
 
        GdkPixbuf* pixbuf_scaled = gdk_pixbuf_scale_simple (pixbuf,
646
 
            icon_width, icon_height, GDK_INTERP_BILINEAR);
647
 
        g_object_unref (pixbuf);
648
 
        midori_view_apply_icon (view, pixbuf_scaled, view->icon_uri);
649
 
    }
650
 
    #else
651
 
    GdkPixbuf* pixbuf_scaled;
652
 
    const gchar* uri = midori_tab_get_uri (MIDORI_TAB (view));
653
 
 
654
 
    if (!midori_uri_is_http (view->icon_uri))
655
 
        katze_assign (view->icon_uri, NULL);
656
 
 
657
 
    if (midori_uri_is_http (uri) || g_str_has_prefix (uri, "file://"))
658
 
    {
659
 
        gchar* icon_file = NULL;
660
 
        if (!view->icon_uri)
661
 
        {
662
 
            guint i = 8;
663
 
            while (uri[i] != '\0' && uri[i] != '/')
664
 
                i++;
665
 
            if (uri[i] == '/')
666
 
            {
667
 
                gchar* path = g_strndup (uri, i);
668
 
                view->icon_uri = g_strdup_printf ("%s/favicon.ico", path);
669
 
                g_free (path);
670
 
            }
671
 
            else
672
 
                view->icon_uri = g_strdup_printf ("%s/favicon.ico", uri);
673
 
        }
674
 
 
675
 
        if (g_hash_table_lookup_extended (midori_view_get_memory (),
676
 
                                          view->icon_uri, NULL, (gpointer)&pixbuf))
677
 
        {
678
 
            g_warn_if_fail (pixbuf != NULL);
679
 
            g_object_ref (pixbuf);
680
 
        }
681
 
        else if ((icon_file = katze_net_get_cached_path (NULL, view->icon_uri, "icons")) &&
682
 
                 (pixbuf = gdk_pixbuf_new_from_file (icon_file, NULL)))
683
 
        {
684
 
            g_hash_table_insert (midori_view_get_memory (),
685
 
                g_strdup (view->icon_uri), g_object_ref (pixbuf));
686
 
        }
687
 
        else if (!midori_tab_get_special (MIDORI_TAB (view)))
688
 
        {
689
 
            katze_net_load_uri (NULL, view->icon_uri,
690
 
                (KatzeNetStatusCb)katze_net_icon_status_cb,
691
 
                (KatzeNetTransferCb)katze_net_icon_transfer_cb, view);
692
 
        }
693
 
 
694
 
        g_free (icon_file);
695
 
    }
696
 
 
697
 
    if (pixbuf)
698
 
    {
699
 
        pixbuf_scaled = gdk_pixbuf_scale_simple (pixbuf,
700
 
            icon_width,  icon_height, GDK_INTERP_BILINEAR);
701
 
        g_object_unref (pixbuf);
702
 
        pixbuf = pixbuf_scaled;
703
 
        midori_view_apply_icon (view, pixbuf, view->icon_uri);
704
 
    }
705
512
    #endif
706
513
}
707
514
 
1347
1154
    }
1348
1155
}
1349
1156
 
1350
 
#if WEBKIT_CHECK_VERSION (1, 1, 23)
1351
1157
static void
1352
1158
midori_view_location_response_cb (GtkWidget*                       infobar,
1353
1159
                                  gint                             response,
1378
1184
    return TRUE;
1379
1185
}
1380
1186
#endif
1381
 
#endif
1382
1187
 
1383
1188
void
1384
1189
midori_view_set_html (MidoriView*     view,
1549
1354
        "f.push ('$' + l[i].href + '|' + l[i].title);"
1550
1355
        "else if (r == 'search' && t == 'application/opensearchdescription+xml') "
1551
1356
        "f.push (':' + l[i].href + '|' + l[i].title); "
1552
 
        #if !WEBKIT_CHECK_VERSION (1, 1, 18)
1553
 
        "else if (r && r.indexOf ('icon') != -1) f.push (l[i].href); "
1554
 
        #endif
1555
1357
        "} if (document.location.href.indexOf ('twitter') != -1)"
1556
1358
        "{ var s = document.location.href.split('/'); "
1557
1359
        "var u = 'https://api.twitter.com/1/statuses/user_timeline.rss"
1613
1415
                    G_CALLBACK (midori_view_open_search_response_cb), view,
1614
1416
                    _("_Save Search engine"), GTK_RESPONSE_ACCEPT, NULL); */
1615
1417
            }
1616
 
            #if !WEBKIT_CHECK_VERSION (1, 1, 18)
1617
 
            else
1618
 
                katze_assign (view->icon_uri, g_strdup (uri_and_title));
1619
 
            #endif
1620
1418
 
1621
1419
            news_feeds_continue:
1622
1420
            current_item++;
1625
1423
 
1626
1424
        g_object_set_data_full (G_OBJECT (view), "news-feeds", default_uri, g_free);
1627
1425
        g_free (value);
1628
 
 
1629
 
        #if !WEBKIT_CHECK_VERSION (1, 4, 3)
1630
 
        _midori_web_view_load_icon (view);
1631
 
        #endif
1632
1426
    }
1633
1427
    #endif
1634
1428
 
1708
1502
}
1709
1503
#endif
1710
1504
 
1711
 
 
1712
 
#if WEBKIT_CHECK_VERSION (1, 1, 18)
1713
1505
static void
1714
1506
midori_web_view_notify_icon_uri_cb (WebKitWebView* web_view,
1715
1507
                                    GParamSpec*    pspec,
1726
1518
    katze_assign (view->icon_uri, icon_uri);
1727
1519
    _midori_web_view_load_icon (view);
1728
1520
}
1729
 
#endif
1730
1521
 
1731
1522
static void
1732
1523
webkit_web_view_notify_uri_cb (WebKitWebView* web_view,
1783
1574
    const gchar* link_uri = webkit_hit_test_result_get_link_uri (hit_test_result);
1784
1575
    #endif
1785
1576
 
1786
 
    #if !(WEBKIT_CHECK_VERSION (1, 3, 1) && defined (HAVE_LIBSOUP_2_29_91))
1787
 
    sokoke_prefetch_uri (view->settings, link_uri, NULL, NULL);
1788
 
    #endif
1789
 
 
1790
1577
    katze_assign (view->link_uri, g_strdup (link_uri));
1791
1578
    if (link_uri && g_str_has_prefix (link_uri, "mailto:"))
1792
1579
    {
2511
2298
#endif
2512
2299
}
2513
2300
 
2514
 
#if WEBKIT_CHECK_VERSION (1, 5, 0)
2515
2301
static void
2516
2302
midori_view_menu_add_search_engine_cb (GtkWidget*  widget,
2517
2303
                                       MidoriView* view)
2522
2308
    KatzeItem* item = g_object_get_data (G_OBJECT (widget), "item");
2523
2309
    midori_search_action_get_editor (MIDORI_SEARCH_ACTION (action), item, TRUE);
2524
2310
}
2525
 
#endif
2526
2311
 
2527
2312
static GtkWidget*
2528
2313
midori_view_insert_menu_item (GtkMenuShell* menu,
2637
2422
            webkit_web_view_can_undo (web_view));
2638
2423
        gtk_menu_shell_prepend (menu_shell, menuitem);
2639
2424
 
2640
 
        #if WEBKIT_CHECK_VERSION (1, 5, 0)
2641
2425
        {
2642
2426
            KatzeItem* item = midori_search_action_get_engine_for_form (
2643
2427
                WEBKIT_WEB_VIEW (view->web_view), view->ellipsize);
2650
2434
                gtk_widget_show (menuitem);
2651
2435
            }
2652
2436
        }
2653
 
        #endif
2654
2437
 
2655
2438
        if (manual)
2656
2439
        {
3923
3706
                      midori_view_web_view_resource_request_cb, view,
3924
3707
                      "signal::database-quota-exceeded",
3925
3708
                      midori_view_web_view_database_quota_exceeded_cb, view,
3926
 
                      #if WEBKIT_CHECK_VERSION (1, 1, 23)
3927
3709
                      "signal::geolocation-policy-decision-requested",
3928
3710
                      midori_view_web_view_geolocation_decision_cb, view,
3929
 
                      #endif
3930
 
                      #if WEBKIT_CHECK_VERSION (1, 1, 18)
3931
3711
                      "signal::notify::icon-uri",
3932
3712
                      midori_web_view_notify_icon_uri_cb, view,
3933
 
                      #endif
3934
3713
                      "signal::hovering-over-link",
3935
3714
                      webkit_web_view_hovering_over_link_cb, view,
3936
3715
                      "signal::status-bar-text-changed",
4119
3898
                    webkit_plugin_get_name (plugins->data),
4120
3899
                    html ? webkit_plugin_get_description (plugins->data) : ""));
4121
3900
        }
4122
 
    #elif WEBKIT_CHECK_VERSION (1, 3, 8)
 
3901
    #else
4123
3902
    WebKitWebPluginDatabase* pdb = webkit_get_web_plugin_database ();
4124
3903
    GSList* plugins = webkit_web_plugin_database_get_plugins (pdb);
4125
3904
    GSList* plugin = plugins;
4132
3911
            html ? webkit_web_plugin_get_description (plugin->data) : ""));
4133
3912
    }
4134
3913
    webkit_web_plugin_database_plugins_list_free (plugins);
4135
 
    #else
4136
 
    if (view == NULL)
4137
 
        return;
4138
 
 
4139
 
    WebKitWebFrame* web_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (view->web_view));
4140
 
    JSContextRef js_context = webkit_web_frame_get_global_context (web_frame);
4141
 
    /* Joins available plugins like this: URI1|title1,URI2|title2 */
4142
 
    gchar* value = sokoke_js_script_eval (js_context,
4143
 
        "function plugins (l) { var f = new Array (); for (var i in l) "
4144
 
        "{ var p = l[i].name + '|' + l[i].filename; "
4145
 
        "if (f.indexOf (p) == -1) f.push (p); } return f; }"
4146
 
        "plugins (navigator.plugins)", NULL);
4147
 
    gchar** items = g_strsplit (value, ",", 0);
4148
 
    guint i = 0;
4149
 
    if (items != NULL)
4150
 
        while (items[i] != NULL)
4151
 
        {
4152
 
            gchar** parts = g_strsplit (items[i], "|", 2);
4153
 
            if (parts[0] && !g_str_equal (parts[1], "undefined")
4154
 
             && !midori_web_settings_skip_plugin (parts[1]))
4155
 
                midori_view_add_version (ns_plugins, html, g_strdup_printf ("%s\t%s",
4156
 
                    parts[1], html ? parts[0] : ""));
4157
 
            g_strfreev (parts);
4158
 
            i++;
4159
 
        }
4160
 
        if (g_str_has_prefix (value, "undefined"))
4161
 
            midori_view_add_version (ns_plugins, html, g_strdup_printf ("%s",
4162
 
                "No plugins found"));
4163
 
        g_strfreev (items);
4164
 
        g_free (value);
4165
3914
    #endif
4166
3915
}
4167
3916
 
4700
4449
midori_view_has_selection (MidoriView* view)
4701
4450
{
4702
4451
#ifndef HAVE_WEBKIT2
4703
 
#if WEBKIT_CHECK_VERSION (1, 4, 3)
4704
4452
    WebKitDOMDocument* doc;
4705
4453
    WebKitDOMDOMWindow* window;
4706
4454
    WebKitDOMDOMSelection* selection;
4707
4455
    WebKitDOMRange* range;
4708
 
#endif
4709
4456
 
4710
4457
    g_return_val_if_fail (MIDORI_IS_VIEW (view), FALSE);
4711
4458
 
4712
4459
 
4713
 
#if WEBKIT_CHECK_VERSION (1, 4, 3)
4714
4460
    doc = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view->web_view));
4715
4461
    window = webkit_dom_document_get_default_view (doc);
4716
4462
    selection = webkit_dom_dom_window_get_selection (window);
4723
4469
        return FALSE;
4724
4470
 
4725
4471
    katze_assign (view->selected_text, webkit_dom_range_get_text (range));
4726
 
#else
4727
 
    katze_assign (view->selected_text, webkit_web_view_get_selected_text (
4728
 
        WEBKIT_WEB_VIEW (view->web_view)));
4729
 
#endif
4730
4472
 
4731
4473
    if (view->selected_text && *view->selected_text)
4732
4474
        return TRUE;