2009-10-06 18:35:56 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2009 Alexander Butenko <a.butenka@gmail.com>
|
2009-11-05 22:50:49 +00:00
|
|
|
Copyright (C) 2009 Christian Dywan <christian@twotoasts.de>
|
2009-10-06 18:35:56 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
2009-11-12 20:54:25 +00:00
|
|
|
#define MAXCHARS 60
|
2009-10-07 20:30:16 +00:00
|
|
|
#define MINCHARS 2
|
|
|
|
|
2009-10-06 18:35:56 +00:00
|
|
|
#include <midori/midori.h>
|
2011-10-31 21:10:39 +00:00
|
|
|
#include <glib/gstdio.h>
|
2009-10-06 18:35:56 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#if HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2009-10-07 20:30:16 +00:00
|
|
|
static GHashTable* global_keys;
|
2009-10-06 18:35:56 +00:00
|
|
|
static gchar* jsforms;
|
|
|
|
|
2011-08-09 13:01:34 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
formhistory_toggle_state_cb (GtkAction* action,
|
|
|
|
MidoriBrowser* browser);
|
|
|
|
|
2009-10-07 20:30:16 +00:00
|
|
|
static gboolean
|
2009-10-06 18:35:56 +00:00
|
|
|
formhistory_prepare_js ()
|
|
|
|
{
|
|
|
|
gchar* autosuggest;
|
|
|
|
gchar* style;
|
|
|
|
guint i;
|
2009-10-07 20:30:16 +00:00
|
|
|
gchar* file;
|
2009-10-06 18:35:56 +00:00
|
|
|
|
2011-10-28 23:16:08 +00:00
|
|
|
file = sokoke_find_data_filename ("autosuggestcontrol.js", TRUE);
|
2009-12-21 22:24:27 +00:00
|
|
|
if (!g_file_get_contents (file, &autosuggest, NULL, NULL))
|
2011-05-22 13:49:49 +00:00
|
|
|
{
|
|
|
|
g_free (file);
|
2009-10-07 20:30:16 +00:00
|
|
|
return FALSE;
|
2011-05-22 13:49:49 +00:00
|
|
|
}
|
2009-10-06 18:35:56 +00:00
|
|
|
g_strchomp (autosuggest);
|
|
|
|
|
2011-10-28 23:16:08 +00:00
|
|
|
katze_assign (file, sokoke_find_data_filename ("autosuggestcontrol.css", TRUE));
|
2011-05-22 13:49:49 +00:00
|
|
|
if (!g_file_get_contents (file, &style, NULL, NULL))
|
|
|
|
{
|
|
|
|
g_free (file);
|
2009-10-07 20:30:16 +00:00
|
|
|
return FALSE;
|
2011-05-22 13:49:49 +00:00
|
|
|
}
|
2009-10-06 18:35:56 +00:00
|
|
|
g_strchomp (style);
|
|
|
|
i = 0;
|
|
|
|
while (style[i])
|
|
|
|
{
|
|
|
|
if (style[i] == '\n')
|
|
|
|
style[i] = ' ';
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
jsforms = g_strdup_printf (
|
|
|
|
"%s"
|
|
|
|
"window.addEventListener ('DOMContentLoaded',"
|
|
|
|
"function () {"
|
2009-12-23 14:35:09 +00:00
|
|
|
" if (document.getElementById('formhistory'))"
|
|
|
|
" return;"
|
2010-06-30 13:51:54 +00:00
|
|
|
" if (!initSuggestions ())"
|
|
|
|
" return;"
|
2009-12-17 19:56:46 +00:00
|
|
|
" var mystyle = document.createElement('style');"
|
|
|
|
" mystyle.setAttribute('type', 'text/css');"
|
2009-12-23 14:35:09 +00:00
|
|
|
" mystyle.setAttribute('id', 'formhistory');"
|
2009-12-17 19:56:46 +00:00
|
|
|
" mystyle.appendChild(document.createTextNode('%s'));"
|
|
|
|
" var head = document.getElementsByTagName('head')[0];"
|
|
|
|
" if (head) head.appendChild(mystyle);"
|
2009-10-06 18:35:56 +00:00
|
|
|
"}, true);",
|
|
|
|
autosuggest,
|
|
|
|
style);
|
|
|
|
g_strstrip (jsforms);
|
2009-10-07 20:30:16 +00:00
|
|
|
g_free (file);
|
2009-10-06 18:35:56 +00:00
|
|
|
g_free (style);
|
|
|
|
g_free (autosuggest);
|
2009-10-07 20:30:16 +00:00
|
|
|
return TRUE;
|
2009-10-06 18:35:56 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 20:54:25 +00:00
|
|
|
static gchar*
|
|
|
|
formhistory_fixup_value (char* value)
|
|
|
|
{
|
|
|
|
guint i = 0;
|
|
|
|
g_strchomp (value);
|
|
|
|
while (value[i])
|
|
|
|
{
|
|
|
|
if (value[i] == '\n')
|
|
|
|
value[i] = ' ';
|
|
|
|
else if (value[i] == '"')
|
|
|
|
value[i] = '\'';
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2009-10-06 18:35:56 +00:00
|
|
|
static gchar*
|
|
|
|
formhistory_build_js ()
|
|
|
|
{
|
2009-10-07 21:04:30 +00:00
|
|
|
gchar* suggestions = g_strdup ("");
|
2009-10-07 20:30:16 +00:00
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer key, value;
|
2009-10-07 21:04:30 +00:00
|
|
|
gchar* script;
|
|
|
|
|
2009-10-07 20:30:16 +00:00
|
|
|
g_hash_table_iter_init (&iter, global_keys);
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
2009-10-07 21:04:30 +00:00
|
|
|
{
|
|
|
|
gchar* _suggestions = g_strdup_printf ("%s arr[\"%s\"] = [%s]; ",
|
|
|
|
suggestions, (char*)key, (char*)value);
|
|
|
|
katze_assign (suggestions, _suggestions);
|
|
|
|
}
|
|
|
|
script = g_strdup_printf ("function FormSuggestions(eid) { "
|
|
|
|
"arr = new Array();"
|
|
|
|
"%s"
|
|
|
|
"this.suggestions = arr[eid]; }"
|
|
|
|
"%s",
|
|
|
|
suggestions,
|
|
|
|
jsforms);
|
|
|
|
g_free (suggestions);
|
2009-11-04 20:28:37 +00:00
|
|
|
return script;
|
2009-10-06 18:35:56 +00:00
|
|
|
}
|
|
|
|
|
2009-10-07 20:30:16 +00:00
|
|
|
static void
|
2009-11-01 22:49:58 +00:00
|
|
|
formhistory_update_database (gpointer db,
|
|
|
|
const gchar* key,
|
|
|
|
const gchar* value)
|
|
|
|
{
|
2009-11-05 22:50:49 +00:00
|
|
|
gchar* sqlcmd;
|
|
|
|
gchar* errmsg;
|
|
|
|
gint success;
|
|
|
|
|
|
|
|
sqlcmd = sqlite3_mprintf ("INSERT INTO forms VALUES"
|
|
|
|
"('%q', '%q', '%q')",
|
|
|
|
NULL, key, value);
|
|
|
|
success = sqlite3_exec (db, sqlcmd, NULL, NULL, &errmsg);
|
|
|
|
sqlite3_free (sqlcmd);
|
|
|
|
if (success != SQLITE_OK)
|
|
|
|
{
|
|
|
|
g_printerr (_("Failed to add form value: %s\n"), errmsg);
|
|
|
|
g_free (errmsg);
|
|
|
|
return;
|
|
|
|
}
|
2009-11-01 22:49:58 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 22:10:37 +00:00
|
|
|
static gboolean
|
2009-11-12 20:54:25 +00:00
|
|
|
formhistory_update_main_hash (gchar* key,
|
|
|
|
gchar* value)
|
2009-10-07 20:30:16 +00:00
|
|
|
{
|
2009-11-12 20:54:25 +00:00
|
|
|
guint length;
|
|
|
|
gchar* tmp;
|
2009-10-12 16:21:12 +00:00
|
|
|
|
2009-11-12 20:54:25 +00:00
|
|
|
if (!(value && *value))
|
2009-11-12 22:10:37 +00:00
|
|
|
return FALSE;
|
2009-11-12 20:54:25 +00:00
|
|
|
length = strlen (value);
|
|
|
|
if (length > MAXCHARS || length < MINCHARS)
|
2009-11-12 22:10:37 +00:00
|
|
|
return FALSE;
|
2009-10-07 20:30:16 +00:00
|
|
|
|
2010-06-30 14:43:18 +00:00
|
|
|
formhistory_fixup_value (key);
|
2009-11-12 22:10:37 +00:00
|
|
|
formhistory_fixup_value (value);
|
2009-11-12 20:54:25 +00:00
|
|
|
if ((tmp = g_hash_table_lookup (global_keys, (gpointer)key)))
|
|
|
|
{
|
|
|
|
gchar* rvalue = g_strdup_printf ("\"%s\"",value);
|
2010-06-30 16:16:05 +00:00
|
|
|
gchar* patt = g_regex_escape_string (rvalue, -1);
|
|
|
|
if (!g_regex_match_simple (patt, tmp,
|
2009-11-12 20:54:25 +00:00
|
|
|
G_REGEX_CASELESS, G_REGEX_MATCH_NOTEMPTY))
|
2009-10-07 20:30:16 +00:00
|
|
|
{
|
2009-11-12 20:54:25 +00:00
|
|
|
gchar* new_value = g_strdup_printf ("%s%s,", tmp, rvalue);
|
|
|
|
g_hash_table_insert (global_keys, g_strdup (key), new_value);
|
2009-11-12 22:10:37 +00:00
|
|
|
g_free (rvalue);
|
2010-06-30 16:16:05 +00:00
|
|
|
g_free (patt);
|
2009-11-12 22:10:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_free (rvalue);
|
2010-06-30 16:16:05 +00:00
|
|
|
g_free (patt);
|
2009-11-12 22:10:37 +00:00
|
|
|
return FALSE;
|
2009-10-07 20:30:16 +00:00
|
|
|
}
|
2009-11-12 20:54:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gchar* new_value = g_strdup_printf ("\"%s\",",value);
|
|
|
|
g_hash_table_replace (global_keys, g_strdup (key), new_value);
|
2009-10-07 20:30:16 +00:00
|
|
|
}
|
2009-11-12 22:10:37 +00:00
|
|
|
return TRUE;
|
2009-10-07 20:30:16 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 20:54:25 +00:00
|
|
|
static gboolean
|
|
|
|
formhistory_navigation_decision_cb (WebKitWebView* web_view,
|
|
|
|
WebKitWebFrame* web_frame,
|
|
|
|
WebKitNetworkRequest* request,
|
|
|
|
WebKitWebNavigationAction* action,
|
|
|
|
WebKitWebPolicyDecision* decision,
|
|
|
|
MidoriExtension* extension)
|
2009-10-06 18:35:56 +00:00
|
|
|
{
|
2009-11-12 20:54:25 +00:00
|
|
|
/* The script returns form data in the form "field_name|,|value|,|field_type".
|
|
|
|
We are handling only input fields with 'text' or 'password' type.
|
|
|
|
The field separator is "|||" */
|
|
|
|
const gchar* script = "function dumpForm (inputs) {"
|
|
|
|
" var out = '';"
|
|
|
|
" for (i=0;i<inputs.length;i++) {"
|
2010-06-30 15:41:19 +00:00
|
|
|
" if (inputs[i].getAttribute('autocomplete') == 'off')"
|
|
|
|
" continue;"
|
2009-11-12 20:54:25 +00:00
|
|
|
" if (inputs[i].value && (inputs[i].type == 'text' || inputs[i].type == 'password')) {"
|
|
|
|
" var ename = inputs[i].getAttribute('name');"
|
|
|
|
" var eid = inputs[i].getAttribute('id');"
|
|
|
|
" if (!ename && eid)"
|
|
|
|
" ename=eid;"
|
2010-01-10 21:57:17 +00:00
|
|
|
" if (inputs[i].getAttribute('autocomplete') != 'off')"
|
|
|
|
" out += ename+'|,|'+inputs[i].value +'|,|'+inputs[i].type +'|||';"
|
2009-11-12 20:54:25 +00:00
|
|
|
" }"
|
|
|
|
" }"
|
|
|
|
" return out;"
|
|
|
|
"}"
|
|
|
|
"dumpForm (document.getElementsByTagName('input'))";
|
|
|
|
|
2009-12-19 09:45:39 +00:00
|
|
|
if (webkit_web_navigation_action_get_reason (action) == WEBKIT_WEB_NAVIGATION_REASON_FORM_SUBMITTED)
|
2009-10-06 18:35:56 +00:00
|
|
|
{
|
2010-01-10 21:57:17 +00:00
|
|
|
JSContextRef js_context = webkit_web_frame_get_global_context (web_frame);
|
2009-11-12 22:48:19 +00:00
|
|
|
gchar* value = sokoke_js_script_eval (js_context, script, NULL);
|
2010-01-10 21:57:17 +00:00
|
|
|
if (value && *value)
|
2009-10-12 16:16:52 +00:00
|
|
|
{
|
2009-11-12 20:54:25 +00:00
|
|
|
gpointer db = g_object_get_data (G_OBJECT (extension), "formhistory-db");
|
|
|
|
gchar** inputs = g_strsplit (value, "|||", 0);
|
|
|
|
guint i = 0;
|
|
|
|
while (inputs[i] != NULL)
|
|
|
|
{
|
|
|
|
gchar** parts = g_strsplit (inputs[i], "|,|", 3);
|
|
|
|
if (parts && parts[0] && parts[1] && parts[2])
|
|
|
|
{
|
|
|
|
/* FIXME: We need to handle passwords */
|
|
|
|
if (strcmp (parts[2], "password"))
|
|
|
|
{
|
2009-11-12 22:10:37 +00:00
|
|
|
if (formhistory_update_main_hash (parts[0], parts[1]))
|
|
|
|
formhistory_update_database (db, parts[0], parts[1]);
|
2009-11-12 20:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
g_strfreev (parts);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
g_strfreev (inputs);
|
|
|
|
g_free (value);
|
2009-10-12 16:16:52 +00:00
|
|
|
}
|
2009-10-06 18:35:56 +00:00
|
|
|
}
|
2009-11-12 20:54:25 +00:00
|
|
|
return FALSE;
|
2009-10-06 18:35:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-12-19 19:21:10 +00:00
|
|
|
formhistory_window_object_cleared_cb (WebKitWebView* web_view,
|
2009-10-06 18:35:56 +00:00
|
|
|
WebKitWebFrame* web_frame,
|
|
|
|
JSContextRef js_context,
|
|
|
|
JSObjectRef js_window)
|
|
|
|
{
|
2010-02-02 20:31:15 +00:00
|
|
|
gchar* script;
|
|
|
|
script = formhistory_build_js ();
|
|
|
|
sokoke_js_script_eval (js_context, script, NULL);
|
|
|
|
g_free (script);
|
2009-10-06 18:35:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-11-01 22:49:58 +00:00
|
|
|
formhistory_add_tab_cb (MidoriBrowser* browser,
|
|
|
|
MidoriView* view,
|
|
|
|
MidoriExtension* extension)
|
2009-10-06 18:35:56 +00:00
|
|
|
{
|
2010-03-30 20:44:04 +00:00
|
|
|
GtkWidget* web_view = midori_view_get_web_view (view);
|
2009-10-06 18:35:56 +00:00
|
|
|
g_signal_connect (web_view, "window-object-cleared",
|
2009-11-01 22:49:58 +00:00
|
|
|
G_CALLBACK (formhistory_window_object_cleared_cb), NULL);
|
2009-11-12 20:54:25 +00:00
|
|
|
g_signal_connect (web_view, "navigation-policy-decision-requested",
|
|
|
|
G_CALLBACK (formhistory_navigation_decision_cb), extension);
|
2009-10-06 18:35:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
formhistory_deactivate_cb (MidoriExtension* extension,
|
|
|
|
MidoriBrowser* browser);
|
|
|
|
|
|
|
|
static void
|
2009-11-01 22:49:58 +00:00
|
|
|
formhistory_add_tab_foreach_cb (MidoriView* view,
|
|
|
|
MidoriBrowser* browser,
|
|
|
|
MidoriExtension* extension)
|
2009-10-06 18:35:56 +00:00
|
|
|
{
|
2009-11-01 22:49:58 +00:00
|
|
|
formhistory_add_tab_cb (browser, view, extension);
|
2009-10-06 18:35:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
formhistory_app_add_browser_cb (MidoriApp* app,
|
|
|
|
MidoriBrowser* browser,
|
|
|
|
MidoriExtension* extension)
|
|
|
|
{
|
2011-08-09 13:01:34 +00:00
|
|
|
GtkAccelGroup* acg = gtk_accel_group_new ();
|
|
|
|
GtkActionGroup* action_group = midori_browser_get_action_group (browser);
|
|
|
|
GtkAction* action = gtk_action_new ("FormHistoryToggleState",
|
|
|
|
_("Toggle form history state"),
|
|
|
|
_("Activate or deactivate form history for the current tab."), NULL);
|
|
|
|
gtk_window_add_accel_group (GTK_WINDOW (browser), acg);
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (browser), "FormHistoryExtension", extension);
|
|
|
|
|
|
|
|
g_signal_connect (action, "activate",
|
|
|
|
G_CALLBACK (formhistory_toggle_state_cb), browser);
|
|
|
|
|
|
|
|
gtk_action_group_add_action_with_accel (action_group, action, "<Ctrl><Shift>F");
|
|
|
|
gtk_action_set_accel_group (action, acg);
|
|
|
|
gtk_action_connect_accelerator (action);
|
|
|
|
|
|
|
|
if (midori_extension_get_boolean (extension, "always-load"))
|
|
|
|
{
|
|
|
|
midori_browser_foreach (browser,
|
|
|
|
(GtkCallback)formhistory_add_tab_foreach_cb, extension);
|
|
|
|
g_signal_connect (browser, "add-tab",
|
|
|
|
G_CALLBACK (formhistory_add_tab_cb), extension);
|
|
|
|
}
|
2009-10-06 18:35:56 +00:00
|
|
|
g_signal_connect (extension, "deactivate",
|
|
|
|
G_CALLBACK (formhistory_deactivate_cb), browser);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-11-01 22:49:58 +00:00
|
|
|
formhistory_deactivate_tabs (MidoriView* view,
|
|
|
|
MidoriBrowser* browser,
|
|
|
|
MidoriExtension* extension)
|
2009-10-06 18:35:56 +00:00
|
|
|
{
|
2010-03-30 20:44:04 +00:00
|
|
|
GtkWidget* web_view = midori_view_get_web_view (view);
|
2009-10-06 18:35:56 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (
|
2009-11-01 22:49:58 +00:00
|
|
|
web_view, formhistory_window_object_cleared_cb, NULL);
|
2009-10-07 20:30:16 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (
|
2009-11-12 20:54:25 +00:00
|
|
|
web_view, formhistory_navigation_decision_cb, extension);
|
2009-10-06 18:35:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
formhistory_deactivate_cb (MidoriExtension* extension,
|
2011-08-09 13:01:34 +00:00
|
|
|
MidoriBrowser* browser)
|
2009-10-06 18:35:56 +00:00
|
|
|
{
|
|
|
|
MidoriApp* app = midori_extension_get_app (extension);
|
2009-11-01 22:49:58 +00:00
|
|
|
sqlite3* db;
|
2009-10-06 18:35:56 +00:00
|
|
|
|
2011-08-09 13:01:34 +00:00
|
|
|
GtkActionGroup* action_group = midori_browser_get_action_group (browser);
|
|
|
|
GtkAction* action;
|
|
|
|
|
2010-02-02 20:31:15 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (
|
|
|
|
browser, formhistory_add_tab_cb, extension);
|
2009-10-06 18:35:56 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (
|
|
|
|
extension, formhistory_deactivate_cb, browser);
|
|
|
|
g_signal_handlers_disconnect_by_func (
|
|
|
|
app, formhistory_app_add_browser_cb, extension);
|
2009-11-01 22:49:58 +00:00
|
|
|
midori_browser_foreach (browser,
|
|
|
|
(GtkCallback)formhistory_deactivate_tabs, extension);
|
2009-10-07 20:30:16 +00:00
|
|
|
|
2011-08-09 13:01:34 +00:00
|
|
|
g_object_set_data (G_OBJECT (browser), "FormHistoryExtension", NULL);
|
|
|
|
action = gtk_action_group_get_action ( action_group, "FormHistoryToggleState");
|
|
|
|
if (action != NULL)
|
|
|
|
{
|
|
|
|
gtk_action_group_remove_action (action_group, action);
|
|
|
|
g_object_unref (action);
|
|
|
|
}
|
|
|
|
|
2010-02-02 20:31:15 +00:00
|
|
|
katze_assign (jsforms, NULL);
|
2009-10-07 20:30:16 +00:00
|
|
|
if (global_keys)
|
|
|
|
g_hash_table_destroy (global_keys);
|
2009-11-01 22:49:58 +00:00
|
|
|
|
|
|
|
if ((db = g_object_get_data (G_OBJECT (extension), "formhistory-db")))
|
|
|
|
sqlite3_close (db);
|
2009-10-06 18:35:56 +00:00
|
|
|
}
|
|
|
|
|
2009-11-05 22:50:49 +00:00
|
|
|
static int
|
|
|
|
formhistory_add_field (gpointer data,
|
|
|
|
int argc,
|
|
|
|
char** argv,
|
|
|
|
char** colname)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
gint ncols = 3;
|
|
|
|
|
|
|
|
/* Test whether have the right number of columns */
|
|
|
|
g_return_val_if_fail (argc % ncols == 0, 1);
|
|
|
|
|
|
|
|
for (i = 0; i < (argc - ncols) + 1; i++)
|
|
|
|
{
|
|
|
|
if (argv[i])
|
|
|
|
{
|
|
|
|
if (colname[i] && !g_ascii_strcasecmp (colname[i], "domain")
|
|
|
|
&& colname[i + 1] && !g_ascii_strcasecmp (colname[i + 1], "field")
|
|
|
|
&& colname[i + 2] && !g_ascii_strcasecmp (colname[i + 2], "value"))
|
|
|
|
{
|
|
|
|
gchar* key = argv[i + 1];
|
2009-11-12 20:54:25 +00:00
|
|
|
formhistory_update_main_hash (g_strdup (key), g_strdup (argv[i + 2]));
|
2009-11-05 22:50:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-06 18:35:56 +00:00
|
|
|
static void
|
|
|
|
formhistory_activate_cb (MidoriExtension* extension,
|
|
|
|
MidoriApp* app)
|
|
|
|
{
|
2009-11-01 22:49:58 +00:00
|
|
|
const gchar* config_dir;
|
|
|
|
gchar* filename;
|
|
|
|
sqlite3* db;
|
2009-11-05 22:50:49 +00:00
|
|
|
char* errmsg = NULL, *errmsg2 = NULL;
|
2009-10-06 18:35:56 +00:00
|
|
|
KatzeArray* browsers;
|
|
|
|
MidoriBrowser* browser;
|
|
|
|
|
2009-10-07 20:30:16 +00:00
|
|
|
global_keys = g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
|
|
(GDestroyNotify)g_free,
|
|
|
|
(GDestroyNotify)g_free);
|
2010-02-02 20:31:15 +00:00
|
|
|
if(!jsforms)
|
|
|
|
formhistory_prepare_js ();
|
2009-11-01 22:49:58 +00:00
|
|
|
config_dir = midori_extension_get_config_dir (extension);
|
|
|
|
katze_mkdir_with_parents (config_dir, 0700);
|
|
|
|
filename = g_build_filename (config_dir, "forms.db", NULL);
|
2010-10-17 21:11:50 +00:00
|
|
|
if (sqlite3_open (filename, &db) != SQLITE_OK)
|
2009-11-01 22:49:58 +00:00
|
|
|
{
|
|
|
|
g_warning (_("Failed to open database: %s\n"), sqlite3_errmsg (db));
|
|
|
|
sqlite3_close (db);
|
|
|
|
}
|
|
|
|
g_free (filename);
|
2009-11-05 22:50:49 +00:00
|
|
|
if ((sqlite3_exec (db, "CREATE TABLE IF NOT EXISTS "
|
|
|
|
"forms (domain text, field text, value text)",
|
|
|
|
NULL, NULL, &errmsg) == SQLITE_OK)
|
|
|
|
&& (sqlite3_exec (db, "SELECT domain, field, value FROM forms ",
|
|
|
|
formhistory_add_field,
|
|
|
|
NULL, &errmsg2) == SQLITE_OK))
|
|
|
|
g_object_set_data (G_OBJECT (extension), "formhistory-db", db);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (errmsg)
|
|
|
|
{
|
|
|
|
g_critical (_("Failed to execute database statement: %s\n"), errmsg);
|
|
|
|
sqlite3_free (errmsg);
|
|
|
|
if (errmsg2)
|
|
|
|
{
|
|
|
|
g_critical (_("Failed to execute database statement: %s\n"), errmsg2);
|
|
|
|
sqlite3_free (errmsg2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sqlite3_close (db);
|
|
|
|
}
|
2009-11-01 22:49:58 +00:00
|
|
|
|
2009-10-06 18:35:56 +00:00
|
|
|
browsers = katze_object_get_object (app, "browsers");
|
2010-09-11 21:39:51 +00:00
|
|
|
KATZE_ARRAY_FOREACH_ITEM (browser, browsers)
|
2009-10-06 18:35:56 +00:00
|
|
|
formhistory_app_add_browser_cb (app, browser, extension);
|
|
|
|
g_signal_connect (app, "add-browser",
|
|
|
|
G_CALLBACK (formhistory_app_add_browser_cb), extension);
|
|
|
|
|
|
|
|
g_object_unref (browsers);
|
|
|
|
}
|
|
|
|
|
2011-08-09 13:01:34 +00:00
|
|
|
static void
|
|
|
|
formhistory_preferences_response_cb (GtkWidget* dialog,
|
|
|
|
gint response_id,
|
|
|
|
MidoriExtension* extension)
|
|
|
|
{
|
|
|
|
GtkWidget* checkbox;
|
|
|
|
gboolean old_state;
|
|
|
|
gboolean new_state;
|
|
|
|
MidoriApp* app;
|
|
|
|
KatzeArray* browsers;
|
|
|
|
MidoriBrowser* browser;
|
|
|
|
|
|
|
|
if (response_id == GTK_RESPONSE_APPLY)
|
|
|
|
{
|
|
|
|
checkbox = g_object_get_data (G_OBJECT (dialog), "always-load-checkbox");
|
|
|
|
new_state = !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox));
|
|
|
|
old_state = midori_extension_get_boolean (extension, "always-load");
|
|
|
|
|
|
|
|
if (old_state != new_state)
|
|
|
|
{
|
|
|
|
midori_extension_set_boolean (extension, "always-load", new_state);
|
|
|
|
|
|
|
|
app = midori_extension_get_app (extension);
|
|
|
|
browsers = katze_object_get_object (app, "browsers");
|
|
|
|
KATZE_ARRAY_FOREACH_ITEM (browser, browsers)
|
|
|
|
{
|
|
|
|
midori_browser_foreach (browser,
|
|
|
|
(GtkCallback)formhistory_deactivate_tabs, extension);
|
|
|
|
g_signal_handlers_disconnect_by_func (
|
|
|
|
browser, formhistory_add_tab_cb, extension);
|
|
|
|
|
|
|
|
if (new_state)
|
|
|
|
{
|
|
|
|
midori_browser_foreach (browser,
|
|
|
|
(GtkCallback)formhistory_add_tab_foreach_cb, extension);
|
|
|
|
g_signal_connect (browser, "add-tab",
|
|
|
|
G_CALLBACK (formhistory_add_tab_cb), extension);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
formhistory_preferences_cb (MidoriExtension* extension)
|
|
|
|
{
|
|
|
|
GtkWidget* dialog;
|
|
|
|
GtkWidget* content_area;
|
|
|
|
GtkWidget* checkbox;
|
|
|
|
|
|
|
|
dialog = gtk_dialog_new ();
|
|
|
|
|
|
|
|
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
|
|
|
|
|
|
|
gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
|
|
|
|
gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_APPLY, GTK_RESPONSE_APPLY);
|
|
|
|
|
|
|
|
content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
|
|
|
|
checkbox = gtk_check_button_new_with_label (_("only activate form history via hotkey (Ctrl+Shift+F) per tab"));
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox),
|
|
|
|
!midori_extension_get_boolean (extension, "always-load"));
|
|
|
|
g_object_set_data (G_OBJECT (dialog), "always-load-checkbox", checkbox);
|
|
|
|
gtk_container_add (GTK_CONTAINER (content_area), checkbox);
|
|
|
|
|
|
|
|
g_signal_connect (dialog,
|
|
|
|
"response",
|
|
|
|
G_CALLBACK (formhistory_preferences_response_cb),
|
|
|
|
extension);
|
|
|
|
gtk_widget_show_all (dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
formhistory_toggle_state_cb (GtkAction* action,
|
|
|
|
MidoriBrowser* browser)
|
|
|
|
{
|
|
|
|
MidoriView* view = MIDORI_VIEW (midori_browser_get_current_tab (browser));
|
|
|
|
MidoriExtension* extension = g_object_get_data (G_OBJECT (browser), "FormHistoryExtension");
|
|
|
|
GtkWidget* web_view = midori_view_get_web_view (view);
|
|
|
|
|
|
|
|
if (g_signal_handler_find (web_view, G_SIGNAL_MATCH_FUNC,
|
|
|
|
g_signal_lookup ("window-object-cleared", MIDORI_TYPE_VIEW), 0, NULL,
|
|
|
|
formhistory_window_object_cleared_cb, extension))
|
|
|
|
{
|
|
|
|
formhistory_deactivate_tabs (view, browser, extension);
|
|
|
|
} else {
|
|
|
|
formhistory_add_tab_cb (browser, view, extension);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-07 20:30:16 +00:00
|
|
|
#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
|
|
|
|
|
2009-10-06 18:35:56 +00:00
|
|
|
MidoriExtension*
|
|
|
|
extension_init (void)
|
|
|
|
{
|
2009-10-07 20:30:16 +00:00
|
|
|
gboolean should_init = TRUE;
|
2009-11-01 22:49:58 +00:00
|
|
|
const gchar* ver;
|
2009-10-07 20:30:16 +00:00
|
|
|
gchar* desc;
|
2009-11-01 22:49:58 +00:00
|
|
|
MidoriExtension* extension;
|
|
|
|
|
2009-10-07 20:30:16 +00:00
|
|
|
if (formhistory_prepare_js ())
|
|
|
|
{
|
2010-01-10 21:57:17 +00:00
|
|
|
ver = "1.0";
|
2009-10-07 20:30:16 +00:00
|
|
|
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;
|
|
|
|
}
|
2009-11-01 22:49:58 +00:00
|
|
|
|
|
|
|
extension = g_object_new (MIDORI_TYPE_EXTENSION,
|
2009-10-06 18:35:56 +00:00
|
|
|
"name", _("Form history filler"),
|
2009-10-07 20:30:16 +00:00
|
|
|
"description", desc,
|
|
|
|
"version", ver,
|
2009-10-06 18:35:56 +00:00
|
|
|
"authors", "Alexander V. Butenko <a.butenka@gmail.com>",
|
|
|
|
NULL);
|
2011-08-09 13:01:34 +00:00
|
|
|
|
2009-10-07 20:30:16 +00:00
|
|
|
g_free (desc);
|
|
|
|
|
|
|
|
if (should_init)
|
2011-08-09 13:01:34 +00:00
|
|
|
{
|
2011-10-15 16:43:19 +00:00
|
|
|
midori_extension_install_boolean (extension, "always-load", TRUE);
|
2009-10-07 20:30:16 +00:00
|
|
|
g_signal_connect (extension, "activate",
|
|
|
|
G_CALLBACK (formhistory_activate_cb), NULL);
|
2011-08-09 13:01:34 +00:00
|
|
|
g_signal_connect (extension, "open-preferences",
|
|
|
|
G_CALLBACK (formhistory_preferences_cb), NULL);
|
|
|
|
}
|
2009-10-06 18:35:56 +00:00
|
|
|
|
|
|
|
return extension;
|
|
|
|
}
|