2012-07-13 23:19:04 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>
|
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-05-10 13:34:26 +03:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* implementation of content handling for text/html scripts.
|
2012-07-13 23:19:04 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <strings.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "utils/config.h"
|
2012-07-22 21:58:22 +04:00
|
|
|
#include "utils/corestrings.h"
|
2012-07-13 23:19:04 +04:00
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
2016-06-06 10:59:23 +03:00
|
|
|
#include "netsurf/content.h"
|
2012-07-13 23:19:04 +04:00
|
|
|
#include "javascript/js.h"
|
|
|
|
#include "content/content_protected.h"
|
|
|
|
#include "content/fetch.h"
|
2012-08-22 15:22:58 +04:00
|
|
|
#include "content/hlcache.h"
|
2016-06-06 10:59:23 +03:00
|
|
|
|
2018-05-10 13:34:26 +03:00
|
|
|
#include "html/html_internal.h"
|
2012-07-13 23:19:04 +04:00
|
|
|
|
|
|
|
typedef bool (script_handler_t)(struct jscontext *jscontext, const char *data, size_t size) ;
|
|
|
|
|
|
|
|
|
|
|
|
static script_handler_t *select_script_handler(content_type ctype)
|
|
|
|
{
|
|
|
|
if (ctype == CONTENT_JS) {
|
|
|
|
return js_exec;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-10 13:34:26 +03:00
|
|
|
/* exported internal interface documented in html/html_internal.h */
|
2015-03-09 16:47:12 +03:00
|
|
|
nserror html_script_exec(html_content *c)
|
2012-07-13 23:19:04 +04:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
struct html_script *s;
|
|
|
|
script_handler_t *script_handler;
|
|
|
|
|
2015-03-09 16:47:12 +03:00
|
|
|
if (c->jscontext == NULL) {
|
|
|
|
return NSERROR_BAD_PARAMETER;
|
|
|
|
}
|
2012-07-13 23:19:04 +04:00
|
|
|
|
|
|
|
for (i = 0, s = c->scripts; i != c->scripts_count; i++, s++) {
|
|
|
|
if (s->already_started) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-08-01 01:33:08 +04:00
|
|
|
if ((s->type == HTML_SCRIPT_ASYNC) ||
|
|
|
|
(s->type == HTML_SCRIPT_DEFER)) {
|
2012-07-13 23:19:04 +04:00
|
|
|
/* ensure script content is present */
|
2012-07-27 16:53:14 +04:00
|
|
|
if (s->data.handle == NULL)
|
2012-07-13 23:19:04 +04:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* ensure script content fetch status is not an error */
|
2012-07-27 16:53:14 +04:00
|
|
|
if (content_get_status(s->data.handle) ==
|
2012-07-22 21:58:22 +04:00
|
|
|
CONTENT_STATUS_ERROR)
|
2012-07-13 23:19:04 +04:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* ensure script handler for content type */
|
2012-07-22 21:58:22 +04:00
|
|
|
script_handler = select_script_handler(
|
2012-07-27 16:53:14 +04:00
|
|
|
content_get_type(s->data.handle));
|
2012-07-13 23:19:04 +04:00
|
|
|
if (script_handler == NULL)
|
|
|
|
continue; /* unsupported type */
|
|
|
|
|
2012-07-27 16:53:14 +04:00
|
|
|
if (content_get_status(s->data.handle) ==
|
2012-07-22 21:58:22 +04:00
|
|
|
CONTENT_STATUS_DONE) {
|
2012-07-13 23:19:04 +04:00
|
|
|
/* external script is now available */
|
|
|
|
const char *data;
|
|
|
|
unsigned long size;
|
2012-07-22 21:58:22 +04:00
|
|
|
data = content_get_source_data(
|
2012-07-27 16:53:14 +04:00
|
|
|
s->data.handle, &size );
|
2012-07-13 23:19:04 +04:00
|
|
|
script_handler(c->jscontext, data, size);
|
|
|
|
|
|
|
|
s->already_started = true;
|
|
|
|
|
2017-09-11 18:43:25 +03:00
|
|
|
}
|
2012-07-13 23:19:04 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-09 16:47:12 +03:00
|
|
|
return NSERROR_OK;
|
2012-07-13 23:19:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* create new html script entry */
|
|
|
|
static struct html_script *
|
2017-09-11 18:43:25 +03:00
|
|
|
html_process_new_script(html_content *c,
|
|
|
|
dom_string *mimetype,
|
2012-07-27 19:59:49 +04:00
|
|
|
enum html_script_type type)
|
2012-07-13 23:19:04 +04:00
|
|
|
{
|
|
|
|
struct html_script *nscript;
|
|
|
|
/* add space for new script entry */
|
|
|
|
nscript = realloc(c->scripts,
|
|
|
|
sizeof(struct html_script) * (c->scripts_count + 1));
|
|
|
|
if (nscript == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
c->scripts = nscript;
|
|
|
|
|
|
|
|
/* increment script entry count */
|
|
|
|
nscript = &c->scripts[c->scripts_count];
|
|
|
|
c->scripts_count++;
|
|
|
|
|
|
|
|
nscript->already_started = false;
|
|
|
|
nscript->parser_inserted = false;
|
|
|
|
nscript->force_async = true;
|
|
|
|
nscript->ready_exec = false;
|
|
|
|
nscript->async = false;
|
|
|
|
nscript->defer = false;
|
|
|
|
|
|
|
|
nscript->type = type;
|
|
|
|
|
2012-07-27 19:59:49 +04:00
|
|
|
nscript->mimetype = dom_string_ref(mimetype); /* reference mimetype */
|
|
|
|
|
2012-07-13 23:19:04 +04:00
|
|
|
return nscript;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-07-27 15:01:50 +04:00
|
|
|
* Callback for asyncronous scripts
|
2012-07-13 23:19:04 +04:00
|
|
|
*/
|
|
|
|
static nserror
|
2012-07-27 15:01:50 +04:00
|
|
|
convert_script_async_cb(hlcache_handle *script,
|
2012-07-13 23:19:04 +04:00
|
|
|
const hlcache_event *event,
|
|
|
|
void *pw)
|
|
|
|
{
|
|
|
|
html_content *parent = pw;
|
|
|
|
unsigned int i;
|
|
|
|
struct html_script *s;
|
|
|
|
|
|
|
|
/* Find script */
|
|
|
|
for (i = 0, s = parent->scripts; i != parent->scripts_count; i++, s++) {
|
2012-07-27 16:53:14 +04:00
|
|
|
if (s->type == HTML_SCRIPT_ASYNC && s->data.handle == script)
|
2012-07-13 23:19:04 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(i != parent->scripts_count);
|
|
|
|
|
|
|
|
switch (event->type) {
|
|
|
|
case CONTENT_MSG_LOADING:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_READY:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_DONE:
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "script %d done '%s'", i,
|
|
|
|
nsurl_access(hlcache_handle_get_url(script)));
|
2012-07-13 23:19:04 +04:00
|
|
|
parent->base.active--;
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "%d fetches active", parent->base.active);
|
2012-07-13 23:19:04 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_ERROR:
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "script %s failed: %s",
|
|
|
|
nsurl_access(hlcache_handle_get_url(script)),
|
|
|
|
event->data.error);
|
2017-09-11 18:43:25 +03:00
|
|
|
/* fall through */
|
|
|
|
|
2017-08-28 12:55:03 +03:00
|
|
|
case CONTENT_MSG_ERRORCODE:
|
2012-07-13 23:19:04 +04:00
|
|
|
hlcache_handle_release(script);
|
2012-07-27 16:53:14 +04:00
|
|
|
s->data.handle = NULL;
|
2012-07-13 23:19:04 +04:00
|
|
|
parent->base.active--;
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "%d fetches active", parent->base.active);
|
2012-07-13 23:19:04 +04:00
|
|
|
content_add_error(&parent->base, "?", 0);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2014-01-05 18:39:08 +04:00
|
|
|
break;
|
2012-07-13 23:19:04 +04:00
|
|
|
}
|
|
|
|
|
2015-10-02 11:29:51 +03:00
|
|
|
/* if there are no active fetches remaining begin post parse
|
|
|
|
* conversion
|
|
|
|
*/
|
|
|
|
if (html_can_begin_conversion(parent)) {
|
|
|
|
html_begin_conversion(parent);
|
|
|
|
}
|
|
|
|
|
2012-07-13 23:19:04 +04:00
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-27 19:59:49 +04:00
|
|
|
/**
|
|
|
|
* Callback for defer scripts
|
|
|
|
*/
|
|
|
|
static nserror
|
|
|
|
convert_script_defer_cb(hlcache_handle *script,
|
|
|
|
const hlcache_event *event,
|
|
|
|
void *pw)
|
|
|
|
{
|
|
|
|
html_content *parent = pw;
|
|
|
|
unsigned int i;
|
|
|
|
struct html_script *s;
|
|
|
|
|
|
|
|
/* Find script */
|
|
|
|
for (i = 0, s = parent->scripts; i != parent->scripts_count; i++, s++) {
|
2013-01-03 03:13:28 +04:00
|
|
|
if (s->type == HTML_SCRIPT_DEFER && s->data.handle == script)
|
2012-07-27 19:59:49 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(i != parent->scripts_count);
|
|
|
|
|
|
|
|
switch (event->type) {
|
|
|
|
|
|
|
|
case CONTENT_MSG_DONE:
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "script %d done '%s'", i,
|
|
|
|
nsurl_access(hlcache_handle_get_url(script)));
|
2012-07-27 19:59:49 +04:00
|
|
|
parent->base.active--;
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "%d fetches active", parent->base.active);
|
2012-07-27 19:59:49 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_ERROR:
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "script %s failed: %s",
|
|
|
|
nsurl_access(hlcache_handle_get_url(script)),
|
|
|
|
event->data.error);
|
2017-09-11 18:43:25 +03:00
|
|
|
/* fall through */
|
|
|
|
|
2017-08-28 12:55:03 +03:00
|
|
|
case CONTENT_MSG_ERRORCODE:
|
2012-07-27 19:59:49 +04:00
|
|
|
hlcache_handle_release(script);
|
|
|
|
s->data.handle = NULL;
|
|
|
|
parent->base.active--;
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "%d fetches active", parent->base.active);
|
2012-07-27 19:59:49 +04:00
|
|
|
content_add_error(&parent->base, "?", 0);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2014-01-05 18:39:08 +04:00
|
|
|
break;
|
2012-07-27 19:59:49 +04:00
|
|
|
}
|
|
|
|
|
2012-07-30 21:18:11 +04:00
|
|
|
/* if there are no active fetches remaining begin post parse
|
|
|
|
* conversion
|
|
|
|
*/
|
2013-03-18 18:48:00 +04:00
|
|
|
if (html_can_begin_conversion(parent)) {
|
2012-07-30 21:18:11 +04:00
|
|
|
html_begin_conversion(parent);
|
|
|
|
}
|
2012-07-27 19:59:49 +04:00
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback for syncronous scripts
|
|
|
|
*/
|
|
|
|
static nserror
|
|
|
|
convert_script_sync_cb(hlcache_handle *script,
|
|
|
|
const hlcache_event *event,
|
|
|
|
void *pw)
|
|
|
|
{
|
|
|
|
html_content *parent = pw;
|
|
|
|
unsigned int i;
|
|
|
|
struct html_script *s;
|
2012-07-30 18:17:57 +04:00
|
|
|
script_handler_t *script_handler;
|
2012-07-30 21:18:11 +04:00
|
|
|
dom_hubbub_error err;
|
2012-07-27 19:59:49 +04:00
|
|
|
|
|
|
|
/* Find script */
|
|
|
|
for (i = 0, s = parent->scripts; i != parent->scripts_count; i++, s++) {
|
2012-07-30 18:17:57 +04:00
|
|
|
if (s->type == HTML_SCRIPT_SYNC && s->data.handle == script)
|
2012-07-27 19:59:49 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(i != parent->scripts_count);
|
|
|
|
|
|
|
|
switch (event->type) {
|
|
|
|
case CONTENT_MSG_DONE:
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "script %d done '%s'", i,
|
|
|
|
nsurl_access(hlcache_handle_get_url(script)));
|
2012-07-27 19:59:49 +04:00
|
|
|
parent->base.active--;
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "%d fetches active", parent->base.active);
|
2012-07-27 19:59:49 +04:00
|
|
|
|
|
|
|
s->already_started = true;
|
|
|
|
|
2012-07-30 18:17:57 +04:00
|
|
|
/* attempt to execute script */
|
|
|
|
script_handler = select_script_handler(content_get_type(s->data.handle));
|
2015-10-31 20:26:43 +03:00
|
|
|
if (script_handler != NULL && parent->jscontext != NULL) {
|
2012-07-30 18:17:57 +04:00
|
|
|
/* script has a handler */
|
2012-07-27 19:59:49 +04:00
|
|
|
const char *data;
|
|
|
|
unsigned long size;
|
|
|
|
data = content_get_source_data(s->data.handle, &size );
|
2012-07-30 18:17:57 +04:00
|
|
|
script_handler(parent->jscontext, data, size);
|
2012-07-27 19:59:49 +04:00
|
|
|
}
|
2012-07-30 18:17:57 +04:00
|
|
|
|
|
|
|
/* continue parse */
|
2012-07-30 21:18:11 +04:00
|
|
|
err = dom_hubbub_parser_pause(parent->parser, false);
|
|
|
|
if (err != DOM_HUBBUB_OK) {
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "unpause returned 0x%x", err);
|
2017-09-11 18:43:25 +03:00
|
|
|
}
|
2012-07-30 18:17:57 +04:00
|
|
|
|
2012-07-27 19:59:49 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_ERROR:
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "script %s failed: %s",
|
|
|
|
nsurl_access(hlcache_handle_get_url(script)),
|
|
|
|
event->data.error);
|
2017-09-11 18:43:25 +03:00
|
|
|
/* fall through */
|
2012-07-27 19:59:49 +04:00
|
|
|
|
2017-09-11 18:43:25 +03:00
|
|
|
case CONTENT_MSG_ERRORCODE:
|
2012-07-27 19:59:49 +04:00
|
|
|
hlcache_handle_release(script);
|
|
|
|
s->data.handle = NULL;
|
|
|
|
parent->base.active--;
|
2012-07-30 18:17:57 +04:00
|
|
|
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "%d fetches active", parent->base.active);
|
2012-07-27 19:59:49 +04:00
|
|
|
content_add_error(&parent->base, "?", 0);
|
|
|
|
|
|
|
|
s->already_started = true;
|
|
|
|
|
2012-08-01 01:59:18 +04:00
|
|
|
/* continue parse */
|
|
|
|
err = dom_hubbub_parser_pause(parent->parser, false);
|
|
|
|
if (err != DOM_HUBBUB_OK) {
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "unpause returned 0x%x", err);
|
2017-09-11 18:43:25 +03:00
|
|
|
}
|
2012-08-01 01:59:18 +04:00
|
|
|
|
2012-07-27 19:59:49 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2014-01-05 18:39:08 +04:00
|
|
|
break;
|
2012-07-27 19:59:49 +04:00
|
|
|
}
|
|
|
|
|
2012-07-30 21:18:11 +04:00
|
|
|
/* if there are no active fetches remaining begin post parse
|
|
|
|
* conversion
|
|
|
|
*/
|
2013-03-18 18:48:00 +04:00
|
|
|
if (html_can_begin_conversion(parent)) {
|
2012-07-30 21:18:11 +04:00
|
|
|
html_begin_conversion(parent);
|
|
|
|
}
|
|
|
|
|
2012-07-27 19:59:49 +04:00
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-27 16:53:14 +04:00
|
|
|
/**
|
|
|
|
* process a script with a src tag
|
2012-07-27 15:01:50 +04:00
|
|
|
*/
|
|
|
|
static dom_hubbub_error
|
2012-07-27 16:53:14 +04:00
|
|
|
exec_src_script(html_content *c,
|
|
|
|
dom_node *node,
|
|
|
|
dom_string *mimetype,
|
2012-07-27 15:01:50 +04:00
|
|
|
dom_string *src)
|
|
|
|
{
|
|
|
|
nserror ns_error;
|
|
|
|
nsurl *joined;
|
|
|
|
hlcache_child_context child;
|
|
|
|
struct html_script *nscript;
|
2012-07-27 19:59:49 +04:00
|
|
|
bool async;
|
|
|
|
bool defer;
|
|
|
|
enum html_script_type script_type;
|
|
|
|
hlcache_handle_callback script_cb;
|
|
|
|
dom_hubbub_error ret = DOM_HUBBUB_OK;
|
|
|
|
dom_exception exc; /* returned by libdom functions */
|
2012-07-27 15:01:50 +04:00
|
|
|
|
2012-07-27 19:59:49 +04:00
|
|
|
/* src url */
|
2012-07-27 15:01:50 +04:00
|
|
|
ns_error = nsurl_join(c->base_url, dom_string_data(src), &joined);
|
|
|
|
if (ns_error != NSERROR_OK) {
|
2017-08-28 13:01:30 +03:00
|
|
|
content_broadcast_errorcode(&c->base, NSERROR_NOMEM);
|
2012-07-30 18:17:57 +04:00
|
|
|
return DOM_HUBBUB_NOMEM;
|
2012-07-27 15:01:50 +04:00
|
|
|
}
|
2012-07-30 18:17:57 +04:00
|
|
|
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "script %i '%s'", c->scripts_count,
|
|
|
|
nsurl_access(joined));
|
2012-07-27 15:01:50 +04:00
|
|
|
|
2012-07-27 19:59:49 +04:00
|
|
|
/* there are three ways to process the script tag at this point:
|
|
|
|
*
|
|
|
|
* Syncronously pause the parent parse and continue after
|
|
|
|
* the script has downloaded and executed. (default)
|
2017-09-11 18:43:25 +03:00
|
|
|
* Async Start the script downloading and execute it when it
|
|
|
|
* becomes available.
|
|
|
|
* Defered Start the script downloading and execute it when
|
|
|
|
* the page has completed parsing, may be set along
|
2012-07-27 19:59:49 +04:00
|
|
|
* with async where it is ignored.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* we interpret the presence of the async and defer attribute
|
|
|
|
* as true and ignore its value, technically only the empty
|
|
|
|
* value or the attribute name itself are valid. However
|
|
|
|
* various browsers interpret this in various ways the most
|
|
|
|
* compatible approach is to be liberal and accept any
|
2017-09-11 18:43:25 +03:00
|
|
|
* value. Note setting the values to "false" still makes them true!
|
2012-07-27 19:59:49 +04:00
|
|
|
*/
|
|
|
|
exc = dom_element_has_attribute(node, corestring_dom_async, &async);
|
|
|
|
if (exc != DOM_NO_ERR) {
|
|
|
|
return DOM_HUBBUB_OK; /* dom error */
|
|
|
|
}
|
2012-07-27 15:01:50 +04:00
|
|
|
|
2012-07-27 19:59:49 +04:00
|
|
|
if (async) {
|
|
|
|
/* asyncronous script */
|
|
|
|
script_type = HTML_SCRIPT_ASYNC;
|
|
|
|
script_cb = convert_script_async_cb;
|
2012-07-27 15:01:50 +04:00
|
|
|
|
2012-07-27 19:59:49 +04:00
|
|
|
} else {
|
2017-09-11 18:43:25 +03:00
|
|
|
exc = dom_element_has_attribute(node,
|
2012-07-27 19:59:49 +04:00
|
|
|
corestring_dom_defer, &defer);
|
|
|
|
if (exc != DOM_NO_ERR) {
|
|
|
|
return DOM_HUBBUB_OK; /* dom error */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defer) {
|
|
|
|
/* defered script */
|
|
|
|
script_type = HTML_SCRIPT_DEFER;
|
|
|
|
script_cb = convert_script_defer_cb;
|
|
|
|
} else {
|
|
|
|
/* syncronous script */
|
|
|
|
script_type = HTML_SCRIPT_SYNC;
|
|
|
|
script_cb = convert_script_sync_cb;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nscript = html_process_new_script(c, mimetype, script_type);
|
|
|
|
if (nscript == NULL) {
|
|
|
|
nsurl_unref(joined);
|
2017-08-28 13:01:30 +03:00
|
|
|
content_broadcast_errorcode(&c->base, NSERROR_NOMEM);
|
2012-07-30 18:17:57 +04:00
|
|
|
return DOM_HUBBUB_NOMEM;
|
2012-07-27 19:59:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set up child fetch encoding and quirks */
|
2012-07-27 15:01:50 +04:00
|
|
|
child.charset = c->encoding;
|
|
|
|
child.quirks = c->base.quirks;
|
|
|
|
|
|
|
|
ns_error = hlcache_handle_retrieve(joined,
|
|
|
|
0,
|
|
|
|
content_get_url(&c->base),
|
|
|
|
NULL,
|
2012-07-27 19:59:49 +04:00
|
|
|
script_cb,
|
2012-07-27 15:01:50 +04:00
|
|
|
c,
|
|
|
|
&child,
|
|
|
|
CONTENT_SCRIPT,
|
2012-07-27 16:53:14 +04:00
|
|
|
&nscript->data.handle);
|
2012-07-27 15:01:50 +04:00
|
|
|
|
2012-07-27 19:59:49 +04:00
|
|
|
|
2012-07-27 15:01:50 +04:00
|
|
|
nsurl_unref(joined);
|
|
|
|
|
|
|
|
if (ns_error != NSERROR_OK) {
|
2012-07-27 19:59:49 +04:00
|
|
|
/* @todo Deal with fetch error better. currently assume
|
2017-09-11 18:43:25 +03:00
|
|
|
* fetch never became active
|
2012-07-27 19:59:49 +04:00
|
|
|
*/
|
|
|
|
/* mark duff script fetch as already started */
|
2017-09-11 18:43:25 +03:00
|
|
|
nscript->already_started = true;
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "Fetch failed with error %d", ns_error);
|
2012-07-27 19:59:49 +04:00
|
|
|
} else {
|
|
|
|
/* update base content active fetch count */
|
2017-09-11 18:43:25 +03:00
|
|
|
c->base.active++;
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "%d fetches active", c->base.active);
|
2012-07-30 18:17:57 +04:00
|
|
|
|
2012-07-27 19:59:49 +04:00
|
|
|
switch (script_type) {
|
|
|
|
case HTML_SCRIPT_SYNC:
|
2012-07-31 15:49:41 +04:00
|
|
|
ret = DOM_HUBBUB_HUBBUB_ERR | HUBBUB_PAUSED;
|
2012-07-27 19:59:49 +04:00
|
|
|
|
|
|
|
case HTML_SCRIPT_ASYNC:
|
|
|
|
break;
|
2012-07-27 15:01:50 +04:00
|
|
|
|
2012-07-27 19:59:49 +04:00
|
|
|
case HTML_SCRIPT_DEFER:
|
|
|
|
break;
|
2012-07-27 15:01:50 +04:00
|
|
|
|
2012-07-27 19:59:49 +04:00
|
|
|
default:
|
2012-07-30 18:17:57 +04:00
|
|
|
assert(0);
|
2012-07-27 19:59:49 +04:00
|
|
|
}
|
|
|
|
}
|
2012-07-27 15:01:50 +04:00
|
|
|
|
2012-07-27 19:59:49 +04:00
|
|
|
return ret;
|
2012-07-27 15:01:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static dom_hubbub_error
|
|
|
|
exec_inline_script(html_content *c, dom_node *node, dom_string *mimetype)
|
|
|
|
{
|
|
|
|
dom_string *script;
|
|
|
|
dom_exception exc; /* returned by libdom functions */
|
|
|
|
struct lwc_string_s *lwcmimetype;
|
|
|
|
script_handler_t *script_handler;
|
|
|
|
struct html_script *nscript;
|
|
|
|
|
|
|
|
/* does not appear to be a src so script is inline content */
|
|
|
|
exc = dom_node_get_text_content(node, &script);
|
|
|
|
if ((exc != DOM_NO_ERR) || (script == NULL)) {
|
|
|
|
return DOM_HUBBUB_OK; /* no contents, skip */
|
|
|
|
}
|
|
|
|
|
2012-07-27 19:59:49 +04:00
|
|
|
nscript = html_process_new_script(c, mimetype, HTML_SCRIPT_INLINE);
|
2012-07-27 15:01:50 +04:00
|
|
|
if (nscript == NULL) {
|
|
|
|
dom_string_unref(script);
|
|
|
|
|
2017-08-28 13:01:30 +03:00
|
|
|
content_broadcast_errorcode(&c->base, NSERROR_NOMEM);
|
2012-07-27 15:01:50 +04:00
|
|
|
return DOM_HUBBUB_NOMEM;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-07-27 16:53:14 +04:00
|
|
|
nscript->data.string = script;
|
2012-07-27 15:01:50 +04:00
|
|
|
nscript->already_started = true;
|
|
|
|
|
|
|
|
/* ensure script handler for content type */
|
|
|
|
dom_string_intern(mimetype, &lwcmimetype);
|
|
|
|
script_handler = select_script_handler(content_factory_type_from_mime_type(lwcmimetype));
|
|
|
|
lwc_string_unref(lwcmimetype);
|
|
|
|
|
|
|
|
if (script_handler != NULL) {
|
|
|
|
script_handler(c->jscontext,
|
|
|
|
dom_string_data(script),
|
|
|
|
dom_string_byte_length(script));
|
|
|
|
}
|
|
|
|
return DOM_HUBBUB_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-27 16:53:14 +04:00
|
|
|
/**
|
2012-07-27 15:01:50 +04:00
|
|
|
* process script node parser callback
|
2012-07-13 23:19:04 +04:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
dom_hubbub_error
|
|
|
|
html_process_script(void *ctx, dom_node *node)
|
|
|
|
{
|
|
|
|
html_content *c = (html_content *)ctx;
|
|
|
|
dom_exception exc; /* returned by libdom functions */
|
2012-07-27 15:01:50 +04:00
|
|
|
dom_string *src, *mimetype;
|
|
|
|
dom_hubbub_error err = DOM_HUBBUB_OK;
|
2012-07-13 23:19:04 +04:00
|
|
|
|
|
|
|
/* ensure javascript context is available */
|
2016-01-21 17:58:38 +03:00
|
|
|
/* We should only ever be here if scripting was enabled for this
|
|
|
|
* content so it's correct to make a javascript context if there
|
|
|
|
* isn't one already. */
|
2012-07-13 23:19:04 +04:00
|
|
|
if (c->jscontext == NULL) {
|
|
|
|
union content_msg_data msg_data;
|
|
|
|
|
|
|
|
msg_data.jscontext = &c->jscontext;
|
2017-08-26 17:50:03 +03:00
|
|
|
content_broadcast(&c->base, CONTENT_MSG_GETCTX, &msg_data);
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "javascript context %p ", c->jscontext);
|
2012-07-13 23:19:04 +04:00
|
|
|
if (c->jscontext == NULL) {
|
|
|
|
/* no context and it could not be created, abort */
|
|
|
|
return DOM_HUBBUB_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "content %p parser %p node %p", c, c->parser,
|
|
|
|
node);
|
2012-07-13 23:19:04 +04:00
|
|
|
|
2012-07-22 21:58:22 +04:00
|
|
|
exc = dom_element_get_attribute(node, corestring_dom_type, &mimetype);
|
2012-07-13 23:19:04 +04:00
|
|
|
if (exc != DOM_NO_ERR || mimetype == NULL) {
|
2012-07-22 21:58:22 +04:00
|
|
|
mimetype = dom_string_ref(corestring_dom_text_javascript);
|
2012-07-13 23:19:04 +04:00
|
|
|
}
|
|
|
|
|
2012-07-22 21:58:22 +04:00
|
|
|
exc = dom_element_get_attribute(node, corestring_dom_src, &src);
|
2012-07-13 23:19:04 +04:00
|
|
|
if (exc != DOM_NO_ERR || src == NULL) {
|
2012-07-27 15:01:50 +04:00
|
|
|
err = exec_inline_script(c, node, mimetype);
|
2012-07-13 23:19:04 +04:00
|
|
|
} else {
|
2012-07-27 15:01:50 +04:00
|
|
|
err = exec_src_script(c, node, mimetype, src);
|
2012-07-13 23:19:04 +04:00
|
|
|
dom_string_unref(src);
|
|
|
|
}
|
|
|
|
|
2012-07-27 19:59:49 +04:00
|
|
|
dom_string_unref(mimetype);
|
|
|
|
|
2012-07-27 15:01:50 +04:00
|
|
|
return err;
|
2012-07-13 23:19:04 +04:00
|
|
|
}
|
2012-07-27 16:53:14 +04:00
|
|
|
|
2018-05-10 13:34:26 +03:00
|
|
|
/* exported internal interface documented in html/html_internal.h */
|
2015-03-09 16:47:12 +03:00
|
|
|
nserror html_script_free(html_content *html)
|
2012-07-27 16:53:14 +04:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i != html->scripts_count; i++) {
|
|
|
|
if (html->scripts[i].mimetype != NULL) {
|
|
|
|
dom_string_unref(html->scripts[i].mimetype);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((html->scripts[i].type == HTML_SCRIPT_INLINE) &&
|
|
|
|
(html->scripts[i].data.string != NULL)) {
|
|
|
|
|
|
|
|
dom_string_unref(html->scripts[i].data.string);
|
|
|
|
|
|
|
|
} else if ((html->scripts[i].type == HTML_SCRIPT_SYNC) &&
|
|
|
|
(html->scripts[i].data.handle != NULL)) {
|
|
|
|
|
|
|
|
hlcache_handle_release(html->scripts[i].data.handle);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(html->scripts);
|
2015-03-09 16:47:12 +03:00
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
2018-05-10 13:34:26 +03:00
|
|
|
/* exported internal interface documented in html/html_internal.h */
|
2015-03-09 16:47:12 +03:00
|
|
|
nserror html_script_invalidate_ctx(html_content *htmlc)
|
|
|
|
{
|
|
|
|
htmlc->jscontext = NULL;
|
|
|
|
return NSERROR_OK;
|
2012-07-27 16:53:14 +04:00
|
|
|
}
|