summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-01-03 12:03:13 +0100
committerAndreas Kling <kling@serenityos.org>2021-01-03 12:10:01 +0100
commit70c59dcbf85dc9ba87140952c44be4cdc8c70f08 (patch)
tree534f5d617bd2d45074d5b673d0e7045cb8447fcc
parent43c2b66b18410d9be6f0205bd2ae11abe90c484c (diff)
downloadserenity-70c59dcbf85dc9ba87140952c44be4cdc8c70f08.zip
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.
-rw-r--r--Libraries/LibDesktop/Launcher.cpp16
-rw-r--r--Libraries/LibDesktop/Launcher.h3
-rw-r--r--Services/LaunchServer/ClientConnection.cpp35
-rw-r--r--Services/LaunchServer/ClientConnection.h9
-rw-r--r--Services/LaunchServer/LaunchServer.ipc3
5 files changed, 48 insertions, 18 deletions
diff --git a/Libraries/LibDesktop/Launcher.cpp b/Libraries/LibDesktop/Launcher.cpp
index 740756c9bf..04e170745f 100644
--- a/Libraries/LibDesktop/Launcher.cpp
+++ b/Libraries/LibDesktop/Launcher.cpp
@@ -78,6 +78,16 @@ static LaunchServerConnection& 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)
{
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;
}
-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) {
- dbgln("Launcher::seal_allowed_handler_list: Failed");
+ dbgln("Launcher::seal_allowlist: Failed");
return false;
}
return true;
diff --git a/Libraries/LibDesktop/Launcher.h b/Libraries/LibDesktop/Launcher.h
index d8412f3ec7..130ca155fc 100644
--- a/Libraries/LibDesktop/Launcher.h
+++ b/Libraries/LibDesktop/Launcher.h
@@ -51,9 +51,10 @@ public:
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_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 Details& details);
static Vector<String> get_handlers_for_url(const URL&);
diff --git a/Services/LaunchServer/ClientConnection.cpp b/Services/LaunchServer/ClientConnection.cpp
index 5c2fbe86be..65f705e0c7 100644
--- a/Services/LaunchServer/ClientConnection.cpp
+++ b/Services/LaunchServer/ClientConnection.cpp
@@ -55,9 +55,9 @@ OwnPtr<Messages::LaunchServer::GreetResponse> ClientConnection::handle(const Mes
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;
- for (auto& allowed_handler : m_allowed_handlers) {
+ for (auto& allowed_handler : m_allowlist) {
if (allowed_handler.handler_name == request.handler_name()
&& (allowed_handler.any_url || allowed_handler.urls.contains_slow(request.url()))) {
allowed = true;
@@ -90,9 +90,26 @@ OwnPtr<Messages::LaunchServer::GetHandlersWithDetailsForURLResponse> ClientConne
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)
{
- 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");
return nullptr;
}
@@ -102,14 +119,14 @@ OwnPtr<Messages::LaunchServer::AddAllowedHandlerWithAnyURLResponse> ClientConnec
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>();
}
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");
return nullptr;
}
@@ -124,19 +141,19 @@ OwnPtr<Messages::LaunchServer::AddAllowedHandlerWithOnlySpecificURLsResponse> Cl
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>();
}
-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");
return nullptr;
}
- return make<Messages::LaunchServer::SealAllowedHandlersListResponse>();
+ return make<Messages::LaunchServer::SealAllowlistResponse>();
}
}
diff --git a/Services/LaunchServer/ClientConnection.h b/Services/LaunchServer/ClientConnection.h
index 9f7c7d2bb5..77eef53374 100644
--- a/Services/LaunchServer/ClientConnection.h
+++ b/Services/LaunchServer/ClientConnection.h
@@ -47,17 +47,18 @@ private:
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::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::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;
bool any_url { false };
Vector<URL> urls;
};
- Vector<AllowedHandler> m_allowed_handlers;
- bool m_allowed_handler_list_is_sealed { false };
+ Vector<AllowlistEntry> m_allowlist;
+ bool m_allowlist_is_sealed { false };
};
}
diff --git a/Services/LaunchServer/LaunchServer.ipc b/Services/LaunchServer/LaunchServer.ipc
index 154198f1d2..4f50221f4b 100644
--- a/Services/LaunchServer/LaunchServer.ipc
+++ b/Services/LaunchServer/LaunchServer.ipc
@@ -5,7 +5,8 @@ endpoint LaunchServer = 101
GetHandlersForURL(URL url) => (Vector<String> handlers)
GetHandlersWithDetailsForURL(URL url) => (Vector<String> handlers_details)
+ AddAllowedURL(URL url) => ()
AddAllowedHandlerWithAnyURL(String handler_name) => ()
AddAllowedHandlerWithOnlySpecificURLs(String handler_name, Vector<URL> urls) => ()
- SealAllowedHandlersList() => ()
+ SealAllowlist() => ()
}