Move form history globals into private struct
This commit is contained in:
parent
66484a7e02
commit
1e941210db
3 changed files with 32 additions and 20 deletions
|
@ -13,9 +13,9 @@
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
sqlite3* db;
|
|
||||||
gchar* domain;
|
gchar* domain;
|
||||||
gchar* form_data;
|
gchar* form_data;
|
||||||
|
FormHistoryPriv* priv;
|
||||||
} FormhistoryPasswordEntry;
|
} FormhistoryPasswordEntry;
|
||||||
|
|
||||||
gchar*
|
gchar*
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#else
|
#else
|
||||||
#define FORMHISTORY_USE_JS 1
|
#define FORMHISTORY_USE_JS 1
|
||||||
#endif
|
#endif
|
||||||
|
#define MAXPASSSIZE 64
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
@ -38,6 +39,9 @@ typedef struct
|
||||||
#else
|
#else
|
||||||
gchar* jsforms;
|
gchar* jsforms;
|
||||||
#endif
|
#endif
|
||||||
|
unsigned char master_password [MAXPASSSIZE];
|
||||||
|
int master_password_canceled;
|
||||||
|
int password_manager_enabled;
|
||||||
} FormHistoryPriv;
|
} FormHistoryPriv;
|
||||||
|
|
||||||
FormHistoryPriv*
|
FormHistoryPriv*
|
||||||
|
|
|
@ -9,15 +9,10 @@
|
||||||
*/
|
*/
|
||||||
#define MAXCHARS 60
|
#define MAXCHARS 60
|
||||||
#define MINCHARS 2
|
#define MINCHARS 2
|
||||||
#define MAXPASSSIZE 64
|
|
||||||
#define GTK_RESPONSE_IGNORE 99
|
#define GTK_RESPONSE_IGNORE 99
|
||||||
#include "formhistory-frontend.h"
|
#include "formhistory-frontend.h"
|
||||||
#include "formhistory-crypt.h"
|
#include "formhistory-crypt.h"
|
||||||
|
|
||||||
unsigned char master_password [MAXPASSSIZE] = {};
|
|
||||||
int master_password_canceled = 0;
|
|
||||||
int password_manager_enabled = 1;
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
formhistory_toggle_state_cb (GtkAction* action,
|
formhistory_toggle_state_cb (GtkAction* action,
|
||||||
MidoriBrowser* browser);
|
MidoriBrowser* browser);
|
||||||
|
@ -72,7 +67,8 @@ formhistory_get_login_data (gpointer db,
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
formhistory_check_master_password (GtkWidget *parent)
|
formhistory_check_master_password (GtkWidget* parent,
|
||||||
|
FormHistoryPriv* priv)
|
||||||
{
|
{
|
||||||
GtkWidget* dialog;
|
GtkWidget* dialog;
|
||||||
GtkWidget* content_area;
|
GtkWidget* content_area;
|
||||||
|
@ -83,7 +79,9 @@ formhistory_check_master_password (GtkWidget *parent)
|
||||||
const gchar* title;
|
const gchar* title;
|
||||||
static int alive;
|
static int alive;
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
|
unsigned char* master_password;
|
||||||
|
|
||||||
|
master_password = priv->master_password;
|
||||||
/* Password is set */
|
/* Password is set */
|
||||||
if (master_password[0] && master_password[1])
|
if (master_password[0] && master_password[1])
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -93,7 +91,7 @@ formhistory_check_master_password (GtkWidget *parent)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* Prompt was cancelled */
|
/* Prompt was cancelled */
|
||||||
if (master_password_canceled == 1)
|
if (priv->master_password_canceled == 1)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
alive = 1;
|
alive = 1;
|
||||||
|
@ -137,7 +135,7 @@ formhistory_check_master_password (GtkWidget *parent)
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
master_password_canceled = 1;
|
priv->master_password_canceled = 1;
|
||||||
|
|
||||||
gtk_widget_destroy (dialog);
|
gtk_widget_destroy (dialog);
|
||||||
alive = 0;
|
alive = 0;
|
||||||
|
@ -155,13 +153,13 @@ formhistory_remember_password_response (GtkWidget* infobar,
|
||||||
if (response_id == GTK_RESPONSE_IGNORE)
|
if (response_id == GTK_RESPONSE_IGNORE)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (formhistory_check_master_password (NULL))
|
if (formhistory_check_master_password (NULL, entry->priv))
|
||||||
{
|
{
|
||||||
if (response_id != GTK_RESPONSE_ACCEPT)
|
if (response_id != GTK_RESPONSE_ACCEPT)
|
||||||
katze_assign (entry->form_data, g_strdup ("never"));
|
katze_assign (entry->form_data, g_strdup ("never"));
|
||||||
|
|
||||||
encrypted_form = formhistory_encrypt (entry->form_data, master_password);
|
encrypted_form = formhistory_encrypt (entry->form_data, entry->priv->master_password);
|
||||||
formhistory_update_database (entry->db, entry->domain, "MidoriPasswordManager", encrypted_form);
|
formhistory_update_database (entry->priv->db, entry->domain, "MidoriPasswordManager", encrypted_form);
|
||||||
|
|
||||||
g_free (encrypted_form);
|
g_free (encrypted_form);
|
||||||
}
|
}
|
||||||
|
@ -232,7 +230,7 @@ formhistory_navigation_decision_cb (WebKitWebView* web_view,
|
||||||
gchar* data;
|
gchar* data;
|
||||||
gchar* domain;
|
gchar* domain;
|
||||||
|
|
||||||
if (!password_manager_enabled)
|
if (!priv->password_manager_enabled)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
domain = midori_uri_parse_hostname (webkit_web_frame_get_uri (web_frame), NULL);
|
domain = midori_uri_parse_hostname (webkit_web_frame_get_uri (web_frame), NULL);
|
||||||
|
@ -247,7 +245,7 @@ formhistory_navigation_decision_cb (WebKitWebView* web_view,
|
||||||
/* Domain and form data are freed from infopanel callback*/
|
/* Domain and form data are freed from infopanel callback*/
|
||||||
entry->form_data = g_strdup (value);
|
entry->form_data = g_strdup (value);
|
||||||
entry->domain = domain;
|
entry->domain = domain;
|
||||||
entry->db = priv->db;
|
entry->priv = priv;
|
||||||
g_object_set_data (G_OBJECT (web_view), "FormHistoryPasswordEntry", entry);
|
g_object_set_data (G_OBJECT (web_view), "FormHistoryPasswordEntry", entry);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -269,6 +267,7 @@ formhistory_window_object_cleared_cb (WebKitWebView* web_view,
|
||||||
MidoriExtension* extension)
|
MidoriExtension* extension)
|
||||||
{
|
{
|
||||||
const gchar* page_uri;
|
const gchar* page_uri;
|
||||||
|
FormHistoryPriv* priv;
|
||||||
FormhistoryPasswordEntry* entry;
|
FormhistoryPasswordEntry* entry;
|
||||||
GtkWidget* view;
|
GtkWidget* view;
|
||||||
|
|
||||||
|
@ -282,7 +281,8 @@ formhistory_window_object_cleared_cb (WebKitWebView* web_view,
|
||||||
formhistory_setup_suggestions (web_view, js_context, extension);
|
formhistory_setup_suggestions (web_view, js_context, extension);
|
||||||
|
|
||||||
#if WEBKIT_CHECK_VERSION (1, 3, 8)
|
#if WEBKIT_CHECK_VERSION (1, 3, 8)
|
||||||
if (!password_manager_enabled)
|
priv = g_object_get_data (G_OBJECT (extension), "priv");
|
||||||
|
if (!priv->password_manager_enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
entry = g_object_get_data (G_OBJECT (web_view), "FormHistoryPasswordEntry");
|
entry = g_object_get_data (G_OBJECT (web_view), "FormHistoryPasswordEntry");
|
||||||
|
@ -304,6 +304,7 @@ formhistory_window_object_cleared_cb (WebKitWebView* web_view,
|
||||||
#if WEBKIT_CHECK_VERSION (1, 3, 8)
|
#if WEBKIT_CHECK_VERSION (1, 3, 8)
|
||||||
static void
|
static void
|
||||||
formhistory_fill_login_data (JSContextRef js_context,
|
formhistory_fill_login_data (JSContextRef js_context,
|
||||||
|
FormHistoryPriv* priv,
|
||||||
const gchar* data)
|
const gchar* data)
|
||||||
{
|
{
|
||||||
gchar* decrypted_data = NULL;
|
gchar* decrypted_data = NULL;
|
||||||
|
@ -315,10 +316,10 @@ formhistory_fill_login_data (JSContextRef js_context,
|
||||||
if (!strncmp (data, "never", 5))
|
if (!strncmp (data, "never", 5))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!formhistory_check_master_password (NULL))
|
if (!formhistory_check_master_password (NULL, priv))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!(decrypted_data = formhistory_decrypt (data, master_password)))
|
if (!(decrypted_data = formhistory_decrypt (data, priv->master_password)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
script = g_string_new ("");
|
script = g_string_new ("");
|
||||||
|
@ -377,7 +378,7 @@ formhistory_frame_loaded_cb (WebKitWebView* web_view,
|
||||||
|
|
||||||
if (!data)
|
if (!data)
|
||||||
return;
|
return;
|
||||||
formhistory_fill_login_data (js_context, data);
|
formhistory_fill_login_data (js_context, priv, data);
|
||||||
g_free (data);
|
g_free (data);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -392,14 +393,16 @@ formhistory_add_tab_cb (MidoriBrowser* browser,
|
||||||
MidoriExtension* extension)
|
MidoriExtension* extension)
|
||||||
{
|
{
|
||||||
GtkWidget* web_view = midori_view_get_web_view (view);
|
GtkWidget* web_view = midori_view_get_web_view (view);
|
||||||
|
FormHistoryPriv* priv;
|
||||||
|
|
||||||
|
priv = g_object_get_data (G_OBJECT (extension), "priv");
|
||||||
g_signal_connect (web_view, "window-object-cleared",
|
g_signal_connect (web_view, "window-object-cleared",
|
||||||
G_CALLBACK (formhistory_window_object_cleared_cb), extension);
|
G_CALLBACK (formhistory_window_object_cleared_cb), extension);
|
||||||
g_signal_connect (web_view, "navigation-policy-decision-requested",
|
g_signal_connect (web_view, "navigation-policy-decision-requested",
|
||||||
G_CALLBACK (formhistory_navigation_decision_cb), extension);
|
G_CALLBACK (formhistory_navigation_decision_cb), extension);
|
||||||
|
|
||||||
#if WEBKIT_CHECK_VERSION (1, 3, 8)
|
#if WEBKIT_CHECK_VERSION (1, 3, 8)
|
||||||
if (!password_manager_enabled)
|
if (!priv->password_manager_enabled)
|
||||||
return;
|
return;
|
||||||
g_signal_connect (web_view, "onload-event",
|
g_signal_connect (web_view, "onload-event",
|
||||||
G_CALLBACK (formhistory_frame_loaded_cb), extension);
|
G_CALLBACK (formhistory_frame_loaded_cb), extension);
|
||||||
|
@ -451,13 +454,15 @@ formhistory_deactivate_tab (MidoriView* view,
|
||||||
MidoriExtension* extension)
|
MidoriExtension* extension)
|
||||||
{
|
{
|
||||||
GtkWidget* web_view = midori_view_get_web_view (view);
|
GtkWidget* web_view = midori_view_get_web_view (view);
|
||||||
|
FormHistoryPriv* priv;
|
||||||
|
|
||||||
|
priv = g_object_get_data (G_OBJECT (extension), "priv");
|
||||||
g_signal_handlers_disconnect_by_func (
|
g_signal_handlers_disconnect_by_func (
|
||||||
web_view, formhistory_window_object_cleared_cb, extension);
|
web_view, formhistory_window_object_cleared_cb, extension);
|
||||||
g_signal_handlers_disconnect_by_func (
|
g_signal_handlers_disconnect_by_func (
|
||||||
web_view, formhistory_navigation_decision_cb, extension);
|
web_view, formhistory_navigation_decision_cb, extension);
|
||||||
#if WEBKIT_CHECK_VERSION (1, 3, 8)
|
#if WEBKIT_CHECK_VERSION (1, 3, 8)
|
||||||
if (!password_manager_enabled)
|
if (!priv->password_manager_enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
g_signal_handlers_disconnect_by_func (
|
g_signal_handlers_disconnect_by_func (
|
||||||
|
@ -508,6 +513,9 @@ formhistory_activate_cb (MidoriExtension* extension,
|
||||||
FormHistoryPriv* priv;
|
FormHistoryPriv* priv;
|
||||||
|
|
||||||
priv = formhistory_private_new ();
|
priv = formhistory_private_new ();
|
||||||
|
strcpy ((char*)priv->master_password, "");
|
||||||
|
priv->master_password_canceled = 0;
|
||||||
|
priv->password_manager_enabled = 1;
|
||||||
formhistory_construct_popup_gui (priv);
|
formhistory_construct_popup_gui (priv);
|
||||||
|
|
||||||
config_dir = midori_extension_get_config_dir (extension);
|
config_dir = midori_extension_get_config_dir (extension);
|
||||||
|
|
Loading…
Reference in a new issue