summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2019-12-01 15:01:24 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2019-12-01 15:01:24 +0000
commit9741df214d7b291c8de40e9b21d4411e523d0bb3 (patch)
tree124a459a6b1ae210d8cee96bb3c3887eaded9844
parent03f72abdb3416fd6fd869beafa03f2c4f3803df0 (diff)
downloadnetsurf-9741df214d7b291c8de40e9b21d4411e523d0bb3.tar.gz
netsurf-9741df214d7b291c8de40e9b21d4411e523d0bb3.tar.bz2
browser_window: Add basic page info state and SSL accessors
In order to begin work on the page info dialog, we need access to the current page's state and SSL chain if available. Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
-rw-r--r--desktop/browser_window.c72
-rw-r--r--include/netsurf/browser_window.h45
2 files changed, 117 insertions, 0 deletions
diff --git a/desktop/browser_window.c b/desktop/browser_window.c
index 28647a44a..a9c277846 100644
--- a/desktop/browser_window.c
+++ b/desktop/browser_window.c
@@ -4638,3 +4638,75 @@ browser_window__reload_current_parameters(struct browser_window *bw)
memset(&bw->current_parameters, 0, sizeof(bw->current_parameters));
return browser_window__navigate_internal(bw, &bw->loading_parameters);
}
+
+/* Exported interface, documented in browser_window.h */
+browser_window_page_info_state browser_window_get_page_info_state(
+ struct browser_window *bw)
+{
+ lwc_string *scheme;
+ bool match;
+
+ assert(bw != NULL);
+
+ /* Do we have any parameters? If not -- UNKNOWN */
+ if (bw->current_parameters.url == NULL) {
+ return PAGE_STATE_UNKNOWN;
+ }
+
+ scheme = nsurl_get_component(bw->current_parameters.url, NSURL_SCHEME);
+
+ /* Is this an internal scheme? */
+ if ((lwc_string_isequal(scheme, corestring_lwc_about,
+ &match) == lwc_error_ok &&
+ (match == true)) ||
+ (lwc_string_isequal(scheme, corestring_lwc_data,
+ &match) == lwc_error_ok &&
+ (match == true)) ||
+ (lwc_string_isequal(scheme, corestring_lwc_resource,
+ &match) == lwc_error_ok &&
+ (match == true))) {
+ return PAGE_STATE_INTERNAL;
+ }
+
+ /* Is this file:/// ? */
+ if (lwc_string_isequal(scheme, corestring_lwc_file,
+ &match) == lwc_error_ok &&
+ match == true) {
+ return PAGE_STATE_LOCAL;
+ }
+
+ /* If not https, from here on down that'd be insecure */
+ if ((lwc_string_isequal(scheme, corestring_lwc_https,
+ &match) == lwc_error_ok &&
+ (match == false))) {
+ /* Some remote content, not https, therefore insecure */
+ return PAGE_STATE_INSECURE;
+ }
+
+ /* Did we have to override this SSL setting? */
+ if (urldb_get_cert_permissions(bw->current_parameters.url)) {
+ return PAGE_STATE_SECURE_OVERRIDE;
+ }
+
+ /** \todo Determine if sub-elements of this fetch were insecure */
+ /* If so, return PAGE_STATE_SECURE_ISSUES */
+
+ /* All is well, return secure state */
+ return PAGE_STATE_SECURE;
+}
+
+/* Exported interface, documented in browser_window.h */
+nserror browser_window_get_ssl_chain(struct browser_window *bw, size_t *num,
+ struct ssl_cert_info **chain)
+{
+ assert(bw != NULL);
+
+ if (bw->current_ssl_info.num == 0) {
+ return NSERROR_NOT_FOUND;
+ }
+
+ *num = bw->current_ssl_info.num;
+ *chain = &(bw->current_ssl_info.certs[0]);
+
+ return NSERROR_OK;
+}
diff --git a/include/netsurf/browser_window.h b/include/netsurf/browser_window.h
index 9bb191c3f..98139aa02 100644
--- a/include/netsurf/browser_window.h
+++ b/include/netsurf/browser_window.h
@@ -42,6 +42,7 @@ struct form_control;
struct nsurl;
struct rect;
struct redraw_context;
+struct ssl_cert_info;
enum content_debug;
/**
@@ -58,6 +59,19 @@ typedef enum {
DRAGGING_OTHER
} browser_drag_type;
+/**
+ * Browser window page information states
+ */
+typedef enum {
+ PAGE_STATE_UNKNOWN, /**< Unable to determine */
+ PAGE_STATE_INTERNAL, /**< Page loaded from internal handler */
+ PAGE_STATE_LOCAL, /**< Page loaded from file:/// etc */
+ PAGE_STATE_INSECURE, /**< Insecure page load */
+ PAGE_STATE_SECURE_OVERRIDE, /**< Secure load, but had to override */
+ PAGE_STATE_SECURE_ISSUES, /**< Secure load, but has insecure elements */
+ PAGE_STATE_SECURE, /**< Secure load */
+} browser_window_page_info_state;
+
typedef enum {
BW_EDITOR_NONE = 0, /**< No selection, no editing */
BW_EDITOR_CAN_COPY = (1 << 0), /**< Have selection */
@@ -740,4 +754,35 @@ nserror browser_window_console_log(struct browser_window *bw,
size_t msglen,
browser_window_console_flags flags);
+/**
+ * Request the current browser window page info state.
+ *
+ * The page information state is an indicator enumeration to be used by
+ * frontends to indicate to the user if the page they are viewing is able
+ * to be trusted. This is often shown as a padlock of some kind.
+ *
+ * This is also used by the internal page information corewindow to render
+ * to the user what the situation is.
+ *
+ * \param bw The browser window
+ * \return The state of the browser window
+ */
+browser_window_page_info_state browser_window_get_page_info_state(
+ struct browser_window *bw);
+
+/**
+ * Request the current browser window SSL certificate chain.
+ *
+ * When the page has SSL information, this will retrieve the certificate chain.
+ *
+ * If there is no chain available, this will return NSERROR_NOT_FOUND
+ *
+ * \param bw The browser window
+ * \param num Pointer to be filled out with chain length
+ * \param chain Pointer to be filled out with chain base
+ * \return Whether or not the chain is available
+ */
+nserror browser_window_get_ssl_chain(struct browser_window *bw, size_t *num,
+ struct ssl_cert_info **chain);
+
#endif