LibIPC+Services: Support URL as a native IPC type

This commit is contained in:
Andreas Kling 2020-06-07 22:54:27 +02:00
parent b81b2a85c4
commit 3654710c41
Notes: sideshowbarker 2024-07-19 05:46:08 +09:00
10 changed files with 26 additions and 16 deletions

View file

@ -244,6 +244,7 @@ int main(int argc, char** argv)
out() << "#pragma once";
out() << "#include <AK/BufferStream.h>";
out() << "#include <AK/OwnPtr.h>";
out() << "#include <AK/URL.h>";
out() << "#include <AK/Utf8View.h>";
out() << "#include <LibGfx/Color.h>";
out() << "#include <LibGfx/Rect.h>";

View file

@ -54,7 +54,7 @@ private:
bool Launcher::open(const URL& url, const String& handler_name)
{
auto connection = LaunchServerConnection::construct();
return connection->send_sync<Messages::LaunchServer::OpenUrl>(url.to_string(), handler_name)->response();
return connection->send_sync<Messages::LaunchServer::OpenURL>(url, handler_name)->response();
}
Vector<String> Launcher::get_handlers_for_url(const URL& url)

View file

@ -25,6 +25,7 @@
*/
#include <AK/BufferStream.h>
#include <AK/URL.h>
#include <LibIPC/Decoder.h>
#include <LibIPC/Dictionary.h>
@ -113,6 +114,15 @@ bool Decoder::decode(String& value)
return !m_stream.handle_read_failure();
}
bool Decoder::decode(URL& value)
{
String string;
if (!decode(string))
return false;
value = URL(string);
return true;
}
bool Decoder::decode(Dictionary& dictionary)
{
u64 size = 0;
@ -136,13 +146,4 @@ bool Decoder::decode(Dictionary& dictionary)
return true;
}
void dongle() {
ByteBuffer buffer;
BufferStream stream(buffer);
Decoder d(stream);
Vector<String> x;
d.decode(x);
}
}

View file

@ -60,6 +60,7 @@ public:
bool decode(i64&);
bool decode(float&);
bool decode(String&);
bool decode(URL&);
bool decode(Dictionary&);
template<typename T>

View file

@ -25,6 +25,7 @@
*/
#include <AK/String.h>
#include <AK/URL.h>
#include <LibIPC/Dictionary.h>
#include <LibIPC/Encoder.h>
@ -140,6 +141,11 @@ Encoder& Encoder::operator<<(const String& value)
return *this << value.view();
}
Encoder& Encoder::operator<<(const URL& value)
{
return *this << value.to_string();
}
Encoder& Encoder::operator<<(const Dictionary& dictionary)
{
*this << (u64)dictionary.size();

View file

@ -58,6 +58,7 @@ public:
Encoder& operator<<(const char*);
Encoder& operator<<(const StringView&);
Encoder& operator<<(const String&);
Encoder& operator<<(const URL&);
Encoder& operator<<(const Dictionary&);
template<typename T>

View file

@ -53,11 +53,11 @@ OwnPtr<Messages::LaunchServer::GreetResponse> ClientConnection::handle(const Mes
return make<Messages::LaunchServer::GreetResponse>(client_id());
}
OwnPtr<Messages::LaunchServer::OpenUrlResponse> ClientConnection::handle(const Messages::LaunchServer::OpenUrl& request)
OwnPtr<Messages::LaunchServer::OpenURLResponse> ClientConnection::handle(const Messages::LaunchServer::OpenURL& request)
{
URL url(request.url());
auto result = Launcher::the().open_url(url, request.handler_name());
return make<Messages::LaunchServer::OpenUrlResponse>(result);
return make<Messages::LaunchServer::OpenURLResponse>(result);
}
OwnPtr<Messages::LaunchServer::GetHandlersForURLResponse> ClientConnection::handle(const Messages::LaunchServer::GetHandlersForURL& request)

View file

@ -43,7 +43,7 @@ private:
explicit ClientConnection(Core::LocalSocket&, int client_id);
virtual OwnPtr<Messages::LaunchServer::GreetResponse> handle(const Messages::LaunchServer::Greet&) override;
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;
};
}

View file

@ -1,6 +1,6 @@
endpoint LaunchServer = 101
{
Greet() => (i32 client_id)
OpenUrl(String url, String handler_name) => (bool response)
GetHandlersForURL(String url) => (Vector<String> handlers)
OpenURL(URL url, String handler_name) => (bool response)
GetHandlersForURL(URL url) => (Vector<String> handlers)
}

View file

@ -10,6 +10,6 @@ endpoint ProtocolServer = 9
IsSupportedProtocol(String protocol) => (bool supported)
// Download API
StartDownload(String url, IPC::Dictionary request_headers) => (i32 download_id)
StartDownload(URL url, IPC::Dictionary request_headers) => (i32 download_id)
StopDownload(i32 download_id) => (bool success)
}