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:
Michael Drake 2013-05-27 14:51:00 +01:00
parent 8dc7ec2cb4
commit ba9769bc8c
9 changed files with 53 additions and 2 deletions

View File

@ -188,6 +188,11 @@ nserror content_llcache_callback(llcache_handle *llcache,
msg_data.explicit_status_text = NULL;
content_broadcast(c, CONTENT_MSG_STATUS, msg_data);
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;

View File

@ -69,6 +69,7 @@ typedef enum {
CONTENT_MSG_DONE, /**< finished */
CONTENT_MSG_ERROR, /**< error occurred */
CONTENT_MSG_ERRORCODE, /**< error occurred return nserror */
CONTENT_MSG_REDIRECT, /**< fetch url redirect occured */
CONTENT_MSG_STATUS, /**< new status string */
CONTENT_MSG_REFORMAT, /**< content_reformat done */
CONTENT_MSG_REDRAW, /**< needs redraw (eg. new animation frame) */
@ -103,6 +104,11 @@ union content_msg_data {
const char *error;
/** CONTENT_MSG_ERRORCODE - Error code */
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 */
struct {
int x, y, width, height;

View File

@ -593,6 +593,17 @@ nserror hlcache_llcache_callback(llcache_handle *handle,
break;
case LLCACHE_EVENT_PROGRESS:
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;

View File

@ -1224,6 +1224,7 @@ static nserror llcache_fetch_redirect(llcache_object *object, const char *target
bool match;
/* Extract HTTP response code from the fetch object */
long http_code = fetch_http_code(object->fetch.fetch);
llcache_event event;
/* Abort fetch for this object */
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 */
#define REDIRECT_LIMIT 10
if (object->fetch.redirect_count > REDIRECT_LIMIT) {
llcache_event event;
LOG(("Too many nested redirects"));
event.type = LLCACHE_EVENT_ERROR;
@ -1254,6 +1253,18 @@ static nserror llcache_fetch_redirect(llcache_object *object, const char *target
if (error != NSERROR_OK)
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
* A "validated" scheme is one over which we have some guarantee that
* the source is trustworthy. */

View File

@ -56,6 +56,8 @@ typedef enum {
LLCACHE_EVENT_ERROR, /**< An error occurred during fetch */
LLCACHE_EVENT_PROGRESS, /**< Fetch progress update */
LLCACHE_EVENT_REDIRECT /**< Fetch URL redirect occured */
} llcache_event_type;
/** Low-level cache events */
@ -67,6 +69,10 @@ typedef struct {
size_t len; /**< Length of buffer, in bytes */
} data; /**< Received data */
const char *msg; /**< Error or progress message */
struct {
nsurl *from; /**< Redirect origin */
nsurl *to; /**< Redirect target */
} redirect; /**< Fetch URL redirect occured */
} data; /**< Event data */
} llcache_event;

View File

@ -1355,6 +1355,11 @@ nserror browser_window_callback(hlcache_handle *c,
browser_window_stop_throbber(bw);
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:
if (event->data.explicit_status_text == NULL) {
/* Object content's status text updated */

View File

@ -238,6 +238,9 @@ static nserror download_callback(llcache_handle *handle,
case LLCACHE_EVENT_PROGRESS:
break;
case LLCACHE_EVENT_REDIRECT:
break;
}
return error;

View File

@ -103,6 +103,9 @@ html_convert_css_callback(hlcache_handle *css,
case CONTENT_MSG_READY:
break;
case CONTENT_MSG_REDIRECT:
break;
case CONTENT_MSG_DONE:
LOG(("done stylesheet slot %d '%s'", i,
nsurl_access(hlcache_handle_get_url(css))));

View File

@ -203,6 +203,7 @@ html_object_callback(hlcache_handle *object,
break;
case CONTENT_MSG_REFORMAT:
case CONTENT_MSG_REDIRECT:
break;
case CONTENT_MSG_REDRAW: