I'm attempting to build a browser with a url bar. The URL bar needs to reflect any navigational changes in the browser, and the docs recommend the use of navigation-policy-decision-requested; the callback takes 5 params, with types WebkitWebView, WebKitWebFrame, WebKitNetworkRequest, WebKitNavigationAction, webKitPolicyDecision, and gpointer.
When I try to compile, I get several errors of the variant "error: unknown type name ". This happens to all of the ones listed, except WebkitWebView. I know I included webkit2.h. I know I tried explicitly defining, by initializing a WebKitWebFrame, for example, but all it did was create more errors. Are the types not already defined? Or do I have to define them myself?
EDIT: My Wifi connection was really weak on the computer I was testing on before, so I was unable to provide code or compile output. Sorry.
main.c
static void uriUpdateCb(WebKitWebView* web_view, WebKitWebFrame* frame, WebkitNetworkRequest* request, WebkitWebNavigationAction* navigation_action, WebkitWebPolicyDecision* policy_decision, gpointer user_data){
const gchar* uri = webkit_network_request_get_uri(request);
char* file_type = strchr(uri, '.');
if(file_type && (!strcmp(file_type, ".pdf") || !strcmp(file_type, ".db") || !strcmp(file_type, ".exe") || !strcmp(file_type, ".deb") || !strcmp(file_type, ".rpm") || !strcmp(file_type, ".dmg"))){
// note to self: replace above if statement with a loop and a file that contains these extensions
webkit_web_policy_decision_download(policy_decision);
}
else{
webkit_web_policy_decision_use(policy_decision);
gtk_entry_set_text(user_data, uri);
}
}
window.h (controls webkitWebview)
g_signal_connect(webView, "navigation-policy-decision-requested", G_CALLBACK(uriUpdateCb), url_bar);
callbacks.h (definition)
static void uriUpdateCb(WebKitWebView* web_view, WebKitWebFrame* frame, WebkitNetworkRequest* request, WebkitWebNavigationAction* navigation_action, WebkitWebPolicyDecision* policy_decision, gpointer user_data);
Compile Errors
In file included from main.c:35:0:
callbacks.h:4:50: error: unknown type name ‘WebKitWebFrame’
static void uriUpdateCb(WebKitWebView* web_view, WebKitWebFrame* frame, WebkitNet
^
callbacks.h:4:73: error: unknown type name ‘WebkitNetworkRequest’
atic void uriUpdateCb(WebKitWebView* web_view, WebKitWebFrame* frame, WebkitNetwo
^
callbacks.h:4:104: error: unknown type name ‘WebkitWebNavigationAction’
View* web_view, WebKitWebFrame* frame, WebkitNetworkRequest* request, WebkitWebNa
^
In file included from main.c:35:0:
callbacks.h:4:150: error: unknown type name ‘WebkitWebPolicyDecision’
etworkRequest* request, WebkitWebNavigationAction* navigation_action, WebkitWebPo
^
In file included from /usr/include/glib-2.0/gobject/gobject.h:28:0,
from /usr/include/glib-2.0/gobject/gbinding.h:29,
from /usr/include/glib-2.0/glib-object.h:23,
from /usr/include/glib-2.0/gio/gioenums.h:28,
from /usr/include/glib-2.0/gio/giotypes.h:28,
from /usr/include/glib-2.0/gio/gio.h:26,
from /usr/include/gtk-3.0/gdk/gdkapplaunchcontext.h:28,
from /usr/include/gtk-3.0/gdk/gdk.h:32,
from /usr/include/gtk-3.0/gtk/gtk.h:30,
from main.c:29:
window.h: In function ‘create_window’:
window.h:56:81: error: ‘uriUpdateCb’ undeclared (first use in this function)
l_connect(webView, "navigation-policy-decision-requested", G_CALLBACK(uriUpdateCb
^
/usr/include/glib-2.0/gobject/gsignal.h:475:60: note: in definition of macro ‘g_signal_connect’
g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NU
^
window.h:56:70: note: in expansion of macro ‘G_CALLBACK’
g_signal_connect(webView, "navigation-policy-decision-requested", G_CALLBACK(u
^
window.h:56:81: note: each undeclared identifier is reported only once for each function it appears in
l_connect(webView, "navigation-policy-decision-requested", G_CALLBACK(uriUpdateCb
^
/usr/include/glib-2.0/gobject/gsignal.h:475:60: note: in definition of macro ‘g_signal_connect’
g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NU
#include <gtk/gtk.h>
#include <string.h>
#include <gtk/gtk.h>
#include <string.h>
#include <stdio.h>
#include <webkit2/webkit2.h>
// window.h
int create_window(){
// Create an 800x600 window that will contain the browser instance
GtkWidget *main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(main_window), 800, 600);
// create the tab manager
GtkWidget *notebook = gtk_notebook_new();
GtkWidget *label = gtk_label_new ("test");
// create the gtk box that'll set the layout and put box in window
GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
gtk_notebook_append_page(GTK_NOTEBOOK (notebook), box, label);
gtk_container_add(GTK_CONTAINER(main_window), GTK_WIDGET(notebook));
GtkWidget *grid = gtk_grid_new();
gtk_container_add(GTK_CONTAINER(box), GTK_WIDGET(grid));
// create url_bar and add to grid
GtkWidget *back_button = gtk_button_new_with_label("Back");
GtkWidget *forward_button = gtk_button_new_with_label("Forward");
GtkWidget *stop_connection_button = gtk_button_new_with_label("Stop");
GtkEntryBuffer *buf = gtk_entry_buffer_new("about:blank", 12);
GtkWidget *url_bar = gtk_entry_new_with_buffer(buf);
gtk_grid_attach(GTK_GRID(grid), back_button, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid), forward_button, 1, 0, 1, 1);
^
window.h:56:70: note: in expansion of macro ‘G_CALLBACK’
g_signal_connect(webView, "navigation-policy-decision-requested", G_CALLBACK(u
^
main.c: At top level:
main.c:107:50: error: unknown type name ‘WebKitWebFrame’
static void uriUpdateCb(WebKitWebView* web_view, WebKitWebFrame* frame, WebkitNet
^
main.c:107:73: error: unknown type name ‘WebkitNetworkRequest’
atic void uriUpdateCb(WebKitWebView* web_view, WebKitWebFrame* frame, WebkitNetwo
^
main.c:107:104: error: unknown type name ‘WebkitWebNavigationAction’
View* web_view, WebKitWebFrame* frame, WebkitNetworkRequest* request, WebkitWebNa
^
main.c:107:150: error: unknown type name ‘WebkitWebPolicyDecision’
etworkRequest* request, WebkitWebNavigationAction* navigation_action, WebkitWebPo