Logging: migrate and provide content interface

Migrate the console enums into netsurf/console.h and add
support so that contents can raise a message to log to
the console.

Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
This commit is contained in:
Daniel Silverstone 2019-05-05 21:05:27 +01:00
parent 6952a23946
commit 8474c5d4c0
5 changed files with 83 additions and 38 deletions

View File

@ -33,6 +33,7 @@
#include "content/content_factory.h"
#include "desktop/search.h" /* search flags enum */
#include "netsurf/mouse.h" /* mouse state enums */
#include "netsurf/console.h" /* console state and flags enums */
struct browser_window;
struct browser_window_features;
@ -56,6 +57,7 @@ typedef enum {
/** Used in callbacks to indicate what has occurred. */
typedef enum {
CONTENT_MSG_LOG, /**< Content wishes to log something */
CONTENT_MSG_LOADING, /**< fetching or converting */
CONTENT_MSG_READY, /**< may be displayed */
CONTENT_MSG_DONE, /**< finished */
@ -95,6 +97,13 @@ struct content_rfc5988_link {
/** Extra data for some content_msg messages. */
union content_msg_data {
/** CONTENT_MSG_LOG - Information for logging */
struct {
browser_window_console_source src; /**< The source of the logging */
const char *msg; /**< The message to log */
size_t msglen; /**< The length of that message */
browser_window_console_flags flags; /**< The flags of the logging */
} log;
/** CONTENT_MSG_ERROR - Error message */
const char *error;
/** CONTENT_MSG_ERRORCODE - Error code */

View File

@ -2514,7 +2514,7 @@ static bool html_exec(struct content *c, const char *src, size_t srclen)
dom_text *text_node;
dom_node *spare_node;
dom_html_script_element *script_node;
if (htmlc->document == NULL) {
NSLOG(netsurf, DEEPDEBUG, "Unable to exec, no document");
goto out_no_string;

View File

@ -1358,6 +1358,13 @@ browser_window_callback(hlcache_handle *c,
float sx, sy;
switch (event->type) {
case CONTENT_MSG_LOG:
browser_window_console_log(bw,
event->data.log.src,
event->data.log.msg,
event->data.log.msglen,
event->data.log.flags);
break;
case CONTENT_MSG_DOWNLOAD:
assert(bw->loading_content == c);

View File

@ -30,6 +30,7 @@
#include "utils/errors.h"
#include "netsurf/mouse.h"
#include "netsurf/console.h"
struct browser_window;
struct hlcache_handle;
@ -143,43 +144,6 @@ struct browser_window_features {
} form_features;
};
/**
* Sources of messages which end up in the browser window console
*/
typedef enum {
BW_CS_INPUT, /**< Input from the client */
BW_CS_SCRIPT_ERROR, /**< Error from some running script */
BW_CS_SCRIPT_CONSOLE, /**< Logging from some running script */
} browser_window_console_source;
/**
* Flags for browser window console logging.
*
* It is valid to bitwise-or some of these flags together where indicated.
*/
typedef enum {
/**
* The log entry is foldable.
*
* Set this to indicate that the text should be folded on the first
* newline on display. If this is set but there are no newlines in
* the logged text, the core will unset it before passing on to
* callbacks or storing the log entry.
*/
BW_CS_FLAG_FOLDABLE = 1 << 0,
/** Logged at the 'log' level, please only use one of the LEVEL flags */
BW_CS_FLAG_LEVEL_LOG = 0 << 1,
/** Logged at the 'info' level, please use only one of the LEVEL flags */
BW_CS_FLAG_LEVEL_INFO = 1 << 1,
/** Logged at the 'warn' level, please use only one of the LEVEL flags */
BW_CS_FLAG_LEVEL_WARN = 2 << 1,
/** Logged at the 'error' level, please use only one of the LEVEL flags */
BW_CS_FLAG_LEVEL_ERROR = 3 << 1,
/** Mask for the error level to allow easy comparison using the above */
BW_CS_FLAG_LEVEL_MASK = 3 << 1,
} browser_window_console_flags;
/**
* Create and open a new root browser window with the given page.
*

65
include/netsurf/console.h Normal file
View File

@ -0,0 +1,65 @@
/*
* Copyright 2019 Daniel Silverstone <dsilvers@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/>.
*/
/**
* \file
* Browser window console stuff
*/
#ifndef _NETSURF_CONSOLE_H_
#define _NETSURF_CONSOLE_H_
/**
* Sources of messages which end up in the browser window console
*/
typedef enum {
BW_CS_INPUT, /**< Input from the client */
BW_CS_SCRIPT_ERROR, /**< Error from some running script */
BW_CS_SCRIPT_CONSOLE, /**< Logging from some running script */
} browser_window_console_source;
/**
* Flags for browser window console logging.
*
* It is valid to bitwise-or some of these flags together where indicated.
*/
typedef enum {
/**
* The log entry is foldable.
*
* Set this to indicate that the text should be folded on the first
* newline on display. If this is set but there are no newlines in
* the logged text, the core will unset it before passing on to
* callbacks or storing the log entry.
*/
BW_CS_FLAG_FOLDABLE = 1 << 0,
/** Logged at the 'log' level, please only use one of the LEVEL flags */
BW_CS_FLAG_LEVEL_LOG = 0 << 1,
/** Logged at the 'info' level, please use only one of the LEVEL flags */
BW_CS_FLAG_LEVEL_INFO = 1 << 1,
/** Logged at the 'warn' level, please use only one of the LEVEL flags */
BW_CS_FLAG_LEVEL_WARN = 2 << 1,
/** Logged at the 'error' level, please use only one of the LEVEL flags */
BW_CS_FLAG_LEVEL_ERROR = 3 << 1,
/** Mask for the error level to allow easy comparison using the above */
BW_CS_FLAG_LEVEL_MASK = 3 << 1,
} browser_window_console_flags;
#endif /* _NETSURF_CONSOLE_H_ */