mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:17:44 +00:00
LaunchServer+LibDesktop: Add ability to allow URL without handler
This lets clients say they want to be able to open a specific URL without specifying which handler to use.
This commit is contained in:
parent
43c2b66b18
commit
70c59dcbf8
5 changed files with 48 additions and 18 deletions
|
@ -78,6 +78,16 @@ static LaunchServerConnection& connection()
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Launcher::add_allowed_url(const URL& url)
|
||||||
|
{
|
||||||
|
auto response = connection().send_sync<Messages::LaunchServer::AddAllowedURL>(url);
|
||||||
|
if (!response) {
|
||||||
|
dbgln("Launcher::add_allowed_url: Failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool Launcher::add_allowed_handler_with_any_url(const String& handler)
|
bool Launcher::add_allowed_handler_with_any_url(const String& handler)
|
||||||
{
|
{
|
||||||
auto response = connection().send_sync<Messages::LaunchServer::AddAllowedHandlerWithAnyURL>(handler);
|
auto response = connection().send_sync<Messages::LaunchServer::AddAllowedHandlerWithAnyURL>(handler);
|
||||||
|
@ -98,11 +108,11 @@ bool Launcher::add_allowed_handler_with_only_specific_urls(const String& handler
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Launcher::seal_allowed_handler_list()
|
bool Launcher::seal_allowlist()
|
||||||
{
|
{
|
||||||
auto response = connection().send_sync<Messages::LaunchServer::SealAllowedHandlersList>();
|
auto response = connection().send_sync<Messages::LaunchServer::SealAllowlist>();
|
||||||
if (!response) {
|
if (!response) {
|
||||||
dbgln("Launcher::seal_allowed_handler_list: Failed");
|
dbgln("Launcher::seal_allowlist: Failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -51,9 +51,10 @@ public:
|
||||||
static NonnullRefPtr<Details> from_details_str(const String&);
|
static NonnullRefPtr<Details> from_details_str(const String&);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[[nodiscard]] static bool add_allowed_url(const URL&);
|
||||||
[[nodiscard]] static bool add_allowed_handler_with_any_url(const String& handler);
|
[[nodiscard]] static bool add_allowed_handler_with_any_url(const String& handler);
|
||||||
[[nodiscard]] static bool add_allowed_handler_with_only_specific_urls(const String& handler, const Vector<URL>&);
|
[[nodiscard]] static bool add_allowed_handler_with_only_specific_urls(const String& handler, const Vector<URL>&);
|
||||||
[[nodiscard]] static bool seal_allowed_handler_list();
|
[[nodiscard]] static bool seal_allowlist();
|
||||||
static bool open(const URL&, const String& handler_name = {});
|
static bool open(const URL&, const String& handler_name = {});
|
||||||
static bool open(const URL&, const Details& details);
|
static bool open(const URL&, const Details& details);
|
||||||
static Vector<String> get_handlers_for_url(const URL&);
|
static Vector<String> get_handlers_for_url(const URL&);
|
||||||
|
|
|
@ -55,9 +55,9 @@ OwnPtr<Messages::LaunchServer::GreetResponse> ClientConnection::handle(const Mes
|
||||||
|
|
||||||
OwnPtr<Messages::LaunchServer::OpenURLResponse> ClientConnection::handle(const Messages::LaunchServer::OpenURL& request)
|
OwnPtr<Messages::LaunchServer::OpenURLResponse> ClientConnection::handle(const Messages::LaunchServer::OpenURL& request)
|
||||||
{
|
{
|
||||||
if (!m_allowed_handlers.is_empty()) {
|
if (!m_allowlist.is_empty()) {
|
||||||
bool allowed = false;
|
bool allowed = false;
|
||||||
for (auto& allowed_handler : m_allowed_handlers) {
|
for (auto& allowed_handler : m_allowlist) {
|
||||||
if (allowed_handler.handler_name == request.handler_name()
|
if (allowed_handler.handler_name == request.handler_name()
|
||||||
&& (allowed_handler.any_url || allowed_handler.urls.contains_slow(request.url()))) {
|
&& (allowed_handler.any_url || allowed_handler.urls.contains_slow(request.url()))) {
|
||||||
allowed = true;
|
allowed = true;
|
||||||
|
@ -90,9 +90,26 @@ OwnPtr<Messages::LaunchServer::GetHandlersWithDetailsForURLResponse> ClientConne
|
||||||
return make<Messages::LaunchServer::GetHandlersWithDetailsForURLResponse>(result);
|
return make<Messages::LaunchServer::GetHandlersWithDetailsForURLResponse>(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OwnPtr<Messages::LaunchServer::AddAllowedURLResponse> ClientConnection::handle(const Messages::LaunchServer::AddAllowedURL& request)
|
||||||
|
{
|
||||||
|
if (m_allowlist_is_sealed) {
|
||||||
|
did_misbehave("Got request to add more allowed handlers after list was sealed");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!request.url().is_valid()) {
|
||||||
|
did_misbehave("Got request to allow invalid URL");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_allowlist.empend(String(), false, Vector<URL> { request.url() });
|
||||||
|
|
||||||
|
return make<Messages::LaunchServer::AddAllowedURLResponse>();
|
||||||
|
}
|
||||||
|
|
||||||
OwnPtr<Messages::LaunchServer::AddAllowedHandlerWithAnyURLResponse> ClientConnection::handle(const Messages::LaunchServer::AddAllowedHandlerWithAnyURL& request)
|
OwnPtr<Messages::LaunchServer::AddAllowedHandlerWithAnyURLResponse> ClientConnection::handle(const Messages::LaunchServer::AddAllowedHandlerWithAnyURL& request)
|
||||||
{
|
{
|
||||||
if (m_allowed_handler_list_is_sealed) {
|
if (m_allowlist_is_sealed) {
|
||||||
did_misbehave("Got request to add more allowed handlers after list was sealed");
|
did_misbehave("Got request to add more allowed handlers after list was sealed");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -102,14 +119,14 @@ OwnPtr<Messages::LaunchServer::AddAllowedHandlerWithAnyURLResponse> ClientConnec
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_allowed_handlers.empend(request.handler_name(), true, Vector<URL>());
|
m_allowlist.empend(request.handler_name(), true, Vector<URL>());
|
||||||
|
|
||||||
return make<Messages::LaunchServer::AddAllowedHandlerWithAnyURLResponse>();
|
return make<Messages::LaunchServer::AddAllowedHandlerWithAnyURLResponse>();
|
||||||
}
|
}
|
||||||
|
|
||||||
OwnPtr<Messages::LaunchServer::AddAllowedHandlerWithOnlySpecificURLsResponse> ClientConnection::handle(const Messages::LaunchServer::AddAllowedHandlerWithOnlySpecificURLs& request)
|
OwnPtr<Messages::LaunchServer::AddAllowedHandlerWithOnlySpecificURLsResponse> ClientConnection::handle(const Messages::LaunchServer::AddAllowedHandlerWithOnlySpecificURLs& request)
|
||||||
{
|
{
|
||||||
if (m_allowed_handler_list_is_sealed) {
|
if (m_allowlist_is_sealed) {
|
||||||
did_misbehave("Got request to add more allowed handlers after list was sealed");
|
did_misbehave("Got request to add more allowed handlers after list was sealed");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -124,19 +141,19 @@ OwnPtr<Messages::LaunchServer::AddAllowedHandlerWithOnlySpecificURLsResponse> Cl
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_allowed_handlers.empend(request.handler_name(), false, request.urls());
|
m_allowlist.empend(request.handler_name(), false, request.urls());
|
||||||
|
|
||||||
return make<Messages::LaunchServer::AddAllowedHandlerWithOnlySpecificURLsResponse>();
|
return make<Messages::LaunchServer::AddAllowedHandlerWithOnlySpecificURLsResponse>();
|
||||||
}
|
}
|
||||||
|
|
||||||
OwnPtr<Messages::LaunchServer::SealAllowedHandlersListResponse> ClientConnection::handle(const Messages::LaunchServer::SealAllowedHandlersList&)
|
OwnPtr<Messages::LaunchServer::SealAllowlistResponse> ClientConnection::handle(const Messages::LaunchServer::SealAllowlist&)
|
||||||
{
|
{
|
||||||
if (m_allowed_handler_list_is_sealed) {
|
if (m_allowlist_is_sealed) {
|
||||||
did_misbehave("Got more than one request to seal the allowed handlers list");
|
did_misbehave("Got more than one request to seal the allowed handlers list");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return make<Messages::LaunchServer::SealAllowedHandlersListResponse>();
|
return make<Messages::LaunchServer::SealAllowlistResponse>();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,17 +47,18 @@ private:
|
||||||
virtual OwnPtr<Messages::LaunchServer::OpenURLResponse> handle(const Messages::LaunchServer::OpenURL&) override;
|
virtual OwnPtr<Messages::LaunchServer::OpenURLResponse> handle(const Messages::LaunchServer::OpenURL&) override;
|
||||||
virtual OwnPtr<Messages::LaunchServer::GetHandlersForURLResponse> handle(const Messages::LaunchServer::GetHandlersForURL&) override;
|
virtual OwnPtr<Messages::LaunchServer::GetHandlersForURLResponse> handle(const Messages::LaunchServer::GetHandlersForURL&) override;
|
||||||
virtual OwnPtr<Messages::LaunchServer::GetHandlersWithDetailsForURLResponse> handle(const Messages::LaunchServer::GetHandlersWithDetailsForURL&) override;
|
virtual OwnPtr<Messages::LaunchServer::GetHandlersWithDetailsForURLResponse> handle(const Messages::LaunchServer::GetHandlersWithDetailsForURL&) override;
|
||||||
|
virtual OwnPtr<Messages::LaunchServer::AddAllowedURLResponse> handle(const Messages::LaunchServer::AddAllowedURL&) override;
|
||||||
virtual OwnPtr<Messages::LaunchServer::AddAllowedHandlerWithAnyURLResponse> handle(const Messages::LaunchServer::AddAllowedHandlerWithAnyURL&) override;
|
virtual OwnPtr<Messages::LaunchServer::AddAllowedHandlerWithAnyURLResponse> handle(const Messages::LaunchServer::AddAllowedHandlerWithAnyURL&) override;
|
||||||
virtual OwnPtr<Messages::LaunchServer::AddAllowedHandlerWithOnlySpecificURLsResponse> handle(const Messages::LaunchServer::AddAllowedHandlerWithOnlySpecificURLs&) override;
|
virtual OwnPtr<Messages::LaunchServer::AddAllowedHandlerWithOnlySpecificURLsResponse> handle(const Messages::LaunchServer::AddAllowedHandlerWithOnlySpecificURLs&) override;
|
||||||
virtual OwnPtr<Messages::LaunchServer::SealAllowedHandlersListResponse> handle(const Messages::LaunchServer::SealAllowedHandlersList&) override;
|
virtual OwnPtr<Messages::LaunchServer::SealAllowlistResponse> handle(const Messages::LaunchServer::SealAllowlist&) override;
|
||||||
|
|
||||||
struct AllowedHandler {
|
struct AllowlistEntry {
|
||||||
String handler_name;
|
String handler_name;
|
||||||
bool any_url { false };
|
bool any_url { false };
|
||||||
Vector<URL> urls;
|
Vector<URL> urls;
|
||||||
};
|
};
|
||||||
|
|
||||||
Vector<AllowedHandler> m_allowed_handlers;
|
Vector<AllowlistEntry> m_allowlist;
|
||||||
bool m_allowed_handler_list_is_sealed { false };
|
bool m_allowlist_is_sealed { false };
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,8 @@ endpoint LaunchServer = 101
|
||||||
GetHandlersForURL(URL url) => (Vector<String> handlers)
|
GetHandlersForURL(URL url) => (Vector<String> handlers)
|
||||||
GetHandlersWithDetailsForURL(URL url) => (Vector<String> handlers_details)
|
GetHandlersWithDetailsForURL(URL url) => (Vector<String> handlers_details)
|
||||||
|
|
||||||
|
AddAllowedURL(URL url) => ()
|
||||||
AddAllowedHandlerWithAnyURL(String handler_name) => ()
|
AddAllowedHandlerWithAnyURL(String handler_name) => ()
|
||||||
AddAllowedHandlerWithOnlySpecificURLs(String handler_name, Vector<URL> urls) => ()
|
AddAllowedHandlerWithOnlySpecificURLs(String handler_name, Vector<URL> urls) => ()
|
||||||
SealAllowedHandlersList() => ()
|
SealAllowlist() => ()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue