Install formhistory resources, don't fill in passwords

Reading post data is there but nothing is written to disk yet.
This commit is contained in:
Alexander Butenko 2009-10-07 22:30:16 +02:00 committed by Christian Dywan
parent 3ed9e482cd
commit 37e2c84b2b
3 changed files with 118 additions and 25 deletions

View file

@ -341,6 +341,9 @@ FormSuggestions.prototype.requestSuggestions = function (oAutoSuggestControl /*:
var aSuggestions = []; var aSuggestions = [];
var sTextboxValue = oAutoSuggestControl.textbox.value; var sTextboxValue = oAutoSuggestControl.textbox.value;
if (!this.suggestions)
return;
if (sTextboxValue.length > 0){ if (sTextboxValue.length > 0){
//search for matching suggestions //search for matching suggestions
for (var i=0; i < this.suggestions.length; i++) { for (var i=0; i < this.suggestions.length; i++) {
@ -361,6 +364,7 @@ function initSuggestions () {
var eid = inputs[i].getAttribute("id"); var eid = inputs[i].getAttribute("id");
if (!ename && eid) if (!ename && eid)
ename=eid; ename=eid;
var smth = new AutoSuggestControl(inputs[i], new FormSuggestions(ename)); if (inputs[i].type == "text")
var smth = new AutoSuggestControl(inputs[i], new FormSuggestions(ename));
} }
}; };

View file

@ -5,12 +5,13 @@
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version. version 2.1 of the License, or (at your option) any later version.
*/ */
#define MAXCHARS 20
#define MINCHARS 2
#include <midori/midori.h> #include <midori/midori.h>
#include <midori/sokoke.h>
#include "config.h" #include "config.h"
#include <glib/gstdio.h> #include <glib/gstdio.h>
@ -18,20 +19,28 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
static GHashTable* global_keys;
static gchar* jsforms; static gchar* jsforms;
static void static gboolean
formhistory_prepare_js () formhistory_prepare_js ()
{ {
gchar* autosuggest; gchar* autosuggest;
gchar* style; gchar* style;
guint i; guint i;
gchar* file;
/* FIXME: Don't hardcode paths */ gchar* data_path = g_build_filename (MDATADIR, PACKAGE_NAME, NULL);
g_file_get_contents ("/usr/local/share/midori/autosuggestcontrol.js", &autosuggest, NULL, NULL); file = g_build_filename (data_path,"/autosuggestcontrol.js",NULL);
if (!g_file_test (file, G_FILE_TEST_EXISTS))
return FALSE;
g_file_get_contents (file, &autosuggest, NULL, NULL);
g_strchomp (autosuggest); g_strchomp (autosuggest);
g_file_get_contents ("/usr/local/share/midori/autosuggestcontrol.css", &style, NULL, NULL); file = g_build_filename (data_path,"/autosuggestcontrol.css",NULL);
if (!g_file_test (file, G_FILE_TEST_EXISTS))
return FALSE;
g_file_get_contents (file, &style, NULL, NULL);
g_strchomp (style); g_strchomp (style);
i = 0; i = 0;
while (style[i]) while (style[i])
@ -40,7 +49,6 @@ formhistory_prepare_js ()
style[i] = ' '; style[i] = ' ';
i++; i++;
} }
g_print ("%s\n", style);
jsforms = g_strdup_printf ( jsforms = g_strdup_printf (
"%s" "%s"
@ -57,15 +65,23 @@ formhistory_prepare_js ()
autosuggest, autosuggest,
style); style);
g_strstrip (jsforms); g_strstrip (jsforms);
g_free (data_path);
g_free (file);
g_free (style); g_free (style);
g_free (autosuggest); g_free (autosuggest);
return TRUE;
} }
static gchar* static gchar*
formhistory_build_js () formhistory_build_js ()
{ {
const gchar* suggestions = "arr[\"txt1\"] = [\"Alabama\", \"Alaska\", \"Arizona\", \"Arkansas\"];" const gchar* suggestions = "";
"arr[\"txt2\"] = [\"Alabama\", \"Alaska\", \"Arizona\", \"Arkansas\"];"; GHashTableIter iter;
gpointer key, value;
g_hash_table_iter_init (&iter, global_keys);
while (g_hash_table_iter_next (&iter, &key, &value))
suggestions = g_strdup_printf ("%s arr[\"%s\"] = [%s]; ",
suggestions, (char*)key, (char*)value);
gchar* script = g_strdup_printf ("function FormSuggestions(eid) { " gchar* script = g_strdup_printf ("function FormSuggestions(eid) { "
"arr = new Array();" "arr = new Array();"
"%s" "%s"
@ -76,6 +92,40 @@ formhistory_build_js ()
return script; return script;
} }
static void
formhistory_update_main_hash (GHashTable* keys)
{
GHashTableIter iter;
gchar* tmp = "";
gchar* new_value = "";
gchar* key = "";
gchar* value = "";
g_hash_table_iter_init (&iter, keys);
while (g_hash_table_iter_next (&iter, (gpointer)&key, (gpointer)&value))
{
if (value && *value && (strlen (value) > MAXCHARS || strlen (value) < MINCHARS))
return;
tmp = g_hash_table_lookup (global_keys, (gpointer)key);
if (tmp)
{
gchar* rvalue = g_strdup_printf ("\"%s\"",value);
if (!g_regex_match_simple (rvalue, tmp,
G_REGEX_CASELESS, G_REGEX_MATCH_NOTEMPTY))
{
new_value = g_strdup_printf ("%s%s,", tmp, rvalue);
g_hash_table_replace (global_keys, key, new_value);
}
g_free (rvalue);
}
else
{
new_value = g_strdup_printf ("\"%s\",",value);
g_hash_table_insert (global_keys, key, new_value);
}
}
}
static void static void
formhistory_session_request_queued_cb (SoupSession* session, formhistory_session_request_queued_cb (SoupSession* session,
SoupMessage* msg) SoupMessage* msg)
@ -84,17 +134,12 @@ formhistory_session_request_queued_cb (SoupSession* session,
if (method[0] == 'P' && method[1] == 'O' && method[2] == 'S') if (method[0] == 'P' && method[1] == 'O' && method[2] == 'S')
{ {
SoupMessageHeaders* hdrs = msg->request_headers; SoupMessageHeaders* hdrs = msg->request_headers;
SoupMessageHeadersIter iter; /* FIXME: Need a permanent storage implementation */
const gchar* name, *value; const char* referer = soup_message_headers_get_one (hdrs, "Referer");
SoupMessageBody* body = msg->request_body; SoupMessageBody* body = msg->request_body;
soup_message_headers_iter_init (&iter, hdrs);
while (soup_message_headers_iter_next (&iter, &name, &value))
{
g_warning ("%s=%s\n", name, value);
}
soup_buffer_free (soup_message_body_flatten (body)); soup_buffer_free (soup_message_body_flatten (body));
g_warning ("BODY: %s\n", body->data); GHashTable* keys = soup_form_decode (body->data);
formhistory_update_main_hash (keys);
} }
g_free (method); g_free (method);
} }
@ -118,7 +163,6 @@ formhistory_add_tab_cb (MidoriBrowser* browser,
SoupSession *session = webkit_get_default_session (); SoupSession *session = webkit_get_default_session ();
g_signal_connect (web_view, "window-object-cleared", g_signal_connect (web_view, "window-object-cleared",
G_CALLBACK (formhistory_window_object_cleared_cb), 0); G_CALLBACK (formhistory_window_object_cleared_cb), 0);
/* FIXME: Deactivate request-queued on unload */
g_signal_connect (session, "request-queued", g_signal_connect (session, "request-queued",
G_CALLBACK (formhistory_session_request_queued_cb), 0); G_CALLBACK (formhistory_session_request_queued_cb), 0);
} }
@ -151,10 +195,13 @@ formhistory_deactivate_tabs (MidoriView* view,
MidoriBrowser* browser) MidoriBrowser* browser)
{ {
GtkWidget* web_view = gtk_bin_get_child (GTK_BIN (view)); GtkWidget* web_view = gtk_bin_get_child (GTK_BIN (view));
SoupSession *session = webkit_get_default_session ();
g_signal_handlers_disconnect_by_func ( g_signal_handlers_disconnect_by_func (
browser, formhistory_add_tab_cb, 0); browser, formhistory_add_tab_cb, 0);
g_signal_handlers_disconnect_by_func ( g_signal_handlers_disconnect_by_func (
web_view, formhistory_window_object_cleared_cb, 0); web_view, formhistory_window_object_cleared_cb, 0);
g_signal_handlers_disconnect_by_func (
session, formhistory_session_request_queued_cb, 0);
} }
static void static void
@ -168,6 +215,10 @@ formhistory_deactivate_cb (MidoriExtension* extension,
g_signal_handlers_disconnect_by_func ( g_signal_handlers_disconnect_by_func (
app, formhistory_app_add_browser_cb, extension); app, formhistory_app_add_browser_cb, extension);
midori_browser_foreach (browser, (GtkCallback)formhistory_deactivate_tabs, browser); midori_browser_foreach (browser, (GtkCallback)formhistory_deactivate_tabs, browser);
jsforms = "";
if (global_keys)
g_hash_table_destroy (global_keys);
} }
static void static void
@ -178,7 +229,9 @@ formhistory_activate_cb (MidoriExtension* extension,
MidoriBrowser* browser; MidoriBrowser* browser;
guint i; guint i;
formhistory_prepare_js (); global_keys = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify)g_free,
(GDestroyNotify)g_free);
browsers = katze_object_get_object (app, "browsers"); browsers = katze_object_get_object (app, "browsers");
i = 0; i = 0;
while ((browser = katze_array_get_nth_item (browsers, i++))) while ((browser = katze_array_get_nth_item (browsers, i++)))
@ -189,17 +242,51 @@ formhistory_activate_cb (MidoriExtension* extension,
g_object_unref (browsers); g_object_unref (browsers);
} }
#if G_ENABLE_DEBUG
/*
<html>
<head>
<title>autosuggest testcase</title>
</head>
<body>
<form method=post>
<p><input type="text" id="txt1" /></p>
<p><input type="text" name="txt2" /></p>
<input type=submit>
</form>
</body>
</html> */
#endif
MidoriExtension* MidoriExtension*
extension_init (void) extension_init (void)
{ {
gboolean should_init = TRUE;
gchar* ver;
gchar* desc;
if (formhistory_prepare_js ())
{
ver = "0.1";
desc = g_strdup (_("Stores history of entered form data"));
}
else
{
desc = g_strdup_printf (_("Not available: %s"),
_("Resource files not installed"));
ver = NULL;
should_init = FALSE;
}
MidoriExtension* extension = g_object_new (MIDORI_TYPE_EXTENSION, MidoriExtension* extension = g_object_new (MIDORI_TYPE_EXTENSION,
"name", _("Form history filler"), "name", _("Form history filler"),
"description", _("Stores history of entered form data"), "description", desc,
"version", "0.1", "version", ver,
"authors", "Alexander V. Butenko <a.butenka@gmail.com>", "authors", "Alexander V. Butenko <a.butenka@gmail.com>",
NULL); NULL);
g_signal_connect (extension, "activate", g_free (desc);
G_CALLBACK (formhistory_activate_cb), NULL);
if (should_init)
g_signal_connect (extension, "activate",
G_CALLBACK (formhistory_activate_cb), NULL);
return extension; return extension;
} }

View file

@ -453,6 +453,8 @@ def build (bld):
bld.install_files ('${MDATADIR}/' + APPNAME + '/res', 'data/speeddial-head.html') bld.install_files ('${MDATADIR}/' + APPNAME + '/res', 'data/speeddial-head.html')
bld.install_files ('${MDATADIR}/' + APPNAME + '/res', 'data/speeddial.json') bld.install_files ('${MDATADIR}/' + APPNAME + '/res', 'data/speeddial.json')
bld.install_files ('${MDATADIR}/' + APPNAME + '/res', 'data/mootools.js') bld.install_files ('${MDATADIR}/' + APPNAME + '/res', 'data/mootools.js')
bld.install_files ('${MDATADIR}/' + APPNAME, 'data/autosuggestcontrol.js')
bld.install_files ('${MDATADIR}/' + APPNAME, 'data/autosuggestcontrol.css')
# FIXME: Determine the library naming for other platforms # FIXME: Determine the library naming for other platforms
if Options.platform == 'linux': if Options.platform == 'linux':