\n" PACKAGE " " VERSION "
\n"
"Copyright (c) 2012 Pierre Pronchery <khorben@"
"defora.org>
\n\n\n";
#if WITH_INSPECTOR
WebKitWebSettings * settings;
WebKitWebInspector * inspector;
#endif
ghtml = g_object_get_data(G_OBJECT(widget), "ghtml");
if((p = _ghtml_make_url(NULL, url)) != NULL)
url = p;
if(strcmp("about:blank", url) == 0)
webkit_web_view_load_string(WEBKIT_WEB_VIEW(ghtml->view), "",
NULL, NULL, url);
else if(strncmp("about:", url, 6) == 0)
webkit_web_view_load_string(WEBKIT_WEB_VIEW(ghtml->view),
about, NULL, NULL, url);
else
{
#if WEBKIT_CHECK_VERSION(1, 1, 1)
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(ghtml->view), url);
#else
webkit_web_view_open(WEBKIT_WEB_VIEW(ghtml->view), url);
#endif
}
#if WITH_INSPECTOR
if(ghtml->inspector == NULL)
{
settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(
ghtml->view));
g_object_set(settings, "enable-developer-extras", TRUE, NULL);
inspector = webkit_web_view_get_inspector(WEBKIT_WEB_VIEW(
ghtml->view));
g_signal_connect(G_OBJECT(inspector), "inspect-web-view",
G_CALLBACK(_load_inspector_inspect), ghtml);
g_signal_connect(G_OBJECT(inspector), "show-window", G_CALLBACK(
_load_inspector_show), ghtml);
g_signal_connect(G_OBJECT(inspector), "notify::inspected-uri",
G_CALLBACK(_load_inspector_inspected_uri),
ghtml);
}
#endif
g_free(p);
g_free(q);
surfer_set_progress(ghtml->surfer, 0.0);
surfer_set_security(ghtml->surfer, SS_NONE);
_ghtml_set_status(widget, _("Connecting..."));
}
#if WITH_INSPECTOR
static WebKitWebView * _load_inspector_inspect(WebKitWebInspector * inspector,
WebKitWebView * view, gpointer data)
{
GHtml * ghtml = data;
ghtml->inspector = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(ghtml->inspector), 800, 600);
gtk_window_set_title(GTK_WINDOW(ghtml->inspector),
_("WebKit Web Inspector"));
view = webkit_web_view_new();
/* FIXME implement more signals and really implement "web-view-ready" */
g_signal_connect_swapped(view, "web-view-ready", gtk_widget_show_all,
ghtml->inspector);
gtk_container_add(GTK_CONTAINER(ghtml->inspector), GTK_WIDGET(view));
return view;
}
static gboolean _load_inspector_show(WebKitWebInspector * inspector,
gpointer data)
{
GHtml * ghtml = data;
gtk_window_present(GTK_WINDOW(ghtml->inspector));
return TRUE;
}
static gboolean _load_inspector_inspected_uri(WebKitWebInspector * inspector,
gpointer data)
{
GHtml * ghtml = data;
char buf[256];
char const * url;
url = webkit_web_inspector_get_inspected_uri(inspector);
snprintf(buf, sizeof(buf), "%s%s%s", _("WebKit Web Inspector"),
(url != NULL) ? " - " : "", (url != NULL) ? url : "");
return FALSE;
}
#endif
/* ghtml_paste */
void ghtml_paste(GtkWidget * widget)
{
GHtml * ghtml;
ghtml = g_object_get_data(G_OBJECT(widget), "ghtml");
webkit_web_view_paste_clipboard(WEBKIT_WEB_VIEW(ghtml->view));
}
/* ghtml_print */
void ghtml_print(GtkWidget * widget)
{
#if WEBKIT_CHECK_VERSION(1, 1, 0) /* XXX may not be accurate */
GHtml * ghtml;
WebKitWebFrame * frame;
ghtml = g_object_get_data(G_OBJECT(widget), "ghtml");
frame = webkit_web_view_get_main_frame(WEBKIT_WEB_VIEW(ghtml->view));
webkit_web_frame_print(frame);
#endif
}
/* ghtml_redo */
void ghtml_redo(GtkWidget * widget)
{
#if WEBKIT_CHECK_VERSION(1, 1, 14)
GHtml * ghtml;
ghtml = g_object_get_data(G_OBJECT(widget), "ghtml");
webkit_web_view_redo(WEBKIT_WEB_VIEW(ghtml->view));
#endif
}
void ghtml_refresh(GtkWidget * widget)
{
GHtml * ghtml;
ghtml = g_object_get_data(G_OBJECT(widget), "ghtml");
webkit_web_view_reload(WEBKIT_WEB_VIEW(ghtml->view));
}
void ghtml_reload(GtkWidget * widget)
{
GHtml * ghtml;
ghtml = g_object_get_data(G_OBJECT(widget), "ghtml");
#if WEBKIT_CHECK_VERSION(1, 0, 3)
webkit_web_view_reload_bypass_cache(WEBKIT_WEB_VIEW(ghtml->view));
#else
webkit_web_view_reload(WEBKIT_WEB_VIEW(ghtml->view));
#endif
}
void ghtml_stop(GtkWidget * widget)
{
GHtml * ghtml;
ghtml = g_object_get_data(G_OBJECT(widget), "ghtml");
webkit_web_view_stop_loading(WEBKIT_WEB_VIEW(ghtml->view));
}
void ghtml_select_all(GtkWidget * widget)
{
GHtml * ghtml;
ghtml = g_object_get_data(G_OBJECT(widget), "ghtml");
webkit_web_view_select_all(WEBKIT_WEB_VIEW(ghtml->view));
}
/* ghtml_undo */
void ghtml_undo(GtkWidget * widget)
{
#if WEBKIT_CHECK_VERSION(1, 1, 14)
GHtml * ghtml;
ghtml = g_object_get_data(G_OBJECT(widget), "ghtml");
webkit_web_view_undo(WEBKIT_WEB_VIEW(ghtml->view));
#endif
}
/* ghtml_unselect_all */
void ghtml_unselect_all(GtkWidget * widget)
{
/* FIXME implement */
}
/* ghtml_zoom_in */
void ghtml_zoom_in(GtkWidget * widget)
{
GHtml * ghtml;
ghtml = g_object_get_data(G_OBJECT(widget), "ghtml");
webkit_web_view_zoom_in(WEBKIT_WEB_VIEW(ghtml->view));
}
/* ghtml_zoom_out */
void ghtml_zoom_out(GtkWidget * widget)
{
GHtml * ghtml;
ghtml = g_object_get_data(G_OBJECT(widget), "ghtml");
webkit_web_view_zoom_out(WEBKIT_WEB_VIEW(ghtml->view));
}
/* ghtml_zoom_reset */
void ghtml_zoom_reset(GtkWidget * widget)
{
GHtml * ghtml;
ghtml = g_object_get_data(G_OBJECT(widget), "ghtml");
webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(ghtml->view), 1.0);
}
/* private */
/* functions */
static void _ghtml_set_status(GtkWidget * widget, char const * status)
{
GHtml * ghtml;
gdouble progress;
ghtml = g_object_get_data(G_OBJECT(widget), "ghtml");
free(ghtml->status);
if(status == NULL)
{
if((progress = ghtml_get_progress(widget)) == 0.0)
status = _("Connecting...");
else if(progress > 0.0)
status = _("Downloading...");
}
/* XXX may fail */
ghtml->status = (status != NULL) ? strdup(status) : NULL;
surfer_set_status(ghtml->surfer, status);
}
/* callbacks */
/* on_console_message */
static gboolean _on_console_message(WebKitWebView * view, const gchar * message,
guint line, const gchar * source, gpointer data)
{
GHtml * ghtml;
ghtml = g_object_get_data(G_OBJECT(data), "ghtml");
surfer_console_message(ghtml->surfer, message, source, line);
return TRUE;
}
/* on_create_web_view */
static WebKitWebView * _on_create_web_view(WebKitWebView * view,
WebKitWebFrame * frame, gpointer data)
{
GHtml * ghtml;
Surfer * surfer;
GtkWidget * widget;
if((surfer = surfer_new(NULL)) == NULL)
return NULL;
/* FIXME we may want the history to be copied (and then more) */
if((widget = surfer_get_view(surfer)) == NULL)
{
surfer_delete(surfer);
return NULL;
}
ghtml = g_object_get_data(G_OBJECT(widget), "ghtml");
g_signal_connect(G_OBJECT(ghtml->view), "web-view-ready", G_CALLBACK(
_on_web_view_ready), widget);
return WEBKIT_WEB_VIEW(ghtml->view);
}
#ifdef WEBKIT_TYPE_DOWNLOAD
/* on_download_requested */
static gboolean _on_download_requested(WebKitWebView * view,
WebKitDownload * download, gpointer data)
{
GHtml * ghtml;
char const * url;
char const * suggested;
ghtml = g_object_get_data(G_OBJECT(data), "ghtml");
url = webkit_download_get_uri(download);
suggested = webkit_download_get_suggested_filename(download);
surfer_download(ghtml->surfer, url, suggested);
webkit_download_cancel(download);
return FALSE;
}
#endif
/* on_hovering_over_link */
static void _on_hovering_over_link(WebKitWebView * view, const gchar * title,
const gchar * url, gpointer data)
{
GtkWidget * widget = data;
_ghtml_set_status(widget, url);
}
/* on_load_committed */
static void _on_load_committed(WebKitWebView * view, WebKitWebFrame * frame,
gpointer data)
{
GHtml * ghtml;
char const * location;
ghtml = g_object_get_data(G_OBJECT(data), "ghtml");
if(frame == webkit_web_view_get_main_frame(view)
&& (location = webkit_web_frame_get_uri(frame)) != NULL)
surfer_set_location(ghtml->surfer, location);
surfer_set_security(ghtml->surfer, ghtml_get_security(ghtml->widget));
}
/* on_load_error */
static gboolean _on_load_error(WebKitWebView * view, WebKitWebFrame * frame,
const gchar * uri, GError * error, gpointer data)
{
GHtml * ghtml;
#ifdef WEBKIT_POLICY_ERROR
char const * suggested;
#endif
ghtml = g_object_get_data(G_OBJECT(data), "ghtml");
if(error == NULL)
return surfer_error(ghtml->surfer, _("Unknown error"), TRUE);
#ifdef WEBKIT_NETWORK_ERROR
if(error->domain == WEBKIT_NETWORK_ERROR
&& error->code == WEBKIT_NETWORK_ERROR_CANCELLED)
return TRUE; /* ignored if the user cancelled it */
#endif
#ifdef WEBKIT_POLICY_ERROR
if(error->domain == WEBKIT_POLICY_ERROR
&& error->code == WEBKIT_POLICY_ERROR_FRAME_LOAD_INTERRUPTED_BY_POLICY_CHANGE)
{
/* FIXME propose to download or cancel instead */
if((suggested = strrchr(uri, '/')) != NULL)
suggested++;
surfer_download(ghtml->surfer, uri, suggested);
return TRUE;
}
#endif
return surfer_error(ghtml->surfer, error->message, TRUE);
}
/* on_load_finished */
static void _on_load_finished(WebKitWebView * view, WebKitWebFrame * arg1,
gpointer data)
{
GHtml * ghtml;
ghtml = g_object_get_data(G_OBJECT(data), "ghtml");
surfer_set_progress(ghtml->surfer, -1.0);
_ghtml_set_status(ghtml->widget, NULL);
}
/* on_load_progress_changed */
static void _on_load_progress_changed(WebKitWebView * view, gint progress,
gpointer data)
{
GHtml * ghtml;
gdouble fraction = progress;
ghtml = g_object_get_data(G_OBJECT(data), "ghtml");
surfer_set_progress(ghtml->surfer, fraction / 100);
_ghtml_set_status(ghtml->widget, _("Downloading..."));
}
/* on_load_started */
static void _on_load_started(WebKitWebView * view, WebKitWebFrame * frame,
gpointer data)
{
GHtml * ghtml;
ghtml = g_object_get_data(G_OBJECT(data), "ghtml");
surfer_set_progress(ghtml->surfer, 0.00);
_ghtml_set_status(ghtml->widget, _("Downloading..."));
}
/* on_script_alert */
static gboolean _on_script_alert(WebKitWebView * view, WebKitWebFrame * frame,
const gchar * message, gpointer data)
{
GHtml * ghtml;
ghtml = g_object_get_data(G_OBJECT(data), "ghtml");
surfer_warning(ghtml->surfer, message);
return TRUE;
}
static gboolean _on_script_confirm(WebKitWebView * view, WebKitWebFrame * frame,
const gchar * message, gboolean * confirmed, gpointer data)
{
GHtml * ghtml;
ghtml = g_object_get_data(G_OBJECT(data), "ghtml");
if(surfer_confirm(ghtml->surfer, message, confirmed) != 0)
*confirmed = FALSE;
return TRUE;
}
static gboolean _on_script_prompt(WebKitWebView * view, WebKitWebFrame * frame,
const gchar * message, const gchar * default_value,
gchar ** value, gpointer data)
{
GHtml * ghtml;
ghtml = g_object_get_data(G_OBJECT(data), "ghtml");
if(surfer_prompt(ghtml->surfer, message, default_value, value) == 0)
return TRUE;
*value = NULL;
return TRUE;
}
static void _on_status_bar_text_changed(WebKitWebView * view, gchar * arg1,
gpointer data)
{
GtkWidget * widget = data;
if(strlen(arg1) == 0)
return;
_ghtml_set_status(widget, arg1);
}
static void _on_title_changed(WebKitWebView * view, WebKitWebFrame * frame,
const gchar * title, gpointer data)
{
GHtml * ghtml;
ghtml = g_object_get_data(G_OBJECT(data), "ghtml");
surfer_set_title(ghtml->surfer, title);
}
#if WEBKIT_CHECK_VERSION(1, 0, 3)
static gboolean _on_web_view_ready(WebKitWebView * view, gpointer data)
{
GHtml * ghtml;
WebKitWebWindowFeatures * features;
gboolean b;
gint w;
gint h;
ghtml = g_object_get_data(G_OBJECT(data), "ghtml");
features = webkit_web_view_get_window_features(WEBKIT_WEB_VIEW(view));
/* FIXME track properties with notify:: instead */
g_object_get(G_OBJECT(features), "width", &w, "height", &h, NULL);
if(w > 0 && h > 0)
surfer_resize(ghtml->surfer, w, h);
g_object_get(G_OBJECT(features), "fullscreen", &b, NULL);
if(b == TRUE)
surfer_set_fullscreen(ghtml->surfer, TRUE);
# ifndef EMBEDDED
g_object_get(G_OBJECT(features), "menubar-visible", &b, NULL);
surfer_show_menubar(ghtml->surfer, b);
# endif
g_object_get(G_OBJECT(features), "toolbar-visible", &b, NULL);
surfer_show_toolbar(ghtml->surfer, b);
g_object_get(G_OBJECT(features), "statusbar-visible", &b, NULL);
surfer_show_statusbar(ghtml->surfer, b);
surfer_show_window(ghtml->surfer, TRUE);
return FALSE;
}
#else /* WebKitWebWindowFeatures is not available */
static gboolean _on_web_view_ready(WebKitWebView * view, gpointer data)
{
GHtml * ghtml;
ghtml = g_object_get_data(G_OBJECT(data), "ghtml");
surfer_show_window(ghtml->surfer, TRUE);
return FALSE;
}
#endif