|
Ultralight C++ API 2.0.0
|
#include <Ultralight/OriginRules.h>
A list of origin patterns that controls which pages get an attached API.
When attaching a js::API, dom::Triggers, or dom::data::Context, you pass OriginRules to AttachTo() to choose which web origins get access.
Pass origin rules when attaching an API to allow a remote domain, its subdomains, and local files:
Each rule follows the scheme://host[:port] format. If a rule fails to parse, the attach call fails and returns false.
| Part | Accepts |
|---|---|
| Scheme | An exact scheme with no wildcards |
| Host | An exact host, *, or *.example.com for the domain and all subdomains |
| Port | A specific port number, :* for any port, or default port if omitted |
Common rules illustrate these patterns:
Attach calls restrict page access when you omit origin rules:
Origin rules match only the scheme, host, and port of a page's web origin. Path segments, query strings, and fragment identifiers are never checked.
Origin matching depends on how a document is loaded:
To allow an API on pages that cannot match an origin rule, set a filter on the View using js::SetInjectionFilter() or dom::SetInjectionFilter(). A dom::data::Context has no filter mechanism.
OriginRules refers to rule strings without copying them.
Public Member Functions | |
| constexpr | OriginRules ()=default |
| Create an empty list (the default policy). | |
| constexpr | OriginRules (std::initializer_list< const char * > rules) |
| Create a list from an inline list of rules. | |
| constexpr | OriginRules (const char *const *rules, size_t size) |
| Create a list from an array of rules. | |
| template<typename Rules> requires std::is_convertible_v<const Rules&, std::span<const char* const>> | |
| constexpr | OriginRules (const Rules &rules) |
| Create a list from a contiguous container of rules (eg, a std::vector, std::array, or std::span of const char*). | |
| constexpr const char *const * | data () const |
| Get the rules. | |
| constexpr size_t | size () const |
| Get the number of rules. | |
| constexpr bool | empty () const |
| Whether or not the list is empty. | |
|
constexprdefault |
Create an empty list (the default policy).
|
inlineconstexpr |
Create a list from an inline list of rules.
| rules | The rules, as null-terminated UTF-8 strings. |
|
inlineconstexpr |
|
inlineconstexpr |
Create a list from a contiguous container of rules (eg, a std::vector, std::array, or std::span of const char*).
| rules | The rules, as null-terminated UTF-8 strings. |
|
inlineconstexpr |
Get the rules.
|
inlineconstexpr |
Whether or not the list is empty.
|
inlineconstexpr |
Get the number of rules.