diff options
author | Michael Drake <tlsa@netsurf-browser.org> | 2013-05-27 14:51:00 +0100 |
---|---|---|
committer | Michael Drake <tlsa@netsurf-browser.org> | 2013-05-27 14:51:00 +0100 |
commit | ba9769bc8c22c49fe1be6536d4684661ea2e079b (patch) | |
tree | c7a3355fb2d84bb21608dc85d12e8de4662eb787 /content | |
parent | 8dc7ec2cb48d74a6fd808f6989ec08771f4bb98f (diff) | |
download | netsurf-ba9769bc8c22c49fe1be6536d4684661ea2e079b.tar.gz netsurf-ba9769bc8c22c49fe1be6536d4684661ea2e079b.tar.bz2 |
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.
Diffstat (limited to 'content')
-rw-r--r-- | content/content.c | 5 | ||||
-rw-r--r-- | content/content.h | 6 | ||||
-rw-r--r-- | content/hlcache.c | 11 | ||||
-rw-r--r-- | content/llcache.c | 15 | ||||
-rw-r--r-- | content/llcache.h | 6 |
5 files changed, 41 insertions, 2 deletions
diff --git a/content/content.c b/content/content.c index 9bf4312ef..1825bdf10 100644 --- a/content/content.c +++ b/content/content.c @@ -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; diff --git a/content/content.h b/content/content.h index 3e5588815..467fa6055 100644 --- a/content/content.h +++ b/content/content.h @@ -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; diff --git a/content/hlcache.c b/content/hlcache.c index e99f238ad..6c84d1671 100644 --- a/content/hlcache.c +++ b/content/hlcache.c @@ -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; diff --git a/content/llcache.c b/content/llcache.c index 938f1e8f6..f2e519f49 100644 --- a/content/llcache.c +++ b/content/llcache.c @@ -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. */ diff --git a/content/llcache.h b/content/llcache.h index b596310e9..3d8232cae 100644 --- a/content/llcache.h +++ b/content/llcache.h @@ -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; |