From 14ca04de25c2e473fd07d39020f8aa5afebb03fa Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Fri, 16 Jun 2023 10:51:38 -0400 Subject: [PATCH] Ladybird+LibWeb+WebContent: Generalize video context menus for all media The data we want to send out of the WebContent process is identical for audio and video elements. Rather than just duplicating all of this for audio, generalize the names used for this IPC for all media elements. This also encapsulates that data into a struct. This makes adding new fields to be sent much easier (such as an upcoming field for muting the element). --- Ladybird/Tab.cpp | 62 +++++++------- Ladybird/Tab.h | 12 +-- Userland/Applications/Browser/Tab.cpp | 48 ++++++----- Userland/Applications/Browser/Tab.h | 8 +- .../Libraries/LibWeb/Page/EventHandler.cpp | 19 +++-- Userland/Libraries/LibWeb/Page/Page.cpp | 85 ++++++++++++------- Userland/Libraries/LibWeb/Page/Page.h | 32 +++++-- .../LibWebView/ViewImplementation.cpp | 12 +-- .../Libraries/LibWebView/ViewImplementation.h | 8 +- .../Libraries/LibWebView/WebContentClient.cpp | 6 +- .../Libraries/LibWebView/WebContentClient.h | 2 +- .../WebContent/ConnectionFromClient.cpp | 12 +-- .../WebContent/ConnectionFromClient.h | 6 +- Userland/Services/WebContent/PageHost.cpp | 16 ++-- Userland/Services/WebContent/PageHost.h | 8 +- .../Services/WebContent/WebContentClient.ipc | 3 +- .../Services/WebContent/WebContentServer.ipc | 6 +- 17 files changed, 198 insertions(+), 147 deletions(-) diff --git a/Ladybird/Tab.cpp b/Ladybird/Tab.cpp index eea62d26963..e4b194fc5cb 100644 --- a/Ladybird/Tab.cpp +++ b/Ladybird/Tab.cpp @@ -374,49 +374,49 @@ Tab::Tab(BrowserWindow* window, StringView webdriver_content_ipc_path, WebView:: m_image_context_menu->exec(screen_position); }; - m_video_context_menu_play_icon = make(QString("%1/res/icons/16x16/play.png").arg(s_serenity_resource_root.characters())); - m_video_context_menu_pause_icon = make(QString("%1/res/icons/16x16/pause.png").arg(s_serenity_resource_root.characters())); + m_media_context_menu_play_icon = make(QString("%1/res/icons/16x16/play.png").arg(s_serenity_resource_root.characters())); + m_media_context_menu_pause_icon = make(QString("%1/res/icons/16x16/pause.png").arg(s_serenity_resource_root.characters())); - m_video_context_menu_play_pause_action = make("&Play", this); - m_video_context_menu_play_pause_action->setIcon(*m_video_context_menu_play_icon); - QObject::connect(m_video_context_menu_play_pause_action, &QAction::triggered, this, [this]() { - view().toggle_video_play_state(); + m_media_context_menu_play_pause_action = make("&Play", this); + m_media_context_menu_play_pause_action->setIcon(*m_media_context_menu_play_icon); + QObject::connect(m_media_context_menu_play_pause_action, &QAction::triggered, this, [this]() { + view().toggle_media_play_state(); }); - m_video_context_menu_controls_action = make("Show &Controls", this); - m_video_context_menu_controls_action->setCheckable(true); - QObject::connect(m_video_context_menu_controls_action, &QAction::triggered, this, [this]() { - view().toggle_video_controls_state(); + m_media_context_menu_controls_action = make("Show &Controls", this); + m_media_context_menu_controls_action->setCheckable(true); + QObject::connect(m_media_context_menu_controls_action, &QAction::triggered, this, [this]() { + view().toggle_media_controls_state(); }); - m_video_context_menu_loop_action = make("&Loop Video", this); - m_video_context_menu_loop_action->setCheckable(true); - QObject::connect(m_video_context_menu_loop_action, &QAction::triggered, this, [this]() { - view().toggle_video_loop_state(); + m_media_context_menu_loop_action = make("&Loop", this); + m_media_context_menu_loop_action->setCheckable(true); + QObject::connect(m_media_context_menu_loop_action, &QAction::triggered, this, [this]() { + view().toggle_media_loop_state(); }); auto* open_video_action = new QAction("&Open Video", this); open_video_action->setIcon(QIcon(QString("%1/res/icons/16x16/filetype-video.png").arg(s_serenity_resource_root.characters()))); QObject::connect(open_video_action, &QAction::triggered, this, [this]() { - open_link(m_video_context_menu_url); + open_link(m_media_context_menu_url); }); auto* open_video_in_new_tab_action = new QAction("Open Video in New &Tab", this); open_video_in_new_tab_action->setIcon(QIcon(QString("%1/res/icons/16x16/new-tab.png").arg(s_serenity_resource_root.characters()))); QObject::connect(open_video_in_new_tab_action, &QAction::triggered, this, [this]() { - open_link_in_new_tab(m_video_context_menu_url); + open_link_in_new_tab(m_media_context_menu_url); }); auto* copy_video_url_action = new QAction("Copy Video &URL", this); copy_video_url_action->setIcon(QIcon(QString("%1/res/icons/16x16/edit-copy.png").arg(s_serenity_resource_root.characters()))); QObject::connect(copy_video_url_action, &QAction::triggered, this, [this]() { - copy_link_url(m_video_context_menu_url); + copy_link_url(m_media_context_menu_url); }); m_video_context_menu = make("Video context menu", this); - m_video_context_menu->addAction(m_video_context_menu_play_pause_action); - m_video_context_menu->addAction(m_video_context_menu_controls_action); - m_video_context_menu->addAction(m_video_context_menu_loop_action); + m_video_context_menu->addAction(m_media_context_menu_play_pause_action); + m_video_context_menu->addAction(m_media_context_menu_controls_action); + m_video_context_menu->addAction(m_media_context_menu_loop_action); m_video_context_menu->addSeparator(); m_video_context_menu->addAction(open_video_action); m_video_context_menu->addAction(open_video_in_new_tab_action); @@ -425,22 +425,24 @@ Tab::Tab(BrowserWindow* window, StringView webdriver_content_ipc_path, WebView:: m_video_context_menu->addSeparator(); m_video_context_menu->addAction(&m_window->inspect_dom_node_action()); - view().on_video_context_menu_request = [this](auto const& video_url, Gfx::IntPoint, bool is_playing, bool has_user_agent_controls, bool is_looping) { - m_video_context_menu_url = video_url; + view().on_media_context_menu_request = [this](Gfx::IntPoint, Web::Page::MediaContextMenu const& menu) { + m_media_context_menu_url = menu.media_url; - if (is_playing) { - m_video_context_menu_play_pause_action->setIcon(*m_video_context_menu_play_icon); - m_video_context_menu_play_pause_action->setText("&Play"); + if (menu.is_playing) { + m_media_context_menu_play_pause_action->setIcon(*m_media_context_menu_pause_icon); + m_media_context_menu_play_pause_action->setText("&Pause"); } else { - m_video_context_menu_play_pause_action->setIcon(*m_video_context_menu_pause_icon); - m_video_context_menu_play_pause_action->setText("&Pause"); + m_media_context_menu_play_pause_action->setIcon(*m_media_context_menu_play_icon); + m_media_context_menu_play_pause_action->setText("&Play"); } - m_video_context_menu_controls_action->setChecked(has_user_agent_controls); - m_video_context_menu_loop_action->setChecked(is_looping); + m_media_context_menu_controls_action->setChecked(menu.has_user_agent_controls); + m_media_context_menu_loop_action->setChecked(menu.is_looping); auto screen_position = QCursor::pos(); - m_video_context_menu->exec(screen_position); + + if (menu.is_video) + m_video_context_menu->exec(screen_position); }; } diff --git a/Ladybird/Tab.h b/Ladybird/Tab.h index 8072bdb2918..ac468646473 100644 --- a/Ladybird/Tab.h +++ b/Ladybird/Tab.h @@ -97,12 +97,12 @@ private: URL m_image_context_menu_url; OwnPtr m_video_context_menu; - OwnPtr m_video_context_menu_play_icon; - OwnPtr m_video_context_menu_pause_icon; - OwnPtr m_video_context_menu_play_pause_action; - OwnPtr m_video_context_menu_controls_action; - OwnPtr m_video_context_menu_loop_action; - URL m_video_context_menu_url; + OwnPtr m_media_context_menu_play_icon; + OwnPtr m_media_context_menu_pause_icon; + OwnPtr m_media_context_menu_play_pause_action; + OwnPtr m_media_context_menu_controls_action; + OwnPtr m_media_context_menu_loop_action; + URL m_media_context_menu_url; int tab_index(); diff --git a/Userland/Applications/Browser/Tab.cpp b/Userland/Applications/Browser/Tab.cpp index 4b8fecd881b..38f0f4d1fee 100644 --- a/Userland/Applications/Browser/Tab.cpp +++ b/Userland/Applications/Browser/Tab.cpp @@ -374,54 +374,56 @@ Tab::Tab(BrowserWindow& window) m_image_context_menu->popup(screen_position); }; - m_video_context_menu_play_pause_action = GUI::Action::create("&Play", g_icon_bag.play, [this](auto&) { - view().toggle_video_play_state(); + m_media_context_menu_play_pause_action = GUI::Action::create("&Play", g_icon_bag.play, [this](auto&) { + view().toggle_media_play_state(); }); - m_video_context_menu_controls_action = GUI::Action::create_checkable("Show &Controls", [this](auto&) { - view().toggle_video_controls_state(); + m_media_context_menu_controls_action = GUI::Action::create_checkable("Show &Controls", [this](auto&) { + view().toggle_media_controls_state(); }); - m_video_context_menu_loop_action = GUI::Action::create_checkable("&Loop Video", [this](auto&) { - view().toggle_video_loop_state(); + m_media_context_menu_loop_action = GUI::Action::create_checkable("&Loop", [this](auto&) { + view().toggle_media_loop_state(); }); m_video_context_menu = GUI::Menu::construct(); - m_video_context_menu->add_action(*m_video_context_menu_play_pause_action); - m_video_context_menu->add_action(*m_video_context_menu_controls_action); - m_video_context_menu->add_action(*m_video_context_menu_loop_action); + m_video_context_menu->add_action(*m_media_context_menu_play_pause_action); + m_video_context_menu->add_action(*m_media_context_menu_controls_action); + m_video_context_menu->add_action(*m_media_context_menu_loop_action); m_video_context_menu->add_separator(); m_video_context_menu->add_action(GUI::Action::create("&Open Video", g_icon_bag.filetype_video, [this](auto&) { - view().on_link_click(m_video_context_menu_url, "", 0); + view().on_link_click(m_media_context_menu_url, "", 0); })); m_video_context_menu->add_action(GUI::Action::create("Open Video in New &Tab", g_icon_bag.new_tab, [this](auto&) { - view().on_link_click(m_video_context_menu_url, "_blank", 0); + view().on_link_click(m_media_context_menu_url, "_blank", 0); })); m_video_context_menu->add_separator(); m_video_context_menu->add_action(GUI::Action::create("Copy Video &URL", g_icon_bag.copy, [this](auto&) { - GUI::Clipboard::the().set_plain_text(m_video_context_menu_url.to_deprecated_string()); + GUI::Clipboard::the().set_plain_text(m_media_context_menu_url.to_deprecated_string()); })); m_video_context_menu->add_separator(); m_video_context_menu->add_action(GUI::Action::create("&Download", g_icon_bag.download, [this](auto&) { - start_download(m_video_context_menu_url); + start_download(m_media_context_menu_url); })); m_video_context_menu->add_separator(); m_video_context_menu->add_action(window.inspect_dom_node_action()); - view().on_video_context_menu_request = [this](auto& video_url, auto widget_position, bool is_playing, bool has_user_agent_controls, bool is_looping) { - m_video_context_menu_url = video_url; + view().on_media_context_menu_request = [this](auto widget_position, Web::Page::MediaContextMenu const& menu) { + m_media_context_menu_url = menu.media_url; - if (is_playing) { - m_video_context_menu_play_pause_action->set_icon(g_icon_bag.play); - m_video_context_menu_play_pause_action->set_text("&Play"sv); + if (menu.is_playing) { + m_media_context_menu_play_pause_action->set_icon(g_icon_bag.pause); + m_media_context_menu_play_pause_action->set_text("&Pause"sv); } else { - m_video_context_menu_play_pause_action->set_icon(g_icon_bag.pause); - m_video_context_menu_play_pause_action->set_text("&Pause"sv); + m_media_context_menu_play_pause_action->set_icon(g_icon_bag.play); + m_media_context_menu_play_pause_action->set_text("&Play"sv); } - m_video_context_menu_controls_action->set_checked(has_user_agent_controls); - m_video_context_menu_loop_action->set_checked(is_looping); + m_media_context_menu_controls_action->set_checked(menu.has_user_agent_controls); + m_media_context_menu_loop_action->set_checked(menu.is_looping); auto screen_position = view().screen_relative_rect().location().translated(widget_position); - m_video_context_menu->popup(screen_position); + + if (menu.is_video) + m_video_context_menu->popup(screen_position); }; view().on_link_middle_click = [this](auto& href, auto&, auto) { diff --git a/Userland/Applications/Browser/Tab.h b/Userland/Applications/Browser/Tab.h index 2846dd34325..4c182912643 100644 --- a/Userland/Applications/Browser/Tab.h +++ b/Userland/Applications/Browser/Tab.h @@ -144,10 +144,10 @@ private: URL m_image_context_menu_url; RefPtr m_video_context_menu; - RefPtr m_video_context_menu_play_pause_action; - RefPtr m_video_context_menu_controls_action; - RefPtr m_video_context_menu_loop_action; - URL m_video_context_menu_url; + RefPtr m_media_context_menu_play_pause_action; + RefPtr m_media_context_menu_controls_action; + RefPtr m_media_context_menu_loop_action; + URL m_media_context_menu_url; RefPtr m_tab_context_menu; RefPtr m_page_context_menu; diff --git a/Userland/Libraries/LibWeb/Page/EventHandler.cpp b/Userland/Libraries/LibWeb/Page/EventHandler.cpp index c39610ad484..f396d9da316 100644 --- a/Userland/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Userland/Libraries/LibWeb/Page/EventHandler.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -307,17 +308,19 @@ bool EventHandler::handle_mouseup(CSSPixelPoint position, unsigned button, unsig auto image_url = image_element.document().parse_url(image_element.src()); if (auto* page = m_browsing_context->page()) page->client().page_did_request_image_context_menu(m_browsing_context->to_top_level_position(position), image_url, "", modifiers, image_element.bitmap()); - } else if (is(*node)) { - auto& video_element = verify_cast(*node); + } else if (is(*node)) { + auto& media_element = verify_cast(*node); - auto video_id = video_element.id(); - auto video_url = video_element.document().parse_url(video_element.current_src()); - auto is_playing = !video_element.potentially_playing(); - auto has_user_agent_controls = video_element.has_attribute(HTML::AttributeNames::controls); - auto is_looping = video_element.has_attribute(HTML::AttributeNames::loop); + Page::MediaContextMenu menu { + .media_url = media_element.document().parse_url(media_element.current_src()), + .is_video = is(*node), + .is_playing = media_element.potentially_playing(), + .has_user_agent_controls = media_element.has_attribute(HTML::AttributeNames::controls), + .is_looping = media_element.has_attribute(HTML::AttributeNames::loop), + }; if (auto* page = m_browsing_context->page()) - page->did_request_video_context_menu(video_id, m_browsing_context->to_top_level_position(position), video_url, "", modifiers, is_playing, has_user_agent_controls, is_looping); + page->did_request_media_context_menu(media_element.id(), m_browsing_context->to_top_level_position(position), "", modifiers, move(menu)); } else if (auto* page = m_browsing_context->page()) { page->client().page_did_request_context_menu(m_browsing_context->to_top_level_position(position)); } diff --git a/Userland/Libraries/LibWeb/Page/Page.cpp b/Userland/Libraries/LibWeb/Page/Page.cpp index 7db222f379c..475d50b3d4a 100644 --- a/Userland/Libraries/LibWeb/Page/Page.cpp +++ b/Userland/Libraries/LibWeb/Page/Page.cpp @@ -7,10 +7,12 @@ #include #include +#include +#include #include #include #include -#include +#include #include #include #include @@ -286,88 +288,111 @@ void Page::accept_dialog() } } -void Page::did_request_video_context_menu(i32 video_id, CSSPixelPoint position, AK::URL const& url, DeprecatedString const& target, unsigned modifiers, bool is_playing, bool has_user_agent_controls, bool is_looping) +void Page::did_request_media_context_menu(i32 media_id, CSSPixelPoint position, DeprecatedString const& target, unsigned modifiers, MediaContextMenu menu) { - m_video_context_menu_element_id = video_id; - client().page_did_request_video_context_menu(position, url, target, modifiers, is_playing, has_user_agent_controls, is_looping); + m_media_context_menu_element_id = media_id; + client().page_did_request_media_context_menu(position, target, modifiers, move(menu)); } -WebIDL::ExceptionOr Page::toggle_video_play_state() +WebIDL::ExceptionOr Page::toggle_media_play_state() { - auto video_element = video_context_menu_element(); - if (!video_element) + auto media_element = media_context_menu_element(); + if (!media_element) return {}; // FIXME: This runs from outside the context of any user script, so we do not have a running execution // context. This pushes one to allow the promise creation hook to run. - auto& environment_settings = video_element->document().relevant_settings_object(); + auto& environment_settings = media_element->document().relevant_settings_object(); environment_settings.prepare_to_run_script(); ScopeGuard guard { [&] { environment_settings.clean_up_after_running_script(); } }; - if (video_element->potentially_playing()) - TRY(video_element->pause()); + if (media_element->potentially_playing()) + TRY(media_element->pause()); else - TRY(video_element->play()); + TRY(media_element->play()); return {}; } -WebIDL::ExceptionOr Page::toggle_video_loop_state() +WebIDL::ExceptionOr Page::toggle_media_loop_state() { - auto video_element = video_context_menu_element(); - if (!video_element) + auto media_element = media_context_menu_element(); + if (!media_element) return {}; // FIXME: This runs from outside the context of any user script, so we do not have a running execution // context. This pushes one to allow the promise creation hook to run. - auto& environment_settings = video_element->document().relevant_settings_object(); + auto& environment_settings = media_element->document().relevant_settings_object(); environment_settings.prepare_to_run_script(); ScopeGuard guard { [&] { environment_settings.clean_up_after_running_script(); } }; - if (video_element->has_attribute(HTML::AttributeNames::loop)) - video_element->remove_attribute(HTML::AttributeNames::loop); + if (media_element->has_attribute(HTML::AttributeNames::loop)) + media_element->remove_attribute(HTML::AttributeNames::loop); else - TRY(video_element->set_attribute(HTML::AttributeNames::loop, {})); + TRY(media_element->set_attribute(HTML::AttributeNames::loop, {})); return {}; } -WebIDL::ExceptionOr Page::toggle_video_controls_state() +WebIDL::ExceptionOr Page::toggle_media_controls_state() { - auto video_element = video_context_menu_element(); - if (!video_element) + auto media_element = media_context_menu_element(); + if (!media_element) return {}; // FIXME: This runs from outside the context of any user script, so we do not have a running execution // context. This pushes one to allow the promise creation hook to run. - auto& environment_settings = video_element->document().relevant_settings_object(); + auto& environment_settings = media_element->document().relevant_settings_object(); environment_settings.prepare_to_run_script(); ScopeGuard guard { [&] { environment_settings.clean_up_after_running_script(); } }; - if (video_element->has_attribute(HTML::AttributeNames::controls)) - video_element->remove_attribute(HTML::AttributeNames::controls); + if (media_element->has_attribute(HTML::AttributeNames::controls)) + media_element->remove_attribute(HTML::AttributeNames::controls); else - TRY(video_element->set_attribute(HTML::AttributeNames::controls, {})); + TRY(media_element->set_attribute(HTML::AttributeNames::controls, {})); return {}; } -JS::GCPtr Page::video_context_menu_element() +JS::GCPtr Page::media_context_menu_element() { - if (!m_video_context_menu_element_id.has_value()) + if (!m_media_context_menu_element_id.has_value()) return nullptr; - auto* dom_node = DOM::Node::from_id(*m_video_context_menu_element_id); + auto* dom_node = DOM::Node::from_id(*m_media_context_menu_element_id); if (dom_node == nullptr) return nullptr; - if (!is(dom_node)) + if (!is(dom_node)) return nullptr; - return static_cast(dom_node); + return static_cast(dom_node); } } + +template<> +ErrorOr IPC::encode(Encoder& encoder, Web::Page::MediaContextMenu const& menu) +{ + TRY(encoder.encode(menu.media_url)); + TRY(encoder.encode(menu.is_video)); + TRY(encoder.encode(menu.is_playing)); + TRY(encoder.encode(menu.has_user_agent_controls)); + TRY(encoder.encode(menu.is_looping)); + return {}; +} + +template<> +ErrorOr IPC::decode(Decoder& decoder) +{ + return Web::Page::MediaContextMenu { + .media_url = TRY(decoder.decode()), + .is_video = TRY(decoder.decode()), + .is_playing = TRY(decoder.decode()), + .has_user_agent_controls = TRY(decoder.decode()), + .is_looping = TRY(decoder.decode()), + }; +} diff --git a/Userland/Libraries/LibWeb/Page/Page.h b/Userland/Libraries/LibWeb/Page/Page.h index d41492f58e4..5a7a306c672 100644 --- a/Userland/Libraries/LibWeb/Page/Page.h +++ b/Userland/Libraries/LibWeb/Page/Page.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -120,15 +121,22 @@ public: void dismiss_dialog(); void accept_dialog(); - void did_request_video_context_menu(i32 video_id, CSSPixelPoint, AK::URL const&, DeprecatedString const& target, unsigned modifiers, bool is_playing, bool has_user_agent_controls, bool is_looping); - WebIDL::ExceptionOr toggle_video_play_state(); - WebIDL::ExceptionOr toggle_video_loop_state(); - WebIDL::ExceptionOr toggle_video_controls_state(); + struct MediaContextMenu { + AK::URL media_url; + bool is_video { false }; + bool is_playing { false }; + bool has_user_agent_controls { false }; + bool is_looping { false }; + }; + void did_request_media_context_menu(i32 media_id, CSSPixelPoint, DeprecatedString const& target, unsigned modifiers, MediaContextMenu); + WebIDL::ExceptionOr toggle_media_play_state(); + WebIDL::ExceptionOr toggle_media_loop_state(); + WebIDL::ExceptionOr toggle_media_controls_state(); bool pdf_viewer_supported() const { return m_pdf_viewer_supported; } private: - JS::GCPtr video_context_menu_element(); + JS::GCPtr media_context_menu_element(); PageClient& m_client; @@ -155,7 +163,7 @@ private: Optional m_pending_confirm_response; Optional> m_pending_prompt_response; - Optional m_video_context_menu_element_id; + Optional m_media_context_menu_element_id; // https://html.spec.whatwg.org/multipage/system-state.html#pdf-viewer-supported // Each user agent has a PDF viewer supported boolean, whose value is implementation-defined (and might vary according to user preferences). @@ -192,7 +200,7 @@ public: virtual void page_did_request_context_menu(CSSPixelPoint) { } virtual void page_did_request_link_context_menu(CSSPixelPoint, AK::URL const&, [[maybe_unused]] DeprecatedString const& target, [[maybe_unused]] unsigned modifiers) { } virtual void page_did_request_image_context_menu(CSSPixelPoint, AK::URL const&, [[maybe_unused]] DeprecatedString const& target, [[maybe_unused]] unsigned modifiers, Gfx::Bitmap const*) { } - virtual void page_did_request_video_context_menu(CSSPixelPoint, AK::URL const&, [[maybe_unused]] DeprecatedString const& target, [[maybe_unused]] unsigned modifiers, [[maybe_unused]] bool is_playing, [[maybe_unused]] bool has_user_agent_controls, [[maybe_unused]] bool is_looping) { } + virtual void page_did_request_media_context_menu(CSSPixelPoint, [[maybe_unused]] DeprecatedString const& target, [[maybe_unused]] unsigned modifiers, Page::MediaContextMenu) { } virtual void page_did_click_link(const AK::URL&, [[maybe_unused]] DeprecatedString const& target, [[maybe_unused]] unsigned modifiers) { } virtual void page_did_middle_click_link(const AK::URL&, [[maybe_unused]] DeprecatedString const& target, [[maybe_unused]] unsigned modifiers) { } virtual void page_did_enter_tooltip_area(CSSPixelPoint, DeprecatedString const&) { } @@ -231,3 +239,13 @@ protected: }; } + +namespace IPC { + +template<> +ErrorOr encode(Encoder&, Web::Page::MediaContextMenu const&); + +template<> +ErrorOr decode(Decoder&); + +} diff --git a/Userland/Libraries/LibWebView/ViewImplementation.cpp b/Userland/Libraries/LibWebView/ViewImplementation.cpp index faded7ab497..12815aa1781 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.cpp +++ b/Userland/Libraries/LibWebView/ViewImplementation.cpp @@ -151,19 +151,19 @@ void ViewImplementation::js_console_request_messages(i32 start_index) client().async_js_console_request_messages(start_index); } -void ViewImplementation::toggle_video_play_state() +void ViewImplementation::toggle_media_play_state() { - client().async_toggle_video_play_state(); + client().async_toggle_media_play_state(); } -void ViewImplementation::toggle_video_loop_state() +void ViewImplementation::toggle_media_loop_state() { - client().async_toggle_video_loop_state(); + client().async_toggle_media_loop_state(); } -void ViewImplementation::toggle_video_controls_state() +void ViewImplementation::toggle_media_controls_state() { - client().async_toggle_video_controls_state(); + client().async_toggle_media_controls_state(); } void ViewImplementation::handle_resize() diff --git a/Userland/Libraries/LibWebView/ViewImplementation.h b/Userland/Libraries/LibWebView/ViewImplementation.h index 432681fa7a9..06741d63722 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.h +++ b/Userland/Libraries/LibWebView/ViewImplementation.h @@ -74,9 +74,9 @@ public: void js_console_input(DeprecatedString const& js_source); void js_console_request_messages(i32 start_index); - void toggle_video_play_state(); - void toggle_video_loop_state(); - void toggle_video_controls_state(); + void toggle_media_play_state(); + void toggle_media_loop_state(); + void toggle_media_controls_state(); enum class ScreenshotType { Visible, @@ -90,7 +90,7 @@ public: Function on_context_menu_request; Function on_link_context_menu_request; Function on_image_context_menu_request; - Function on_video_context_menu_request; + Function on_media_context_menu_request; Function on_link_hover; Function on_link_unhover; Function on_link_click; diff --git a/Userland/Libraries/LibWebView/WebContentClient.cpp b/Userland/Libraries/LibWebView/WebContentClient.cpp index 0152b726bd5..2cc9bfd575f 100644 --- a/Userland/Libraries/LibWebView/WebContentClient.cpp +++ b/Userland/Libraries/LibWebView/WebContentClient.cpp @@ -176,10 +176,10 @@ void WebContentClient::did_request_image_context_menu(Gfx::IntPoint content_posi m_view.on_image_context_menu_request(url, m_view.to_widget_position(content_position), bitmap); } -void WebContentClient::did_request_video_context_menu(Gfx::IntPoint content_position, AK::URL const& url, DeprecatedString const&, unsigned, bool is_playing, bool has_user_agent_controls, bool is_looping) +void WebContentClient::did_request_media_context_menu(Gfx::IntPoint content_position, DeprecatedString const&, unsigned, Web::Page::MediaContextMenu const& menu) { - if (m_view.on_video_context_menu_request) - m_view.on_video_context_menu_request(url, m_view.to_widget_position(content_position), is_playing, has_user_agent_controls, is_looping); + if (m_view.on_media_context_menu_request) + m_view.on_media_context_menu_request(m_view.to_widget_position(content_position), menu); } void WebContentClient::did_get_source(AK::URL const& url, DeprecatedString const& source) diff --git a/Userland/Libraries/LibWebView/WebContentClient.h b/Userland/Libraries/LibWebView/WebContentClient.h index 2d2b2227bcf..b10aca679d3 100644 --- a/Userland/Libraries/LibWebView/WebContentClient.h +++ b/Userland/Libraries/LibWebView/WebContentClient.h @@ -52,7 +52,7 @@ private: virtual void did_request_context_menu(Gfx::IntPoint) override; virtual void did_request_link_context_menu(Gfx::IntPoint, AK::URL const&, DeprecatedString const&, unsigned) override; virtual void did_request_image_context_menu(Gfx::IntPoint, AK::URL const&, DeprecatedString const&, unsigned, Gfx::ShareableBitmap const&) override; - virtual void did_request_video_context_menu(Gfx::IntPoint, AK::URL const&, DeprecatedString const&, unsigned, bool, bool, bool) override; + virtual void did_request_media_context_menu(Gfx::IntPoint, DeprecatedString const&, unsigned, Web::Page::MediaContextMenu const&) override; virtual void did_get_source(AK::URL const&, DeprecatedString const&) override; virtual void did_get_dom_tree(DeprecatedString const&) override; virtual void did_get_dom_node_properties(i32 node_id, DeprecatedString const& computed_style, DeprecatedString const& resolved_style, DeprecatedString const& custom_properties, DeprecatedString const& node_box_sizing) override; diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp index a7613353dab..5bc14a481f6 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.cpp +++ b/Userland/Services/WebContent/ConnectionFromClient.cpp @@ -785,19 +785,19 @@ void ConnectionFromClient::prompt_closed(Optional const& response) m_page_host->prompt_closed(response); } -void ConnectionFromClient::toggle_video_play_state() +void ConnectionFromClient::toggle_media_play_state() { - m_page_host->toggle_video_play_state().release_value_but_fixme_should_propagate_errors(); + m_page_host->toggle_media_play_state().release_value_but_fixme_should_propagate_errors(); } -void ConnectionFromClient::toggle_video_loop_state() +void ConnectionFromClient::toggle_media_loop_state() { - m_page_host->toggle_video_loop_state().release_value_but_fixme_should_propagate_errors(); + m_page_host->toggle_media_loop_state().release_value_but_fixme_should_propagate_errors(); } -void ConnectionFromClient::toggle_video_controls_state() +void ConnectionFromClient::toggle_media_controls_state() { - m_page_host->toggle_video_controls_state().release_value_but_fixme_should_propagate_errors(); + m_page_host->toggle_media_controls_state().release_value_but_fixme_should_propagate_errors(); } void ConnectionFromClient::inspect_accessibility_tree() diff --git a/Userland/Services/WebContent/ConnectionFromClient.h b/Userland/Services/WebContent/ConnectionFromClient.h index a8d66c5ed62..9780c4b79fd 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.h +++ b/Userland/Services/WebContent/ConnectionFromClient.h @@ -96,9 +96,9 @@ private: virtual void confirm_closed(bool accepted) override; virtual void prompt_closed(Optional const& response) override; - virtual void toggle_video_play_state() override; - virtual void toggle_video_loop_state() override; - virtual void toggle_video_controls_state() override; + virtual void toggle_media_play_state() override; + virtual void toggle_media_loop_state() override; + virtual void toggle_media_controls_state() override; virtual Messages::WebContentServer::TakeDocumentScreenshotResponse take_document_screenshot() override; diff --git a/Userland/Services/WebContent/PageHost.cpp b/Userland/Services/WebContent/PageHost.cpp index ef672658443..1b42386d870 100644 --- a/Userland/Services/WebContent/PageHost.cpp +++ b/Userland/Services/WebContent/PageHost.cpp @@ -334,19 +334,19 @@ void PageHost::prompt_closed(Optional response) page().prompt_closed(move(response)); } -Web::WebIDL::ExceptionOr PageHost::toggle_video_play_state() +Web::WebIDL::ExceptionOr PageHost::toggle_media_play_state() { - return page().toggle_video_play_state(); + return page().toggle_media_play_state(); } -Web::WebIDL::ExceptionOr PageHost::toggle_video_loop_state() +Web::WebIDL::ExceptionOr PageHost::toggle_media_loop_state() { - return page().toggle_video_loop_state(); + return page().toggle_media_loop_state(); } -Web::WebIDL::ExceptionOr PageHost::toggle_video_controls_state() +Web::WebIDL::ExceptionOr PageHost::toggle_media_controls_state() { - return page().toggle_video_controls_state(); + return page().toggle_media_controls_state(); } void PageHost::page_did_request_accept_dialog() @@ -370,9 +370,9 @@ void PageHost::page_did_request_image_context_menu(Web::CSSPixelPoint content_po m_client.async_did_request_image_context_menu({ content_position.x().to_int(), content_position.y().to_int() }, url, target, modifiers, bitmap); } -void PageHost::page_did_request_video_context_menu(Web::CSSPixelPoint content_position, URL const& url, DeprecatedString const& target, unsigned modifiers, bool is_playing, bool has_user_agent_controls, bool is_looping) +void PageHost::page_did_request_media_context_menu(Web::CSSPixelPoint content_position, DeprecatedString const& target, unsigned modifiers, Web::Page::MediaContextMenu menu) { - m_client.async_did_request_video_context_menu({ content_position.x().to_int(), content_position.y().to_int() }, url, target, modifiers, is_playing, has_user_agent_controls, is_looping); + m_client.async_did_request_media_context_menu({ content_position.x().to_int(), content_position.y().to_int() }, target, modifiers, move(menu)); } Vector PageHost::page_did_request_all_cookies(URL const& url) diff --git a/Userland/Services/WebContent/PageHost.h b/Userland/Services/WebContent/PageHost.h index 615dde4aa41..0270eabd9c9 100644 --- a/Userland/Services/WebContent/PageHost.h +++ b/Userland/Services/WebContent/PageHost.h @@ -49,9 +49,9 @@ public: void confirm_closed(bool accepted); void prompt_closed(Optional response); - Web::WebIDL::ExceptionOr toggle_video_play_state(); - Web::WebIDL::ExceptionOr toggle_video_loop_state(); - Web::WebIDL::ExceptionOr toggle_video_controls_state(); + Web::WebIDL::ExceptionOr toggle_media_play_state(); + Web::WebIDL::ExceptionOr toggle_media_loop_state(); + Web::WebIDL::ExceptionOr toggle_media_controls_state(); [[nodiscard]] Gfx::Color background_color() const; @@ -98,7 +98,7 @@ private: virtual void page_did_request_dismiss_dialog() override; virtual void page_did_change_favicon(Gfx::Bitmap const&) override; virtual void page_did_request_image_context_menu(Web::CSSPixelPoint, const URL&, DeprecatedString const& target, unsigned modifiers, Gfx::Bitmap const*) override; - virtual void page_did_request_video_context_menu(Web::CSSPixelPoint, const URL&, DeprecatedString const& target, unsigned modifiers, bool is_playing, bool has_user_agent_controls, bool is_looping) override; + virtual void page_did_request_media_context_menu(Web::CSSPixelPoint, DeprecatedString const& target, unsigned modifiers, Web::Page::MediaContextMenu) override; virtual Vector page_did_request_all_cookies(URL const&) override; virtual Optional page_did_request_named_cookie(URL const&, DeprecatedString const&) override; virtual DeprecatedString page_did_request_cookie(const URL&, Web::Cookie::Source) override; diff --git a/Userland/Services/WebContent/WebContentClient.ipc b/Userland/Services/WebContent/WebContentClient.ipc index 3cde0db35fb..0806227a1fe 100644 --- a/Userland/Services/WebContent/WebContentClient.ipc +++ b/Userland/Services/WebContent/WebContentClient.ipc @@ -4,6 +4,7 @@ #include #include #include +#include endpoint WebContentClient { @@ -30,7 +31,7 @@ endpoint WebContentClient did_request_context_menu(Gfx::IntPoint content_position) =| did_request_link_context_menu(Gfx::IntPoint content_position, URL url, DeprecatedString target, unsigned modifiers) =| did_request_image_context_menu(Gfx::IntPoint content_position, URL url, DeprecatedString target, unsigned modifiers, Gfx::ShareableBitmap bitmap) =| - did_request_video_context_menu(Gfx::IntPoint content_position, URL url, DeprecatedString target, unsigned modifiers, bool is_playing, bool has_user_agent_controls, bool is_looping) =| + did_request_media_context_menu(Gfx::IntPoint content_position, DeprecatedString target, unsigned modifiers, Web::Page::MediaContextMenu menu) =| did_request_alert(String message) =| did_request_confirm(String message) =| did_request_prompt(String message, String default_) =| diff --git a/Userland/Services/WebContent/WebContentServer.ipc b/Userland/Services/WebContent/WebContentServer.ipc index ceea4f0375c..da609f6be69 100644 --- a/Userland/Services/WebContent/WebContentServer.ipc +++ b/Userland/Services/WebContent/WebContentServer.ipc @@ -78,7 +78,7 @@ endpoint WebContentServer confirm_closed(bool accepted) =| prompt_closed(Optional response) =| - toggle_video_play_state() =| - toggle_video_loop_state() =| - toggle_video_controls_state() =| + toggle_media_play_state() =| + toggle_media_loop_state() =| + toggle_media_controls_state() =| }