错误:类型名称未知的"WebKitWebFrame" [英] error: unknown type name ‘WebKitWebFrame’

查看:85
本文介绍了错误:类型名称未知的"WebKitWebFrame"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建带有网址栏的浏览器.URL栏需要反映浏览器中的任何导航更改,并且文档建议使用所请求的navigation-policy-decision来使用;回调使用5个参数,类型分别为WebkitWebView,WebKitWebFrame,WebKitNetworkRequest,WebKitNavigationAction,webKitPolicyDecision和gpointer.

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.

当我尝试进行编译时,我遇到了一些变体错误:未知类型名称"的错误.除WebkitWebView之外,所有列出的事件都会发生这种情况.我知道我包含了webkit2.h.我知道我尝试通过初始化WebKitWebFrame来明确定义,但是所做的只是创建更多错误.类型尚未定义吗?还是我必须自己定义它们?

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?

在以前测试过的计算机上,我的Wifi连接确实很弱,因此无法提供代码或编译输出.抱歉.

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(控制webkitWebview)

window.h (controls webkitWebview)

g_signal_connect(webView, "navigation-policy-decision-requested", G_CALLBACK(uriUpdateCb), url_bar);

callbacks.h(定义)

callbacks.h (definition)

static void uriUpdateCb(WebKitWebView* web_view, WebKitWebFrame* frame, WebkitNetworkRequest* request, WebkitWebNavigationAction* navigation_action, WebkitWebPolicyDecision* policy_decision, gpointer user_data);

编译错误

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

推荐答案

WebKitWebFrame和WebKitNetworkRequest是来自过时的webkitgtk-1.0和webkitgtk-3.0 API的类型,但是由于包含了webkit2.h,因此很显然,您正在尝试使用现代的webkit2gtk-4.0 API(应该如此).您可能正在查看旧API的文档.这是现代文档.

WebKitWebFrame and WebKitNetworkRequest are types from the obsolete webkitgtk-1.0 and webkitgtk-3.0 APIs, but since you are including webkit2.h it is clear that you are trying to use the modern webkit2gtk-4.0 API (as you should be). You're probably looking at documentation for the old APIs. Here is the modern documentation.

您无需听取导航政策决定即可获取URL.只需通过连接notify :: uri信号来查找对WebKitWebView :: uri的属性更改.如果不确定如何执行操作,请查阅g_signal_connect()的文档.

You don't need to listen to navigation policy decisions to get the URL. Just look for property changes to WebKitWebView::uri by connecting to the notify::uri signal. Look up the documentation of g_signal_connect() if you're not sure how to do this.

这篇关于错误:类型名称未知的"WebKitWebFrame"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆