~ubuntu-branches/ubuntu/oneiric/midori/oneiric-updates

« back to all changes in this revision

Viewing changes to midori/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Yves-Alexis Perez
  • Date: 2011-08-02 09:44:09 UTC
  • mfrom: (1.1.17 upstream) (3.3.11 sid)
  • Revision ID: james.westby@ubuntu.com-20110802094409-b0eekdkttqs5a528
Tags: 0.4.0-1
* New upstream release.
* debian/control:
  - bump webkit build-dep to 1.1.17.
  - bump valac build-dep to 0.10.

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
    #include <gdk/gdkx.h>
62
62
#endif
63
63
 
 
64
#ifdef G_OS_WIN32
 
65
    #define LIBPREFIX ""
 
66
#else
 
67
    #define LIBPREFIX "lib"
 
68
#endif
 
69
 
64
70
static gchar*
65
71
build_config_filename (const gchar* filename)
66
72
{
420
426
                           char**       errmsg)
421
427
{
422
428
    sqlite3* db;
423
 
    gboolean has_day;
 
429
    gboolean has_day = FALSE;
424
430
    sqlite3_stmt* stmt;
425
431
    gint result;
426
432
    gchar* sql;
427
433
 
428
 
    has_day = FALSE;
429
 
 
430
434
    if (sqlite3_open (filename, &db) != SQLITE_OK)
431
435
    {
432
436
        if (errmsg)
593
597
{
594
598
    KatzeItem* item;
595
599
    KATZE_ARRAY_FOREACH_ITEM (item, session)
596
 
        katze_item_set_meta_integer (item, "delay", 1);
 
600
    {
 
601
        if (katze_item_get_meta_integer (item, "delay") == -1)
 
602
            katze_item_set_meta_integer (item, "delay", 1);
 
603
    }
597
604
}
598
605
 
599
606
static void
718
725
}
719
726
 
720
727
static void
721
 
midori_preferences_delete_cookies_changed_cb (GtkComboBox*       combo,
722
 
                                              MidoriWebSettings* settings)
723
 
{
724
 
    gint active = gtk_combo_box_get_active (combo);
725
 
    gint max_age;
726
 
    switch (active)
727
 
    {
728
 
    case 0: max_age =   0; break;
729
 
    case 1: max_age =   1; break;
730
 
    case 2: max_age =   7; break;
731
 
    case 3: max_age =  30; break;
732
 
    case 4: max_age = 365; break;
733
 
    default:
734
 
        max_age = 30;
735
 
    }
736
 
    g_object_set (settings, "maximum-cookie-age", max_age, NULL);
737
 
}
738
 
 
739
 
static void
740
728
midori_browser_privacy_preferences_cb (MidoriBrowser*    browser,
741
729
                                       KatzePreferences* preferences,
742
730
                                       MidoriApp*        app)
744
732
    MidoriWebSettings* settings = midori_browser_get_settings (browser);
745
733
    GtkWidget* button;
746
734
    GtkWidget* label;
747
 
    gint max_age = katze_object_get_int (settings, "maximum-cookie-age");
748
 
    guint active;
749
735
    gchar* markup;
750
736
 
751
737
    katze_preferences_add_category (preferences, _("Privacy"), GTK_STOCK_INDEX);
752
738
    katze_preferences_add_group (preferences, NULL);
753
739
    button = katze_property_label (settings, "maximum-cookie-age");
754
740
    katze_preferences_add_widget (preferences, button, "indented");
755
 
    button = gtk_combo_box_new_text ();
756
 
    gtk_combo_box_append_text (GTK_COMBO_BOX (button), _("Delete old cookies after 1 hour"));
757
 
    gtk_combo_box_append_text (GTK_COMBO_BOX (button), _("Delete old cookies after 1 day"));
758
 
    gtk_combo_box_append_text (GTK_COMBO_BOX (button), _("Delete old cookies after 1 week"));
759
 
    gtk_combo_box_append_text (GTK_COMBO_BOX (button), _("Delete old cookies after 1 month"));
760
 
    gtk_combo_box_append_text (GTK_COMBO_BOX (button), _("Delete old cookies after 1 year"));
761
 
 
762
 
    switch (max_age)
763
 
    {
764
 
    case   0: active = 0; break;
765
 
    case   1: active = 1; break;
766
 
    case   7: active = 2; break;
767
 
    case  30: active = 3; break;
768
 
    case 365: active = 4; break;
769
 
    default:
770
 
        active = 3;
771
 
    }
772
 
    gtk_combo_box_set_active (GTK_COMBO_BOX (button), active);
773
 
    g_signal_connect (button, "changed",
774
 
        G_CALLBACK (midori_preferences_delete_cookies_changed_cb), settings);
 
741
    button = katze_property_proxy (settings, "maximum-cookie-age", "days");
775
742
    katze_preferences_add_widget (preferences, button, "spanned");
776
743
 
777
744
    markup = g_strdup_printf ("<span size=\"smaller\">%s</span>",
781
748
    gtk_label_set_markup (GTK_LABEL (label), markup);
782
749
    g_free (markup);
783
750
    katze_preferences_add_widget (preferences, label, "filled");
784
 
    #if WEBKIT_CHECK_VERSION (1, 1, 13)
785
751
    button = katze_property_proxy (settings, "enable-offline-web-application-cache", NULL);
786
752
    katze_preferences_add_widget (preferences, button, "indented");
787
 
    #endif
788
 
    #if WEBKIT_CHECK_VERSION (1, 1, 8)
789
753
    button = katze_property_proxy (settings, "enable-html5-local-storage", NULL);
790
754
    katze_preferences_add_widget (preferences, button, "spanned");
791
 
    #if !WEBKIT_CHECK_VERSION (1, 1, 14)
792
 
    button = katze_property_proxy (settings, "enable-html5-database", NULL);
793
 
    katze_preferences_add_widget (preferences, button, "indented");
794
 
    #endif
795
 
    #endif
796
755
    #if HAVE_LIBSOUP_2_27_90
797
756
    button = katze_property_proxy (settings, "strip-referer", NULL);
798
757
    katze_preferences_add_widget (preferences, button, "indented");
799
758
    #endif
800
 
    katze_preferences_add_group (preferences, NULL);
 
759
    katze_preferences_add_widget (preferences, gtk_label_new (NULL), "indented");
801
760
    button = katze_property_label (settings, "maximum-history-age");
802
761
    katze_preferences_add_widget (preferences, button, "indented");
803
 
    button = katze_property_proxy (settings, "maximum-history-age", NULL);
 
762
    button = katze_property_proxy (settings, "maximum-history-age", "days");
804
763
    katze_preferences_add_widget (preferences, button, "spanned");
805
 
    label = gtk_label_new (_("days"));
806
 
    katze_preferences_add_widget (preferences, label, "spanned");
807
764
}
808
765
 
809
766
static void
827
784
    midori_panel_append_page (MIDORI_PANEL (panel), MIDORI_VIEWABLE (addon));
828
785
 
829
786
    /* Transfers */
830
 
    #if WEBKIT_CHECK_VERSION (1, 1, 3)
831
787
    addon = g_object_new (MIDORI_TYPE_TRANSFERS, "app", app, NULL);
832
788
    gtk_widget_show (addon);
833
789
    midori_panel_append_page (MIDORI_PANEL (panel), MIDORI_VIEWABLE (addon));
834
 
    #endif
835
790
 
836
791
    /* Extensions */
837
792
    g_signal_connect (browser, "show-preferences",
954
909
        midori_soup_session_set_proxy_uri (session, NULL);
955
910
}
956
911
 
957
 
#if !WEBKIT_CHECK_VERSION (1, 1, 11)
958
 
static void
959
 
soup_session_settings_notify_ident_string_cb (MidoriWebSettings* settings,
960
 
                                              GParamSpec*        pspec,
961
 
                                              SoupSession*       session)
962
 
{
963
 
    gchar* ident_string = katze_object_get_string (settings, "user-agent");
964
 
    g_object_set (session, "user-agent", ident_string, NULL);
965
 
    g_free (ident_string);
966
 
}
967
 
#endif
968
 
 
969
912
static void
970
913
midori_soup_session_settings_accept_language_cb (SoupSession*       session,
971
914
                                                 SoupMessage*       msg,
1036
979
{
1037
980
    SoupSession* session = webkit_get_default_session ();
1038
981
 
1039
 
    #if WEBKIT_CHECK_VERSION (1, 1, 14) && defined (HAVE_LIBSOUP_2_29_91)
 
982
    #if defined (HAVE_LIBSOUP_2_29_91)
1040
983
    const gchar* certificate_files[] =
1041
984
    {
1042
985
        "/etc/pki/tls/certs/ca-bundle.crt",
1074
1017
    g_signal_connect (settings, "notify::proxy-type",
1075
1018
        G_CALLBACK (soup_session_settings_notify_http_proxy_cb), session);
1076
1019
 
1077
 
    #if !WEBKIT_CHECK_VERSION (1, 1, 11)
1078
 
    soup_session_settings_notify_ident_string_cb (settings, NULL, session);
1079
 
    g_signal_connect (settings, "notify::user-agent",
1080
 
        G_CALLBACK (soup_session_settings_notify_ident_string_cb), session);
1081
 
    #endif
1082
 
 
1083
1020
    g_signal_connect (session, "request-queued",
1084
1021
        G_CALLBACK (midori_soup_session_settings_accept_language_cb), settings);
1085
1022
 
1086
1023
    midori_soup_session_debug (session);
1087
1024
 
 
1025
    g_object_set_data (G_OBJECT (session), "midori-session-initialized", (void*)1);
 
1026
 
1088
1027
    return FALSE;
1089
1028
}
1090
1029
 
1099
1038
}
1100
1039
 
1101
1040
static void
1102
 
button_reset_session_clicked_cb (GtkWidget*  button,
1103
 
                                 KatzeArray* session)
1104
 
{
1105
 
    gchar* config_file = build_config_filename ("session.old.xbel");
1106
 
    GError* error = NULL;
1107
 
    if (!midori_array_to_file (session, config_file, "xbel", &error))
1108
 
    {
1109
 
        g_warning (_("The session couldn't be saved. %s"), error->message);
1110
 
        g_error_free (error);
1111
 
    }
1112
 
    g_free (config_file);
1113
 
    katze_array_clear (session);
1114
 
    gtk_widget_set_sensitive (button, FALSE);
1115
 
}
1116
 
 
1117
 
static void
1118
1041
button_disable_extensions_clicked_cb (GtkWidget* button,
1119
1042
                                      MidoriApp* app)
1120
1043
{
1122
1045
    gtk_widget_set_sensitive (button, FALSE);
1123
1046
}
1124
1047
 
1125
 
static GtkWidget*
1126
 
midori_create_diagnostic_dialog (MidoriWebSettings* settings,
1127
 
                                 KatzeArray*        _session)
 
1048
static MidoriStartup
 
1049
midori_show_diagnostic_dialog (MidoriWebSettings* settings,
 
1050
                               KatzeArray*        _session)
1128
1051
{
1129
1052
    GtkWidget* dialog;
1130
1053
    GtkWidget* content_area;
1131
1054
    GdkScreen* screen;
1132
1055
    GtkIconTheme* icon_theme;
 
1056
    GtkWidget* align;
1133
1057
    GtkWidget* box;
1134
1058
    GtkWidget* button;
1135
1059
    MidoriApp* app = katze_item_get_parent (KATZE_ITEM (_session));
 
1060
    MidoriStartup load_on_startup = katze_object_get_enum (settings, "load-on-startup");
 
1061
    gint response;
1136
1062
 
1137
1063
    dialog = gtk_message_dialog_new (
1138
 
        NULL, 0, GTK_MESSAGE_WARNING,
1139
 
        #ifdef HAVE_HILDON_2_2
1140
 
        GTK_BUTTONS_NONE,
1141
 
        #else
1142
 
        GTK_BUTTONS_OK,
1143
 
        #endif
 
1064
        NULL, 0, GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE,
1144
1065
        _("Midori seems to have crashed the last time it was opened. "
1145
1066
          "If this happened repeatedly, try one of the following options "
1146
1067
          "to solve the problem."));
1156
1077
        else
1157
1078
            gtk_window_set_icon_name (GTK_WINDOW (dialog), "web-browser");
1158
1079
    }
 
1080
    align = gtk_alignment_new (0.5, 0.5, 0.5, 0.5);
 
1081
    gtk_container_add (GTK_CONTAINER (content_area), align);
1159
1082
    box = gtk_hbox_new (FALSE, 0);
 
1083
    gtk_container_add (GTK_CONTAINER (align), box);
1160
1084
    button = gtk_button_new_with_mnemonic (_("Modify _preferences"));
1161
1085
    g_signal_connect (button, "clicked",
1162
1086
        G_CALLBACK (button_modify_preferences_clicked_cb), settings);
1163
1087
    gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 4);
1164
 
    button = gtk_button_new_with_mnemonic (_("Reset the last _session"));
1165
 
    g_signal_connect (button, "clicked",
1166
 
        G_CALLBACK (button_reset_session_clicked_cb), _session);
1167
 
    gtk_widget_set_sensitive (button, !katze_array_is_empty (_session));
1168
 
    gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 4);
1169
1088
    button = gtk_button_new_with_mnemonic (_("Disable all _extensions"));
1170
1089
    if (g_object_get_data (G_OBJECT (app), "extensions"))
1171
1090
        g_signal_connect (button, "clicked",
1173
1092
    else
1174
1093
        gtk_widget_set_sensitive (button, FALSE);
1175
1094
    gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 4);
1176
 
    gtk_widget_show_all (box);
1177
 
    gtk_container_add (GTK_CONTAINER (content_area), box);
 
1095
    gtk_widget_show_all (align);
1178
1096
    button = katze_property_proxy (settings, "show-crash-dialog", NULL);
1179
1097
    gtk_widget_show (button);
1180
1098
    gtk_container_add (GTK_CONTAINER (content_area), button);
1181
 
    #ifdef HAVE_HILDON_2_2
1182
 
    box = gtk_hbox_new (FALSE, 4);
1183
 
    gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), box, TRUE, FALSE, 4);
1184
 
    button = hildon_gtk_button_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_HALFSCREEN_WIDTH);
1185
 
    gtk_button_set_label (GTK_BUTTON (button), GTK_STOCK_OK);
1186
 
    gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
1187
 
    g_signal_connect_swapped (button, "clicked",
1188
 
        G_CALLBACK (gtk_widget_destroy), dialog);
1189
 
    gtk_box_pack_start (GTK_BOX (box), button, TRUE, FALSE, 4);
1190
 
    gtk_widget_show_all (box);
1191
 
    #endif
 
1099
    gtk_container_set_focus_child (GTK_CONTAINER (dialog), gtk_dialog_get_action_area (GTK_DIALOG (dialog)));
 
1100
    gtk_dialog_add_buttons (GTK_DIALOG (dialog),
 
1101
        _("Discard old tabs"), MIDORI_STARTUP_BLANK_PAGE,
 
1102
        _("Show last tabs without loading"), MIDORI_STARTUP_DELAYED_PAGES,
 
1103
        _("Show last open tabs"), MIDORI_STARTUP_LAST_OPEN_PAGES,
 
1104
        NULL);
 
1105
    gtk_dialog_set_default_response (GTK_DIALOG (dialog),
 
1106
        load_on_startup == MIDORI_STARTUP_HOMEPAGE
 
1107
        ? MIDORI_STARTUP_BLANK_PAGE : load_on_startup);
1192
1108
    if (1)
1193
1109
    {
1194
1110
        /* GtkLabel can't wrap the text properly. Until some day
1211
1127
        gtk_widget_size_request (content_area, &req);
1212
1128
        gtk_widget_set_size_request (label, req.width * 0.9, -1);
1213
1129
    }
1214
 
    return dialog;
 
1130
 
 
1131
    response = gtk_dialog_run (GTK_DIALOG (dialog));
 
1132
    gtk_widget_destroy (dialog);
 
1133
    if (response == GTK_RESPONSE_DELETE_EVENT)
 
1134
        response = G_MAXINT;
 
1135
    else if (response == MIDORI_STARTUP_BLANK_PAGE)
 
1136
        katze_array_clear (_session);
 
1137
    return response;
1215
1138
}
1216
1139
 
1217
1140
static gboolean
1403
1326
    MidoriBrowser* browser;
1404
1327
    MidoriApp* app = katze_item_get_parent (KATZE_ITEM (_session));
1405
1328
    MidoriWebSettings* settings = katze_object_get_object (app, "settings");
 
1329
    MidoriStartup load_on_startup;
1406
1330
    gchar* config_file;
1407
1331
    KatzeArray* session;
1408
1332
    KatzeItem* item;
1409
1333
    gint64 current;
1410
 
    MidoriStartup load_on_startup;
1411
1334
    gchar** command = g_object_get_data (G_OBJECT (app), "execute-command");
1412
1335
    #ifdef G_ENABLE_DEBUG
1413
1336
    gboolean startup_timer = g_getenv ("MIDORI_STARTTIME") != NULL;
1436
1359
    g_signal_connect_after (gtk_accel_map_get (), "changed",
1437
1360
        G_CALLBACK (accel_map_changed_cb), NULL);
1438
1361
 
1439
 
    g_object_get (settings, "load-on-startup", &load_on_startup, NULL);
1440
 
 
 
1362
    load_on_startup = (MidoriStartup)g_object_get_data (G_OBJECT (settings), "load-on-startup");
1441
1363
    if (katze_array_is_empty (_session))
1442
1364
    {
1443
1365
        gchar* homepage;
1536
1458
    return 1;
1537
1459
}
1538
1460
 
1539
 
#if WEBKIT_CHECK_VERSION (1, 1, 6)
1540
1461
static void
1541
1462
snapshot_load_finished_cb (GtkWidget*      web_view,
1542
1463
                           WebKitWebFrame* web_frame,
1560
1481
    g_print (_("Snapshot saved to: %s\n"), filename);
1561
1482
    gtk_main_quit ();
1562
1483
}
1563
 
#endif
1564
1484
 
1565
1485
static void
1566
1486
midori_web_app_browser_notify_load_status_cb (MidoriBrowser* browser,
1597
1517
 
1598
1518
    if (g_path_is_absolute (uri))
1599
1519
        return g_filename_to_uri (uri, NULL, NULL);
 
1520
    else if (g_str_has_prefix(uri, "javascript:"))
 
1521
        return g_strdup (uri);
1600
1522
    else if (g_file_test (uri, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))
1601
1523
    {
1602
1524
        gchar* current_dir = g_get_current_dir ();
1647
1569
    }
1648
1570
 
1649
1571
    katze_assign (config_file, g_build_filename (config, "speeddial.json", NULL));
1650
 
    g_file_get_contents (config_file, &json_content, &json_length, NULL);
 
1572
    if (!g_file_get_contents (config_file, &json_content, &json_length, NULL))
 
1573
    {
 
1574
        katze_assign (json_content, g_strdup ("'{}'"));
 
1575
        json_length = strlen ("'{}'");
 
1576
    }
 
1577
 
1651
1578
    script = g_string_sized_new (json_length);
1652
1579
    g_string_append (script, "var json = JSON.parse (");
1653
1580
    g_string_append_len (script, json_content, json_length);
1661
1588
        "        +  'title=' + tile['title'] + '\\n\\n';"
1662
1589
        "} "
1663
1590
        "var columns = json['width'] ? json['width'] : 3;"
1664
 
        "var rows = json['shortcuts'].length / columns;"
 
1591
        "var rows = json['shortcuts'] ? json['shortcuts'].length / columns : 0;"
1665
1592
        "keyfile += '[settings]\\n'"
1666
1593
        "        +  'columns=' + columns + '\\n'"
1667
1594
        "        +  'rows=' + (rows > 3 ? rows : 3) + '\\n\\n';"
1848
1775
}
1849
1776
#endif
1850
1777
 
1851
 
#if WEBKIT_CHECK_VERSION (1, 1, 14)
 
1778
static void
 
1779
midori_clear_saved_logins_cb (void)
 
1780
{
 
1781
    sqlite3* db;
 
1782
    gchar* path = g_build_filename (sokoke_set_config_dir (NULL), "logins", NULL);
 
1783
    g_unlink (path);
 
1784
    /* Form History database, written by the extension */
 
1785
    katze_assign (path, g_build_filename (sokoke_set_config_dir (NULL),
 
1786
        "extensions", LIBPREFIX "formhistory." G_MODULE_SUFFIX, "forms.db", NULL));
 
1787
    if (sqlite3_open (path, &db) == SQLITE_OK)
 
1788
    {
 
1789
        sqlite3_exec (db, "DELETE FROM forms", NULL, NULL, NULL);
 
1790
        sqlite3_close (db);
 
1791
    }
 
1792
    g_free (path);
 
1793
}
 
1794
 
1852
1795
static void
1853
1796
midori_clear_html5_databases_cb (void)
1854
1797
{
1855
1798
    webkit_remove_all_web_databases ();
1856
1799
}
1857
 
#endif
1858
1800
 
1859
1801
#if WEBKIT_CHECK_VERSION (1, 3, 11)
1860
1802
static void
1880
1822
}
1881
1823
#endif
1882
1824
 
 
1825
static void
 
1826
midori_log_to_file (const gchar*   log_domain,
 
1827
                    GLogLevelFlags log_level,
 
1828
                    const gchar*   message,
 
1829
                    gpointer       user_data)
 
1830
{
 
1831
    FILE* logfile = fopen ((const char*)user_data, "a");
 
1832
    gchar* level_name = "";
 
1833
    time_t timestamp = time (NULL);
 
1834
 
 
1835
    switch (log_level)
 
1836
    {
 
1837
        /* skip irrelevant flags */
 
1838
        case G_LOG_LEVEL_MASK:
 
1839
        case G_LOG_FLAG_FATAL:
 
1840
        case G_LOG_FLAG_RECURSION:
 
1841
 
 
1842
        case G_LOG_LEVEL_ERROR:
 
1843
            level_name = "ERROR";
 
1844
            break;
 
1845
        case G_LOG_LEVEL_CRITICAL:
 
1846
            level_name = "CRITICAL";
 
1847
            break;
 
1848
        case G_LOG_LEVEL_WARNING:
 
1849
            level_name = "WARNING";
 
1850
            break;
 
1851
        case G_LOG_LEVEL_MESSAGE:
 
1852
            level_name = "MESSAGE";
 
1853
            break;
 
1854
        case G_LOG_LEVEL_INFO:
 
1855
            level_name = "INFO";
 
1856
            break;
 
1857
        case G_LOG_LEVEL_DEBUG:
 
1858
            level_name = "DEBUG";
 
1859
            break;
 
1860
    }
 
1861
 
 
1862
    fprintf (logfile, "%s%s-%s **: %s\n", asctime (localtime (&timestamp)),
 
1863
        log_domain ? log_domain : "Midori", level_name, message);
 
1864
    fclose (logfile);
 
1865
}
 
1866
 
1883
1867
int
1884
1868
main (int    argc,
1885
1869
      char** argv)
1891
1875
    gboolean back_from_crash;
1892
1876
    gboolean run;
1893
1877
    gchar* snapshot;
 
1878
    gchar* logfile;
1894
1879
    gboolean execute;
1895
1880
    gboolean help_execute;
1896
1881
    gboolean version;
1914
1899
       N_("Show a diagnostic dialog"), NULL },
1915
1900
       { "run", 'r', 0, G_OPTION_ARG_NONE, &run,
1916
1901
       N_("Run the specified filename as javascript"), NULL },
1917
 
       #if WEBKIT_CHECK_VERSION (1, 1, 6)
1918
1902
       { "snapshot", 's', 0, G_OPTION_ARG_STRING, &snapshot,
1919
1903
       N_("Take a snapshot of the specified URI"), NULL },
1920
 
       #endif
1921
1904
       { "execute", 'e', 0, G_OPTION_ARG_NONE, &execute,
1922
1905
       N_("Execute the specified command"), NULL },
1923
1906
       { "help-execute", 0, 0, G_OPTION_ARG_NONE, &help_execute,
1933
1916
       /* i18n: CLI: Close tabs, clear private data, open starting page */
1934
1917
       N_("Reset Midori after SECONDS seconds of inactivity"), N_("SECONDS") },
1935
1918
       #endif
 
1919
       { "log-file", 'l', 0, G_OPTION_ARG_FILENAME, &logfile,
 
1920
       N_("Redirects console warnings to the specified FILENAME"), N_("FILENAME")},
1936
1921
     { NULL }
1937
1922
    };
1938
1923
    GString* error_messages;
2008
1993
    diagnostic_dialog = FALSE;
2009
1994
    run = FALSE;
2010
1995
    snapshot = NULL;
 
1996
    logfile = NULL;
2011
1997
    execute = FALSE;
2012
1998
    help_execute = FALSE;
2013
1999
    version = FALSE;
2036
2022
    /* Private browsing, window title, default config folder */
2037
2023
    if (private)
2038
2024
    {
2039
 
        g_set_application_name (_("Midori (Private Browsing)"));
2040
2025
        if (!config && !webapp)
2041
2026
            config = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL);
2042
2027
        /* Mask the timezone, which can be read by Javascript */
2093
2078
        return 0;
2094
2079
    }
2095
2080
 
2096
 
    #if WEBKIT_CHECK_VERSION (1, 1, 6)
2097
2081
    if (snapshot)
2098
2082
    {
2099
2083
        gchar* filename;
2124
2108
        g_free (filename);
2125
2109
        return 0;
2126
2110
    }
2127
 
    #endif
 
2111
 
 
2112
    if (logfile)
 
2113
    {
 
2114
        g_log_set_default_handler (midori_log_to_file, (gpointer)logfile);
 
2115
    }
2128
2116
 
2129
2117
    sokoke_register_privacy_item ("page-icons", _("Website icons"),
2130
2118
        G_CALLBACK (midori_clear_page_icons_cb));
 
2119
    /* i18n: Logins and passwords in websites and web forms */
 
2120
    sokoke_register_privacy_item ("formhistory", _("Saved logins and _passwords"),
 
2121
        G_CALLBACK (midori_clear_saved_logins_cb));
2131
2122
    sokoke_register_privacy_item ("web-cookies", _("Cookies"),
2132
2123
        G_CALLBACK (midori_clear_web_cookies_cb));
2133
2124
    #ifdef GDK_WINDOWING_X11
2134
2125
    sokoke_register_privacy_item ("flash-cookies", _("'Flash' Cookies"),
2135
2126
        G_CALLBACK (midori_clear_flash_cookies_cb));
2136
2127
    #endif
2137
 
    #if WEBKIT_CHECK_VERSION (1, 1, 14)
2138
2128
    sokoke_register_privacy_item ("html5-databases", _("HTML5 _Databases"),
2139
2129
        G_CALLBACK (midori_clear_html5_databases_cb));
2140
 
    #endif
2141
2130
    #if WEBKIT_CHECK_VERSION (1, 3, 11)
2142
2131
    sokoke_register_privacy_item ("web-cache", _("Web Cache"),
2143
2132
        G_CALLBACK (midori_clear_web_cache_cb));
2167
2156
        else
2168
2157
            settings = g_object_ref (midori_browser_get_settings (browser));
2169
2158
 
 
2159
        if (private)
 
2160
        {
 
2161
            g_object_set (settings,
 
2162
                          "preferred-languages", "en",
 
2163
                          "enable-private-browsing", TRUE,
 
2164
                          "enable-html5-database", FALSE,
 
2165
                          "enable-html5-local-storage", FALSE,
 
2166
                          "enable-offline-web-application-cache", FALSE,
 
2167
            /* Arguably DNS prefetching is or isn't a privacy concern. For the
 
2168
             * lack of more fine-grained control we'll go the safe route. */
 
2169
                          "enable-dns-prefetching", FALSE,
 
2170
                          "strip-referer", TRUE, NULL);
 
2171
            midori_browser_set_action_visible (browser, "Tools", FALSE);
 
2172
            midori_browser_set_action_visible (browser, "ClearPrivateData", FALSE);
 
2173
        }
 
2174
 
 
2175
        if (private || !config)
 
2176
        {
 
2177
            /* Disable saving by setting an unwritable folder */
 
2178
            sokoke_set_config_dir ("/");
 
2179
        }
 
2180
 
 
2181
        midori_load_soup_session (settings);
 
2182
        if (block_uris)
 
2183
            g_signal_connect (session, "request-queued",
 
2184
                G_CALLBACK (midori_soup_session_block_uris_cb),
 
2185
                g_strdup (block_uris));
 
2186
 
2170
2187
        if (webapp)
2171
2188
        {
2172
2189
            gchar* tmp_uri = midori_prepare_uri (webapp);
2186
2203
                G_CALLBACK (midori_web_app_browser_notify_load_status_cb), NULL);
2187
2204
        }
2188
2205
 
2189
 
        if (private)
2190
 
        {
2191
 
            g_object_set (settings,
2192
 
                          "preferred-languages", "en",
2193
 
            #if WEBKIT_CHECK_VERSION (1, 1, 2)
2194
 
                          "enable-private-browsing", TRUE,
2195
 
            #endif
2196
 
            #if WEBKIT_CHECK_VERSION (1, 1, 8)
2197
 
                          "enable-html5-database", FALSE,
2198
 
                          "enable-html5-local-storage", FALSE,
2199
 
                          "enable-offline-web-application-cache", FALSE,
2200
 
            #endif
2201
 
            /* Arguably DNS prefetching is or isn't a privacy concern. For the
2202
 
             * lack of more fine-grained control we'll go the safe route. */
2203
 
                          "enable-dns-prefetching", FALSE,
2204
 
                          "strip-referer", TRUE, NULL);
2205
 
            midori_browser_set_action_visible (browser, "Tools", FALSE);
2206
 
            midori_browser_set_action_visible (browser, "ClearPrivateData", FALSE);
2207
 
        }
2208
 
 
2209
 
        if (private || !config)
2210
 
        {
2211
 
            /* Disable saving by setting an unwritable folder */
2212
 
            sokoke_set_config_dir ("/");
2213
 
        }
2214
 
 
2215
 
        g_object_set (settings, "show-panel", FALSE,
 
2206
       g_object_set (settings, "show-panel", FALSE,
2216
2207
                      "last-window-state", MIDORI_WINDOW_NORMAL,
2217
2208
                      NULL);
2218
2209
        midori_browser_set_action_visible (browser, "Panel", FALSE);
2243
2234
        if (midori_browser_get_current_uri (browser) == NULL)
2244
2235
            midori_browser_add_uri (browser, "about:blank");
2245
2236
 
2246
 
        if (block_uris)
2247
 
            g_signal_connect (session, "request-queued",
2248
 
                G_CALLBACK (midori_soup_session_block_uris_cb),
2249
 
                g_strdup (block_uris));
2250
2237
        midori_setup_inactivity_reset (browser, inactivity_reset, webapp);
2251
 
        midori_load_soup_session (settings);
2252
2238
        midori_startup_timer ("App created: \t%f");
2253
2239
        gtk_main ();
2254
2240
        return 0;
2319
2305
    error = NULL;
2320
2306
    settings = settings_and_accels_new (config, &extensions);
2321
2307
    g_object_set (settings, "enable-developer-extras", TRUE, NULL);
2322
 
    #if WEBKIT_CHECK_VERSION (1, 1, 14)
2323
2308
    g_object_set (settings, "enable-html5-database", TRUE, NULL);
2324
 
    #endif
2325
2309
    midori_startup_timer ("Config and accels read: \t%f");
2326
2310
 
2327
2311
    /* Load search engines */
2345
2329
    {
2346
2330
        g_string_append_printf (error_messages,
2347
2331
            _("Bookmarks couldn't be loaded: %s\n"), errmsg);
2348
 
        g_free (errmsg);
 
2332
        errmsg = NULL;
2349
2333
    }
2350
2334
    else if (!bookmarks_exist)
2351
2335
    {
2367
2351
 
2368
2352
    config_file = NULL;
2369
2353
    _session = katze_array_new (KATZE_TYPE_ITEM);
 
2354
    load_on_startup = katze_object_get_enum (settings, "load-on-startup");
2370
2355
    #if HAVE_LIBXML
2371
 
    g_object_get (settings, "load-on-startup", &load_on_startup, NULL);
2372
2356
    if (load_on_startup >= MIDORI_STARTUP_LAST_OPEN_PAGES)
2373
2357
    {
2374
2358
        katze_assign (config_file, build_config_filename ("session.xbel"));
2406
2390
    {
2407
2391
        g_string_append_printf (error_messages,
2408
2392
            _("The history couldn't be loaded: %s\n"), errmsg);
2409
 
        g_free (errmsg);
 
2393
        errmsg = NULL;
2410
2394
    }
2411
2395
    g_free (bookmarks_file);
2412
2396
    midori_startup_timer ("History read: \t%f");
2413
2397
 
 
2398
    error = NULL;
2414
2399
    speeddial = speeddial_new_from_file (config, &error);
2415
2400
 
2416
2401
    /* In case of errors */
2469
2454
            uri_ready = midori_prepare_uri (uri);
2470
2455
            katze_item_set_uri (item, uri_ready);
2471
2456
            g_free (uri_ready);
 
2457
            /* Never delay command line arguments */
 
2458
            katze_item_set_meta_integer (item, "delay", 0);
2472
2459
            katze_array_add_item (_session, item);
2473
2460
            uri = strtok (NULL, "|");
2474
2461
        }
2507
2494
    else
2508
2495
        g_file_set_contents (config_file, "RUNNING", -1, NULL);
2509
2496
 
2510
 
    if (back_from_crash)
2511
 
    {
2512
 
        if (katze_object_get_int (settings, "load-on-startup")
2513
 
            >= MIDORI_STARTUP_LAST_OPEN_PAGES)
2514
 
            midori_session_add_delay (_session);
2515
 
 
2516
 
        if (katze_object_get_boolean (settings, "show-crash-dialog"))
2517
 
            diagnostic_dialog = TRUE;
2518
 
    }
 
2497
    if (back_from_crash && katze_object_get_boolean (settings, "show-crash-dialog"))
 
2498
        diagnostic_dialog = TRUE;
2519
2499
 
2520
2500
    if (diagnostic_dialog)
2521
2501
    {
2522
 
        GtkWidget* dialog = midori_create_diagnostic_dialog (settings, _session);
2523
 
        gint response = gtk_dialog_run (GTK_DIALOG (dialog));
2524
 
        gtk_widget_destroy (dialog);
2525
 
        if (response == GTK_RESPONSE_DELETE_EVENT)
 
2502
        load_on_startup = midori_show_diagnostic_dialog (settings, _session);
 
2503
        if (load_on_startup == G_MAXINT)
2526
2504
            return 0;
2527
2505
    }
 
2506
    g_object_set_data (G_OBJECT (settings), "load-on-startup", GINT_TO_POINTER (load_on_startup));
2528
2507
    midori_startup_timer ("Signal setup: \t%f");
2529
2508
 
2530
2509
    g_object_set (app, "settings", settings,
2573
2552
        GList* data_items = sokoke_register_privacy_item (NULL, NULL, NULL);
2574
2553
        gchar* clear_data = katze_object_get_string (settings, "clear-data");
2575
2554
 
 
2555
        midori_remove_config_file (clear_prefs, MIDORI_CLEAR_SESSION, "session.xbel");
2576
2556
        midori_remove_config_file (clear_prefs, MIDORI_CLEAR_HISTORY, "history.db");
2577
2557
        midori_remove_config_file (clear_prefs, MIDORI_CLEAR_TRASH, "tabtrash.xbel");
2578
2558
 
2585
2565
        g_free (clear_data);
2586
2566
    }
2587
2567
 
2588
 
    if (katze_object_get_int (settings, "load-on-startup")
2589
 
        < MIDORI_STARTUP_LAST_OPEN_PAGES)
 
2568
    load_on_startup = katze_object_get_int (settings, "load-on-startup");
 
2569
    if (load_on_startup < MIDORI_STARTUP_LAST_OPEN_PAGES)
2590
2570
    {
2591
2571
        katze_assign (config_file, g_build_filename (config, "session.xbel", NULL));
2592
2572
        g_unlink (config_file);