mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-01-03 01:34:25 +03:00
Pass fetch redirect info up to content layer as content_msg. Mark redirect origin URLs as visited in browser window content callback. Note this doesn't mean we track redirects, it just lets us get the :visited link style on links that redirect.
This commit is contained in:
parent
8dc7ec2cb4
commit
ba9769bc8c
@ -188,6 +188,11 @@ nserror content_llcache_callback(llcache_handle *llcache,
|
|||||||
msg_data.explicit_status_text = NULL;
|
msg_data.explicit_status_text = NULL;
|
||||||
content_broadcast(c, CONTENT_MSG_STATUS, msg_data);
|
content_broadcast(c, CONTENT_MSG_STATUS, msg_data);
|
||||||
break;
|
break;
|
||||||
|
case LLCACHE_EVENT_REDIRECT:
|
||||||
|
msg_data.redirect.from = event->data.redirect.from;
|
||||||
|
msg_data.redirect.to = event->data.redirect.to;
|
||||||
|
content_broadcast(c, CONTENT_MSG_REDIRECT, msg_data);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
|
@ -69,6 +69,7 @@ typedef enum {
|
|||||||
CONTENT_MSG_DONE, /**< finished */
|
CONTENT_MSG_DONE, /**< finished */
|
||||||
CONTENT_MSG_ERROR, /**< error occurred */
|
CONTENT_MSG_ERROR, /**< error occurred */
|
||||||
CONTENT_MSG_ERRORCODE, /**< error occurred return nserror */
|
CONTENT_MSG_ERRORCODE, /**< error occurred return nserror */
|
||||||
|
CONTENT_MSG_REDIRECT, /**< fetch url redirect occured */
|
||||||
CONTENT_MSG_STATUS, /**< new status string */
|
CONTENT_MSG_STATUS, /**< new status string */
|
||||||
CONTENT_MSG_REFORMAT, /**< content_reformat done */
|
CONTENT_MSG_REFORMAT, /**< content_reformat done */
|
||||||
CONTENT_MSG_REDRAW, /**< needs redraw (eg. new animation frame) */
|
CONTENT_MSG_REDRAW, /**< needs redraw (eg. new animation frame) */
|
||||||
@ -103,6 +104,11 @@ union content_msg_data {
|
|||||||
const char *error;
|
const char *error;
|
||||||
/** CONTENT_MSG_ERRORCODE - Error code */
|
/** CONTENT_MSG_ERRORCODE - Error code */
|
||||||
nserror errorcode;
|
nserror errorcode;
|
||||||
|
/** CONTENT_MSG_REDIRECT - Redirect info */
|
||||||
|
struct {
|
||||||
|
nsurl *from; /**< Redirect origin */
|
||||||
|
nsurl *to; /**< Redirect target */
|
||||||
|
} redirect; /**< Fetch URL redirect occured */
|
||||||
/** CONTENT_MSG_REDRAW - Area of content which needs redrawing */
|
/** CONTENT_MSG_REDRAW - Area of content which needs redrawing */
|
||||||
struct {
|
struct {
|
||||||
int x, y, width, height;
|
int x, y, width, height;
|
||||||
|
@ -593,6 +593,17 @@ nserror hlcache_llcache_callback(llcache_handle *handle,
|
|||||||
break;
|
break;
|
||||||
case LLCACHE_EVENT_PROGRESS:
|
case LLCACHE_EVENT_PROGRESS:
|
||||||
break;
|
break;
|
||||||
|
case LLCACHE_EVENT_REDIRECT:
|
||||||
|
if (ctx->handle->cb != NULL) {
|
||||||
|
hlcache_event hlevent;
|
||||||
|
|
||||||
|
hlevent.type = CONTENT_MSG_REDIRECT;
|
||||||
|
hlevent.data.redirect.from = event->data.redirect.from;
|
||||||
|
hlevent.data.redirect.to = event->data.redirect.to;
|
||||||
|
|
||||||
|
ctx->handle->cb(ctx->handle, &hlevent, ctx->handle->pw);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NSERROR_OK;
|
return NSERROR_OK;
|
||||||
|
@ -1224,6 +1224,7 @@ static nserror llcache_fetch_redirect(llcache_object *object, const char *target
|
|||||||
bool match;
|
bool match;
|
||||||
/* Extract HTTP response code from the fetch object */
|
/* Extract HTTP response code from the fetch object */
|
||||||
long http_code = fetch_http_code(object->fetch.fetch);
|
long http_code = fetch_http_code(object->fetch.fetch);
|
||||||
|
llcache_event event;
|
||||||
|
|
||||||
/* Abort fetch for this object */
|
/* Abort fetch for this object */
|
||||||
fetch_abort(object->fetch.fetch);
|
fetch_abort(object->fetch.fetch);
|
||||||
@ -1238,8 +1239,6 @@ static nserror llcache_fetch_redirect(llcache_object *object, const char *target
|
|||||||
/* Forcibly stop redirecting if we've followed too many redirects */
|
/* Forcibly stop redirecting if we've followed too many redirects */
|
||||||
#define REDIRECT_LIMIT 10
|
#define REDIRECT_LIMIT 10
|
||||||
if (object->fetch.redirect_count > REDIRECT_LIMIT) {
|
if (object->fetch.redirect_count > REDIRECT_LIMIT) {
|
||||||
llcache_event event;
|
|
||||||
|
|
||||||
LOG(("Too many nested redirects"));
|
LOG(("Too many nested redirects"));
|
||||||
|
|
||||||
event.type = LLCACHE_EVENT_ERROR;
|
event.type = LLCACHE_EVENT_ERROR;
|
||||||
@ -1254,6 +1253,18 @@ static nserror llcache_fetch_redirect(llcache_object *object, const char *target
|
|||||||
if (error != NSERROR_OK)
|
if (error != NSERROR_OK)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
|
/* Inform users of redirect */
|
||||||
|
event.type = LLCACHE_EVENT_REDIRECT;
|
||||||
|
event.data.redirect.from = object->url;
|
||||||
|
event.data.redirect.to = url;
|
||||||
|
|
||||||
|
error = llcache_send_event_to_users(object, &event);
|
||||||
|
|
||||||
|
if (error != NSERROR_OK) {
|
||||||
|
nsurl_unref(url);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
/* Reject attempts to redirect from unvalidated to validated schemes
|
/* Reject attempts to redirect from unvalidated to validated schemes
|
||||||
* A "validated" scheme is one over which we have some guarantee that
|
* A "validated" scheme is one over which we have some guarantee that
|
||||||
* the source is trustworthy. */
|
* the source is trustworthy. */
|
||||||
|
@ -56,6 +56,8 @@ typedef enum {
|
|||||||
|
|
||||||
LLCACHE_EVENT_ERROR, /**< An error occurred during fetch */
|
LLCACHE_EVENT_ERROR, /**< An error occurred during fetch */
|
||||||
LLCACHE_EVENT_PROGRESS, /**< Fetch progress update */
|
LLCACHE_EVENT_PROGRESS, /**< Fetch progress update */
|
||||||
|
|
||||||
|
LLCACHE_EVENT_REDIRECT /**< Fetch URL redirect occured */
|
||||||
} llcache_event_type;
|
} llcache_event_type;
|
||||||
|
|
||||||
/** Low-level cache events */
|
/** Low-level cache events */
|
||||||
@ -67,6 +69,10 @@ typedef struct {
|
|||||||
size_t len; /**< Length of buffer, in bytes */
|
size_t len; /**< Length of buffer, in bytes */
|
||||||
} data; /**< Received data */
|
} data; /**< Received data */
|
||||||
const char *msg; /**< Error or progress message */
|
const char *msg; /**< Error or progress message */
|
||||||
|
struct {
|
||||||
|
nsurl *from; /**< Redirect origin */
|
||||||
|
nsurl *to; /**< Redirect target */
|
||||||
|
} redirect; /**< Fetch URL redirect occured */
|
||||||
} data; /**< Event data */
|
} data; /**< Event data */
|
||||||
} llcache_event;
|
} llcache_event;
|
||||||
|
|
||||||
|
@ -1355,6 +1355,11 @@ nserror browser_window_callback(hlcache_handle *c,
|
|||||||
browser_window_stop_throbber(bw);
|
browser_window_stop_throbber(bw);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case CONTENT_MSG_REDIRECT:
|
||||||
|
if (urldb_add_url(event->data.redirect.from))
|
||||||
|
urldb_update_url_visit_data(event->data.redirect.from);
|
||||||
|
break;
|
||||||
|
|
||||||
case CONTENT_MSG_STATUS:
|
case CONTENT_MSG_STATUS:
|
||||||
if (event->data.explicit_status_text == NULL) {
|
if (event->data.explicit_status_text == NULL) {
|
||||||
/* Object content's status text updated */
|
/* Object content's status text updated */
|
||||||
|
@ -238,6 +238,9 @@ static nserror download_callback(llcache_handle *handle,
|
|||||||
|
|
||||||
case LLCACHE_EVENT_PROGRESS:
|
case LLCACHE_EVENT_PROGRESS:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case LLCACHE_EVENT_REDIRECT:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
|
@ -103,6 +103,9 @@ html_convert_css_callback(hlcache_handle *css,
|
|||||||
case CONTENT_MSG_READY:
|
case CONTENT_MSG_READY:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case CONTENT_MSG_REDIRECT:
|
||||||
|
break;
|
||||||
|
|
||||||
case CONTENT_MSG_DONE:
|
case CONTENT_MSG_DONE:
|
||||||
LOG(("done stylesheet slot %d '%s'", i,
|
LOG(("done stylesheet slot %d '%s'", i,
|
||||||
nsurl_access(hlcache_handle_get_url(css))));
|
nsurl_access(hlcache_handle_get_url(css))));
|
||||||
|
@ -203,6 +203,7 @@ html_object_callback(hlcache_handle *object,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CONTENT_MSG_REFORMAT:
|
case CONTENT_MSG_REFORMAT:
|
||||||
|
case CONTENT_MSG_REDIRECT:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CONTENT_MSG_REDRAW:
|
case CONTENT_MSG_REDRAW:
|
||||||
|
Loading…
Reference in New Issue
Block a user