From 5feb7018c5228a22d370d070c1f7c3dad2c71e25 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Fri, 10 Jul 2009 00:26:37 +0000 Subject: Replace parent_url with a pointer to the parent content. svn path=/trunk/netsurf/; revision=8428 --- content/content.c | 5 +++-- content/fetch.c | 28 +++++++++++--------------- content/fetch.h | 11 +++++----- content/fetchcache.c | 57 +++++++++------------------------------------------- content/fetchcache.h | 2 +- css/css.c | 2 +- desktop/browser.c | 25 ++++++++++++----------- desktop/browser.h | 3 ++- desktop/frames.c | 17 ++++++++-------- render/html.c | 10 ++++----- 10 files changed, 62 insertions(+), 98 deletions(-) diff --git a/content/content.c b/content/content.c index 72ed2f292..bda652fad 100644 --- a/content/content.c +++ b/content/content.c @@ -596,6 +596,8 @@ bool content_set_type(struct content *c, content_type type, * a content per user */ const char *referer = c->fetch ? fetch_get_referer(c->fetch) : NULL; + struct content *parent = + c->fetch ? fetch_get_parent(c->fetch) : NULL; while (c->user_list->next->next) { clone = content_create(c->url); @@ -630,8 +632,7 @@ bool content_set_type(struct content *c, content_type type, fetchcache_go(clone, referer, callback, p1, p2, clone->width, clone->height, - 0, 0, false, - referer ? referer : c->url); + 0, 0, false, parent); } } diff --git a/content/fetch.c b/content/fetch.c index 31c1fd3cd..f9414172b 100644 --- a/content/fetch.c +++ b/content/fetch.c @@ -77,7 +77,7 @@ struct fetch { char *referer; /**< Referer URL. */ bool send_referer; /**< Valid to send the referer */ bool verifiable; /**< Transaction is verifiable */ - char *parent_fetch_url; /**< URL of parent fetch */ + struct content *parent; /**< Parent content, or NULL */ void *p; /**< Private data for callback. */ char *host; /**< Host part of URL. */ long http_code; /**< HTTP response code, or 0. */ @@ -215,7 +215,7 @@ struct fetch * fetch_start(const char *url, const char *referer, fetch_callback callback, void *p, bool only_2xx, const char *post_urlenc, struct form_successful_control *post_multipart, - bool verifiable, const char *parent_url, + bool verifiable, struct content *parent, char *headers[]) { char *host; @@ -263,7 +263,7 @@ struct fetch * fetch_start(const char *url, const char *referer, fetch->callback = callback; fetch->url = strdup(url); fetch->verifiable = verifiable; - fetch->parent_fetch_url = parent_url ? strdup(parent_url) : NULL; + fetch->parent = parent; fetch->p = p; fetch->host = host; fetch->http_code = 0; @@ -299,8 +299,7 @@ struct fetch * fetch_start(const char *url, const char *referer, } } - if (fetch->url == NULL || - (parent_url && fetch->parent_fetch_url == NULL)) + if (fetch->url == NULL) goto failed; /* Pick the scheme ops */ @@ -340,7 +339,6 @@ failed: free(host); free(ref_scheme); free(scheme); - free(fetch->parent_fetch_url); free(fetch->url); free(fetch->referer); free(fetch); @@ -478,7 +476,6 @@ void fetch_free(struct fetch *f) #endif f->ops->free_fetch(f->fetcher_handle); fetch_unref_fetcher(f->ops); - free(f->parent_fetch_url); free(f->url); free(f->host); if (f->referer) @@ -578,14 +575,13 @@ const char *fetch_get_referer(struct fetch *fetch) * Get the parent URL for this fetch * * \param fetch fetch to retrieve parent url from - * \return Pointer to parent url, or NULL if none. + * \return Pointer to parent content, or NULL if none. */ -const char *fetch_get_parent_url(struct fetch *fetch) +struct content *fetch_get_parent(struct fetch *fetch) { assert(fetch); - /* If the fetch is verifiable, then its own URL suffices */ - return fetch->verifiable ? fetch->url : fetch->parent_fetch_url; + return fetch->parent; } /** @@ -660,16 +656,16 @@ fetch_set_cookie(struct fetch *fetch, const char *data) { assert(fetch && data); - /* If the fetch is unverifiable and there's no parent fetch - * url, err on the side of caution and do not set the cookie */ + /* If the fetch is unverifiable and there's no parent content, + * err on the side of caution and do not set the cookie */ - if (fetch->verifiable || fetch->parent_fetch_url) { + if (fetch->verifiable || fetch->parent) { /* If the transaction's verifiable, we don't require * that the request uri and the parent domain match, * so don't pass in the parent in this case. */ urldb_set_cookie(data, fetch->url, - fetch->verifiable ? 0 - : fetch->parent_fetch_url); + fetch->verifiable ? NULL + : fetch->parent->url); } } diff --git a/content/fetch.h b/content/fetch.h index 42b6323c5..3206acc39 100644 --- a/content/fetch.h +++ b/content/fetch.h @@ -63,10 +63,11 @@ typedef void (*fetch_callback)(fetch_msg msg, void *p, const void *data, void fetch_init(void); struct fetch * fetch_start(const char *url, const char *referer, - fetch_callback callback, - void *p, bool only_2xx, const char *post_urlenc, - struct form_successful_control *post_multipart, - bool verifiable, const char *parent_url, char *headers[]); + fetch_callback callback, + void *p, bool only_2xx, const char *post_urlenc, + struct form_successful_control *post_multipart, + bool verifiable, struct content *parent, + char *headers[]); void fetch_abort(struct fetch *f); void fetch_poll(void); void fetch_quit(void); @@ -78,7 +79,7 @@ void fetch_change_callback(struct fetch *fetch, void *p); long fetch_http_code(struct fetch *fetch); const char *fetch_get_referer(struct fetch *fetch); -const char *fetch_get_parent_url(struct fetch *fetch); +struct content *fetch_get_parent(struct fetch *fetch); bool fetch_get_verifiable(struct fetch *fetch); /* API for fetchers themselves */ diff --git a/content/fetchcache.c b/content/fetchcache.c index a606be6d5..cb5cc9132 100644 --- a/content/fetchcache.c +++ b/content/fetchcache.c @@ -228,7 +228,7 @@ struct content * fetchcache(const char *url, * \param post_urlenc url encoded post data, or 0 if none * \param post_multipart multipart post data, or 0 if none * \param verifiable this transaction is verifiable - * \param parent_url URL of fetch which spawned this one, or 0 if none + * \param parent Content which spawned this one, or NULL if none * * Errors will be sent back through the callback. */ @@ -240,7 +240,7 @@ void fetchcache_go(struct content *content, const char *referer, int width, int height, char *post_urlenc, struct form_successful_control *post_multipart, - bool verifiable, const char *parent_url) + bool verifiable, struct content *parent) { char error_message[500]; union content_msg_data msg_data; @@ -348,7 +348,7 @@ void fetchcache_go(struct content *content, const char *referer, fetchcache_callback, content, content->no_error_pages, post_urlenc, post_multipart, verifiable, - parent_url, headers); + parent, headers); for (i = 0; headers[i]; i++) free(headers[i]); free(headers); @@ -884,9 +884,8 @@ void fetchcache_notmodified(struct content *c, const void *data) /* No cached content, so unconditionally refetch */ struct content_user *u; const char *ref = fetch_get_referer(c->fetch); - const char *parent = fetch_get_parent_url(c->fetch); + struct content *parent = fetch_get_parent(c->fetch); char *referer = NULL; - char *parent_url = NULL; if (ref) { referer = strdup(ref); @@ -900,19 +899,6 @@ void fetchcache_notmodified(struct content *c, const void *data) } } - if (parent) { - parent_url = strdup(parent); - if (!parent_url) { - c->type = CONTENT_UNKNOWN; - c->status = CONTENT_STATUS_ERROR; - msg_data.error = messages_get("NoMemory"); - content_broadcast(c, CONTENT_MSG_ERROR, - msg_data); - free(referer); - return; - } - } - fetch_abort(c->fetch); c->fetch = 0; @@ -923,10 +909,9 @@ void fetchcache_notmodified(struct content *c, const void *data) for (u = c->user_list->next; u; u = u->next) { fetchcache_go(c, referer, u->callback, u->p1, u->p2, c->width, c->height, 0, 0, - false, parent_url); + false, parent); } - free(parent_url); free(referer); } } @@ -939,11 +924,11 @@ void fetchcache_redirect(struct content *c, const void *data, unsigned long size) { char *url, *url1; - char *referer, *parent_url; + char *referer; char *scheme; long http_code; const char *ref; - const char *parent; + struct content *parent; bool can_fetch; bool parent_was_verifiable; union content_msg_data msg_data; @@ -956,7 +941,7 @@ void fetchcache_redirect(struct content *c, const void *data, /* Extract fetch details */ http_code = fetch_http_code(c->fetch); ref = fetch_get_referer(c->fetch); - parent = fetch_get_parent_url(c->fetch); + parent = fetch_get_parent(c->fetch); parent_was_verifiable = fetch_get_verifiable(c->fetch); /* Ensure a redirect happened */ @@ -964,10 +949,8 @@ void fetchcache_redirect(struct content *c, const void *data, /* 304 is handled by fetch_notmodified() */ assert(http_code != 304); - /* Clone referer and parent url - * originals are destroyed in fetch_abort() */ + /* Clone referer -- original is destroyed in fetch_abort() */ referer = ref ? strdup(ref) : NULL; - parent_url = parent ? strdup(parent) : NULL; /* set the status to ERROR so that this content is * destroyed in content_clean() */ @@ -986,18 +969,6 @@ void fetchcache_redirect(struct content *c, const void *data, return; } - /* Ensure parent url cloning succeeded - * _must_ be after content invalidation */ - if (parent && !parent_url) { - LOG(("Failed cloning parent url")); - - msg_data.error = messages_get("BadRedirect"); - content_broadcast(c, CONTENT_MSG_ERROR, msg_data); - - free(referer); - return; - } - /** \todo 300, 305, 307 * More specifically: * + 300 needs to serve up the fetch body to the user @@ -1018,7 +989,6 @@ void fetchcache_redirect(struct content *c, const void *data, msg_data.error = messages_get("BadRedirect"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); - free(parent_url); free(referer); return; } @@ -1031,7 +1001,6 @@ void fetchcache_redirect(struct content *c, const void *data, msg_data.error = messages_get("BadRedirect"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); - free(parent_url); free(referer); return; } @@ -1045,7 +1014,6 @@ void fetchcache_redirect(struct content *c, const void *data, msg_data.error = messages_get("BadRedirect"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); - free(parent_url); free(referer); return; } @@ -1058,7 +1026,6 @@ void fetchcache_redirect(struct content *c, const void *data, content_broadcast(c, CONTENT_MSG_ERROR, msg_data); free(url1); - free(parent_url); free(referer); return; } @@ -1073,7 +1040,6 @@ void fetchcache_redirect(struct content *c, const void *data, content_broadcast(c, CONTENT_MSG_ERROR, msg_data); free(url); - free(parent_url); free(referer); return; } @@ -1084,7 +1050,6 @@ void fetchcache_redirect(struct content *c, const void *data, free(scheme); free(url); - free(parent_url); free(referer); return; } @@ -1143,7 +1108,6 @@ void fetchcache_redirect(struct content *c, const void *data, msg_data); free(url); - free(parent_url); free(referer); return; } @@ -1160,13 +1124,12 @@ void fetchcache_redirect(struct content *c, const void *data, /* Start fetching the replacement content */ fetchcache_go(replacement, referer, callback, p1, p2, c->width, c->height, NULL, NULL, - parent_was_verifiable, parent_url); + parent_was_verifiable, parent); } } /* Clean up */ free(url); - free(parent_url); free(referer); } diff --git a/content/fetchcache.h b/content/fetchcache.h index 93e40b00d..24ed564ad 100644 --- a/content/fetchcache.h +++ b/content/fetchcache.h @@ -50,6 +50,6 @@ void fetchcache_go(struct content *content, const char *referer, int width, int height, char *post_urlenc, struct form_successful_control *post_multipart, - bool verifiable, const char *parent_url); + bool verifiable, struct content *parent); #endif diff --git a/css/css.c b/css/css.c index 133b9ec92..0f652c2e6 100644 --- a/css/css.c +++ b/css/css.c @@ -908,7 +908,7 @@ void css_atimport(struct content *c, struct css_node *node) fetchcache_go(c->data.css.import_content[i], c->url, css_atimport_callback, (intptr_t) c, i, c->width, c->height, - 0, 0, false, c->url); + 0, 0, false, c); } free(url); diff --git a/desktop/browser.c b/desktop/browser.c index 6b03dc900..c28eca12e 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -77,7 +77,7 @@ static void browser_window_go_post(struct browser_window *bw, const char *url, char *post_urlenc, struct form_successful_control *post_multipart, bool add_to_history, const char *referer, bool download, - bool verifiable, const char *parent_url); + bool verifiable, struct content *parent); static void browser_window_callback(content_msg msg, struct content *c, intptr_t p1, intptr_t p2, union content_msg_data data); static void browser_window_refresh(void *p); @@ -213,7 +213,7 @@ void browser_window_go(struct browser_window *bw, const char *url, /* All fetches passing through here are verifiable * (i.e are the result of user action) */ browser_window_go_post(bw, url, 0, 0, history_add, referer, - false, true, referer); + false, true, NULL); } @@ -226,10 +226,10 @@ void browser_window_go(struct browser_window *bw, const char *url, */ void browser_window_download(struct browser_window *bw, const char *url, - const char *referrer) + const char *referer) { - browser_window_go_post(bw, url, 0, 0, false, referrer, - true, true, 0); + browser_window_go_post(bw, url, 0, 0, false, referer, + true, true, NULL); } @@ -244,12 +244,13 @@ void browser_window_download(struct browser_window *bw, const char *url, */ void browser_window_go_unverifiable(struct browser_window *bw, - const char *url, const char *referer, bool history_add) + const char *url, const char *referer, bool history_add, + struct content *parent) { /* All fetches passing through here are unverifiable * (i.e are not the result of user action) */ browser_window_go_post(bw, url, 0, 0, history_add, referer, - false, false, referer); + false, false, parent); } /** @@ -263,8 +264,7 @@ void browser_window_go_unverifiable(struct browser_window *bw, * \param referer the referring uri (copied), or 0 if none * \param download download, rather than render the uri * \param verifiable this transaction is verifiable - * \param parent_url URL of fetch which spawned this one (copied), - * or 0 if none + * \param parent Parent content, or NULL * * Any existing fetches in the window are aborted. * @@ -278,7 +278,7 @@ void browser_window_go_post(struct browser_window *bw, const char *url, char *post_urlenc, struct form_successful_control *post_multipart, bool add_to_history, const char *referer, bool download, - bool verifiable, const char *parent_url) + bool verifiable, struct content *parent) { struct content *c; char *url2; @@ -389,7 +389,7 @@ void browser_window_go_post(struct browser_window *bw, const char *url, bw->download = download; fetchcache_go(c, referer, browser_window_callback, (intptr_t) bw, 0, width, height, - post_urlenc, post_multipart, verifiable, parent_url); + post_urlenc, post_multipart, verifiable, parent); } @@ -702,7 +702,8 @@ void browser_window_refresh(void *p) bw->current_content->url, history_add); } else { browser_window_go_unverifiable(bw, bw->current_content->refresh, - bw->current_content->url, history_add); + bw->current_content->url, history_add, + bw->current_content); } } diff --git a/desktop/browser.h b/desktop/browser.h index 1c88b4f44..65ea1b3c0 100644 --- a/desktop/browser.h +++ b/desktop/browser.h @@ -223,7 +223,8 @@ void browser_window_initialise_common(struct browser_window *bw, void browser_window_go(struct browser_window *bw, const char *url, const char *referrer, bool history_add); void browser_window_go_unverifiable(struct browser_window *bw, - const char *url, const char *referrer, bool history_add); + const char *url, const char *referrer, bool history_add, + struct content *parent); void browser_window_download(struct browser_window *bw, const char *url, const char *referrer); void browser_window_update(struct browser_window *bw, bool scroll_to_top); diff --git a/desktop/frames.c b/desktop/frames.c index d631f0962..acabdc1b9 100644 --- a/desktop/frames.c +++ b/desktop/frames.c @@ -105,7 +105,8 @@ void browser_window_create_iframes(struct browser_window *bw, window = &(bw->iframes[index++]); if (cur->url) browser_window_go_unverifiable(window, cur->url, - bw->current_content->url, false); + bw->current_content->url, false, + bw->current_content); } } @@ -154,7 +155,7 @@ void browser_window_create_frameset(struct browser_window *bw, int row, col, index; struct content_html_frames *frame; struct browser_window *window; - const char *referer; + struct content *parent; assert(bw && frameset); @@ -233,10 +234,8 @@ void browser_window_create_frameset(struct browser_window *bw, window->current_content->type == CONTENT_HTML) break; } - if (window->current_content) - referer = window->current_content->url; - else - referer = NULL; + + parent = window->current_content; /* 4. Launch content */ for (row = 0; row < bw->rows; row++) { @@ -248,8 +247,10 @@ void browser_window_create_frameset(struct browser_window *bw, if (frame->url) { browser_window_go_unverifiable(window, frame->url, - referer, - true); + parent != NULL + ? parent->url : NULL, + true, + parent); } } } diff --git a/render/html.c b/render/html.c index 729a10cee..aff24afe1 100644 --- a/render/html.c +++ b/render/html.c @@ -803,7 +803,7 @@ bool html_find_stylesheets(struct content *c, xmlNode *html) fetchcache_go(c->data.html.stylesheet_content[STYLESHEET_BASE], c->url, html_convert_css_callback, (intptr_t) c, STYLESHEET_BASE, c->width, c->height, - 0, 0, false, 0); + 0, 0, false, c); if (option_block_ads) { c->data.html.stylesheet_content[STYLESHEET_ADBLOCK] = @@ -818,7 +818,7 @@ bool html_find_stylesheets(struct content *c, xmlNode *html) stylesheet_content[STYLESHEET_ADBLOCK], c->url, html_convert_css_callback, (intptr_t) c, STYLESHEET_ADBLOCK, c->width, - c->height, 0, 0, false, 0); + c->height, 0, 0, false, c); } node = html; @@ -927,7 +927,7 @@ bool html_find_stylesheets(struct content *c, xmlNode *html) c->url, html_convert_css_callback, (intptr_t) c, i, c->width, c->height, - 0, 0, false, c->url); + 0, 0, false, c); i++; } else if (strcmp((const char *) node->name, "style") == 0) { @@ -1230,7 +1230,7 @@ bool html_fetch_object(struct content *c, char *url, struct box *box, fetchcache_go(c_fetch, c->url, html_object_callback, (intptr_t) c, i, available_width, available_height, - 0, 0, false, c->url); + 0, 0, false, c); return true; } @@ -1298,7 +1298,7 @@ bool html_replace_object(struct content *c, unsigned int i, char *url, html_object_callback, (intptr_t) c, i, c->data.html.object[i].box->width, c->data.html.object[i].box->height, - post_urlenc, post_multipart, false, c->url); + post_urlenc, post_multipart, false, c); return true; } -- cgit v1.2.3