Slick Trader 0.11.0
Multi-broker algorithmic trading engine with plugin strategies and a live web dashboard
Loading...
Searching...
No Matches
browser_policy.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <nlohmann/json.hpp>
4#include <array>
5#include <cstdint>
6#include <span>
7#include <string>
8#include <string_view>
9
10namespace slick::trader {
11
12// Chrome and Edge let a click open one pop-up, unless the site may open them: a workspace opens
13// several at once. These URL list policies, under HKCU, name the sites that may. Each entry is a
14// REG_SZ value named "1", "2", ..., read up to the first number missing.
15inline constexpr std::string_view EDGE_POPUPS_KEY = R"(Software\Policies\Microsoft\Edge\PopupsAllowedForUrls)";
16inline constexpr std::string_view CHROME_POPUPS_KEY = R"(Software\Policies\Google\Chrome\PopupsAllowedForUrls)";
17inline constexpr std::array<std::string_view, 2> POPUP_POLICY_KEYS{EDGE_POPUPS_KEY, CHROME_POPUPS_KEY};
18
19// Some APIs are for secure origins only: https, and http on localhost. Placing a workspace's windows
20// on other screens is one. These list origins to treat as secure too, as the flag "Insecure origins
21// treated as secure" does, in the same format.
22inline constexpr std::string_view EDGE_SECURE_KEY =
23 R"(Software\Policies\Microsoft\Edge\OverrideSecurityRestrictionsOnInsecureOrigin)";
24inline constexpr std::string_view CHROME_SECURE_KEY =
25 R"(Software\Policies\Google\Chrome\OverrideSecurityRestrictionsOnInsecureOrigin)";
26inline constexpr std::array<std::string_view, 2> SECURE_POLICY_KEYS{EDGE_SECURE_KEY, CHROME_SECURE_KEY};
27
28// "http://<ip>:<port>", an IPv6 address in brackets. Empty unless `ip` is an address or host name
29// and `port` is 1..65535.
30std::string dashboard_origin(std::string_view ip, int64_t port);
31
32enum class PolicyUrl { ADDED, LISTED, FAILED };
33
34// Lists `url` in the URL list policy at HKCU<key>, under the lowest number no entry holds.
35// FAILED, with `error`, when the key can't be written, and anywhere but Windows.
36PolicyUrl add_policy_url(std::string_view key, std::string_view url, std::string& error);
37
38// When `config` has `setting`, {"ip": ..., "port": ...}, lists that origin in each of `keys` and
39// logs what it did. `ip` defaults to localhost, `port` to `default_port`.
40void list_origin(const nlohmann::json& config, std::string_view setting, int64_t default_port,
41 std::span<const std::string_view> keys);
42
43} // namespace slick::trader
constexpr std::string_view EDGE_POPUPS_KEY
constexpr std::array< std::string_view, 2 > SECURE_POLICY_KEYS
std::string dashboard_origin(std::string_view ip, int64_t port)
constexpr std::array< std::string_view, 2 > POPUP_POLICY_KEYS
PolicyUrl add_policy_url(std::string_view key, std::string_view url, std::string &error)
void list_origin(const nlohmann::json &config, std::string_view setting, int64_t default_port, std::span< const std::string_view > keys)
constexpr std::string_view CHROME_POPUPS_KEY
constexpr std::string_view CHROME_SECURE_KEY
constexpr std::string_view EDGE_SECURE_KEY