X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=surf.c;h=2e8ca70766172fdb7eed7f663ad52b3517314160;hb=26a2dbac6501d095937568cdb9f00083e0b02146;hp=4f7b691cc9ba5a3a83736ce77a9973284b864fd2;hpb=bce814b30ae026f97067bdd3c43a3b08f78c33bf;p=surf.git diff --git a/surf.c b/surf.c index 4f7b691..2e8ca70 100644 --- a/surf.c +++ b/surf.c @@ -60,11 +60,12 @@ typedef struct Client { WebKitWebView *view; WebKitWebInspector *inspector; WebKitHitTestResult *mousepos; + GTlsCertificateFlags tlsflags; const char *title, *targeturi; const char *needle; gint progress; struct Client *next; - gboolean zoomed, fullscreen, isinspecting, sslfailed; + gboolean zoomed, fullscreen, isinspecting; } Client; typedef struct { @@ -153,8 +154,7 @@ static gboolean keypress(GtkAccelGroup *group, GObject *obj, guint key, GdkModifierType mods, Client *c); static void mousetargetchanged(WebKitWebView *v, WebKitHitTestResult *h, guint modifiers, Client *c); -static void loadstatuschange(WebKitWebView *view, GParamSpec *pspec, - Client *c); +static void loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c); static void loaduri(Client *c, const Arg *arg); static void navigate(Client *c, const Arg *arg); static Client *newclient(Client *c); @@ -169,7 +169,7 @@ static void menuactivate(GtkMenuItem *item, Client *c); static void print(Client *c, const Arg *arg); static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event, gpointer d); -static void progresschange(WebKitWebView *view, GParamSpec *pspec, Client *c); +static void progresschanged(WebKitWebView *v, GParamSpec *ps, Client *c); static void linkopen(Client *c, const Arg *arg); static void linkopenembed(Client *c, const Arg *arg); static void reload(Client *c, const Arg *arg); @@ -809,37 +809,34 @@ mousetargetchanged(WebKitWebView *v, WebKitHitTestResult *h, guint modifiers, } void -loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c) +loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c) { - WebKitWebFrame *frame; - WebKitWebDataSource *src; - WebKitNetworkRequest *request; - SoupMessage *msg; - char *uri; - - switch (webkit_web_view_get_load_status (c->view)) { + switch (e) { + case WEBKIT_LOAD_STARTED: + c->tlsflags = G_TLS_CERTIFICATE_VALIDATE_ALL + 1; + break; + case WEBKIT_LOAD_REDIRECTED: + setatom(c, AtomUri, geturi(c)); + break; case WEBKIT_LOAD_COMMITTED: - uri = geturi(c); - if (strstr(uri, "https://") == uri) { - frame = webkit_web_view_get_main_frame(c->view); - src = webkit_web_frame_get_data_source(frame); - request = webkit_web_data_source_get_request(src); - msg = webkit_network_request_get_message(request); - c->sslfailed = !(soup_message_get_flags(msg) - & SOUP_MESSAGE_CERTIFICATE_TRUSTED); - } - setatom(c, AtomUri, uri); + if (!webkit_web_view_get_tls_info(c->view, NULL, &(c->tlsflags))) + c->tlsflags = G_TLS_CERTIFICATE_VALIDATE_ALL + 1; + + setatom(c, AtomUri, geturi(c)); if (enablestyle) - setstyle(c, getstyle(uri)); + setstyle(c, getstyle(geturi(c))); break; case WEBKIT_LOAD_FINISHED: - c->progress = 100; - updatetitle(c); - break; - default: + /* Disabled until we write some WebKitWebExtension for + * manipulating the DOM directly. + evalscript(c, "document.documentElement.style.overflow = '%s'", + enablescrollbars ? "auto" : "hidden"); + */ + runscript(c); break; } + updatetitle(c); } void @@ -900,6 +897,7 @@ newclient(Client *rc) clients = c; c->view = newview(c, rc ? rc->view : NULL); + c->tlsflags = G_TLS_CERTIFICATE_VALIDATE_ALL + 1; return c; } @@ -992,11 +990,11 @@ newview(Client *c, WebKitWebView *rv) "window-object-cleared", G_CALLBACK(windowobjectcleared), c); g_signal_connect(G_OBJECT(v), - "notify::load-status", - G_CALLBACK(loadstatuschange), c); + "load-changed", + G_CALLBACK(loadchanged), c); g_signal_connect(G_OBJECT(v), - "notify::progress", - G_CALLBACK(progresschange), c); + "notify::estimated-load-progress", + G_CALLBACK(progresschanged), c); g_signal_connect(G_OBJECT(v), "download-requested", G_CALLBACK(initdownload), c); @@ -1222,9 +1220,10 @@ processx(GdkXEvent *e, GdkEvent *event, gpointer d) } void -progresschange(WebKitWebView *view, GParamSpec *pspec, Client *c) +progresschanged(WebKitWebView *v, GParamSpec *ps, Client *c) { - c->progress = webkit_web_view_get_progress(c->view) * 100; + c->progress = webkit_web_view_get_estimated_load_progress(c->view) * + 100; updatetitle(c); } @@ -1522,11 +1521,8 @@ getpagestat(Client *c) { const char *uri = geturi(c); - if (strstr(uri, "https://") == uri) - pagestat[0] = c->sslfailed ? 'U' : 'T'; - else - pagestat[0] = '-'; - + pagestats[0] = c->tlsflags > G_TLS_CERTIFICATE_VALIDATE_ALL ? '-' : + c->tlsflags > 0 ? 'U' : 'T'; pagestat[1] = '\0'; }