Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim:set ts=2 sw=2 sts=2 et cindent: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include <stdio.h> |
michael@0 | 8 | #include <gtk/gtk.h> |
michael@0 | 9 | #include <unistd.h> |
michael@0 | 10 | #include "progressui.h" |
michael@0 | 11 | #include "readstrings.h" |
michael@0 | 12 | #include "errors.h" |
michael@0 | 13 | |
michael@0 | 14 | #define TIMER_INTERVAL 100 |
michael@0 | 15 | |
michael@0 | 16 | static float sProgressVal; // between 0 and 100 |
michael@0 | 17 | static gboolean sQuit = FALSE; |
michael@0 | 18 | static gboolean sEnableUI; |
michael@0 | 19 | static guint sTimerID; |
michael@0 | 20 | |
michael@0 | 21 | static GtkWidget *sWin; |
michael@0 | 22 | static GtkWidget *sLabel; |
michael@0 | 23 | static GtkWidget *sProgressBar; |
michael@0 | 24 | |
michael@0 | 25 | static const char *sProgramPath; |
michael@0 | 26 | |
michael@0 | 27 | static gboolean |
michael@0 | 28 | UpdateDialog(gpointer data) |
michael@0 | 29 | { |
michael@0 | 30 | if (sQuit) |
michael@0 | 31 | { |
michael@0 | 32 | gtk_widget_hide(sWin); |
michael@0 | 33 | gtk_main_quit(); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | float progress = sProgressVal; |
michael@0 | 37 | |
michael@0 | 38 | gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(sProgressBar), |
michael@0 | 39 | progress / 100.0); |
michael@0 | 40 | |
michael@0 | 41 | return TRUE; |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | static gboolean |
michael@0 | 45 | OnDeleteEvent(GtkWidget *widget, GdkEvent *event, gpointer user_data) |
michael@0 | 46 | { |
michael@0 | 47 | return TRUE; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | int |
michael@0 | 51 | InitProgressUI(int *pargc, char ***pargv) |
michael@0 | 52 | { |
michael@0 | 53 | sProgramPath = (*pargv)[0]; |
michael@0 | 54 | |
michael@0 | 55 | sEnableUI = gtk_init_check(pargc, pargv); |
michael@0 | 56 | return 0; |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | int |
michael@0 | 60 | ShowProgressUI() |
michael@0 | 61 | { |
michael@0 | 62 | if (!sEnableUI) |
michael@0 | 63 | return -1; |
michael@0 | 64 | |
michael@0 | 65 | // Only show the Progress UI if the process is taking a significant amount of |
michael@0 | 66 | // time where a significant amount of time is defined as .5 seconds after |
michael@0 | 67 | // ShowProgressUI is called sProgress is less than 70. |
michael@0 | 68 | usleep(500000); |
michael@0 | 69 | |
michael@0 | 70 | if (sQuit || sProgressVal > 70.0f) |
michael@0 | 71 | return 0; |
michael@0 | 72 | |
michael@0 | 73 | char ini_path[PATH_MAX]; |
michael@0 | 74 | snprintf(ini_path, sizeof(ini_path), "%s.ini", sProgramPath); |
michael@0 | 75 | |
michael@0 | 76 | StringTable strings; |
michael@0 | 77 | if (ReadStrings(ini_path, &strings) != OK) |
michael@0 | 78 | return -1; |
michael@0 | 79 | |
michael@0 | 80 | sWin = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
michael@0 | 81 | if (!sWin) |
michael@0 | 82 | return -1; |
michael@0 | 83 | |
michael@0 | 84 | static GdkPixbuf *pixbuf; |
michael@0 | 85 | char icon_path[PATH_MAX]; |
michael@0 | 86 | snprintf(icon_path, sizeof(icon_path), "%s.png", sProgramPath); |
michael@0 | 87 | |
michael@0 | 88 | g_signal_connect(G_OBJECT(sWin), "delete_event", |
michael@0 | 89 | G_CALLBACK(OnDeleteEvent), nullptr); |
michael@0 | 90 | |
michael@0 | 91 | gtk_window_set_title(GTK_WINDOW(sWin), strings.title); |
michael@0 | 92 | gtk_window_set_type_hint(GTK_WINDOW(sWin), GDK_WINDOW_TYPE_HINT_DIALOG); |
michael@0 | 93 | gtk_window_set_position(GTK_WINDOW(sWin), GTK_WIN_POS_CENTER_ALWAYS); |
michael@0 | 94 | gtk_window_set_resizable(GTK_WINDOW(sWin), FALSE); |
michael@0 | 95 | gtk_window_set_decorated(GTK_WINDOW(sWin), TRUE); |
michael@0 | 96 | gtk_window_set_deletable(GTK_WINDOW(sWin),FALSE); |
michael@0 | 97 | pixbuf = gdk_pixbuf_new_from_file (icon_path, nullptr); |
michael@0 | 98 | gtk_window_set_icon(GTK_WINDOW(sWin), pixbuf); |
michael@0 | 99 | g_object_unref(pixbuf); |
michael@0 | 100 | |
michael@0 | 101 | GtkWidget *vbox = gtk_vbox_new(TRUE, 6); |
michael@0 | 102 | sLabel = gtk_label_new(strings.info); |
michael@0 | 103 | gtk_misc_set_alignment(GTK_MISC(sLabel), 0.0f, 0.0f); |
michael@0 | 104 | sProgressBar = gtk_progress_bar_new(); |
michael@0 | 105 | |
michael@0 | 106 | gtk_box_pack_start(GTK_BOX(vbox), sLabel, FALSE, FALSE, 0); |
michael@0 | 107 | gtk_box_pack_start(GTK_BOX(vbox), sProgressBar, TRUE, TRUE, 0); |
michael@0 | 108 | |
michael@0 | 109 | sTimerID = g_timeout_add(TIMER_INTERVAL, UpdateDialog, nullptr); |
michael@0 | 110 | |
michael@0 | 111 | gtk_container_set_border_width(GTK_CONTAINER(sWin), 10); |
michael@0 | 112 | gtk_container_add(GTK_CONTAINER(sWin), vbox); |
michael@0 | 113 | gtk_widget_show_all(sWin); |
michael@0 | 114 | |
michael@0 | 115 | gtk_main(); |
michael@0 | 116 | return 0; |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | // Called on a background thread |
michael@0 | 120 | void |
michael@0 | 121 | QuitProgressUI() |
michael@0 | 122 | { |
michael@0 | 123 | sQuit = TRUE; |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | // Called on a background thread |
michael@0 | 127 | void |
michael@0 | 128 | UpdateProgressUI(float progress) |
michael@0 | 129 | { |
michael@0 | 130 | sProgressVal = progress; // 32-bit writes are atomic |
michael@0 | 131 | } |