diff options
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/401login.h | 6 | ||||
-rw-r--r-- | desktop/browser.c | 726 | ||||
-rw-r--r-- | desktop/browser.h | 63 | ||||
-rw-r--r-- | desktop/frames.c | 15 | ||||
-rw-r--r-- | desktop/gui.h | 13 | ||||
-rw-r--r-- | desktop/history_core.c | 28 | ||||
-rw-r--r-- | desktop/history_core.h | 6 | ||||
-rw-r--r-- | desktop/netsurf.c | 81 | ||||
-rw-r--r-- | desktop/netsurf.h | 1 | ||||
-rw-r--r-- | desktop/print.c | 42 | ||||
-rw-r--r-- | desktop/print.h | 8 | ||||
-rw-r--r-- | desktop/save_complete.c | 150 | ||||
-rw-r--r-- | desktop/save_complete.h | 4 | ||||
-rw-r--r-- | desktop/save_pdf/pdf_plotters.c | 42 | ||||
-rw-r--r-- | desktop/save_text.c | 7 | ||||
-rw-r--r-- | desktop/save_text.h | 4 | ||||
-rw-r--r-- | desktop/search.c | 32 | ||||
-rw-r--r-- | desktop/searchweb.c | 58 | ||||
-rw-r--r-- | desktop/searchweb.h | 11 | ||||
-rw-r--r-- | desktop/selection.c | 14 | ||||
-rw-r--r-- | desktop/textinput.c | 7 |
21 files changed, 646 insertions, 672 deletions
diff --git a/desktop/401login.h b/desktop/401login.h index 8a45477fd..8b5a0a778 100644 --- a/desktop/401login.h +++ b/desktop/401login.h @@ -21,10 +21,10 @@ #include "utils/config.h" -#include "content/content.h" -#include "desktop/browser.h" +struct hlcache_handle; +struct browser_window; -void gui_401login_open(struct browser_window *bw, struct content *c, +void gui_401login_open(struct browser_window *bw, struct hlcache_handle *c, const char *realm); #endif diff --git a/desktop/browser.c b/desktop/browser.c index a4c1e2156..115c16c5c 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -38,7 +38,7 @@ #include "curl/curl.h" #include "utils/config.h" #include "content/fetch.h" -#include "content/fetchcache.h" +#include "content/hlcache.h" #include "content/urldb.h" #include "css/css.h" #include "desktop/401login.h" @@ -66,9 +66,6 @@ /** browser window which is being redrawn. Valid only during redraw. */ struct browser_window *current_redraw_browser; -/** fake content for <a> being saved as a link */ -struct content browser_window_href_content; - /** one or more windows require a reformat */ bool browser_reformat_pending; @@ -77,11 +74,11 @@ bool browser_reformat_pending; static void browser_window_go_post(struct browser_window *bw, const char *url, char *post_urlenc, - struct form_successful_control *post_multipart, + struct fetch_multipart_data *post_multipart, bool add_to_history, const char *referer, bool download, - 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); + bool verifiable, hlcache_handle *parent); +static nserror browser_window_callback(hlcache_handle *c, + const hlcache_event *event, void *pw); static void browser_window_refresh(void *p); static bool browser_window_check_throbber(struct browser_window *bw); static void browser_window_convert_to_download(struct browser_window *bw); @@ -92,8 +89,8 @@ static void browser_window_set_status(struct browser_window *bw, const char *text); static void browser_window_set_pointer(struct gui_window *g, gui_pointer_shape shape); -static void download_window_callback(fetch_msg msg, void *p, const void *data, - unsigned long size, fetch_error_code errorcode); +static nserror download_window_callback(llcache_handle *handle, + const llcache_event *event, void *pw); static void browser_window_destroy_children(struct browser_window *bw); static void browser_window_destroy_internal(struct browser_window *bw); static void browser_window_set_scale_internal(struct browser_window *bw, @@ -112,7 +109,7 @@ static void browser_window_mouse_track_html(struct browser_window *bw, browser_mouse_state mouse, int x, int y); static void browser_window_mouse_track_text(struct browser_window *bw, browser_mouse_state mouse, int x, int y); -static void browser_radio_set(struct content *content, +static void browser_radio_set(hlcache_handle *content, struct form_control *radio); static gui_pointer_shape get_pointer_shape(struct browser_window *bw, struct box *box, bool imagemap); @@ -253,7 +250,7 @@ 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, - struct content *parent) + hlcache_handle *parent) { /* All fetches passing through here are unverifiable * (i.e are not the result of user action) */ @@ -284,17 +281,22 @@ void browser_window_go_unverifiable(struct browser_window *bw, void browser_window_go_post(struct browser_window *bw, const char *url, char *post_urlenc, - struct form_successful_control *post_multipart, + struct fetch_multipart_data *post_multipart, bool add_to_history, const char *referer, bool download, - bool verifiable, struct content *parent) + bool verifiable, hlcache_handle *parent) { - struct content *c; + hlcache_handle *c; char *url2; char *fragment; url_func_result res; int depth = 0; struct browser_window *cur; int width, height; + uint32_t fetch_flags = 0; + bool fetch_is_post = (post_urlenc != NULL || post_multipart != NULL); + llcache_post_data post; + hlcache_child_context child; + nserror error; LOG(("bw %p, url %s", bw, url)); assert(bw); @@ -308,16 +310,44 @@ void browser_window_go_post(struct browser_window *bw, const char *url, return; } + /* Set up retrieval parameters */ + if (verifiable) + fetch_flags |= LLCACHE_RETRIEVE_VERIFIABLE; + + if (post_multipart != NULL) { + post.type = LLCACHE_POST_MULTIPART; + post.data.multipart = post_multipart; + } else if (post_urlenc != NULL) { + post.type = LLCACHE_POST_URL_ENCODED; + post.data.urlenc = post_urlenc; + } + + if (parent != NULL) { +//newcache extract charset and quirks from parent content + child.charset = NULL; + child.quirks = false; + } + + /* Normalize the request URL */ res = url_normalize(url, &url2); if (res != URL_FUNC_OK) { LOG(("failed to normalize url %s", url)); return; } - /* check we can actually handle this URL */ - if (!fetch_can_fetch(url2)) { - gui_launch_url(url2); + /* Get download out of the way */ + if (download) { + llcache_handle *l; + + error = llcache_handle_retrieve(url2, + fetch_flags | LLCACHE_RETRIEVE_FORCE_FETCH, + referer, fetch_is_post ? &post : NULL, + download_window_callback, NULL, &l); + if (error != NSERROR_OK) + LOG(("Failed to fetch download: %d", error)); + free(url2); + return; } @@ -336,9 +366,10 @@ void browser_window_go_post(struct browser_window *bw, const char *url, bw->frag_id = fragment; /* Compare new URL with existing one (ignoring fragments) */ - if (bw->current_content && bw->current_content->url) { - res = url_compare(bw->current_content->url, url2, - true, &same_url); + if (bw->current_content != NULL && + content_get_url(bw->current_content) != NULL) { + res = url_compare(content_get_url(bw->current_content), + url2, true, &same_url); if (res == URL_FUNC_NOMEM) { free(url2); warn_user("NoMemory", 0); @@ -351,17 +382,17 @@ void browser_window_go_post(struct browser_window *bw, const char *url, /* if we're simply moving to another ID on the same page, * don't bother to fetch, just update the window. */ - if (same_url && !post_urlenc && !post_multipart && - !strchr(url2, '?')) { + if (same_url && fetch_is_post == false && + strchr(url2, '?') == 0) { free(url2); if (add_to_history) history_add(bw->history, bw->current_content, bw->frag_id); browser_window_update(bw, false); - if (bw->current_content) { + if (bw->current_content != NULL) { browser_window_refresh_url_bar(bw, - bw->current_content->url, - bw->frag_id); + content_get_url(bw->current_content), + bw->frag_id); } return; } @@ -376,28 +407,26 @@ void browser_window_go_post(struct browser_window *bw, const char *url, browser_window_set_status(bw, messages_get("Loading")); bw->history_add = add_to_history; - c = fetchcache(url2, browser_window_callback, (intptr_t) bw, 0, - width, height, false, - post_urlenc, post_multipart, verifiable, download); - free(url2); - if (!c) { + + error = hlcache_handle_retrieve(url2, 0, referer, + fetch_is_post ? &post : NULL, width, height, + browser_window_callback, bw, + parent != NULL ? &child : NULL, &c); + if (error == NSERROR_NO_FETCH_HANDLER) { + gui_launch_url(url2); + free(url2); + return; + } else if (error != NSERROR_OK) { + free(url2); browser_window_set_status(bw, messages_get("NoMemory")); warn_user("NoMemory", 0); return; } + free(url2); + bw->loading_content = c; browser_window_start_throbber(bw); - - if (referer && referer != bw->referer) { - free(bw->referer); - bw->referer = strdup(referer); - } - - bw->download = download; - fetchcache_go(c, referer, browser_window_callback, - (intptr_t) bw, 0, width, height, - post_urlenc, post_multipart, verifiable, parent); } @@ -405,89 +434,95 @@ void browser_window_go_post(struct browser_window *bw, const char *url, * Callback for fetchcache() for browser window fetches. */ -void browser_window_callback(content_msg msg, struct content *c, - intptr_t p1, intptr_t p2, union content_msg_data data) +nserror browser_window_callback(hlcache_handle *c, + const hlcache_event *event, void *pw) { - struct browser_window *bw = (struct browser_window *) p1; + struct browser_window *bw = pw; - switch (msg) { + switch (event->type) { case CONTENT_MSG_LOADING: assert(bw->loading_content == c); - if (c->type == CONTENT_OTHER) + if (content_get_type(c) == CONTENT_OTHER) browser_window_convert_to_download(bw); #ifdef WITH_THEME_INSTALL - else if (c->type == CONTENT_THEME) { + else if (content_get_type(c) == CONTENT_THEME) { theme_install_start(c); - bw->loading_content = 0; - content_remove_user(c, browser_window_callback, - (intptr_t) bw, 0); + bw->loading_content = NULL; +//newcache do we not just pass ownership to the theme installation stuff? + hlcache_handle_release(c); browser_window_stop_throbber(bw); } #endif else { bw->refresh_interval = -1; - browser_window_set_status(bw, c->status_message); + browser_window_set_status(bw, + content_get_status_message(c)); } break; case CONTENT_MSG_READY: assert(bw->loading_content == c); - if (bw->current_content) { - if (bw->current_content->status == - CONTENT_STATUS_READY || - bw->current_content->status == - CONTENT_STATUS_DONE) + if (bw->current_content != NULL) { + content_status status = + content_get_status(bw->current_content); + + if (status == CONTENT_STATUS_READY || + status == CONTENT_STATUS_DONE) content_close(bw->current_content); - content_remove_user(bw->current_content, - browser_window_callback, - (intptr_t) bw, 0); + + hlcache_handle_release(bw->current_content); } + bw->current_content = c; bw->loading_content = NULL; + browser_window_remove_caret(bw); + bw->scroll = NULL; + gui_window_new_content(bw->window); - if (bw->current_content) { - browser_window_refresh_url_bar(bw, - bw->current_content->url, - bw->frag_id); - } + + browser_window_refresh_url_bar(bw, + content_get_url(bw->current_content), + bw->frag_id); + /* new content; set scroll_to_top */ browser_window_update(bw, true); content_open(c, bw, 0, 0, 0, 0); - browser_window_set_status(bw, c->status_message); + browser_window_set_status(bw, content_get_status_message(c)); /* history */ if (bw->history_add && bw->history) { + const char *url = content_get_url(c); + history_add(bw->history, c, bw->frag_id); - if (urldb_add_url(c->url)) { - urldb_set_url_title(c->url, - c->title ? c->title : c->url); - urldb_update_url_visit_data(c->url); - urldb_set_url_content_type(c->url, - c->type); - /* This is safe as we've just - * added the URL */ - global_history_add( - urldb_get_url(c->url)); + if (urldb_add_url(url)) { + urldb_set_url_title(url, content_get_title(c)); + urldb_update_url_visit_data(url); + urldb_set_url_content_type(url, + content_get_type(c)); + /* This is safe as we've just added the URL */ + global_history_add(urldb_get_url(url)); } } /* text selection */ - if (c->type == CONTENT_HTML) + if (content_get_type(c) == CONTENT_HTML) selection_init(bw->sel, - bw->current_content->data.html.layout); - if (c->type == CONTENT_TEXTPLAIN) + html_get_box_tree(bw->current_content)); + if (content_get_type(c) == CONTENT_TEXTPLAIN) selection_init(bw->sel, NULL); /* frames */ - if (c->type == CONTENT_HTML && c->data.html.frameset) - browser_window_create_frameset(bw, - c->data.html.frameset); - if (c->type == CONTENT_HTML && c->data.html.iframe) - browser_window_create_iframes(bw, c->data.html.iframe); + if (content_get_type(c) == CONTENT_HTML && + html_get_frameset(c) != NULL) + browser_window_create_frameset(bw, + html_get_frameset(c)); + if (content_get_type(c) == CONTENT_HTML && + html_get_iframe(c) != NULL) + browser_window_create_iframes(bw, html_get_iframe(c)); break; @@ -495,137 +530,75 @@ void browser_window_callback(content_msg msg, struct content *c, assert(bw->current_content == c); browser_window_update(bw, false); - browser_window_set_status(bw, c->status_message); + browser_window_set_status(bw, content_get_status_message(c)); browser_window_stop_throbber(bw); browser_window_set_icon(bw); + history_update(bw->history, c); hotlist_visited(c); - free(bw->referer); - bw->referer = 0; + if (bw->refresh_interval != -1) schedule(bw->refresh_interval, browser_window_refresh, bw); break; case CONTENT_MSG_ERROR: - browser_window_set_status(bw, data.error); + browser_window_set_status(bw, event->data.error); /* Only warn the user about errors in top-level windows */ if (bw->browser_window_type == BROWSER_WINDOW_NORMAL) - warn_user(data.error, 0); + warn_user(event->data.error, 0); if (c == bw->loading_content) - bw->loading_content = 0; + bw->loading_content = NULL; else if (c == bw->current_content) { - bw->current_content = 0; + bw->current_content = NULL; browser_window_remove_caret(bw); bw->scroll = NULL; selection_init(bw->sel, NULL); } + + hlcache_handle_release(c); + browser_window_stop_throbber(bw); - free(bw->referer); - bw->referer = 0; break; case CONTENT_MSG_STATUS: - browser_window_set_status(bw, c->status_message); + browser_window_set_status(bw, content_get_status_message(c)); break; case CONTENT_MSG_REFORMAT: if (c == bw->current_content && - c->type == CONTENT_HTML) { + content_get_type(c) == CONTENT_HTML) { /* reposition frames */ - if (c->data.html.frameset) + if (html_get_frameset(c) != NULL) browser_window_recalculate_frameset(bw); /* reflow iframe positions */ - if (c->data.html.iframe) + if (html_get_iframe(c) != NULL) browser_window_recalculate_iframes(bw); /* box tree may have changed, need to relabel */ - selection_reinit(bw->sel, c->data.html.layout); + selection_reinit(bw->sel, html_get_box_tree(c)); } + if (bw->move_callback) bw->move_callback(bw, bw->caret_p); + browser_window_update(bw, false); break; case CONTENT_MSG_REDRAW: - gui_window_update_box(bw->window, &data); - break; - - case CONTENT_MSG_NEWPTR: - bw->loading_content = c; - if (data.new_url) { - /* Replacement URL too, so check for new fragment */ - char *fragment; - url_func_result res; - - /* Remove any existing fragment */ - free(bw->frag_id); - bw->frag_id = NULL; - - /* Extract new one, if any */ - res = url_fragment(data.new_url, &fragment); - if (res == URL_FUNC_OK) { - /* Save for later use */ - bw->frag_id = fragment; - } - /* Ignore memory exhaustion here -- it'll simply result - * in the window being scrolled to the top rather than - * to the fragment. That's acceptable, given that it's - * likely that more important things will complain - * about memory shortage. */ - } - break; - - case CONTENT_MSG_LAUNCH: - assert(data.launch_url != NULL); - - bw->loading_content = NULL; - - gui_launch_url(data.launch_url); - - browser_window_stop_throbber(bw); - free(bw->referer); - bw->referer = 0; - break; - - case CONTENT_MSG_AUTH: - gui_401login_open(bw, c, data.auth_realm); - if (c == bw->loading_content) - bw->loading_content = 0; - else if (c == bw->current_content) { - bw->current_content = 0; - browser_window_remove_caret(bw); - bw->scroll = NULL; - selection_init(bw->sel, NULL); - } - browser_window_stop_throbber(bw); - free(bw->referer); - bw->referer = 0; - break; - - case CONTENT_MSG_SSL: - gui_cert_verify(bw, c, data.ssl.certs, data.ssl.num); - if (c == bw->loading_content) - bw->loading_content = 0; - else if (c == bw->current_content) { - bw->current_content = 0; - browser_window_remove_caret(bw); - bw->scroll = NULL; - selection_init(bw->sel, NULL); - } - browser_window_stop_throbber(bw); - free(bw->referer); - bw->referer = 0; + gui_window_update_box(bw->window, &event->data); break; case CONTENT_MSG_REFRESH: - bw->refresh_interval = data.delay * 100; + bw->refresh_interval = event->data.delay * 100; break; default: assert(0); } + + return NSERROR_OK; } @@ -636,34 +609,26 @@ void browser_window_callback(content_msg msg, struct content *c, void browser_window_convert_to_download(struct browser_window *bw) { struct gui_download_window *download_window; - struct content *c = bw->loading_content; - struct fetch *fetch; + hlcache_handle *c = bw->loading_content; + llcache_handle *stream; assert(c); - fetch = c->fetch; + stream = content_convert_to_download(c); - if (fetch) { - /* create download window */ - download_window = gui_download_window_create(c->url, - c->mime_type, fetch, c->total_size, - bw->window); + /** \todo Sort parameters out here */ + download_window = gui_download_window_create( + llcache_handle_get_url(stream), + llcache_handle_get_header(stream, "Content-Type"), + NULL, 0, NULL); - if (download_window) { - /* extract fetch from content */ - c->fetch = 0; - c->fresh = false; - fetch_change_callback(fetch, download_window_callback, - download_window); - } - } else { - /* must already be a download window for this fetch */ - /** \todo open it at top of stack */ - } + llcache_handle_change_callback(stream, + download_window_callback, download_window); /* remove content from browser window */ - bw->loading_content = 0; - content_remove_user(c, browser_window_callback, (intptr_t) bw, 0); + hlcache_handle_release(bw->loading_content); + bw->loading_content = NULL; + browser_window_stop_throbber(bw); } @@ -678,23 +643,26 @@ void browser_window_refresh(void *p) { struct browser_window *bw = p; bool history_add = true; + const char *url; + const char *refresh; - assert(bw->current_content && - (bw->current_content->status == CONTENT_STATUS_READY || - bw->current_content->status == CONTENT_STATUS_DONE)); + assert(bw->current_content != NULL && + (content_get_status(bw->current_content) == + CONTENT_STATUS_READY || + content_get_status(bw->current_content) == + CONTENT_STATUS_DONE)); /* Ignore if the refresh URL has gone * (may happen if a fetch error occurred) */ - if (!bw->current_content->refresh) + refresh = content_get_refresh_url(bw->current_content); + if (refresh == NULL) return; /* mark this content as invalid so it gets flushed from the cache */ - bw->current_content->fresh = false; + content_invalidate_reuse_data(bw->current_content); - if ((bw->current_content->url) && - (bw->current_content->refresh) && - (!strcmp(bw->current_content->url, - bw->current_content->refresh))) + url = content_get_url(bw->current_content); + if (url != NULL && strcmp(url, refresh) == 0) history_add = false; /* Treat an (almost) immediate refresh in a top-level browser window as @@ -705,11 +673,9 @@ void browser_window_refresh(void *p) * all. */ if (bw->refresh_interval <= 100 && bw->parent == NULL) { - browser_window_go(bw, bw->current_content->refresh, - bw->current_content->url, history_add); + browser_window_go(bw, refresh, url, history_add); } else { - browser_window_go_unverifiable(bw, bw->current_content->refresh, - bw->current_content->url, history_add, + browser_window_go_unverifiable(bw, refresh, url, history_add, bw->current_content); } } @@ -727,6 +693,7 @@ void browser_window_start_throbber(struct browser_window *bw) while (bw->parent) bw = bw->parent; + gui_window_start_throbber(bw->window); } @@ -780,9 +747,11 @@ void browser_window_set_icon(struct browser_window *bw) { while (bw->parent) bw = bw->parent; - if ((bw->current_content != NULL) && (bw->current_content->type == CONTENT_HTML)) + + if (bw->current_content != NULL && + content_get_type(bw->current_content) == CONTENT_HTML) gui_window_set_icon(bw->window, - bw->current_content->data.html.favicon); + html_get_favicon(bw->current_content)); else gui_window_set_icon(bw->window, NULL); } @@ -794,19 +763,16 @@ void browser_window_set_icon(struct browser_window *bw) * \param scroll_to_top move view to top of page */ -void browser_window_update(struct browser_window *bw, - bool scroll_to_top) +void browser_window_update(struct browser_window *bw, bool scroll_to_top) { struct box *pos; int x, y; - if (!bw->current_content) + if (bw->current_content == NULL) return; - if (bw->current_content->title != NULL) { - gui_window_set_title(bw->window, bw->current_content->title); - } else - gui_window_set_title(bw->window, bw->current_content->url); + gui_window_set_title(bw->window, + content_get_title(bw->current_content)); gui_window_update_extent(bw->window); @@ -815,9 +781,11 @@ void browser_window_update(struct browser_window *bw, /** \todo don't do this if the user has scrolled */ /* if frag_id exists, then try to scroll to it */ - if (bw->frag_id && bw->current_content->type == CONTENT_HTML) { - if ((pos = box_find_by_id(bw->current_content->data.html.layout, - bw->frag_id)) != 0) { + if (bw->frag_id && + content_get_type(bw->current_content) == CONTENT_HTML) { + struct box *layout = html_get_box_tree(bw->current_content); + + if ((pos = box_find_by_id(layout, bw->frag_id)) != 0) { box_coords(pos, &x, &y); gui_window_set_scroll(bw->window, x, y); } @@ -837,17 +805,17 @@ void browser_window_stop(struct browser_window *bw) { int children, index; - if (bw->loading_content) { - content_remove_user(bw->loading_content, - browser_window_callback, (intptr_t) bw, 0); - bw->loading_content = 0; + if (bw->loading_content != NULL) { + hlcache_handle_release(bw->loading_content); + bw->loading_content = NULL; } - if (bw->current_content && - bw->current_content->status != CONTENT_STATUS_DONE) { - assert(bw->current_content->status == CONTENT_STATUS_READY); + if (bw->current_content != NULL && content_get_status( + bw->current_content) != CONTENT_STATUS_DONE) { + assert(content_get_status(bw->current_content) == + CONTENT_STATUS_READY); content_stop(bw->current_content, - browser_window_callback, (intptr_t) bw, 0); + browser_window_callback, bw); } schedule_remove(browser_window_refresh, bw); @@ -876,29 +844,43 @@ void browser_window_stop(struct browser_window *bw) void browser_window_reload(struct browser_window *bw, bool all) { - struct content *c; + hlcache_handle *c; unsigned int i; - if (!bw->current_content || bw->loading_content) + if (bw->current_content == NULL || bw->loading_content != NULL) return; - if (all && bw->current_content->type == CONTENT_HTML) { + if (all && content_get_type(bw->current_content) == CONTENT_HTML) { + struct html_stylesheet *sheets; + struct content_html_object *objects; + unsigned int count; + c = bw->current_content; + /* invalidate objects */ - for (i = 0; i != c->data.html.object_count; i++) { - if (c->data.html.object[i].content) - c->data.html.object[i].content->fresh = false; + objects = html_get_objects(c, &count); + + for (i = 0; i != count; i++) { + if (objects[i].content != NULL) + content_invalidate_reuse_data( + objects[i].content); } + /* invalidate stylesheets */ - for (i = STYLESHEET_START; i != c->data.html.stylesheet_count; - i++) { - if (c->data.html.stylesheets[i].c) - c->data.html.stylesheets[i].c->fresh = - false; + sheets = html_get_stylesheets(c, &count); + + for (i = STYLESHEET_START; i != count; i++) { + if (sheets[i].type == HTML_STYLESHEET_EXTERNAL && + sheets[i].data.external != NULL) { + content_invalidate_reuse_data( + sheets[i].data.external); + } } } - bw->current_content->fresh = false; - browser_window_go_post(bw, bw->current_content->url, 0, 0, + + content_invalidate_reuse_data(bw->current_content); + + browser_window_go_post(bw, content_get_url(bw->current_content), 0, 0, false, 0, false, true, 0); } @@ -1012,21 +994,22 @@ void browser_window_destroy_internal(struct browser_window *bw) LOG(("Destroying window")); - if ((bw->children) || (bw->iframes)) + if (bw->children != NULL || bw->iframes != NULL) browser_window_destroy_children(bw); - if (bw->loading_content) { - content_remove_user(bw->loading_content, - browser_window_callback, (intptr_t) bw, 0); - bw->loading_content = 0; + + if (bw->loading_content != NULL) { + hlcache_handle_release(bw->loading_content); + bw->loading_content = NULL; } - if (bw->current_content) { - if (bw->current_content->status == CONTENT_STATUS_READY || - bw->current_content->status == - CONTENT_STATUS_DONE) + + if (bw->current_content != NULL) { + content_status status = content_get_status(bw->current_content); + if (status == CONTENT_STATUS_READY || + status == CONTENT_STATUS_DONE) content_close(bw->current_content); - content_remove_user(bw->current_content, - browser_window_callback, (intptr_t) bw, 0); - bw->current_content = 0; + + hlcache_handle_release(bw->current_content); + bw->current_content = NULL; } schedule_remove(browser_window_refresh, bw); @@ -1058,15 +1041,15 @@ struct browser_window *browser_window_owner(struct browser_window *bw) return bw->parent; /* the parent of a frameset is either a NORMAL window or an IFRAME */ - while (bw->parent) { + while (bw->parent != NULL) { switch (bw->browser_window_type) { - case BROWSER_WINDOW_NORMAL: - case BROWSER_WINDOW_IFRAME: - return bw; - case BROWSER_WINDOW_FRAME: - case BROWSER_WINDOW_FRAMESET: - bw = bw->parent; - break; + case BROWSER_WINDOW_NORMAL: + case BROWSER_WINDOW_IFRAME: + return bw; + case BROWSER_WINDOW_FRAME: + case BROWSER_WINDOW_FRAMESET: + bw = bw->parent; + break; } } return bw; @@ -1083,9 +1066,9 @@ struct browser_window *browser_window_owner(struct browser_window *bw) void browser_window_reformat(struct browser_window *bw, int width, int height) { - struct content *c = bw->current_content; + hlcache_handle *c = bw->current_content; - if (!c) + if (c == NULL) return; content_reformat(c, width / bw->scale, height / bw->scale); @@ -1104,23 +1087,28 @@ void browser_window_set_scale(struct browser_window *bw, float scale, bool all) { while (bw->parent && all) bw = bw->parent; + browser_window_set_scale_internal(bw, scale); + if (bw->parent) bw = bw->parent; + browser_window_recalculate_frameset(bw); } void browser_window_set_scale_internal(struct browser_window *bw, float scale) { int i; - struct content *c; + hlcache_handle *c; if (fabs(bw->scale-scale) < 0.0001) return; + bw->scale = scale; c = bw->current_content; - if (c) { - if (!content_can_reformat(c)) { + + if (c != NULL) { + if (content_can_reformat(c) == false) { browser_window_update(bw, false); } else { bw->reformat_pending = true; @@ -1189,14 +1177,14 @@ struct browser_window *browser_window_find_target(struct browser_window *bw, { struct browser_window *bw_target; struct browser_window *top; - struct content *c; + hlcache_handle *c; int rdepth; /* use the base target if we don't have one */ c = bw->current_content; - if (!target && c && c->data.html.base_target) - target = c->data.html.base_target; - if (!target) + if (target == NULL && c != NULL && content_get_type(c) == CONTENT_HTML) + target = html_get_base_target(c); + if (target == NULL) target = TARGET_SELF; /* allow the simple case of target="_blank" to be ignored if requested @@ -1348,35 +1336,57 @@ void browser_window_find_target_internal(struct browser_window *bw, * Callback for fetch for download window fetches. */ -void download_window_callback(fetch_msg msg, void *p, const void *data, - unsigned long size, fetch_error_code errorcode) +nserror download_window_callback(llcache_handle *handle, + const llcache_event *event, void *pw) { - struct gui_download_window *download_window = p; + struct gui_download_window *download_window = pw; + + switch (event->type) { + case LLCACHE_EVENT_HAD_HEADERS: + assert(download_window == NULL); + + /** \todo Ensure parameters are correct here */ + download_window = gui_download_window_create( + llcache_handle_get_url(handle), + llcache_handle_get_header(handle, + "Content-Type"), + NULL, 0, NULL); + if (download_window == NULL) + return NSERROR_NOMEM; + + llcache_handle_change_callback(handle, + download_window_callback, download_window); + break; - switch (msg) { - case FETCH_PROGRESS: - break; - case FETCH_DATA: - gui_download_window_data(download_window, data, size); - break; + case LLCACHE_EVENT_HAD_DATA: + assert(download_window != NULL); - case FETCH_FINISHED: - gui_download_window_done(download_window); - break; + /** \todo Lose ugly cast */ + gui_download_window_data(download_window, + (char *) event->data.data.buf, + event->data.data.len); - case FETCH_ERROR: - gui_download_window_error(download_window, data); - break; + break; - case FETCH_TYPE: - case FETCH_NOTMODIFIED: - case FETCH_AUTH: - case FETCH_CERT_ERR: - default: - /* not possible */ - assert(0); - break; + case LLCACHE_EVENT_DONE: + assert(download_window != NULL); + + gui_download_window_done(download_window); + + break; + + case LLCACHE_EVENT_ERROR: + if (download_window != NULL) + gui_download_window_error(download_window, + event->data.msg); + + break; + + case LLCACHE_EVENT_PROGRESS: + break; } + + return NSERROR_OK; } @@ -1392,12 +1402,12 @@ void download_window_callback(fetch_msg msg, void *p, const void *data, void browser_window_mouse_click(struct browser_window *bw, browser_mouse_state mouse, int x, int y) { - struct content *c = bw->current_content; + hlcache_handle *c = bw->current_content; if (!c) return; - switch (c->type) { + switch (content_get_type(c)) { case CONTENT_HTML: browser_window_mouse_action_html(bw, mouse, x, y); break; @@ -1457,12 +1467,12 @@ void browser_window_mouse_action_html(struct browser_window *bw, struct box *url_box = 0; struct box *gadget_box = 0; struct box *text_box = 0; - struct content *c = bw->current_content; + hlcache_handle *c = bw->current_content; struct box *box; - struct content *content = c; - struct content *gadget_content = c; + hlcache_handle *content = c; + hlcache_handle *gadget_content = c; struct form_control *gadget = 0; - struct content *object = NULL; + hlcache_handle *object = NULL; struct box *next_box; struct box *drag_candidate = NULL; struct scroll *scroll = NULL; @@ -1522,7 +1532,7 @@ void browser_window_mouse_action_html(struct browser_window *bw, /* search the box tree for a link, imagemap, form control, or * box with scrollbars */ - box = c->data.html.layout; + box = html_get_box_tree(c); /* Consider the margins of the html page now */ box_x = box->margin[LEFT]; @@ -1715,7 +1725,7 @@ void browser_window_mouse_action_html(struct browser_window *bw, bw->drag_type = DRAGGING_SELECTION; status = messages_get("Selecting"); } else - status = c->status_message; + status = content_get_status_message(c); } else if (mouse & BROWSER_MOUSE_PRESS_1) selection_clear(bw->sel, true); @@ -1787,7 +1797,7 @@ void browser_window_mouse_action_html(struct browser_window *bw, bw->window); /* \todo should have a drag-saving object msg */ - status = c->status_message; + status = content_get_status_message(c); } else if (url) { if (title) { @@ -1803,17 +1813,10 @@ void browser_window_mouse_action_html(struct browser_window *bw, mouse & BROWSER_MOUSE_MOD_1) { /* force download of link */ browser_window_go_post(bw, url, 0, 0, false, - c->url, true, true, 0); + content_get_url(c), true, true, 0); } else if (mouse & BROWSER_MOUSE_CLICK_2 && mouse & BROWSER_MOUSE_MOD_1) { - free(browser_window_href_content.url); - browser_window_href_content.url = strdup(url); - if (!browser_window_href_content.url) - warn_user("NoMemory", 0); - else - gui_window_save_as_link(bw->window, - &browser_window_href_content); - + gui_window_save_link(bw->window, url, title); } else if (mouse & (BROWSER_MOUSE_CLICK_1 | BROWSER_MOUSE_CLICK_2)) action = ACTION_GO; @@ -1834,11 +1837,13 @@ void browser_window_mouse_action_html(struct browser_window *bw, /* if clicking in the main page, remove the selection from any * text areas */ if (!done) { + struct box *layout = html_get_box_tree(c); + if (text_box && (mouse & (BROWSER_MOUSE_CLICK_1 | BROWSER_MOUSE_CLICK_2)) && - selection_root(bw->sel) != c->data.html.layout) - selection_init(bw->sel, c->data.html.layout); + selection_root(bw->sel) != layout) + selection_init(bw->sel, layout); if (text_box) { int pixel_offset; @@ -1866,7 +1871,7 @@ void browser_window_mouse_action_html(struct browser_window *bw, status = messages_get("Selecting"); } else - status = c->status_message; + status = content_get_status_message(c); done = true; } @@ -1879,9 +1884,10 @@ void browser_window_mouse_action_html(struct browser_window *bw, if (title) status = title; else if (bw->loading_content) - status = bw->loading_content->status_message; + status = content_get_status_message( + bw->loading_content); else - status = c->status_message; + status = content_get_status_message(c); if (mouse & BROWSER_MOUSE_DRAG_1) { if (mouse & BROWSER_MOUSE_MOD_2) { @@ -1944,7 +1950,7 @@ void browser_window_mouse_action_html(struct browser_window *bw, break; case ACTION_GO: browser_window_go(browser_window_find_target(bw, target, mouse), - url, c->url, true); + url, content_get_url(c), true); break; case ACTION_NONE: break; @@ -1970,7 +1976,7 @@ void browser_window_mouse_action_html(struct browser_window *bw, void browser_window_mouse_action_text(struct browser_window *bw, browser_mouse_state mouse, int x, int y) { - struct content *c = bw->current_content; + hlcache_handle *c = bw->current_content; gui_pointer_shape pointer = GUI_POINTER_DEFAULT; const char *status = 0; size_t idx; @@ -1988,13 +1994,14 @@ void browser_window_mouse_action_text(struct browser_window *bw, status = messages_get("Selecting"); } else - status = c->status_message; + status = content_get_status_message(c); } else { if (bw->loading_content) - status = bw->loading_content->status_message; + status = content_get_status_message( + bw->loading_content); else - status = c->status_message; + status = content_get_status_message(c); if (mouse & (BROWSER_MOUSE_DRAG_1 | BROWSER_MOUSE_DRAG_2)) { browser_window_page_drag_start(bw, x, y); @@ -2021,7 +2028,7 @@ void browser_window_mouse_action_text(struct browser_window *bw, void browser_window_mouse_track(struct browser_window *bw, browser_mouse_state mouse, int x, int y) { - struct content *c = bw->current_content; + hlcache_handle *c = bw->current_content; if (c == NULL && bw->drag_type != DRAGGING_FRAME) return; @@ -2051,7 +2058,7 @@ void browser_window_mouse_track(struct browser_window *bw, } else { assert(c != NULL); - switch (c->type) { + switch (content_get_type(c)) { case CONTENT_HTML: browser_window_mouse_track_html(bw, mouse, x, y); break; @@ -2129,7 +2136,7 @@ void browser_window_mouse_track_text(struct browser_window *bw, switch (bw->drag_type) { case DRAGGING_SELECTION: { - struct content *c = bw->current_content; + hlcache_handle *c = bw->current_content; int dir = -1; size_t idx; @@ -2198,7 +2205,7 @@ void browser_window_mouse_drag_end(struct browser_window *bw, switch (bw->drag_type) { case DRAGGING_SELECTION: { - struct content *c = bw->current_content; + hlcache_handle *c = bw->current_content; if (c) { bool found = true; int dir = -1; @@ -2206,7 +2213,7 @@ void browser_window_mouse_drag_end(struct browser_window *bw, if (selection_dragging_start(bw->sel)) dir = 1; - if (c->type == CONTENT_HTML) { + if (content_get_type(c) == CONTENT_HTML) { int pixel_offset; struct box *box; int dx, dy; @@ -2236,7 +2243,8 @@ void browser_window_mouse_drag_end(struct browser_window *bw, found = false; } else { - assert(c->type == CONTENT_TEXTPLAIN); + assert(content_get_type(c) == + CONTENT_TEXTPLAIN); idx = textplain_offset_from_coords(c, x, y, dir); } @@ -2263,7 +2271,7 @@ void browser_window_mouse_drag_end(struct browser_window *bw, * \param radio form control of type GADGET_RADIO */ -void browser_radio_set(struct content *content, +void browser_radio_set(hlcache_handle *content, struct form_control *radio) { struct form_control *control; @@ -2309,26 +2317,7 @@ void browser_radio_set(struct content *content, void browser_window_redraw_rect(struct browser_window *bw, int x, int y, int width, int height) { - struct content *c = bw->current_content; - - if (c) { - union content_msg_data data; - - data.redraw.x = x; - data.redraw.y = y; - data.redraw.width = width; - data.redraw.height = height; - - data.redraw.full_redraw = true; - - data.redraw.object = c; - data.redraw.object_x = 0; - data.redraw.object_y = 0; - data.redraw.object_width = c->width; - data.redraw.object_height = c->height; - - content_broadcast(c, CONTENT_MSG_REDRAW, data); - } + content_request_redraw(bw->current_content, x, y, width, height); } @@ -2339,29 +2328,15 @@ void browser_window_redraw_rect(struct browser_window *bw, int x, int y, * \param box box to redraw */ -void browser_redraw_box(struct content *c, struct box *box) +void browser_redraw_box(hlcache_handle *c, struct box *box) { int x, y; - union content_msg_data data; box_coords(box, &x, &y); - data.redraw.x = x; - data.redraw.y = y; - data.redraw.width = box->padding[LEFT] + box->width + - box->padding[RIGHT]; - data.redraw.height = box->padding[TOP] + box->height + - box->padding[BOTTOM]; - - data.redraw.full_redraw = true; - - data.redraw.object = c; - data.redraw.object_x = 0; - data.redraw.object_y = 0; - data.redraw.object_width = c->width; - data.redraw.object_height = c->height; - - content_broadcast(c, CONTENT_MSG_REDRAW, data); + content_request_redraw(c, x, y, + box->padding[LEFT] + box->width + box->padding[RIGHT], + box->padding[TOP] + box->height + box->padding[BOTTOM]); } @@ -2441,7 +2416,8 @@ gui_pointer_shape get_pointer_shape(struct browser_window *bw, struct box *box, assert(bw); loading = (bw->loading_content != NULL || (bw->current_content && - bw->current_content->status == CONTENT_STATUS_READY)); + content_get_status(bw->current_content) == + CONTENT_STATUS_READY)); if (wallclock() - bw->last_action < 100 && loading) /* If less than 1 second since last link followed, show @@ -2540,14 +2516,15 @@ gui_pointer_shape get_pointer_shape(struct browser_window *bw, struct box *box, * Collect controls and submit a form. */ -void browser_form_submit(struct browser_window *bw, struct browser_window *target, +void browser_form_submit(struct browser_window *bw, + struct browser_window *target, struct form *form, struct form_control *submit_button) { char *data = 0, *url = 0; - struct form_successful_control *success; + struct fetch_multipart_data *success; assert(form); - assert(bw->current_content->type == CONTENT_HTML); + assert(content_get_type(bw->current_content) == CONTENT_HTML); if (!form_successful_controls(form, submit_button, &success)) { warn_user("NoMemory", 0); @@ -2558,14 +2535,14 @@ void browser_form_submit(struct browser_window *bw, struct browser_window *targe case method_GET: data = form_url_encode(form, success); if (!data) { - form_free_successful(success); + fetch_multipart_data_destroy(success); warn_user("NoMemory", 0); return; } url = calloc(1, strlen(form->action) + strlen(data) + 2); if (!url) { - form_free_successful(success); + fetch_multipart_data_destroy(success); free(data); warn_user("NoMemory", 0); return; @@ -2577,25 +2554,27 @@ void browser_form_submit(struct browser_window *bw, struct browser_window *targe sprintf(url, "%s?%s", form->action, data); } browser_window_go(target, url, - bw->current_content->url, true); + content_get_url(bw->current_content), + true); break; case method_POST_URLENC: data = form_url_encode(form, success); if (!data) { - form_free_successful(success); + fetch_multipart_data_destroy(success); warn_user("NoMemory", 0); return; } browser_window_go_post(target, form->action, data, 0, - true, bw->current_content->url, + true, + content_get_url(bw->current_content), false, true, 0); break; case method_POST_MULTIPART: browser_window_go_post(target, form->action, 0, success, true, - bw->current_content->url, + content_get_url(bw->current_content), false, true, 0); break; @@ -2603,7 +2582,7 @@ void browser_form_submit(struct browser_window *bw, struct browser_window *targe assert(0); } - form_free_successful(success); + fetch_multipart_data_destroy(success); free(data); free(url); } @@ -2864,11 +2843,11 @@ bool browser_window_nearest_text_box(struct box *box, int bx, int by, struct box *browser_window_pick_text_box(struct browser_window *bw, int x, int y, int dir, int *dx, int *dy) { - struct content *c = bw->current_content; + hlcache_handle *c = bw->current_content; struct box *text_box = NULL; - if (c && c->type == CONTENT_HTML) { - struct box *box = c->data.html.layout; + if (c && content_get_type(c) == CONTENT_HTML) { + struct box *box = html_get_box_tree(c); int nr_xd, nr_yd; int bx = box->margin[LEFT]; int by = box->margin[TOP]; @@ -3013,5 +2992,6 @@ bool browser_window_stop_available(struct browser_window *bw) { return (bw && (bw->loading_content || (bw->current_content && - (bw->current_content->status != CONTENT_STATUS_DONE)))); + (content_get_status(bw->current_content) != + CONTENT_STATUS_DONE)))); } diff --git a/desktop/browser.h b/desktop/browser.h index 52be9dedb..d72143968 100644 --- a/desktop/browser.h +++ b/desktop/browser.h @@ -31,10 +31,9 @@ #include "render/html.h" struct box; -struct content; +struct hlcache_handle; struct form; struct form_control; -struct form_successful_control; struct gui_window; struct history; struct selection; @@ -44,20 +43,20 @@ struct bitmap; struct scroll_msg_data; typedef bool (*browser_caret_callback)(struct browser_window *bw, - uint32_t key, void *p); + uint32_t key, void *p); typedef bool (*browser_paste_callback)(struct browser_window *bw, - const char *utf8, unsigned utf8_len, bool last, void *p); + const char *utf8, unsigned utf8_len, bool last, void *p); typedef void (*browser_move_callback)(struct browser_window *bw, - void *p); + void *p); /** Browser window data. */ struct browser_window { /** Page currently displayed, or 0. Must have status READY or DONE. */ - struct content *current_content; + struct hlcache_handle *current_content; /** Page being loaded, or 0. */ - struct content *loading_content; + struct hlcache_handle *loading_content; /** Window history structure. */ struct history *history; @@ -109,9 +108,6 @@ struct browser_window { /** Scroll capturing all mouse events */ struct scroll *scroll; - /** Referrer for current fetch, or 0. */ - char *referer; - /** Current fetch is download */ bool download; @@ -230,17 +226,17 @@ extern struct browser_window *current_redraw_browser; extern bool browser_reformat_pending; struct browser_window * browser_window_create(const char *url, - struct browser_window *clone, const char *referrer, - bool history_add, bool new_tab); + struct browser_window *clone, const char *referrer, + bool history_add, bool new_tab); void browser_window_initialise_common(struct browser_window *bw, - struct browser_window *clone); + struct browser_window *clone); void browser_window_go(struct browser_window *bw, const char *url, - const char *referrer, bool history_add); + const char *referrer, bool history_add); void browser_window_go_unverifiable(struct browser_window *bw, - const char *url, const char *referrer, bool history_add, - struct content *parent); + const char *url, const char *referrer, bool history_add, + struct hlcache_handle *parent); void browser_window_download(struct browser_window *bw, - const char *url, const char *referrer); + const char *url, const char *referrer); void browser_window_update(struct browser_window *bw, bool scroll_to_top); void browser_window_stop(struct browser_window *bw); void browser_window_reload(struct browser_window *bw, bool all); @@ -250,31 +246,32 @@ void browser_window_reformat(struct browser_window *bw, int width, int height); void browser_window_set_scale(struct browser_window *bw, float scale, bool all); void browser_window_refresh_url_bar(struct browser_window *bw, const char *url, - const char *frag); + const char *frag); void browser_window_mouse_click(struct browser_window *bw, - browser_mouse_state mouse, int x, int y); + browser_mouse_state mouse, int x, int y); void browser_window_mouse_track(struct browser_window *bw, - browser_mouse_state mouse, int x, int y); + browser_mouse_state mouse, int x, int y); void browser_window_mouse_drag_end(struct browser_window *bw, - browser_mouse_state mouse, int x, int y); + browser_mouse_state mouse, int x, int y); bool browser_window_key_press(struct browser_window *bw, uint32_t key); bool browser_window_paste_text(struct browser_window *bw, const char *utf8, - unsigned utf8_len, bool last); + unsigned utf8_len, bool last); void browser_window_form_select(struct browser_window *bw, - struct form_control *control, int item); -void browser_redraw_box(struct content *c, struct box *box); -void browser_form_submit(struct browser_window *bw, struct browser_window *target, - struct form *form, struct form_control *submit_button); + struct form_control *control, int item); +void browser_redraw_box(struct hlcache_handle *c, struct box *box); +void browser_form_submit(struct browser_window *bw, + struct browser_window *target, struct form *form, + struct form_control *submit_button); void browser_scroll_callback(void *client_data, - struct scroll_msg_data *scroll_data); + struct scroll_msg_data *scroll_data); void browser_select_menu_callback(void *client_data, - int x, int y, int width, int height); + int x, int y, int width, int height); void browser_window_redraw_rect(struct browser_window *bw, int x, int y, - int width, int height); + int width, int height); bool browser_window_back_available(struct browser_window *bw); bool browser_window_forward_available(struct browser_window *bw); @@ -282,7 +279,7 @@ bool browser_window_reload_available(struct browser_window *bw); bool browser_window_stop_available(struct browser_window *bw); /* In platform specific hotlist.c. */ -void hotlist_visited(struct content *content); +void hotlist_visited(struct hlcache_handle *content); /* In platform specific global_history.c. */ void global_history_add(const char *url); @@ -290,8 +287,8 @@ void global_history_add_recent(const char *url); char **global_history_get_recent(int *count); /* In platform specific thumbnail.c. */ -bool thumbnail_create(struct content *content, struct bitmap *bitmap, - const char *url); +bool thumbnail_create(struct hlcache_handle *content, struct bitmap *bitmap, + const char *url); /* In platform specific schedule.c. */ void schedule(int t, void (*callback)(void *p), void *p); @@ -300,7 +297,7 @@ bool schedule_run(void); /* In platform specific theme_install.c. */ #ifdef WITH_THEME_INSTALL -void theme_install_start(struct content *c); +void theme_install_start(struct hlcache_handle *c); #endif #endif diff --git a/desktop/frames.c b/desktop/frames.c index acabdc1b9..663ebcdbf 100644 --- a/desktop/frames.c +++ b/desktop/frames.c @@ -29,6 +29,7 @@ #include <time.h> #include <math.h> #include "utils/config.h" +#include "content/hlcache.h" #include "desktop/browser.h" #include "desktop/frames.h" #include "desktop/history_core.h" @@ -105,8 +106,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); + content_get_url(bw->current_content), + false, bw->current_content); } } @@ -155,7 +156,7 @@ void browser_window_create_frameset(struct browser_window *bw, int row, col, index; struct content_html_frames *frame; struct browser_window *window; - struct content *parent; + hlcache_handle *parent; assert(bw && frameset); @@ -230,8 +231,9 @@ void browser_window_create_frameset(struct browser_window *bw, /* Use the URL of the first ancestor window containing html content * as the referer */ for (window = bw; window->parent; window = window->parent) { - if (window->current_content && - window->current_content->type == CONTENT_HTML) + if (window->current_content && + content_get_type(window->current_content) == + CONTENT_HTML) break; } @@ -247,8 +249,7 @@ void browser_window_create_frameset(struct browser_window *bw, if (frame->url) { browser_window_go_unverifiable(window, frame->url, - parent != NULL - ? parent->url : NULL, + content_get_url(parent), true, parent); } diff --git a/desktop/gui.h b/desktop/gui.h index f09e5f20f..162632a1a 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -41,6 +41,7 @@ typedef enum { GUI_SAVE_CLIPBOARD_CONTENTS } gui_save_type; +struct fetch; struct gui_window; struct gui_download_window; @@ -55,6 +56,7 @@ typedef enum { GUI_POINTER_DEFAULT, GUI_POINTER_POINT, GUI_POINTER_CARET, #include <stdbool.h> #include "utils/config.h" #include "content/content.h" +#include "content/hlcache.h" #include "desktop/browser.h" #include "desktop/search.h" @@ -89,8 +91,8 @@ void gui_window_hide_pointer(struct gui_window *g); void gui_window_set_url(struct gui_window *g, const char *url); void gui_window_start_throbber(struct gui_window *g); void gui_window_stop_throbber(struct gui_window *g); -void gui_window_set_icon(struct gui_window *g, struct content *icon); -void gui_window_set_search_ico(struct content *ico); +void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon); +void gui_window_set_search_ico(hlcache_handle *ico); void gui_window_place_caret(struct gui_window *g, int x, int y, int height); void gui_window_remove_caret(struct gui_window *g); void gui_window_new_content(struct gui_window *g); @@ -98,7 +100,8 @@ bool gui_window_scroll_start(struct gui_window *g); bool gui_window_box_scroll_start(struct gui_window *g, int x0, int y0, int x1, int y1); bool gui_window_frame_resize_start(struct gui_window *g); -void gui_window_save_as_link(struct gui_window *g, struct content *c); +void gui_window_save_link(struct gui_window *g, const char *url, + const char *title); void gui_window_set_scale(struct gui_window *g, float scale); struct gui_download_window *gui_download_window_create(const char *url, @@ -110,7 +113,7 @@ void gui_download_window_error(struct gui_download_window *dw, const char *error_msg); void gui_download_window_done(struct gui_download_window *dw); -void gui_drag_save_object(gui_save_type type, struct content *c, +void gui_drag_save_object(gui_save_type type, hlcache_handle *c, struct gui_window *g); void gui_drag_save_selection(struct selection *s, struct gui_window *g); void gui_start_selection(struct gui_window *g); @@ -133,7 +136,7 @@ bool gui_search_term_highlighted(struct gui_window *g, struct ssl_cert_info; -void gui_cert_verify(struct browser_window *bw, struct content *c, +void gui_cert_verify(struct browser_window *bw, hlcache_handle *c, const struct ssl_cert_info *certs, unsigned long num); #endif diff --git a/desktop/history_core.c b/desktop/history_core.c index 197a42327..fc807e928 100644 --- a/desktop/history_core.c +++ b/desktop/history_core.c @@ -27,6 +27,7 @@ #include <string.h> #include <time.h> #include "content/content.h" +#include "content/hlcache.h" #include "content/urldb.h" #include "css/css.h" #include "desktop/gui.h" @@ -220,7 +221,7 @@ struct history_entry *history_clone_entry(struct history *history, * The page is added after the current entry and becomes current. */ -void history_add(struct history *history, struct content *content, +void history_add(struct history *history, hlcache_handle *content, char *frag_id) { url_func_result res; @@ -237,14 +238,14 @@ void history_add(struct history *history, struct content *content, if (entry == NULL) return; - res = url_normalize(content->url, &url); + res = url_normalize(content_get_url(content), &url); if (res != URL_FUNC_OK) { warn_user("NoMemory", 0); free(entry); return; } - title = strdup(content->title ? content->title : url); + title = strdup(content_get_title(content)); if (title == NULL) { warn_user("NoMemory", 0); free(url); @@ -303,11 +304,9 @@ void history_add(struct history *history, struct content *content, * \param content content for current entry */ -void history_update(struct history *history, struct content *content) +void history_update(struct history *history, hlcache_handle *content) { char *title; - char *url; - url_func_result res; if (!history || !history->current || !history->current->bitmap) return; @@ -315,19 +314,10 @@ void history_update(struct history *history, struct content *content) assert(history->current->page.url); assert(history->current->page.title); - if (content->title) { - title = strdup(content->title); - if (!title) { - warn_user("NoMemory", 0); - return; - } - } else { - res = url_normalize(content->url, &url); - if (res != URL_FUNC_OK) { - warn_user("NoMemory", 0); - return; - } - title = url; + title = strdup(content_get_title(content)); + if (!title) { + warn_user("NoMemory", 0); + return; } assert(title); diff --git a/desktop/history_core.h b/desktop/history_core.h index 46de18848..55b4e0bf1 100644 --- a/desktop/history_core.h +++ b/desktop/history_core.h @@ -25,15 +25,15 @@ #include <stdbool.h> -struct content; +struct hlcache_handle; struct history; struct browser_window; struct history *history_create(void); struct history *history_clone(struct history *history); -void history_add(struct history *history, struct content *content, +void history_add(struct history *history, struct hlcache_handle *content, char *frag_id); -void history_update(struct history *history, struct content *content); +void history_update(struct history *history, struct hlcache_handle *content); void history_destroy(struct history *history); void history_back(struct browser_window *bw, struct history *history); void history_forward(struct browser_window *bw, struct history *history); diff --git a/desktop/netsurf.c b/desktop/netsurf.c index 9acddaf87..192ddc185 100644 --- a/desktop/netsurf.c +++ b/desktop/netsurf.c @@ -28,10 +28,13 @@ #include <libxml/globals.h> #include <libxml/xmlversion.h> +#include <libwapcaplet/libwapcaplet.h> + #include "utils/config.h" #include "utils/utsname.h" #include "content/fetch.h" #include "content/fetchcache.h" +#include "content/llcache.h" #include "content/urldb.h" #include "desktop/netsurf.h" #include "desktop/browser.h" @@ -44,39 +47,11 @@ bool netsurf_quit = false; bool verbose_log = false; -static void netsurf_poll(void); -static void lib_init(void); - - -/** - * Gui NetSurf main(). - */ - -int netsurf_main(int argc, char** argv) -{ - netsurf_init(argc, argv); - - netsurf_main_loop(); - - netsurf_exit(); - - return EXIT_SUCCESS; -} - - -/** - * Gui NetSurf main loop. - */ - -int netsurf_main_loop(void) +static void *netsurf_lwc_alloc(void *ptr, size_t len, void *pw) { - while (!netsurf_quit) - netsurf_poll(); - - return 0; + return realloc(ptr, len); } - /** * Initialise components used by gui NetSurf. */ @@ -126,35 +101,30 @@ void netsurf_init(int argc, char** argv) utsname.nodename, utsname.release, utsname.version, utsname.machine)); - lib_init(); + lwc_initialise(netsurf_lwc_alloc, NULL, 0); url_init(); gui_init(argc, argv); setlocale(LC_ALL, "C"); fetch_init(); - fetchcache_init(); + /** \todo The frontend needs to provide the llcache_query_handler */ + llcache_initialise(NULL, NULL); gui_init2(argc, argv); } + /** - * Poll components which require it. + * Gui NetSurf main loop. */ - -void netsurf_poll(void) +int netsurf_main_loop(void) { - static unsigned int last_clean = 0; - unsigned int current_time = wallclock(); - - /* avoid calling content_clean() more often than once every 5 - * seconds. - */ - if (last_clean + 500 < current_time) { - last_clean = current_time; - content_clean(); + while (!netsurf_quit) { + gui_poll(fetch_active); + fetch_poll(); + llcache_poll(); } - gui_poll(fetch_active); - fetch_poll(); -} + return 0; +} /** * Clean up components used by gui NetSurf. @@ -164,8 +134,6 @@ void netsurf_exit(void) { LOG(("Closing GUI")); gui_quit(); - LOG(("Closing content")); - content_quit(); LOG(("Closing fetches")); fetch_quit(); LOG(("Closing utf8")); @@ -176,18 +144,3 @@ void netsurf_exit(void) } -/** - * Initialises the libraries used in NetSurf. - */ -void lib_init(void) -{ - LOG(("xmlParserVersion %s, LIBXML_VERSION_STRING %s", - xmlParserVersion, LIBXML_VERSION_STRING)); - - /* Using encoding "X-SJIS" (unknown to libxmp2/iconv) instead as - * "Shift-JIS" is rather popular. - */ - if (xmlAddEncodingAlias(xmlGetCharEncodingName( - XML_CHAR_ENCODING_SHIFT_JIS), "X-SJIS") != 0) - die("Failed to add encoding alias"); -} diff --git a/desktop/netsurf.h b/desktop/netsurf.h index 05b870333..33733fa40 100644 --- a/desktop/netsurf.h +++ b/desktop/netsurf.h @@ -29,7 +29,6 @@ extern const int netsurf_version_minor; extern void netsurf_init(int argc, char** argv); extern void netsurf_exit(void); -extern int netsurf_main(int argc, char** argv); extern int netsurf_main_loop(void); #endif diff --git a/desktop/print.c b/desktop/print.c index 4f86bbc22..a5b5c125a 100644 --- a/desktop/print.c +++ b/desktop/print.c @@ -26,6 +26,7 @@ #include <string.h> #include "content/content.h" +#include "content/hlcache.h" #include "css/utils.h" #include "desktop/options.h" #include "desktop/print.h" @@ -39,11 +40,11 @@ #define DEFAULT_PAGE_HEIGHT 840 #define DEFAULT_COPIES 1 -static struct content *print_init(struct content *, struct print_settings *); -static bool print_apply_settings(struct content *, struct print_settings *); +static hlcache_handle *print_init(hlcache_handle *, struct print_settings *); +static bool print_apply_settings(hlcache_handle *, struct print_settings *); static float page_content_width, page_content_height; -static struct content *printed_content; +static hlcache_handle *printed_content; static float done_height; bool html_redraw_printing = false; @@ -59,7 +60,7 @@ int html_redraw_printing_top_cropped = 0; * \param settings The settings for printing to use * \return true if successful, false otherwise */ -bool print_basic_run(struct content *content, +bool print_basic_run(hlcache_handle *content, const struct printer *printer, struct print_settings *settings) { @@ -69,8 +70,8 @@ bool print_basic_run(struct content *content, if (!print_set_up(content, printer, settings, NULL)) ret = false; - - while (ret && (done_height < printed_content->height) ) + + while (ret && (done_height < content_get_height(printed_content)) ) ret = print_draw_next_page(printer, settings); print_cleanup(content, printer, settings); @@ -88,7 +89,7 @@ bool print_basic_run(struct content *content, * \param height updated to the height of the printed content * \return true if successful, false otherwise */ -bool print_set_up(struct content *content, +bool print_set_up(hlcache_handle *content, const struct printer *printer, struct print_settings *settings, double *height) { @@ -100,7 +101,7 @@ bool print_set_up(struct content *content, print_apply_settings(printed_content, settings); if (height) - *height = printed_content->height; + *height = content_get_height(printed_content); printer->print_begin(settings); @@ -158,11 +159,13 @@ bool print_draw_next_page(const struct printer *printer, * \param settings The settings for printing to use * \return true if successful, false otherwise */ -struct content *print_init(struct content *content, +hlcache_handle *print_init(hlcache_handle *content, struct print_settings *settings) { - struct content* printed_content; - struct content_user *user_sentinel; +// newcache +#if 0 + hlcache_handle* printed_content; + hlcache_handle_user *user_sentinel; content_add_user(content, NULL, (intptr_t) print_init, 0); @@ -173,7 +176,7 @@ struct content *print_init(struct content *content, printed_content->data.html.bw = 0; - user_sentinel = talloc(printed_content, struct content_user); + user_sentinel = talloc(printed_content, hlcache_handle_user); user_sentinel->callback = 0; user_sentinel->p1 = user_sentinel->p2 = 0; user_sentinel->next = 0; @@ -194,6 +197,9 @@ struct content *print_init(struct content *content, printed_content->data.html.font_func = settings->font_func; return printed_content; +#else + return NULL; +#endif } /** @@ -203,7 +209,7 @@ struct content *print_init(struct content *content, * \param settings The settings for printing to use * \return true if successful, false otherwise */ -bool print_apply_settings(struct content *content, +bool print_apply_settings(hlcache_handle *content, struct print_settings *settings) { if (settings == NULL) @@ -222,7 +228,8 @@ bool print_apply_settings(struct content *content, content_reformat(content, page_content_width, 0); LOG(("New layout applied.New height = %d ; New width = %d ", - content->height, content->width)); + content_get_height(content), + content_get_width(content))); return true; } @@ -234,7 +241,7 @@ bool print_apply_settings(struct content *content, * \param printer The printer interface for the printer to be used * \return true if successful, false otherwise */ -bool print_cleanup(struct content *content, const struct printer *printer, +bool print_cleanup(hlcache_handle *content, const struct printer *printer, struct print_settings *settings) { printer->print_end(); @@ -242,12 +249,11 @@ bool print_cleanup(struct content *content, const struct printer *printer, html_redraw_printing = false; if (printed_content) { - content_remove_user(printed_content, NULL, - (intptr_t) print_init, 0); + content_remove_user(printed_content, NULL, print_init); talloc_free(printed_content); } - content_remove_user(content, NULL, (intptr_t)print_init, 0); + content_remove_user(content, NULL, print_init); free((void *)settings->output); free(settings); diff --git a/desktop/print.h b/desktop/print.h index fece526be..63c2935f1 100644 --- a/desktop/print.h +++ b/desktop/print.h @@ -36,7 +36,7 @@ #include "css/css.h" -struct content; +struct hlcache_handle; struct printer; enum { MARGINLEFT = 0, MARGINRIGHT = 1, MARGINTOP = 2, MARGINBOTTOM = 3}; @@ -64,13 +64,13 @@ struct print_settings{ }; -bool print_basic_run(struct content *, const struct printer *, +bool print_basic_run(struct hlcache_handle *, const struct printer *, struct print_settings *); -bool print_set_up(struct content *content, const struct printer *printer, +bool print_set_up(struct hlcache_handle *content, const struct printer *printer, struct print_settings *settings, double *height); bool print_draw_next_page(const struct printer *printer, struct print_settings *settings); -bool print_cleanup(struct content *, const struct printer *, +bool print_cleanup(struct hlcache_handle *, const struct printer *, struct print_settings *settings); struct print_settings *print_make_settings(print_configuration configuration, diff --git a/desktop/save_complete.c b/desktop/save_complete.c index d55cde08f..78b2d7646 100644 --- a/desktop/save_complete.c +++ b/desktop/save_complete.c @@ -35,6 +35,7 @@ #include <libxml/parserInternals.h> #include "utils/config.h" #include "content/content.h" +#include "content/hlcache.h" #include "css/css.h" #include "render/box.h" #include "desktop/save_complete.h" @@ -46,14 +47,14 @@ regex_t save_complete_import_re; /** An entry in save_complete_list. */ struct save_complete_entry { - struct content *content; + hlcache_handle *content; struct save_complete_entry *next; /**< Next entry in list */ }; -static bool save_complete_html(struct content *c, const char *path, +static bool save_complete_html(hlcache_handle *c, const char *path, bool index, struct save_complete_entry **list); -static bool save_imported_sheets(struct content *c, const char *path, - struct save_complete_entry **list); +static bool save_imported_sheets(struct nscss_import *imports, uint32_t count, + const char *path, struct save_complete_entry **list); static char * rewrite_stylesheet_urls(const char *source, unsigned int size, int *osize, const char *base, struct save_complete_entry *list); @@ -63,11 +64,11 @@ static bool rewrite_urls(xmlNode *n, const char *base, struct save_complete_entry *list); static bool rewrite_url(xmlNode *n, const char *attr, const char *base, struct save_complete_entry *list); -static bool save_complete_list_add(struct content *content, +static bool save_complete_list_add(hlcache_handle *content, struct save_complete_entry **list); -static struct content * save_complete_list_find(const char *url, +static hlcache_handle * save_complete_list_find(const char *url, struct save_complete_entry *list); -static bool save_complete_list_check(struct content *content, +static bool save_complete_list_check(hlcache_handle *content, struct save_complete_entry *list); /* static void save_complete_list_dump(void); */ static bool save_complete_inventory(const char *path, @@ -81,7 +82,7 @@ static bool save_complete_inventory(const char *path, * \return true on success, false on error and error reported */ -bool save_complete(struct content *c, const char *path) +bool save_complete(hlcache_handle *c, const char *path) { bool result; struct save_complete_entry *list = NULL; @@ -111,50 +112,69 @@ bool save_complete(struct content *c, const char *path) * \return true on success, false on error and error reported */ -bool save_complete_html(struct content *c, const char *path, bool index, +bool save_complete_html(hlcache_handle *c, const char *path, bool index, struct save_complete_entry **list) { + struct html_stylesheet *sheets; + struct content_html_object *objects; + const char *base_url; char filename[256]; - unsigned int i; + unsigned int i, count; xmlDocPtr doc; bool res; - if (c->type != CONTENT_HTML) + if (content_get_type(c) != CONTENT_HTML) return false; if (save_complete_list_check(c, *list)) return true; - + + base_url = html_get_base_url(c); + /* save stylesheets, ignoring the base and adblocking sheets */ - for (i = STYLESHEET_START; i != c->data.html.stylesheet_count; i++) { - struct content *css = c->data.html.stylesheets[i].c; + sheets = html_get_stylesheets(c, &count); + + for (i = STYLESHEET_START; i != count; i++) { + hlcache_handle *css; + const char *css_data; + unsigned long css_size; char *source; int source_len; - bool is_style; + struct nscss_import *imports; + uint32_t import_count; + + if (sheets[i].type == HTML_STYLESHEET_INTERNAL) { + if (save_imported_sheets( + sheets[i].data.internal->imports, + sheets[i].data.internal->import_count, + path, list) == false) + return false; + + continue; + } + + css = sheets[i].data.external; if (!css) continue; if (save_complete_list_check(css, *list)) continue; - is_style = (strcmp(css->url, c->data.html.base_url) == 0); - - if (is_style == false) { - if (!save_complete_list_add(css, list)) { - warn_user("NoMemory", 0); - return false; - } + if (!save_complete_list_add(css, list)) { + warn_user("NoMemory", 0); + return false; } - if (!save_imported_sheets(css, path, list)) + imports = nscss_get_imports(css, &import_count); + if (!save_imported_sheets(imports, import_count, path, list)) return false; - if (is_style) - continue; /* don't save <style> elements */ - snprintf(filename, sizeof filename, "%p", css); - source = rewrite_stylesheet_urls(css->source_data, - css->source_size, &source_len, css->url, + + css_data = content_get_source_data(css, &css_size); + + source = rewrite_stylesheet_urls(css_data, css_size, + &source_len, content_get_url(css), *list); if (!source) { warn_user("NoMemory", 0); @@ -168,12 +188,21 @@ bool save_complete_html(struct content *c, const char *path, bool index, } /* save objects */ - for (i = 0; i != c->data.html.object_count; i++) { - struct content *obj = c->data.html.object[i].content; + objects = html_get_objects(c, &count); + + for (i = 0; i != count; i++) { + hlcache_handle *obj = objects[i].content; + const char *obj_data; + unsigned long obj_size; - /* skip difficult content types */ - if (!obj || obj->type >= CONTENT_OTHER || !obj->source_data) + if (obj == NULL || content_get_type(obj) >= CONTENT_OTHER) continue; + + obj_data = content_get_source_data(obj, &obj_size); + + if (obj_data == NULL) + continue; + if (save_complete_list_check(obj, *list)) continue; @@ -182,7 +211,7 @@ bool save_complete_html(struct content *c, const char *path, bool index, return false; } - if (obj->type == CONTENT_HTML) { + if (content_get_type(obj) == CONTENT_HTML) { if (!save_complete_html(obj, path, false, list)) return false; continue; @@ -190,7 +219,7 @@ bool save_complete_html(struct content *c, const char *path, bool index, snprintf(filename, sizeof filename, "%p", obj); res = save_complete_gui_save(path, filename, - obj->source_size, obj->source_data, obj->type); + obj_size, obj_data, content_get_type(obj)); if(res == false) return false; } @@ -198,14 +227,14 @@ bool save_complete_html(struct content *c, const char *path, bool index, /*save_complete_list_dump();*/ /* copy document */ - doc = xmlCopyDoc(c->data.html.document, 1); + doc = xmlCopyDoc(html_get_document(c), 1); if (doc == NULL) { warn_user("NoMemory", 0); return false; } /* rewrite all urls we know about */ - if (!rewrite_document_urls(doc, c->data.html.base_url, *list)) { + if (!rewrite_document_urls(doc, html_get_base_url(c), *list)) { xmlFreeDoc(doc); warn_user("NoMemory", 0); return false; @@ -237,13 +266,13 @@ bool save_complete_html(struct content *c, const char *path, bool index, /** * Save stylesheets imported by a CONTENT_CSS. * - * \param c a CONTENT_CSS - * \param path path to save to + * \param imports Array of imports + * \param count Number of imports in list + * \param path Path to save to * \return true on success, false on error and error reported */ - -bool save_imported_sheets(struct content *c, const char *path, - struct save_complete_entry **list) +bool save_imported_sheets(struct nscss_import *imports, uint32_t count, + const char *path, struct save_complete_entry **list) { char filename[256]; unsigned int j; @@ -251,10 +280,14 @@ bool save_imported_sheets(struct content *c, const char *path, int source_len; bool res; - for (j = 0; j != c->data.css.import_count; j++) { - struct content *css = c->data.css.imports[j].c; + for (j = 0; j != count; j++) { + hlcache_handle *css = imports[j].c; + const char *css_data; + unsigned long css_size; + struct nscss_import *child_imports; + uint32_t child_import_count; - if (!css) + if (css == NULL) continue; if (save_complete_list_check(css, *list)) continue; @@ -264,12 +297,17 @@ bool save_imported_sheets(struct content *c, const char *path, return false; } - if (!save_imported_sheets(css, path, list)) + child_imports = nscss_get_imports(css, &child_import_count); + if (!save_imported_sheets(child_imports, child_import_count, + path, list)) return false; snprintf(filename, sizeof filename, "%p", css); - source = rewrite_stylesheet_urls(css->source_data, - css->source_size, &source_len, css->url, + + css_data = content_get_source_data(css, &css_size); + + source = rewrite_stylesheet_urls(css_data, css_size, + &source_len, content_get_url(css), *list); if (!source) { warn_user("NoMemory", 0); @@ -344,7 +382,7 @@ char * rewrite_stylesheet_urls(const char *source, unsigned int size, char buf[20]; unsigned int offset = 0; int url_len = 0; - struct content *content; + hlcache_handle *content; int m; unsigned int i; unsigned int imports = 0; @@ -609,7 +647,7 @@ bool rewrite_url(xmlNode *n, const char *attr, const char *base, { char *url, *data; char rel[20]; - struct content *content; + hlcache_handle *content; url_func_result res; if (!xmlHasProp(n, (const xmlChar *) attr)) @@ -654,7 +692,7 @@ bool rewrite_url(xmlNode *n, const char *attr, const char *base, * \return true on success, false on out of memory */ -bool save_complete_list_add(struct content *content, +bool save_complete_list_add(hlcache_handle *content, struct save_complete_entry **list) { struct save_complete_entry *entry; @@ -675,12 +713,12 @@ bool save_complete_list_add(struct content *content, * \return content if found, 0 otherwise */ -struct content * save_complete_list_find(const char *url, +hlcache_handle * save_complete_list_find(const char *url, struct save_complete_entry *list) { struct save_complete_entry *entry; for (entry = list; entry; entry = entry->next) - if (strcmp(url, entry->content->url) == 0) + if (strcmp(url, content_get_url(entry->content)) == 0) return entry->content; return 0; } @@ -693,7 +731,7 @@ struct content * save_complete_list_find(const char *url, * \return true if the content is in the save_complete_list */ -bool save_complete_list_check(struct content *content, +bool save_complete_list_check(hlcache_handle *content, struct save_complete_entry *list) { struct save_complete_entry *entry; @@ -746,8 +784,10 @@ bool save_complete_inventory(const char *path, return false; } - for (entry = list; entry; entry = entry->next) - fprintf(fp, "%p %s\n", entry->content, entry->content->url); + for (entry = list; entry; entry = entry->next) { + fprintf(fp, "%p %s\n", entry->content, + content_get_url(entry->content)); + } fclose(fp); diff --git a/desktop/save_complete.h b/desktop/save_complete.h index e23092471..ad31fa486 100644 --- a/desktop/save_complete.h +++ b/desktop/save_complete.h @@ -28,10 +28,10 @@ #include <libxml/HTMLtree.h> #include "content/content.h" -struct content; +struct hlcache_handle; void save_complete_init(void); -bool save_complete(struct content *c, const char *path); +bool save_complete(struct hlcache_handle *c, const char *path); bool save_complete_gui_save(const char *path, const char *filename, size_t len, const char *sourcedata, content_type type); diff --git a/desktop/save_pdf/pdf_plotters.c b/desktop/save_pdf/pdf_plotters.c index 8dbe43971..f33070edb 100644 --- a/desktop/save_pdf/pdf_plotters.c +++ b/desktop/save_pdf/pdf_plotters.c @@ -30,6 +30,7 @@ #include <hpdf.h> +#include "content/hlcache.h" #include "desktop/options.h" #include "desktop/plotters.h" #include "desktop/print.h" @@ -410,32 +411,37 @@ bool pdf_plot_bitmap_tile(int x, int y, int width, int height, HPDF_Image pdf_extract_image(struct bitmap *bitmap) { HPDF_Image image = NULL; - struct content *content = NULL; + hlcache_handle *content = NULL; /* TODO - get content from bitmap pointer */ if (content) { + const char *source_data; + unsigned long source_size; + /*Not sure if I don't have to check if downloading has been finished. Other way - lock pdf plotting while fetching a website */ - switch(content->type){ - /*Handle "embeddable" types of images*/ - case CONTENT_JPEG: - image = HPDF_LoadJpegImageFromMem(pdf_doc, - (const HPDF_BYTE *)content->source_data, - content->source_size); - break; - - /*Disabled until HARU PNG support will be more stable. - - case CONTENT_PNG: - image = HPDF_LoadPngImageFromMem(pdf_doc, - (const HPDF_BYTE *)content->source_data, - content->total_size); - break;*/ - default: - break; + source_data = content_get_source_data(content, &source_size); + + switch(content_get_type(content)){ + /*Handle "embeddable" types of images*/ + case CONTENT_JPEG: + image = HPDF_LoadJpegImageFromMem(pdf_doc, + (const HPDF_BYTE *) source_data, + source_size); + break; + + /*Disabled until HARU PNG support will be more stable. + + case CONTENT_PNG: + image = HPDF_LoadPngImageFromMem(pdf_doc, + (const HPDF_BYTE *)content->source_data, + content->total_size); + break;*/ + default: + break; } } diff --git a/desktop/save_text.c b/desktop/save_text.c index e34b9ceb0..5e5cef761 100644 --- a/desktop/save_text.c +++ b/desktop/save_text.c @@ -27,6 +27,7 @@ #include "utils/config.h" #include "content/content.h" +#include "content/hlcache.h" #include "desktop/save_text.h" #include "render/box.h" #include "utils/log.h" @@ -48,7 +49,7 @@ static bool save_text_add_to_buffer(const char *text, size_t length, * \param path Path to save text file too. */ -void save_as_text(struct content *c, char *path) +void save_as_text(hlcache_handle *c, char *path) { FILE *out; struct save_text_state save = { NULL, 0, 0 }; @@ -57,11 +58,11 @@ void save_as_text(struct content *c, char *path) utf8_convert_ret ret; char *result; - if (!c || c->type != CONTENT_HTML) { + if (!c || content_get_type(c) != CONTENT_HTML) { return; } - extract_text(c->data.html.layout, &first, &before, &save); + extract_text(html_get_box_tree(c), &first, &before, &save); if (!save.block) return; diff --git a/desktop/save_text.h b/desktop/save_text.h index 825d08f63..06446cd58 100644 --- a/desktop/save_text.h +++ b/desktop/save_text.h @@ -25,7 +25,7 @@ #define _NETSURF_DESKTOP_SAVE_TEXT_H_ struct box; -struct content; +struct hlcache_handle; /* text currently being saved */ struct save_text_state { @@ -41,7 +41,7 @@ typedef enum { WHITESPACE_TWO_NEW_LINES } save_text_whitespace; -void save_as_text(struct content *c, char *path); +void save_as_text(struct hlcache_handle *c, char *path); void save_text_solve_whitespace(struct box *box, bool *first, save_text_whitespace *before, const char **whitespace_text, size_t *whitespace_length); diff --git a/desktop/search.c b/desktop/search.c index ba472fd41..f84f1f06e 100644 --- a/desktop/search.c +++ b/desktop/search.c @@ -26,6 +26,7 @@ #include <ctype.h> #include <string.h> #include "content/content.h" +#include "content/hlcache.h" #include "desktop/browser.h" #include "desktop/gui.h" #include "desktop/options.h" @@ -33,6 +34,7 @@ #include "desktop/selection.h" #include "render/box.h" #include "render/html.h" +#include "render/textplain.h" #include "utils/config.h" #include "utils/log.h" #include "utils/messages.h" @@ -60,7 +62,7 @@ struct list_entry { struct search_context { struct browser_window *bw; - struct content *content; + hlcache_handle *content; char *string; bool prev_case_sens; bool newsearch; @@ -80,7 +82,7 @@ static bool find_occurrences_html(const char *pattern, int p_len, struct box *cur, bool case_sens, struct search_context *context); static bool find_occurrences_text(const char *pattern, int p_len, - struct content *c, bool case_sens, + hlcache_handle *c, bool case_sens, struct search_context *context); static struct list_entry *add_entry(unsigned start_idx, unsigned end_idx, struct search_context *context); @@ -236,7 +238,7 @@ void search_text(const char *string, int string_len, struct search_context *context, search_flags_t flags) { struct rect bounds; - struct content *c; + hlcache_handle *c; struct box *box; bool case_sensitive, forwards, showall; @@ -250,11 +252,11 @@ void search_text(const char *string, int string_len, c = context->bw->current_content; /* only handle html contents */ - if ((!c) || (c->type != CONTENT_HTML && - c->type != CONTENT_TEXTPLAIN)) + if ((!c) || (content_get_type(c) != CONTENT_HTML && + content_get_type(c) != CONTENT_TEXTPLAIN)) return; - box = c->data.html.layout; + box = html_get_box_tree(c); if (!box) return; @@ -282,11 +284,11 @@ void search_text(const char *string, int string_len, (context->callbacks->hourglass != NULL)) context->callbacks->hourglass(true, context->p); - if (c->type == CONTENT_HTML) + if (content_get_type(c) == CONTENT_HTML) res = find_occurrences_html(string, string_len, box, case_sensitive, context); else { - assert(c->type == CONTENT_TEXTPLAIN); + assert(content_get_type(c) == CONTENT_TEXTPLAIN); res = find_occurrences_text(string, string_len, c, case_sensitive, context); } @@ -342,7 +344,7 @@ void search_text(const char *string, int string_len, if (context->current == NULL) return; - switch (c->type) { + switch (content_get_type(c)) { case CONTENT_HTML: /* get box position and jump to it */ box_coords(context->current->start_box, @@ -356,7 +358,7 @@ void search_text(const char *string, int string_len, break; default: - assert(c->type == CONTENT_TEXTPLAIN); + assert(content_get_type(c) == CONTENT_TEXTPLAIN); textplain_coords_from_range(c, context->current->start_idx, context->current->end_idx, &bounds); @@ -551,7 +553,7 @@ bool find_occurrences_html(const char *pattern, int p_len, struct box *cur, */ bool find_occurrences_text(const char *pattern, int p_len, - struct content *c, bool case_sens, + hlcache_handle *c, bool case_sens, struct search_context *context) { int nlines = textplain_line_count(c); @@ -642,15 +644,15 @@ void search_show_all(bool all, struct search_context *context) if (add && !a->sel) { a->sel = selection_create(context->bw); if (a->sel) { - struct content *c = context->bw-> + hlcache_handle *c = context->bw-> current_content; - switch (c->type) { + switch (content_get_type(c)) { case CONTENT_HTML: selection_init(a->sel, - c->data.html.layout); + html_get_box_tree(c)); break; default: - assert(c->type == + assert(content_get_type(c) == CONTENT_TEXTPLAIN); selection_init(a->sel, NULL); break; diff --git a/desktop/searchweb.c b/desktop/searchweb.c index bc0f71ad4..724edc9dd 100644 --- a/desktop/searchweb.c +++ b/desktop/searchweb.c @@ -24,8 +24,7 @@ #include <ctype.h> #include <string.h> #include "content/content.h" -#include "content/fetchcache.h" -#include "content/fetch.h" +#include "content/hlcache.h" #include "desktop/browser.h" #include "desktop/gui.h" #include "desktop/options.h" @@ -43,10 +42,13 @@ static struct search_provider { char *ico; /** < location of domain's favicon */ } current_search_provider; -static struct content *search_ico = NULL; +static hlcache_handle *search_ico = NULL; char *search_engines_file_location; char *search_default_ico_location; +static nserror search_web_ico_callback(hlcache_handle *ico, + const hlcache_event *event, void *pw); + /** * creates a new browser window according to the search term * \param searchterm such as "my search term" @@ -205,7 +207,8 @@ char *search_web_get_url(const char *encsearchterm) void search_web_retrieve_ico(bool localdefault) { char *url; - struct content *icocontent; + nserror error; + if (localdefault) { if (search_default_ico_location == NULL) return; @@ -221,26 +224,17 @@ void search_web_retrieve_ico(bool localdefault) url = search_web_ico_name(); } - icocontent = NULL; if (url == NULL) { warn_user(messages_get("NoMemory"), 0); return; } - icocontent = fetchcache(url, search_web_ico_callback, - 0, 0, 20, 20, true, 0, - 0, false, false); - free(url); - if (icocontent == NULL) - return; - - fetchcache_go(icocontent, 0, search_web_ico_callback, - 0, 0, 20, 20, - 0, 0, false, 0); - if (icocontent == NULL) - LOG(("web search ico loading delayed")); - else - search_ico = icocontent; + error = hlcache_handle_retrieve(url, 0, NULL, NULL, 20, 20, + search_web_ico_callback, NULL, NULL, &search_ico); + if (error != NSERROR_OK) + search_ico = NULL; + + free(url); } /** @@ -249,7 +243,7 @@ void search_web_retrieve_ico(bool localdefault) * responsibility */ -struct content *search_web_ico(void) +hlcache_handle *search_web_ico(void) { return search_ico; } @@ -259,20 +253,18 @@ struct content *search_web_ico(void) * else retry default from local file system */ -void search_web_ico_callback(content_msg msg, struct content *ico, - intptr_t p1, intptr_t p2, union content_msg_data data) +nserror search_web_ico_callback(hlcache_handle *ico, + const hlcache_event *event, void *pw) { - - switch (msg) { + switch (event->type) { case CONTENT_MSG_LOADING: case CONTENT_MSG_READY: break; case CONTENT_MSG_DONE: - LOG(("got favicon '%s'", ico->url)); + LOG(("got favicon '%s'", content_get_url(ico))); #ifdef WITH_BMP - if (ico->type == CONTENT_ICO) { - search_ico = ico; /* cache */ + if (content_get_type(ico) == CONTENT_ICO) { gui_window_set_search_ico(search_ico); } else #endif @@ -281,20 +273,20 @@ void search_web_ico_callback(content_msg msg, struct content *ico, } break; - case CONTENT_MSG_LAUNCH: case CONTENT_MSG_ERROR: - LOG(("favicon %s error: %s", ico->url, data.error)); - ico = 0; + LOG(("favicon %s error: %s", + content_get_url(ico), event->data.error)); + hlcache_handle_release(search_ico); + search_ico = NULL; search_web_retrieve_ico(true); break; case CONTENT_MSG_STATUS: - case CONTENT_MSG_NEWPTR: - case CONTENT_MSG_AUTH: - case CONTENT_MSG_SSL: break; default: assert(0); } + + return NSERROR_OK; } diff --git a/desktop/searchweb.h b/desktop/searchweb.h index f8dcb9db0..6cc23036a 100644 --- a/desktop/searchweb.h +++ b/desktop/searchweb.h @@ -20,9 +20,11 @@ #define _NETSURF_DESKTOP_SEARCH_WEB_H_ #include <ctype.h> +#include <stdbool.h> #include <string.h> -#include "content/content.h" -#include "desktop/browser.h" + +struct browser_window; +struct hlcache_handle; extern char *search_engines_file_location; extern char *search_default_ico_location; @@ -71,9 +73,6 @@ bool search_is_url(const char *url); void search_web_retrieve_ico(bool localdefault); -struct content *search_web_ico(void); - -void search_web_ico_callback(content_msg msg, struct content *ico, - intptr_t p1, intptr_t p2, union content_msg_data data); +struct hlcache_handle *search_web_ico(void); #endif diff --git a/desktop/selection.c b/desktop/selection.c index 93f5cc1a3..821dbb9bc 100644 --- a/desktop/selection.c +++ b/desktop/selection.c @@ -27,6 +27,7 @@ #include <stdbool.h> #include <string.h> +#include "content/hlcache.h" #include "desktop/gui.h" #include "desktop/plotters.h" #include "desktop/save_text.h" @@ -155,8 +156,8 @@ void selection_reinit(struct selection *s, struct box *root) s->max_idx = selection_label_subtree(root, root_idx); } else { - struct content *c = s->bw->current_content; - if (c && c->type == CONTENT_TEXTPLAIN) + hlcache_handle *c = s->bw->current_content; + if (c && content_get_type(c) == CONTENT_TEXTPLAIN) s->max_idx = textplain_size(c); else s->max_idx = 0; @@ -560,7 +561,7 @@ bool traverse_tree(struct box *box, unsigned start_idx, unsigned end_idx, bool selection_traverse(struct selection *s, seln_traverse_handler handler, void *handle) { - struct content *c; + hlcache_handle *c; save_text_whitespace before = WHITESPACE_NONE; bool first = true; const char *text; @@ -664,8 +665,9 @@ void selection_redraw(struct selection *s, unsigned start_idx, unsigned end_idx) return; } else { - struct content *c = s->bw->current_content; - if (c && c->type == CONTENT_TEXTPLAIN && end_idx > start_idx) { + hlcache_handle *c = s->bw->current_content; + if (c && content_get_type(c) == CONTENT_TEXTPLAIN && + end_idx > start_idx) { textplain_coords_from_range(c, start_idx, end_idx, &rdw.r); rdw.inited = true; @@ -952,7 +954,7 @@ bool save_handler(const char *text, size_t length, struct box *box, bool selection_save_text(struct selection *s, const char *path) { - struct content *c = s->bw->current_content; + hlcache_handle *c = s->bw->current_content; struct save_text_state sv = { NULL, 0, 0 }; utf8_convert_ret ret; char *result; diff --git a/desktop/textinput.c b/desktop/textinput.c index 5083d8c78..7739140fb 100644 --- a/desktop/textinput.c +++ b/desktop/textinput.c @@ -2091,11 +2091,14 @@ bool textarea_cut(struct browser_window *bw, void textarea_reflow(struct browser_window *bw, struct box *textarea, struct box *inline_container) { + struct content *c = hlcache_handle_get_content(bw->current_content); int width = textarea->width; int height = textarea->height; + + assert(c != NULL); + if (!layout_inline_container(inline_container, width, - textarea, 0, 0, - bw->current_content)) + textarea, 0, 0, c)) warn_user("NoMemory", 0); textarea->width = width; textarea->height = height; |