Пример #1
0
/* attempt defer and async script execution
 *
 * execute scripts using algorithm found in:
 * http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.html#the-script-element
 *
 */
bool html_scripts_exec(html_content *c)
{
	unsigned int i;
	struct html_script *s;
	script_handler_t *script_handler;

	if (c->jscontext == NULL)
		return false;

	for (i = 0, s = c->scripts; i != c->scripts_count; i++, s++) {
		if (s->already_started) {
			continue;
		}

		if ((s->type == HTML_SCRIPT_ASYNC) ||
		    (s->type == HTML_SCRIPT_DEFER)) {
			/* ensure script content is present */
			if (s->data.handle == NULL)
				continue;

			/* ensure script content fetch status is not an error */
			if (content_get_status(s->data.handle) ==
					CONTENT_STATUS_ERROR)
				continue;

			/* ensure script handler for content type */
			script_handler = select_script_handler(
					content_get_type(s->data.handle));
			if (script_handler == NULL)
				continue; /* unsupported type */

			if (content_get_status(s->data.handle) ==
					CONTENT_STATUS_DONE) {
				/* external script is now available */
				const char *data;
				unsigned long size;
				data = content_get_source_data(
						s->data.handle, &size );
				script_handler(c->jscontext, data, size);

				s->already_started = true;

			} 
		}
	}

	return true;
}
Пример #2
0
static dom_hubbub_error
exec_inline_script(html_content *c, dom_node *node, dom_string *mimetype)
{
	union content_msg_data msg_data;
	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 */
	}

	nscript = html_process_new_script(c, mimetype, HTML_SCRIPT_INLINE);
	if (nscript == NULL) {
		dom_string_unref(script);

		msg_data.error = messages_get("NoMemory");
		content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
		return DOM_HUBBUB_NOMEM;

	}

	nscript->data.string = script;
	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;
}
Пример #3
0
//Kommunikation
void command(uint8_t *buf) {
	uint8_t m_comand = buf[0];
	struct rgb rgb_color;
	struct hsv hsv_color;
		
	switch (m_comand) {
		case mpxl_cmd_off:
			led_off();
			break;
				
		case mpxl_cmd_on:
			led_on();
			break;
				
		case mpxl_cmd_setRGB:
			rgb_color.Red = buf[1];
			rgb_color.Green = buf[2];
			rgb_color.Blue = buf[3];
			set_led_color(&rgb_color);
			break;
			
		case mpxl_cmd_setHSV:
			hsv_color.hsv[0] = buf[1];
			hsv_color.hsv[1] = buf[2];
			hsv_color.saturation = buf[3];
			hsv_color.value = buf[4];
			hsv2rgb(&hsv_color,&rgb_color);
			set_led_color(&rgb_color);
			break;
			
	   case mpxl_cmd_fade:
			rgb_color.Red = buf[1];
 			rgb_color.Green = buf[2];
 			rgb_color.Blue = buf[3];
 			rgb_fade_int(rgb_color, buf[4]);
 			
		case mpxl_cmd_script:
			script_handler(buf);
			break;
	}		
}
Пример #4
0
/**
 * 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;
	script_handler_t *script_handler;
	dom_hubbub_error err;

	/* Find script */
	for (i = 0, s = parent->scripts; i != parent->scripts_count; i++, s++) {
		if (s->type == HTML_SCRIPT_SYNC && s->data.handle == script)
			break;
	}

	assert(i != parent->scripts_count);

	switch (event->type) {
	case CONTENT_MSG_LOADING:
		break;

	case CONTENT_MSG_READY:
		break;

	case CONTENT_MSG_DONE:
		LOG(("script %d done '%s'", i,
				nsurl_access(hlcache_handle_get_url(script))));
		parent->base.active--;
		LOG(("%d fetches active", parent->base.active));

		s->already_started = true;

		/* attempt to execute script */
		script_handler = select_script_handler(content_get_type(s->data.handle));
		if (script_handler != NULL) {
			/* script has a handler */
			const char *data;
			unsigned long size;
			data = content_get_source_data(s->data.handle, &size );
			script_handler(parent->jscontext, data, size);
		}

		/* continue parse */
		err = dom_hubbub_parser_pause(parent->parser, false);
		if (err != DOM_HUBBUB_OK) {
			LOG(("unpause returned 0x%x", err));
		} 

		break;

	case CONTENT_MSG_ERROR:
		LOG(("script %s failed: %s",
				nsurl_access(hlcache_handle_get_url(script)),
				event->data.error));

		hlcache_handle_release(script);
		s->data.handle = NULL;
		parent->base.active--;

		LOG(("%d fetches active", parent->base.active));
		content_add_error(&parent->base, "?", 0);

		s->already_started = true;

		/* continue parse */
		err = dom_hubbub_parser_pause(parent->parser, false);
		if (err != DOM_HUBBUB_OK) {
			LOG(("unpause returned 0x%x", err));
		} 

		break;

	case CONTENT_MSG_STATUS:
		break;

	default:
		assert(0);
	}

	/* if there are no active fetches remaining begin post parse
	 * conversion
	 */
	if (html_can_begin_conversion(parent)) {
		html_begin_conversion(parent);
	}

	return NSERROR_OK;
}