Skip to content

Commit

Permalink
refactor: limit symbol visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Curve committed Aug 7, 2024
1 parent 9d1d3c5 commit c0e957d
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 93 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build
include/saucer/export.h

.vs
.cache
Expand Down
17 changes: 16 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ project(saucer-bindings LANGUAGES CXX VERSION 3.0.0)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)

# --------------------------------------------------------------------------------------------------------
# Create executable
# --------------------------------------------------------------------------------------------------------
Expand All @@ -15,13 +19,24 @@ add_library(${PROJECT_NAME} SHARED)
add_library(saucer::bindings ALIAS ${PROJECT_NAME})

target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_23)
set_target_properties(${PROJECT_NAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 23 CXX_EXTENSIONS OFF CXX_STANDARD_REQUIRED ON)

if (PROJECT_IS_TOP_LEVEL AND NOT MSVC AND NOT CMAKE_CXX_SIMULATE_ID MATCHES "MSVC")
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic -Werror -pedantic -pedantic-errors -Wfatal-errors)
endif()

# --------------------------------------------------------------------------------------------------------
# Export header
# --------------------------------------------------------------------------------------------------------

include(GenerateExportHeader)

generate_export_header(
${PROJECT_NAME}
EXPORT_MACRO_NAME "SAUCER_EXPORT"
EXPORT_FILE_NAME "${CMAKE_CURRENT_SOURCE_DIR}/include/saucer/export.h"
)

# --------------------------------------------------------------------------------------------------------
# Include directories
# --------------------------------------------------------------------------------------------------------
Expand Down
10 changes: 6 additions & 4 deletions include/saucer/icon.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,29 @@ extern "C"
{
#endif

#include "export.h"

#include "stash.h"
#include <stdbool.h>

struct saucer_icon;

void saucer_icon_free(saucer_icon *);
bool saucer_icon_empty(saucer_icon *);
SAUCER_EXPORT void saucer_icon_free(saucer_icon *);
SAUCER_EXPORT bool saucer_icon_empty(saucer_icon *);

/**
* @brief Try to construct an icon from a given file.
* @note The pointer pointed to by @param result will be set to a saucer_icon in case of success. The returned icon
* must be free'd.
*/
void saucer_icon_from_file(saucer_icon **result, const char *file);
SAUCER_EXPORT void saucer_icon_from_file(saucer_icon **result, const char *file);

/**
* @brief Try to construct an icon from a given stash (raw bytes).
* @note The pointer pointed to by @param result will be set to a saucer_icon in case of success. The returned icon
* must be free'd.
*/
void saucer_icon_from_data(saucer_icon **result, saucer_stash *stash);
SAUCER_EXPORT void saucer_icon_from_data(saucer_icon **result, saucer_stash *stash);

#ifdef __cplusplus
}
Expand Down
6 changes: 4 additions & 2 deletions include/saucer/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ extern "C"
{
#endif

#include "export.h"

#include <stddef.h>

void saucer_memory_free(void *data);
void *saucer_memory_alloc(size_t size);
SAUCER_EXPORT void saucer_memory_free(void *data);
SAUCER_EXPORT void *saucer_memory_alloc(size_t size);

#ifdef __cplusplus
}
Expand Down
14 changes: 8 additions & 6 deletions include/saucer/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ extern "C"
{
#endif

#include "export.h"

#include <stddef.h>

struct saucer_options;

saucer_options *saucer_options_new();
void saucer_options_free(saucer_options *);
SAUCER_EXPORT saucer_options *saucer_options_new();
SAUCER_EXPORT void saucer_options_free(saucer_options *);

void saucer_options_set_persistent_cookies(saucer_options *, bool enabled);
void saucer_options_set_hardware_acceleration(saucer_options *, bool enabled);
SAUCER_EXPORT void saucer_options_set_persistent_cookies(saucer_options *, bool enabled);
SAUCER_EXPORT void saucer_options_set_hardware_acceleration(saucer_options *, bool enabled);

void saucer_options_set_storage_path(saucer_options *, const char *path);
void saucer_options_add_chrome_flag(saucer_options *, const char *flag);
SAUCER_EXPORT void saucer_options_set_storage_path(saucer_options *, const char *path);
SAUCER_EXPORT void saucer_options_add_chrome_flag(saucer_options *, const char *flag);

#ifdef __cplusplus
}
Expand Down
18 changes: 10 additions & 8 deletions include/saucer/scheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ extern "C"
{
#endif

#include "export.h"

#include "stash.h"
#include "window.h"

Expand All @@ -19,24 +21,24 @@ extern "C"

struct saucer_response;

saucer_response *saucer_response_new(saucer_stash *data, const char *mime);
saucer_response *saucer_response_unexpected(SAUCER_REQUEST_ERROR error);
SAUCER_EXPORT saucer_response *saucer_response_new(saucer_stash *data, const char *mime);
SAUCER_EXPORT saucer_response *saucer_response_unexpected(SAUCER_REQUEST_ERROR error);

/**
* @note Under normal circumstances this function should not be used. Once a saucer_response is
* returned from within a saucer_scheme_handler it is automatically deleted.
* You may use this function to free the response in case of an exception.
*/
void saucer_response_free(saucer_response *);
SAUCER_EXPORT void saucer_response_free(saucer_response *);

void saucer_response_add_header(saucer_response *, const char *header, const char *value);
SAUCER_EXPORT void saucer_response_add_header(saucer_response *, const char *header, const char *value);

struct saucer_request;

/*[[sc::requires_free]]*/ char *saucer_request_url(saucer_request *);
/*[[sc::requires_free]]*/ char *saucer_request_method(saucer_request *);
/*[[sc::requires_free]]*/ SAUCER_EXPORT char *saucer_request_url(saucer_request *);
/*[[sc::requires_free]]*/ SAUCER_EXPORT char *saucer_request_method(saucer_request *);

/*[[sc::requires_free]]*/ saucer_stash *saucer_request_content(saucer_request *);
/*[[sc::requires_free]]*/ SAUCER_EXPORT saucer_stash *saucer_request_content(saucer_request *);

/**
* @note The arrays pointed to by @param headers and @param values will be populated with strings which are
Expand All @@ -46,7 +48,7 @@ extern "C"
* - Free all strings within the headers and values array
* - Free the array itself
*/
void saucer_request_headers(saucer_request *, char ***headers, char ***values, size_t *count);
SAUCER_EXPORT void saucer_request_headers(saucer_request *, char ***headers, char ***values, size_t *count);

typedef saucer_response *(*saucer_scheme_handler)(saucer_handle *, saucer_request *);

Expand Down
14 changes: 8 additions & 6 deletions include/saucer/stash.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,28 @@ extern "C"
{
#endif

#include "export.h"

#include <stdint.h>
#include <stddef.h>

struct saucer_stash;

void saucer_stash_free(saucer_stash *);
SAUCER_EXPORT void saucer_stash_free(saucer_stash *);

size_t saucer_stash_size(saucer_stash *);
const uint8_t *saucer_stash_data(saucer_stash *);
SAUCER_EXPORT size_t saucer_stash_size(saucer_stash *);
SAUCER_EXPORT const uint8_t *saucer_stash_data(saucer_stash *);

saucer_stash *saucer_stash_from(const uint8_t *data, size_t size);
saucer_stash *saucer_stash_view(const uint8_t *data, size_t size);
SAUCER_EXPORT saucer_stash *saucer_stash_from(const uint8_t *data, size_t size);
SAUCER_EXPORT saucer_stash *saucer_stash_view(const uint8_t *data, size_t size);

typedef saucer_stash *(*saucer_stash_lazy_callback)();

/**
* @note The stash returned from within the @param callback is automatically deleted. However, the stash returned
* from this function must still be free'd accordingly.
*/
saucer_stash *saucer_stash_lazy(saucer_stash_lazy_callback callback);
SAUCER_EXPORT saucer_stash *saucer_stash_lazy(saucer_stash_lazy_callback callback);

#ifdef __cplusplus
}
Expand Down
68 changes: 35 additions & 33 deletions include/saucer/webview.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ extern "C"
{
#endif

#include "export.h"

#include "window.h"
#include "scheme.h"

Expand All @@ -30,54 +32,54 @@ extern "C"

struct saucer_embedded_file;

/*[[sc::requires_free]]*/ saucer_embedded_file *saucer_embed(saucer_stash *content, const char *mime);
void saucer_embed_free(saucer_embedded_file *);
/*[[sc::requires_free]]*/ SAUCER_EXPORT saucer_embedded_file *saucer_embed(saucer_stash *content, const char *mime);
SAUCER_EXPORT void saucer_embed_free(saucer_embedded_file *);

/*[[sc::requires_free]]*/ saucer_handle *saucer_new(saucer_options *options);
void saucer_free(saucer_handle *);
/*[[sc::requires_free]]*/ SAUCER_EXPORT saucer_handle *saucer_new(saucer_options *options);
SAUCER_EXPORT void saucer_free(saucer_handle *);

typedef bool (*saucer_on_message)(const char *);
void saucer_webview_on_message(saucer_handle *, saucer_on_message callback);
SAUCER_EXPORT void saucer_webview_on_message(saucer_handle *, saucer_on_message callback);

/*[[sc::requires_free]]*/ saucer_icon *saucer_webview_favicon(saucer_handle *);
/*[[sc::requires_free]]*/ char *saucer_webview_page_title(saucer_handle *);
/*[[sc::requires_free]]*/ SAUCER_EXPORT saucer_icon *saucer_webview_favicon(saucer_handle *);
/*[[sc::requires_free]]*/ SAUCER_EXPORT char *saucer_webview_page_title(saucer_handle *);

bool saucer_webview_dev_tools(saucer_handle *);
/*[[sc::requires_free]]*/ char *saucer_webview_url(saucer_handle *);
bool saucer_webview_context_menu(saucer_handle *);
SAUCER_EXPORT bool saucer_webview_dev_tools(saucer_handle *);
/*[[sc::requires_free]]*/ SAUCER_EXPORT char *saucer_webview_url(saucer_handle *);
SAUCER_EXPORT bool saucer_webview_context_menu(saucer_handle *);

void saucer_webview_background(saucer_handle *, uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *a);
bool saucer_webview_force_dark_mode(saucer_handle *);
SAUCER_EXPORT void saucer_webview_background(saucer_handle *, uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *a);
SAUCER_EXPORT bool saucer_webview_force_dark_mode(saucer_handle *);

void saucer_webview_set_dev_tools(saucer_handle *, bool enabled);
void saucer_webview_set_context_menu(saucer_handle *, bool enabled);
SAUCER_EXPORT void saucer_webview_set_dev_tools(saucer_handle *, bool enabled);
SAUCER_EXPORT void saucer_webview_set_context_menu(saucer_handle *, bool enabled);

void saucer_webview_set_force_dark_mode(saucer_handle *, bool enabled);
void saucer_webview_set_background(saucer_handle *, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
SAUCER_EXPORT void saucer_webview_set_force_dark_mode(saucer_handle *, bool enabled);
SAUCER_EXPORT void saucer_webview_set_background(saucer_handle *, uint8_t r, uint8_t g, uint8_t b, uint8_t a);

void saucer_webview_set_file(saucer_handle *, const char *file);
void saucer_webview_set_url(saucer_handle *, const char *url);
SAUCER_EXPORT void saucer_webview_set_file(saucer_handle *, const char *file);
SAUCER_EXPORT void saucer_webview_set_url(saucer_handle *, const char *url);

void saucer_webview_embed_file(saucer_handle *, const char *name, saucer_embedded_file *file);
void saucer_webview_serve(saucer_handle *, const char *file);
void saucer_webview_serve_scheme(saucer_handle *, const char *file, const char *scheme);
SAUCER_EXPORT void saucer_webview_embed_file(saucer_handle *, const char *name, saucer_embedded_file *file);
SAUCER_EXPORT void saucer_webview_serve(saucer_handle *, const char *file);
SAUCER_EXPORT void saucer_webview_serve_scheme(saucer_handle *, const char *file, const char *scheme);

void saucer_webview_clear_scripts(saucer_handle *);
SAUCER_EXPORT void saucer_webview_clear_scripts(saucer_handle *);

void saucer_webview_clear_embedded(saucer_handle *);
void saucer_webview_clear_embedded_file(saucer_handle *, const char *file);
SAUCER_EXPORT void saucer_webview_clear_embedded(saucer_handle *);
SAUCER_EXPORT void saucer_webview_clear_embedded_file(saucer_handle *, const char *file);

void saucer_webview_execute(saucer_handle *, const char *java_script);
void saucer_webview_inject(saucer_handle *, const char *java_script, SAUCER_LOAD_TIME load_time);
SAUCER_EXPORT void saucer_webview_execute(saucer_handle *, const char *java_script);
SAUCER_EXPORT void saucer_webview_inject(saucer_handle *, const char *java_script, SAUCER_LOAD_TIME load_time);

/**
* @note The stash returned from within the @param handler is automatically free'd
*/
void saucer_webview_handle_scheme(saucer_handle *, const char *name, saucer_scheme_handler handler);
void saucer_webview_remove_scheme(saucer_handle *, const char *name);
SAUCER_EXPORT void saucer_webview_handle_scheme(saucer_handle *, const char *name, saucer_scheme_handler handler);
SAUCER_EXPORT void saucer_webview_remove_scheme(saucer_handle *, const char *name);

void saucer_webview_clear(saucer_handle *, SAUCER_WEB_EVENT event);
void saucer_webview_remove(saucer_handle *, SAUCER_WEB_EVENT event, uint64_t id);
SAUCER_EXPORT void saucer_webview_clear(saucer_handle *, SAUCER_WEB_EVENT event);
SAUCER_EXPORT void saucer_webview_remove(saucer_handle *, SAUCER_WEB_EVENT event, uint64_t id);

/**
* @note The @param callback should be a function pointer to a function matching the event, that is:
Expand All @@ -89,10 +91,10 @@ extern "C"
* @example web_event::title_changed => void(*)(saucer_handle *, const char *)
*/

void saucer_webview_once(saucer_handle *, SAUCER_WEB_EVENT event, void *callback);
uint64_t saucer_webview_on(saucer_handle *, SAUCER_WEB_EVENT event, void *callback);
SAUCER_EXPORT void saucer_webview_once(saucer_handle *, SAUCER_WEB_EVENT event, void *callback);
SAUCER_EXPORT uint64_t saucer_webview_on(saucer_handle *, SAUCER_WEB_EVENT event, void *callback);

/*[[sc::before_init]]*/ void saucer_register_scheme(const char *name);
/*[[sc::before_init]]*/ SAUCER_EXPORT void saucer_register_scheme(const char *name);

#ifdef __cplusplus
}
Expand Down
Loading

0 comments on commit c0e957d

Please sign in to comment.