Only apply parameters when needed

Specify which parameter should be applied on which load state.
This commit is contained in:
Quentin Rameau 2017-05-19 01:10:30 +02:00
parent 2223417c91
commit 70c1b548ab

74
surf.c
View File

@ -92,7 +92,7 @@ typedef enum {
StrictTLS, StrictTLS,
Style, Style,
ZoomLevel, ZoomLevel,
ParameterLast, ParameterLast
} ParamName; } ParamName;
typedef union { typedef union {
@ -170,7 +170,7 @@ static void gettogglestats(Client *c);
static void getpagestats(Client *c); static void getpagestats(Client *c);
static WebKitCookieAcceptPolicy cookiepolicy_get(void); static WebKitCookieAcceptPolicy cookiepolicy_get(void);
static char cookiepolicy_set(const WebKitCookieAcceptPolicy p); static char cookiepolicy_set(const WebKitCookieAcceptPolicy p);
static void seturiparameters(Client *c, const char *uri); static void seturiparameters(Client *c, const char *uri, ParamName *params);
static void setparameter(Client *c, int refresh, ParamName p, const Arg *a); static void setparameter(Client *c, int refresh, ParamName p, const Arg *a);
static const char *getcert(const char *uri); static const char *getcert(const char *uri);
static void setcert(Client *c, const char *file); static void setcert(Client *c, const char *file);
@ -256,6 +256,50 @@ static const char *useragent;
static Parameter *curconfig; static Parameter *curconfig;
char *argv0; char *argv0;
static ParamName loadtransient[] = {
Certificate,
CookiePolicies,
DiskCache,
DNSPrefetch,
FileURLsCrossAccess,
JavaScript,
LoadImages,
PreferredLanguages,
ShowIndicators,
StrictTLS,
ParameterLast
};
static ParamName loadcommitted[] = {
AcceleratedCanvas,
// AccessMicrophone,
// AccessWebcam,
CaretBrowsing,
DefaultCharset,
FontSize,
FrameFlattening,
Geolocation,
HideBackground,
Inspector,
Java,
// KioskMode,
MediaManualPlay,
Plugins,
RunInFullscreen,
ScrollBars,
SiteQuirks,
SmoothScrolling,
SpellChecking,
SpellLanguages,
Style,
ZoomLevel,
ParameterLast
};
static ParamName loadfinished[] = {
ParameterLast
};
/* configuration, allows nested code to access above variables */ /* configuration, allows nested code to access above variables */
#include "config.h" #include "config.h"
@ -641,10 +685,10 @@ cookiepolicy_set(const WebKitCookieAcceptPolicy p)
} }
void void
seturiparameters(Client *c, const char *uri) seturiparameters(Client *c, const char *uri, ParamName *params)
{ {
Parameter *config, *newconfig = NULL; Parameter *config, *newconfig = NULL;
int i; int i, p;
for (i = 0; i < LENGTH(uriparams); ++i) { for (i = 0; i < LENGTH(uriparams); ++i) {
if (uriparams[i].uri && if (uriparams[i].uri &&
@ -657,25 +701,25 @@ seturiparameters(Client *c, const char *uri)
if (!newconfig) if (!newconfig)
newconfig = defconfig; newconfig = defconfig;
for (i = 0; i < ParameterLast; ++i) { for (i = 0; (p = params[i]) != ParameterLast; ++i) {
switch(i) { switch(p) {
case Certificate: case Certificate:
case CookiePolicies: case CookiePolicies:
case Style: case Style:
config = defconfig[i].force ? defconfig : config = defconfig[p].force ? defconfig :
newconfig[i].force ? newconfig : newconfig[p].force ? newconfig :
defconfig; defconfig;
break; break;
default: default:
if (newconfig == curconfig || defconfig[i].force) if (defconfig[p].force)
continue; continue;
config = newconfig[i].force ? newconfig : config = newconfig[p].force ? newconfig :
curconfig[i].force ? defconfig : curconfig[p].force ? defconfig :
NULL; NULL;
} }
if (config) if (config)
setparameter(c, 0, i, &config[i].val); setparameter(c, 0, p, &config[p].val);
} }
curconfig = newconfig; curconfig = newconfig;
@ -1405,7 +1449,7 @@ loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c)
setatom(c, AtomUri, uri); setatom(c, AtomUri, uri);
c->title = uri; c->title = uri;
c->https = c->insecure = 0; c->https = c->insecure = 0;
seturiparameters(c, uri); seturiparameters(c, uri, loadtransient);
if (c->errorpage) if (c->errorpage)
c->errorpage = 0; c->errorpage = 0;
else else
@ -1414,13 +1458,15 @@ loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c)
case WEBKIT_LOAD_REDIRECTED: case WEBKIT_LOAD_REDIRECTED:
setatom(c, AtomUri, uri); setatom(c, AtomUri, uri);
c->title = uri; c->title = uri;
seturiparameters(c, uri); seturiparameters(c, uri, loadtransient);
break; break;
case WEBKIT_LOAD_COMMITTED: case WEBKIT_LOAD_COMMITTED:
seturiparameters(c, uri, loadcommitted);
c->https = webkit_web_view_get_tls_info(c->view, &c->cert, c->https = webkit_web_view_get_tls_info(c->view, &c->cert,
&c->tlserr); &c->tlserr);
break; break;
case WEBKIT_LOAD_FINISHED: case WEBKIT_LOAD_FINISHED:
seturiparameters(c, uri, loadfinished);
/* Disabled until we write some WebKitWebExtension for /* Disabled until we write some WebKitWebExtension for
* manipulating the DOM directly. * manipulating the DOM directly.
evalscript(c, "document.documentElement.style.overflow = '%s'", evalscript(c, "document.documentElement.style.overflow = '%s'",