|
@@ -104,6 +104,7 @@ static struct br_layout_box layout_boxes[BR_MAX_NODES];
|
|
|
/* Images are loaded one per main-loop iteration so the parsed page stays
|
|
/* Images are loaded one per main-loop iteration so the parsed page stays
|
|
|
* interactive while a slow network/TLS fetch or 4K decode is in progress. */
|
|
* interactive while a slow network/TLS fetch or 4K decode is in progress. */
|
|
|
static int preload_active;
|
|
static int preload_active;
|
|
|
|
|
+static int preload_max_jobs;
|
|
|
static int preload_pending;
|
|
static int preload_pending;
|
|
|
static int preload_wait;
|
|
static int preload_wait;
|
|
|
static unsigned int preload_node;
|
|
static unsigned int preload_node;
|
|
@@ -1098,6 +1099,27 @@ static int fetch_script_text(const char *url, unsigned char **out,
|
|
|
unsigned int *outlen, char *err,
|
|
unsigned int *outlen, char *err,
|
|
|
unsigned int errcap);
|
|
unsigned int errcap);
|
|
|
|
|
|
|
|
|
|
+struct fetch_worker;
|
|
|
|
|
+static struct fetch_worker *fetch_worker_alloc(void);
|
|
|
|
|
+static void fetch_worker_release(struct fetch_worker *w);
|
|
|
|
|
+static int fetch_worker_submit(struct fetch_worker *w, const char *url,
|
|
|
|
|
+ unsigned int cap, const char *post,
|
|
|
|
|
+ unsigned int post_len, unsigned int node,
|
|
|
|
|
+ int bg, char *err, unsigned int errcap);
|
|
|
|
|
+static int fetch_worker_wait(struct fetch_worker *w, char *err,
|
|
|
|
|
+ unsigned int errcap);
|
|
|
|
|
+static int fetch_worker_read_body(struct fetch_worker *w,
|
|
|
|
|
+ unsigned char *plain,
|
|
|
|
|
+ unsigned int plaincap,
|
|
|
|
|
+ unsigned char *comp,
|
|
|
|
|
+ unsigned int compcap,
|
|
|
|
|
+ int *truncated, char *err,
|
|
|
|
|
+ unsigned int errcap);
|
|
|
|
|
+static void fetch_workers_stop_all(void);
|
|
|
|
|
+static int script_cache_has(const char *url);
|
|
|
|
|
+static void script_cache_put(const char *url, const unsigned char *data,
|
|
|
|
|
+ unsigned int len);
|
|
|
|
|
+
|
|
|
static void script_error(const char *what, const char *url, const char *why)
|
|
static void script_error(const char *what, const char *url, const char *why)
|
|
|
{
|
|
{
|
|
|
char msg[192];
|
|
char msg[192];
|
|
@@ -1115,12 +1137,51 @@ static void script_error(const char *what, const char *url, const char *why)
|
|
|
js_host_report(msg);
|
|
js_host_report(msg);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-/* Run the page's scripts in document order: external <script src> bodies are
|
|
|
|
|
- * fetched, inline bodies are copied because MuJS needs NUL-terminated text. */
|
|
|
|
|
|
|
+/* Script prefetch state: one entry per <script> block. Remote bodies are
|
|
|
|
|
+ * submitted to helper workers ahead of time, but scripts still execute in
|
|
|
|
|
+ * document order. */
|
|
|
|
|
+#define SCRIPT_INLINE 0
|
|
|
|
|
+#define SCRIPT_LOCAL 1
|
|
|
|
|
+#define SCRIPT_REMOTE 2
|
|
|
|
|
+#define SCRIPT_ERROR 3
|
|
|
|
|
+
|
|
|
|
|
+static char script_urls[BR_MAX_SCRIPTS][BR_URL_MAX];
|
|
|
|
|
+static unsigned char script_kind[BR_MAX_SCRIPTS];
|
|
|
|
|
+static struct fetch_worker *script_slot[BR_MAX_SCRIPTS];
|
|
|
|
|
+
|
|
|
|
|
+static void script_submit_window(unsigned int *next, char *err,
|
|
|
|
|
+ unsigned int errcap)
|
|
|
|
|
+{
|
|
|
|
|
+ while (*next < doc.nscripts) {
|
|
|
|
|
+ struct fetch_worker *w;
|
|
|
|
|
+
|
|
|
|
|
+ if (script_kind[*next] != SCRIPT_REMOTE) {
|
|
|
|
|
+ (*next)++;
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ w = fetch_worker_alloc();
|
|
|
|
|
+ if (!w)
|
|
|
|
|
+ return;
|
|
|
|
|
+ if (fetch_worker_submit(w, script_urls[*next], BR_SCRIPT_MAX,
|
|
|
|
|
+ 0, 0, 0, 0, err, errcap) != 0) {
|
|
|
|
|
+ fetch_worker_release(w);
|
|
|
|
|
+ script_kind[*next] = SCRIPT_ERROR;
|
|
|
|
|
+ (*next)++;
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ script_slot[*next] = w;
|
|
|
|
|
+ (*next)++;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/* Run the page's scripts in document order. External bodies are prefetched
|
|
|
|
|
+ * in parallel so downloading script N+1 overlaps executing script N; inline
|
|
|
|
|
+ * bodies are copied because MuJS needs NUL-terminated text. */
|
|
|
static void run_page_scripts(void)
|
|
static void run_page_scripts(void)
|
|
|
{
|
|
{
|
|
|
struct js_browser_host host;
|
|
struct js_browser_host host;
|
|
|
- unsigned int i;
|
|
|
|
|
|
|
+ unsigned int i, next = 0;
|
|
|
|
|
+ char err[64], ferr[64];
|
|
|
|
|
|
|
|
if (!doc.nscripts)
|
|
if (!doc.nscripts)
|
|
|
return;
|
|
return;
|
|
@@ -1147,37 +1208,36 @@ static void run_page_scripts(void)
|
|
|
js_host_status("JavaScript: out of memory", 1);
|
|
js_host_status("JavaScript: out of memory", 1);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
for (i = 0; i < doc.nscripts; i++) {
|
|
for (i = 0; i < doc.nscripts; i++) {
|
|
|
struct br_script *script = &doc.scripts[i];
|
|
struct br_script *script = &doc.scripts[i];
|
|
|
|
|
+ const char *src_attr = script->src_off ?
|
|
|
|
|
+ doc.attrs + script->src_off : "";
|
|
|
|
|
|
|
|
- if (script->src_off) {
|
|
|
|
|
- const char *src_attr = doc.attrs + script->src_off;
|
|
|
|
|
- char url[BR_URL_MAX];
|
|
|
|
|
- unsigned char *data;
|
|
|
|
|
- unsigned int len;
|
|
|
|
|
- char err[64];
|
|
|
|
|
- int rv;
|
|
|
|
|
|
|
+ script_slot[i] = 0;
|
|
|
|
|
+ if (!script->src_off) {
|
|
|
|
|
+ script_kind[i] = SCRIPT_INLINE;
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!src_attr[0] ||
|
|
|
|
|
+ resolve_link(page_url, src_attr, script_urls[i],
|
|
|
|
|
+ sizeof(script_urls[i])) != 0) {
|
|
|
|
|
+ script_urls[i][0] = '\0';
|
|
|
|
|
+ script_kind[i] = SCRIPT_ERROR;
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (script_urls[i][0] == '/' ||
|
|
|
|
|
+ script_cache_has(script_urls[i]))
|
|
|
|
|
+ script_kind[i] = SCRIPT_LOCAL;
|
|
|
|
|
+ else
|
|
|
|
|
+ script_kind[i] = SCRIPT_REMOTE;
|
|
|
|
|
+ }
|
|
|
|
|
+ script_submit_window(&next, ferr, sizeof(ferr));
|
|
|
|
|
|
|
|
- if (!src_attr[0])
|
|
|
|
|
- continue;
|
|
|
|
|
- if (resolve_link(page_url, src_attr, url,
|
|
|
|
|
- sizeof(url)) != 0) {
|
|
|
|
|
- script_error("Cannot load script", src_attr,
|
|
|
|
|
- "unsupported URL");
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- set_status("Loading script...", 0, 0);
|
|
|
|
|
- rv = fetch_script_text(url, &data, &len, err,
|
|
|
|
|
- sizeof(err));
|
|
|
|
|
- if (rv == FETCH_ABORT)
|
|
|
|
|
- break;
|
|
|
|
|
- if (rv != 0) {
|
|
|
|
|
- script_error("Cannot load script", url, err);
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- js_browser_run((const char *)data, url);
|
|
|
|
|
- free(data);
|
|
|
|
|
- } else {
|
|
|
|
|
|
|
+ for (i = 0; i < doc.nscripts; i++) {
|
|
|
|
|
+ struct br_script *script = &doc.scripts[i];
|
|
|
|
|
+
|
|
|
|
|
+ if (script_kind[i] == SCRIPT_INLINE) {
|
|
|
unsigned int off = script->off;
|
|
unsigned int off = script->off;
|
|
|
unsigned int len = script->len;
|
|
unsigned int len = script->len;
|
|
|
unsigned int k;
|
|
unsigned int k;
|
|
@@ -1192,6 +1252,92 @@ static void run_page_scripts(void)
|
|
|
src[len] = '\0';
|
|
src[len] = '\0';
|
|
|
js_browser_run(src, page_url);
|
|
js_browser_run(src, page_url);
|
|
|
free(src);
|
|
free(src);
|
|
|
|
|
+ } else if (script->src_off) {
|
|
|
|
|
+ const char *src_attr = doc.attrs + script->src_off;
|
|
|
|
|
+
|
|
|
|
|
+ if (script_kind[i] == SCRIPT_ERROR) {
|
|
|
|
|
+ script_error("Cannot load script", src_attr,
|
|
|
|
|
+ script_urls[i][0] ?
|
|
|
|
|
+ "network busy" :
|
|
|
|
|
+ "unsupported URL");
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (script_kind[i] == SCRIPT_LOCAL) {
|
|
|
|
|
+ unsigned char *data = 0;
|
|
|
|
|
+ unsigned int len = 0;
|
|
|
|
|
+ int rv;
|
|
|
|
|
+
|
|
|
|
|
+ set_status("Loading script...", 0, 0);
|
|
|
|
|
+ rv = fetch_script_text(script_urls[i], &data,
|
|
|
|
|
+ &len, err, sizeof(err));
|
|
|
|
|
+ if (rv == FETCH_ABORT)
|
|
|
|
|
+ break;
|
|
|
|
|
+ if (rv != 0) {
|
|
|
|
|
+ script_error("Cannot load script",
|
|
|
|
|
+ script_urls[i], err);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ js_browser_run((const char *)data,
|
|
|
|
|
+ script_urls[i]);
|
|
|
|
|
+ free(data);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ struct fetch_worker *w = script_slot[i];
|
|
|
|
|
+ int tr = 0, rv;
|
|
|
|
|
+
|
|
|
|
|
+ if (!w) {
|
|
|
|
|
+ w = fetch_worker_alloc();
|
|
|
|
|
+ if (!w)
|
|
|
|
|
+ continue;
|
|
|
|
|
+ if (fetch_worker_submit(w,
|
|
|
|
|
+ script_urls[i],
|
|
|
|
|
+ BR_SCRIPT_MAX,
|
|
|
|
|
+ 0, 0, 0, 0, err,
|
|
|
|
|
+ sizeof(err)) != 0) {
|
|
|
|
|
+ fetch_worker_release(w);
|
|
|
|
|
+ script_kind[i] = SCRIPT_ERROR;
|
|
|
|
|
+ if (i == next)
|
|
|
|
|
+ next++;
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ script_slot[i] = w;
|
|
|
|
|
+ if (i == next)
|
|
|
|
|
+ next++;
|
|
|
|
|
+ }
|
|
|
|
|
+ set_status("Loading script...", 0, 0);
|
|
|
|
|
+ rv = fetch_worker_wait(w, err, sizeof(err));
|
|
|
|
|
+ if (rv == FETCH_ABORT) {
|
|
|
|
|
+ fetch_workers_stop_all();
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (rv == 0)
|
|
|
|
|
+ rv = fetch_worker_read_body(w,
|
|
|
|
|
+ image_io_buf, BR_SCRIPT_MAX,
|
|
|
|
|
+ image_io_buf + BR_SCRIPT_MAX,
|
|
|
|
|
+ BR_IMG_FILE_MAX, &tr, err,
|
|
|
|
|
+ sizeof(err));
|
|
|
|
|
+ else
|
|
|
|
|
+ rv = -1;
|
|
|
|
|
+ fetch_worker_release(w);
|
|
|
|
|
+ script_slot[i] = 0;
|
|
|
|
|
+ script_submit_window(&next, ferr, sizeof(ferr));
|
|
|
|
|
+ if (rv <= 0)
|
|
|
|
|
+ script_error("Cannot load script",
|
|
|
|
|
+ script_urls[i], err);
|
|
|
|
|
+ else if (tr || (unsigned int)rv >=
|
|
|
|
|
+ BR_SCRIPT_MAX)
|
|
|
|
|
+ script_error("Cannot load script",
|
|
|
|
|
+ script_urls[i],
|
|
|
|
|
+ "script is too large");
|
|
|
|
|
+ else {
|
|
|
|
|
+ image_io_buf[rv] = '\0';
|
|
|
|
|
+ script_cache_put(script_urls[i],
|
|
|
|
|
+ image_io_buf,
|
|
|
|
|
+ (unsigned int)rv);
|
|
|
|
|
+ js_browser_run(
|
|
|
|
|
+ (const char *)image_io_buf,
|
|
|
|
|
+ script_urls[i]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
if (pending_action)
|
|
if (pending_action)
|
|
|
break;
|
|
break;
|
|
@@ -1790,7 +1936,7 @@ struct fetch_meta {
|
|
|
static void draw(unsigned int *action);
|
|
static void draw(unsigned int *action);
|
|
|
static void handle_keys(unsigned int *action);
|
|
static void handle_keys(unsigned int *action);
|
|
|
static void handle_page_click(unsigned int *action);
|
|
static void handle_page_click(unsigned int *action);
|
|
|
-#define FETCH_WORKERS 3
|
|
|
|
|
|
|
+#define FETCH_WORKERS 4
|
|
|
#define FETCH_PATH_MAX 32
|
|
#define FETCH_PATH_MAX 32
|
|
|
|
|
|
|
|
/* One long-lived curl __serve helper per worker. Each worker has its own
|
|
/* One long-lived curl __serve helper per worker. Each worker has its own
|
|
@@ -1802,6 +1948,7 @@ struct fetch_worker {
|
|
|
int slot;
|
|
int slot;
|
|
|
int busy;
|
|
int busy;
|
|
|
int ready;
|
|
int ready;
|
|
|
|
|
+ int image_job;
|
|
|
unsigned int seq;
|
|
unsigned int seq;
|
|
|
unsigned int deadline;
|
|
unsigned int deadline;
|
|
|
int retried;
|
|
int retried;
|
|
@@ -1930,6 +2077,7 @@ static void fetch_worker_stop(struct fetch_worker *w)
|
|
|
w->pid = -1;
|
|
w->pid = -1;
|
|
|
w->busy = 0;
|
|
w->busy = 0;
|
|
|
w->ready = 0;
|
|
w->ready = 0;
|
|
|
|
|
+ w->image_job = 0;
|
|
|
if (w->req[0]) {
|
|
if (w->req[0]) {
|
|
|
u_syscall1(SYS_UNLINK, (int)w->done);
|
|
u_syscall1(SYS_UNLINK, (int)w->done);
|
|
|
u_syscall1(SYS_UNLINK, (int)w->meta);
|
|
u_syscall1(SYS_UNLINK, (int)w->meta);
|
|
@@ -2026,6 +2174,7 @@ static int fetch_worker_submit(struct fetch_worker *w, const char *url,
|
|
|
fetch_seq = 1;
|
|
fetch_seq = 1;
|
|
|
w->seq = fetch_seq;
|
|
w->seq = fetch_seq;
|
|
|
w->ready = 0;
|
|
w->ready = 0;
|
|
|
|
|
+ w->image_job = 0;
|
|
|
w->retried = 0;
|
|
w->retried = 0;
|
|
|
w->m.error = 0;
|
|
w->m.error = 0;
|
|
|
w->node = node;
|
|
w->node = node;
|
|
@@ -2209,6 +2358,7 @@ static void fetch_worker_release(struct fetch_worker *w)
|
|
|
u_syscall1(SYS_UNLINK, (int)w->req);
|
|
u_syscall1(SYS_UNLINK, (int)w->req);
|
|
|
w->busy = 0;
|
|
w->busy = 0;
|
|
|
w->ready = 0;
|
|
w->ready = 0;
|
|
|
|
|
+ w->image_job = 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* Blocking wait used by page/CSS/script fetches; keeps the UI alive. */
|
|
/* Blocking wait used by page/CSS/script fetches; keeps the UI alive. */
|
|
@@ -2506,6 +2656,16 @@ static void script_cache_put(const char *url, const unsigned char *data,
|
|
|
script_cache_count++;
|
|
script_cache_count++;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+static int script_cache_has(const char *url)
|
|
|
|
|
+{
|
|
|
|
|
+ char path[96];
|
|
|
|
|
+ struct sys_stat st;
|
|
|
|
|
+
|
|
|
|
|
+ script_cache_path(url, path, sizeof(path));
|
|
|
|
|
+ return u_stat(path, &st) == 0 && !st.is_dir && st.size > 0 &&
|
|
|
|
|
+ st.size < SCRIPT_CACHE_FILE_MAX;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/* Fetch one external script into a heap buffer and NUL-terminate it. */
|
|
/* Fetch one external script into a heap buffer and NUL-terminate it. */
|
|
|
static int fetch_script_text(const char *url, unsigned char **out,
|
|
static int fetch_script_text(const char *url, unsigned char **out,
|
|
|
unsigned int *outlen, char *err,
|
|
unsigned int *outlen, char *err,
|
|
@@ -2679,6 +2839,16 @@ static void css_cache_put(const char *url, const unsigned char *data,
|
|
|
css_cache_count++;
|
|
css_cache_count++;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+static int css_cache_has(const char *url)
|
|
|
|
|
+{
|
|
|
|
|
+ char path[96];
|
|
|
|
|
+ struct sys_stat st;
|
|
|
|
|
+
|
|
|
|
|
+ css_cache_path(url, path, sizeof(path));
|
|
|
|
|
+ return u_stat(path, &st) == 0 && !st.is_dir && st.size > 0 &&
|
|
|
|
|
+ st.size < CSS_CACHE_FILE_MAX;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/* Read one stylesheet into the shared static buffer. CSS is parsed
|
|
/* Read one stylesheet into the shared static buffer. CSS is parsed
|
|
|
* immediately, so it does not need the page heap; this leaves the heap for
|
|
* immediately, so it does not need the page heap; this leaves the heap for
|
|
|
* the 2 MB page body, the rules and the scaled image bitmaps. */
|
|
* the 2 MB page body, the rules and the scaled image bitmaps. */
|
|
@@ -2785,19 +2955,21 @@ static int ancestor_is(unsigned int node, unsigned int tag)
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/* Fetch and parse the page's stylesheets. Remote bodies are downloaded in
|
|
|
|
|
+ * parallel but parsed in document order, so the cascade is unchanged. */
|
|
|
static int load_stylesheets(void)
|
|
static int load_stylesheets(void)
|
|
|
{
|
|
{
|
|
|
- static char seen[BR_MAX_SHEETS][BR_URL_MAX];
|
|
|
|
|
- unsigned int i, sheets = 0, nseen = 0;
|
|
|
|
|
|
|
+ static char urls[BR_MAX_SHEETS][BR_URL_MAX];
|
|
|
|
|
+ static unsigned char remote[BR_MAX_SHEETS];
|
|
|
|
|
+ struct fetch_worker *slot[BR_MAX_SHEETS];
|
|
|
|
|
+ unsigned int i, n = 0, next = 0, k;
|
|
|
|
|
+ char err[64];
|
|
|
|
|
|
|
|
- for (i = 0; i < doc.nnode && sheets < BR_MAX_SHEETS; i++) {
|
|
|
|
|
|
|
+ for (i = 0; i < doc.nnode && n < BR_MAX_SHEETS; i++) {
|
|
|
struct br_node *nd = &doc.nodes[i];
|
|
struct br_node *nd = &doc.nodes[i];
|
|
|
const char *rel, *href;
|
|
const char *rel, *href;
|
|
|
char url[BR_URL_MAX];
|
|
char url[BR_URL_MAX];
|
|
|
- unsigned char *data;
|
|
|
|
|
- unsigned int len;
|
|
|
|
|
- char err[64];
|
|
|
|
|
- int rv;
|
|
|
|
|
|
|
+ int dup = 0;
|
|
|
|
|
|
|
|
if (nd->type != BR_NODE_ELEM || nd->tag != BR_TAG_LINK)
|
|
if (nd->type != BR_NODE_ELEM || nd->tag != BR_TAG_LINK)
|
|
|
continue;
|
|
continue;
|
|
@@ -2809,32 +2981,117 @@ static int load_stylesheets(void)
|
|
|
continue;
|
|
continue;
|
|
|
if (resolve_link(page_url, href, url, sizeof(url)) != 0)
|
|
if (resolve_link(page_url, href, url, sizeof(url)) != 0)
|
|
|
continue;
|
|
continue;
|
|
|
- {
|
|
|
|
|
- unsigned int k;
|
|
|
|
|
- int dup = 0;
|
|
|
|
|
|
|
+ for (k = 0; k < n; k++)
|
|
|
|
|
+ if (s_eq(urls[k], url)) {
|
|
|
|
|
+ dup = 1;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (dup)
|
|
|
|
|
+ continue;
|
|
|
|
|
+ s_copy(urls[n], url, BR_URL_MAX);
|
|
|
|
|
+ remote[n] = url[0] != '/' && !css_cache_has(url);
|
|
|
|
|
+ n++;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for (i = 0; i < BR_MAX_SHEETS; i++)
|
|
|
|
|
+ slot[i] = 0;
|
|
|
|
|
+
|
|
|
|
|
+ /* Start as many remote sheets as there are free workers. */
|
|
|
|
|
+ for (; next < n; next++) {
|
|
|
|
|
+ struct fetch_worker *w;
|
|
|
|
|
+
|
|
|
|
|
+ if (!remote[next])
|
|
|
|
|
+ continue;
|
|
|
|
|
+ w = fetch_worker_alloc();
|
|
|
|
|
+ if (!w)
|
|
|
|
|
+ break;
|
|
|
|
|
+ if (fetch_worker_submit(w, urls[next], BR_CSS_MAX, 0, 0, 0, 0,
|
|
|
|
|
+ err, sizeof(err)) != 0) {
|
|
|
|
|
+ fetch_worker_release(w);
|
|
|
|
|
+ remote[next] = 0;
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ slot[next] = w;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for (i = 0; i < n; i++) {
|
|
|
|
|
+ unsigned char *data = 0;
|
|
|
|
|
+ unsigned int len = 0;
|
|
|
|
|
+ int rv;
|
|
|
|
|
|
|
|
- for (k = 0; k < nseen; k++)
|
|
|
|
|
- if (s_eq(seen[k], url)) {
|
|
|
|
|
- dup = 1;
|
|
|
|
|
|
|
+ if (!remote[i]) {
|
|
|
|
|
+ rv = fetch_css(urls[i], &data, &len, err, sizeof(err));
|
|
|
|
|
+ if (rv == FETCH_ABORT) {
|
|
|
|
|
+ fetch_workers_stop_all();
|
|
|
|
|
+ return FETCH_ABORT;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (rv != 0 || !len)
|
|
|
|
|
+ continue;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ struct fetch_worker *w = slot[i];
|
|
|
|
|
+ int tr = 0;
|
|
|
|
|
+
|
|
|
|
|
+ if (!w) {
|
|
|
|
|
+ w = fetch_worker_alloc();
|
|
|
|
|
+ if (!w)
|
|
|
|
|
+ continue;
|
|
|
|
|
+ if (fetch_worker_submit(w, urls[i], BR_CSS_MAX,
|
|
|
|
|
+ 0, 0, 0, 0, err,
|
|
|
|
|
+ sizeof(err)) != 0) {
|
|
|
|
|
+ fetch_worker_release(w);
|
|
|
|
|
+ remote[i] = 0;
|
|
|
|
|
+ if (i == next)
|
|
|
|
|
+ next++;
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ slot[i] = w;
|
|
|
|
|
+ if (i == next)
|
|
|
|
|
+ next++;
|
|
|
|
|
+ }
|
|
|
|
|
+ rv = fetch_worker_wait(w, err, sizeof(err));
|
|
|
|
|
+ if (rv == FETCH_ABORT) {
|
|
|
|
|
+ fetch_workers_stop_all();
|
|
|
|
|
+ return FETCH_ABORT;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (rv == 0)
|
|
|
|
|
+ rv = fetch_worker_read_body(w, image_io_buf,
|
|
|
|
|
+ BR_CSS_MAX,
|
|
|
|
|
+ image_io_buf + BR_CSS_MAX,
|
|
|
|
|
+ BR_CSS_COMP_MAX, &tr,
|
|
|
|
|
+ err, sizeof(err));
|
|
|
|
|
+ else
|
|
|
|
|
+ rv = -1;
|
|
|
|
|
+ fetch_worker_release(w);
|
|
|
|
|
+ slot[i] = 0;
|
|
|
|
|
+
|
|
|
|
|
+ /* Refill the worker window before parsing this sheet. */
|
|
|
|
|
+ for (; next < n; next++) {
|
|
|
|
|
+ struct fetch_worker *nw;
|
|
|
|
|
+
|
|
|
|
|
+ if (!remote[next])
|
|
|
|
|
+ continue;
|
|
|
|
|
+ nw = fetch_worker_alloc();
|
|
|
|
|
+ if (!nw)
|
|
|
break;
|
|
break;
|
|
|
|
|
+ if (fetch_worker_submit(nw, urls[next],
|
|
|
|
|
+ BR_CSS_MAX, 0, 0, 0, 0,
|
|
|
|
|
+ err, sizeof(err)) != 0) {
|
|
|
|
|
+ fetch_worker_release(nw);
|
|
|
|
|
+ remote[next] = 0;
|
|
|
|
|
+ continue;
|
|
|
}
|
|
}
|
|
|
- if (dup)
|
|
|
|
|
- continue;
|
|
|
|
|
- if (nseen < BR_MAX_SHEETS) {
|
|
|
|
|
- s_copy(seen[nseen], url, BR_URL_MAX);
|
|
|
|
|
- nseen++;
|
|
|
|
|
|
|
+ slot[next] = nw;
|
|
|
}
|
|
}
|
|
|
|
|
+ if (rv <= 0)
|
|
|
|
|
+ continue;
|
|
|
|
|
+ len = (unsigned int)rv;
|
|
|
|
|
+ data = image_io_buf;
|
|
|
|
|
+ css_cache_put(urls[i], data, len);
|
|
|
}
|
|
}
|
|
|
- rv = fetch_css(url, &data, &len, err, sizeof(err));
|
|
|
|
|
- if (rv == FETCH_ABORT)
|
|
|
|
|
- return FETCH_ABORT;
|
|
|
|
|
- if (rv != 0)
|
|
|
|
|
- continue;
|
|
|
|
|
if (len) {
|
|
if (len) {
|
|
|
- br_set_font_base(url);
|
|
|
|
|
|
|
+ br_set_font_base(urls[i]);
|
|
|
br_parse_css_text(&doc, (const char *)data, len);
|
|
br_parse_css_text(&doc, (const char *)data, len);
|
|
|
}
|
|
}
|
|
|
- sheets++;
|
|
|
|
|
}
|
|
}
|
|
|
br_set_font_base(page_url);
|
|
br_set_font_base(page_url);
|
|
|
br_parse_inline_css(&doc);
|
|
br_parse_inline_css(&doc);
|
|
@@ -2849,6 +3106,7 @@ static void preload_begin(void)
|
|
|
preload_active = 1;
|
|
preload_active = 1;
|
|
|
preload_pending = 0;
|
|
preload_pending = 0;
|
|
|
preload_wait = 1;
|
|
preload_wait = 1;
|
|
|
|
|
+ preload_max_jobs = FETCH_WORKERS;
|
|
|
preload_node = 0;
|
|
preload_node = 0;
|
|
|
preload_loaded = 0;
|
|
preload_loaded = 0;
|
|
|
preload_scroll = 0;
|
|
preload_scroll = 0;
|
|
@@ -2908,7 +3166,7 @@ static int preload_active_jobs(void)
|
|
|
int i, n = 0;
|
|
int i, n = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < FETCH_WORKERS; i++)
|
|
for (i = 0; i < FETCH_WORKERS; i++)
|
|
|
- if (fetch_workers[i].busy)
|
|
|
|
|
|
|
+ if (fetch_workers[i].busy && fetch_workers[i].image_job)
|
|
|
n++;
|
|
n++;
|
|
|
return n;
|
|
return n;
|
|
|
}
|
|
}
|
|
@@ -2992,6 +3250,9 @@ static int preload_fill_jobs(void)
|
|
|
char url[BR_URL_MAX];
|
|
char url[BR_URL_MAX];
|
|
|
struct fetch_worker *w;
|
|
struct fetch_worker *w;
|
|
|
|
|
|
|
|
|
|
+ if (preload_active_jobs() >= preload_max_jobs)
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
if (nd->type != BR_NODE_ELEM) {
|
|
if (nd->type != BR_NODE_ELEM) {
|
|
|
preload_node++;
|
|
preload_node++;
|
|
|
continue;
|
|
continue;
|
|
@@ -3046,6 +3307,7 @@ static int preload_fill_jobs(void)
|
|
|
fetch_worker_release(w);
|
|
fetch_worker_release(w);
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
+ w->image_job = 1;
|
|
|
started++;
|
|
started++;
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
@@ -3122,6 +3384,7 @@ static int preload_fill_jobs(void)
|
|
|
fetch_worker_release(w);
|
|
fetch_worker_release(w);
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
+ w->image_job = 1;
|
|
|
started++;
|
|
started++;
|
|
|
}
|
|
}
|
|
|
return started;
|
|
return started;
|
|
@@ -3347,7 +3610,14 @@ static void load_page(const char *url, int local, int push)
|
|
|
* screen; the fetch helper pumps this UI while it waits. */
|
|
* screen; the fetch helper pumps this UI while it waits. */
|
|
|
set_status("Loading scripts...", 0, 0);
|
|
set_status("Loading scripts...", 0, 0);
|
|
|
redraw_now();
|
|
redraw_now();
|
|
|
|
|
+ /* Start one image download before the scripts. The other workers
|
|
|
|
|
+ * fetch the external script bodies in parallel, and the remaining
|
|
|
|
|
+ * images start as soon as the script phase ends. */
|
|
|
|
|
+ preload_max_jobs = 1;
|
|
|
|
|
+ preload_fill_jobs();
|
|
|
|
|
+ preload_wait = 0;
|
|
|
run_page_scripts();
|
|
run_page_scripts();
|
|
|
|
|
+ preload_max_jobs = FETCH_WORKERS;
|
|
|
if (pending_action)
|
|
if (pending_action)
|
|
|
return;
|
|
return;
|
|
|
|
|
|