Skip to content

Storage config

Generated from crates/niso-storage/include/storage-config.h when the site was built at 7aa23e2.

This is the storage-config section of niso_runtime.h, owned by niso-storage and kept in crates/niso-storage/include/storage-config.h. The build composes it with the other sections in the order crates/niso-compose/sections.txt gives.

Functions: niso_dom_set_storage_directory, niso_dom_set_storage_driver, niso_dom_set_app_origin

Storage (IndexedDB and localStorage; sessionStorage always lives in memory) is keyed by the document’s origin, and a document with an opaque origin has none. A document whose URL matches about:blank (with any query or fragment), as a native app’s does, has the app’s origin: the origin of the URL given to niso_dom_set_app_origin, which must have a tuple origin (else NISO_SYNTAX_ERROR) and come before script first uses storage (else NISO_INVALID_STATE_ERROR); else https://.app.niso, for the executable’s name. So a host that loads third-party HTML at about:blank hands it the app’s storage: give such a page its own URL. By default storage goes to SQLite files under $NISO_STORAGE_DIR, else a directory named for the executable in the platform’s per-user data directory (Library/Application Support/niso/ on Apple platforms, %APPDATA%/niso/ on Windows, $XDG_DATA_HOME/niso/ or ~/.local/share/niso/ elsewhere), else the temporary directory. Apps that share an executable (every Android app; JVM apps run by java) share these defaults, so their hosts set both. niso_dom_set_storage_directory puts the files under path instead, or keeps everything in memory when len is 0; niso_dom_set_storage_driver hands storage to the host’s own driver, which the DOM copies. Either must come before script first uses storage, else NISO_INVALID_STATE_ERROR. Every function of the driver but drop must be set, else NISO_TYPE_ERROR. The DOM owns the driver’s userdata only once niso_dom_set_storage_driver returns 0, and then calls drop when it lets go of it; on an error the host still owns it.

int32_t niso_dom_set_storage_directory(niso_dom* dom, const char* path, size_t len);
int32_t niso_dom_set_storage_driver(niso_dom* dom, const struct niso_storage_driver* driver);
int32_t niso_dom_set_app_origin(niso_dom* dom, const char* origin, size_t len);