mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 02:48:11 +00:00
WindowServer: Post error messages to clients on protocol failure.
This commit is contained in:
parent
f33f094483
commit
222a6f7bbc
4 changed files with 53 additions and 17 deletions
|
@ -58,6 +58,7 @@ struct GUI_KeyModifiers { enum {
|
||||||
struct GUI_ServerMessage {
|
struct GUI_ServerMessage {
|
||||||
enum Type : unsigned {
|
enum Type : unsigned {
|
||||||
Invalid,
|
Invalid,
|
||||||
|
Error,
|
||||||
Paint,
|
Paint,
|
||||||
MouseMove,
|
MouseMove,
|
||||||
MouseDown,
|
MouseDown,
|
||||||
|
|
|
@ -232,6 +232,14 @@ void GEventLoop::wait_for_event()
|
||||||
|
|
||||||
auto unprocessed_events = move(m_unprocessed_messages);
|
auto unprocessed_events = move(m_unprocessed_messages);
|
||||||
for (auto& event : unprocessed_events) {
|
for (auto& event : unprocessed_events) {
|
||||||
|
|
||||||
|
if (event.type == GUI_ServerMessage::Error) {
|
||||||
|
dbgprintf("GEventLoop got error message from server\n");
|
||||||
|
dbgprintf(" - error message: %s\n", String(event.text, event.text_length).characters());
|
||||||
|
exit(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case GUI_ServerMessage::MenuItemActivated:
|
case GUI_ServerMessage::MenuItemActivated:
|
||||||
handle_menu_event(event);
|
handle_menu_event(event);
|
||||||
|
|
|
@ -46,6 +46,17 @@ WSClientConnection::~WSClientConnection()
|
||||||
s_connections->resource().remove(m_client_id);
|
s_connections->resource().remove(m_client_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WSClientConnection::post_error(const String& error_message)
|
||||||
|
{
|
||||||
|
dbgprintf("WSClientConnection::post_error: client_id=%d: %s\n", m_client_id, error_message.characters());
|
||||||
|
GUI_ServerMessage message;
|
||||||
|
message.type = GUI_ServerMessage::Type::Error;
|
||||||
|
ASSERT(error_message.length() < sizeof(message.text));
|
||||||
|
strcpy(message.text, error_message.characters());
|
||||||
|
message.text_length = error_message.length();
|
||||||
|
WSMessageLoop::the().post_message_to_client(m_client_id, message);
|
||||||
|
}
|
||||||
|
|
||||||
void WSClientConnection::on_message(WSMessage& message)
|
void WSClientConnection::on_message(WSMessage& message)
|
||||||
{
|
{
|
||||||
if (message.is_client_request()) {
|
if (message.is_client_request()) {
|
||||||
|
@ -106,8 +117,7 @@ void WSClientConnection::handle_request(WSAPIDestroyMenuRequest& request)
|
||||||
int menu_id = static_cast<WSAPIDestroyMenuRequest&>(request).menu_id();
|
int menu_id = static_cast<WSAPIDestroyMenuRequest&>(request).menu_id();
|
||||||
auto it = m_menus.find(menu_id);
|
auto it = m_menus.find(menu_id);
|
||||||
if (it == m_menus.end()) {
|
if (it == m_menus.end()) {
|
||||||
ASSERT_NOT_REACHED();
|
post_error("Bad menu ID");
|
||||||
// FIXME: Send an error.
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto& menu = *(*it).value;
|
auto& menu = *(*it).value;
|
||||||
|
@ -124,8 +134,7 @@ void WSClientConnection::handle_request(WSAPISetApplicationMenubarRequest& reque
|
||||||
int menubar_id = request.menubar_id();
|
int menubar_id = request.menubar_id();
|
||||||
auto it = m_menubars.find(menubar_id);
|
auto it = m_menubars.find(menubar_id);
|
||||||
if (it == m_menubars.end()) {
|
if (it == m_menubars.end()) {
|
||||||
ASSERT_NOT_REACHED();
|
post_error("Bad menubar ID");
|
||||||
// FIXME: Send an error.
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto& menubar = *(*it).value;
|
auto& menubar = *(*it).value;
|
||||||
|
@ -143,8 +152,13 @@ void WSClientConnection::handle_request(WSAPIAddMenuToMenubarRequest& request)
|
||||||
int menu_id = request.menu_id();
|
int menu_id = request.menu_id();
|
||||||
auto it = m_menubars.find(menubar_id);
|
auto it = m_menubars.find(menubar_id);
|
||||||
auto jt = m_menus.find(menu_id);
|
auto jt = m_menus.find(menu_id);
|
||||||
if (it == m_menubars.end() || jt == m_menus.end()) {
|
if (it == m_menubars.end()) {
|
||||||
ASSERT_NOT_REACHED();
|
post_error("Bad menubar ID");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (jt == m_menus.end()) {
|
||||||
|
post_error("Bad menu ID");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
auto& menubar = *(*it).value;
|
auto& menubar = *(*it).value;
|
||||||
auto& menu = *(*jt).value;
|
auto& menu = *(*jt).value;
|
||||||
|
@ -163,7 +177,8 @@ void WSClientConnection::handle_request(WSAPIAddMenuItemRequest& request)
|
||||||
String text = request.text();
|
String text = request.text();
|
||||||
auto it = m_menus.find(menu_id);
|
auto it = m_menus.find(menu_id);
|
||||||
if (it == m_menus.end()) {
|
if (it == m_menus.end()) {
|
||||||
ASSERT_NOT_REACHED();
|
post_error("Bad menu ID");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
auto& menu = *(*it).value;
|
auto& menu = *(*it).value;
|
||||||
menu.add_item(make<WSMenuItem>(identifier, move(text)));
|
menu.add_item(make<WSMenuItem>(identifier, move(text)));
|
||||||
|
@ -179,7 +194,8 @@ void WSClientConnection::handle_request(WSAPIAddMenuSeparatorRequest& request)
|
||||||
int menu_id = request.menu_id();
|
int menu_id = request.menu_id();
|
||||||
auto it = m_menus.find(menu_id);
|
auto it = m_menus.find(menu_id);
|
||||||
if (it == m_menus.end()) {
|
if (it == m_menus.end()) {
|
||||||
ASSERT_NOT_REACHED();
|
post_error("Bad menu ID");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
auto& menu = *(*it).value;
|
auto& menu = *(*it).value;
|
||||||
menu.add_item(make<WSMenuItem>(WSMenuItem::Separator));
|
menu.add_item(make<WSMenuItem>(WSMenuItem::Separator));
|
||||||
|
@ -194,7 +210,8 @@ void WSClientConnection::handle_request(WSAPISetWindowTitleRequest& request)
|
||||||
int window_id = request.window_id();
|
int window_id = request.window_id();
|
||||||
auto it = m_windows.find(window_id);
|
auto it = m_windows.find(window_id);
|
||||||
if (it == m_windows.end()) {
|
if (it == m_windows.end()) {
|
||||||
ASSERT_NOT_REACHED();
|
post_error("Bad window ID");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
auto& window = *(*it).value;
|
auto& window = *(*it).value;
|
||||||
window.set_title(request.title());
|
window.set_title(request.title());
|
||||||
|
@ -205,7 +222,8 @@ void WSClientConnection::handle_request(WSAPIGetWindowTitleRequest& request)
|
||||||
int window_id = request.window_id();
|
int window_id = request.window_id();
|
||||||
auto it = m_windows.find(window_id);
|
auto it = m_windows.find(window_id);
|
||||||
if (it == m_windows.end()) {
|
if (it == m_windows.end()) {
|
||||||
ASSERT_NOT_REACHED();
|
post_error("Bad window ID");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
auto& window = *(*it).value;
|
auto& window = *(*it).value;
|
||||||
GUI_ServerMessage response;
|
GUI_ServerMessage response;
|
||||||
|
@ -222,7 +240,8 @@ void WSClientConnection::handle_request(WSAPISetWindowRectRequest& request)
|
||||||
int window_id = request.window_id();
|
int window_id = request.window_id();
|
||||||
auto it = m_windows.find(window_id);
|
auto it = m_windows.find(window_id);
|
||||||
if (it == m_windows.end()) {
|
if (it == m_windows.end()) {
|
||||||
ASSERT_NOT_REACHED();
|
post_error("Bad window ID");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
auto& window = *(*it).value;
|
auto& window = *(*it).value;
|
||||||
window.set_rect(request.rect());
|
window.set_rect(request.rect());
|
||||||
|
@ -233,7 +252,8 @@ void WSClientConnection::handle_request(WSAPIGetWindowRectRequest& request)
|
||||||
int window_id = request.window_id();
|
int window_id = request.window_id();
|
||||||
auto it = m_windows.find(window_id);
|
auto it = m_windows.find(window_id);
|
||||||
if (it == m_windows.end()) {
|
if (it == m_windows.end()) {
|
||||||
ASSERT_NOT_REACHED();
|
post_error("Bad window ID");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
auto& window = *(*it).value;
|
auto& window = *(*it).value;
|
||||||
GUI_ServerMessage response;
|
GUI_ServerMessage response;
|
||||||
|
@ -261,7 +281,8 @@ void WSClientConnection::handle_request(WSAPIDestroyWindowRequest& request)
|
||||||
int window_id = request.window_id();
|
int window_id = request.window_id();
|
||||||
auto it = m_windows.find(window_id);
|
auto it = m_windows.find(window_id);
|
||||||
if (it == m_windows.end()) {
|
if (it == m_windows.end()) {
|
||||||
ASSERT_NOT_REACHED();
|
post_error("Bad window ID");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
auto& window = *(*it).value;
|
auto& window = *(*it).value;
|
||||||
WSWindowManager::the().invalidate(window);
|
WSWindowManager::the().invalidate(window);
|
||||||
|
@ -273,7 +294,8 @@ void WSClientConnection::handle_request(WSAPIInvalidateRectRequest& request)
|
||||||
int window_id = request.window_id();
|
int window_id = request.window_id();
|
||||||
auto it = m_windows.find(window_id);
|
auto it = m_windows.find(window_id);
|
||||||
if (it == m_windows.end()) {
|
if (it == m_windows.end()) {
|
||||||
ASSERT_NOT_REACHED();
|
post_error("Bad window ID");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
GUI_ServerMessage response;
|
GUI_ServerMessage response;
|
||||||
response.type = GUI_ServerMessage::Type::Paint;
|
response.type = GUI_ServerMessage::Type::Paint;
|
||||||
|
@ -287,7 +309,8 @@ void WSClientConnection::handle_request(WSAPIDidFinishPaintingNotification& requ
|
||||||
int window_id = request.window_id();
|
int window_id = request.window_id();
|
||||||
auto it = m_windows.find(window_id);
|
auto it = m_windows.find(window_id);
|
||||||
if (it == m_windows.end()) {
|
if (it == m_windows.end()) {
|
||||||
ASSERT_NOT_REACHED();
|
post_error("Bad window ID");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
auto& window = *(*it).value;
|
auto& window = *(*it).value;
|
||||||
WSWindowManager::the().invalidate(window, request.rect());
|
WSWindowManager::the().invalidate(window, request.rect());
|
||||||
|
@ -298,7 +321,8 @@ void WSClientConnection::handle_request(WSAPIGetWindowBackingStoreRequest& reque
|
||||||
int window_id = request.window_id();
|
int window_id = request.window_id();
|
||||||
auto it = m_windows.find(window_id);
|
auto it = m_windows.find(window_id);
|
||||||
if (it == m_windows.end()) {
|
if (it == m_windows.end()) {
|
||||||
ASSERT_NOT_REACHED();
|
post_error("Bad window ID");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
auto& window = *(*it).value;
|
auto& window = *(*it).value;
|
||||||
auto* backing_store = window.backing();
|
auto* backing_store = window.backing();
|
||||||
|
@ -330,7 +354,8 @@ void WSClientConnection::handle_request(WSAPISetGlobalCursorTrackingRequest& req
|
||||||
int window_id = request.window_id();
|
int window_id = request.window_id();
|
||||||
auto it = m_windows.find(window_id);
|
auto it = m_windows.find(window_id);
|
||||||
if (it == m_windows.end()) {
|
if (it == m_windows.end()) {
|
||||||
ASSERT_NOT_REACHED();
|
post_error("Bad window ID");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
auto& window = *(*it).value;
|
auto& window = *(*it).value;
|
||||||
window.set_global_cursor_tracking_enabled(request.value());
|
window.set_global_cursor_tracking_enabled(request.value());
|
||||||
|
|
|
@ -51,6 +51,8 @@ private:
|
||||||
void handle_request(WSAPIReleaseWindowBackingStoreRequest&);
|
void handle_request(WSAPIReleaseWindowBackingStoreRequest&);
|
||||||
void handle_request(WSAPISetGlobalCursorTrackingRequest&);
|
void handle_request(WSAPISetGlobalCursorTrackingRequest&);
|
||||||
|
|
||||||
|
void post_error(const String&);
|
||||||
|
|
||||||
int m_client_id { 0 };
|
int m_client_id { 0 };
|
||||||
|
|
||||||
HashMap<int, OwnPtr<WSWindow>> m_windows;
|
HashMap<int, OwnPtr<WSWindow>> m_windows;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue