summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-05-15 09:42:56 -0400
committerAndreas Kling <kling@serenityos.org>2023-05-16 12:48:39 +0200
commitd8f03dda08b26025469026e5498918e2fc352de5 (patch)
treeebeadd3c8c4aad138eb05e35c2a57bbac3308252 /Userland
parent5f473bcb5f4486a93d90bd8cb58192521a4768e9 (diff)
downloadserenity-d8f03dda08b26025469026e5498918e2fc352de5.zip
Browser+LibWeb+WebContent: Broadcast video element context menu requests
This just sets up the IPC to notify the browser process of context menu requests on video elements. The IPC contains a few pieces of information about the state of the video element.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/Page/EventHandler.cpp12
-rw-r--r--Userland/Libraries/LibWeb/Page/Page.cpp6
-rw-r--r--Userland/Libraries/LibWeb/Page/Page.h5
-rw-r--r--Userland/Libraries/LibWebView/OutOfProcessWebView.cpp6
-rw-r--r--Userland/Libraries/LibWebView/OutOfProcessWebView.h2
-rw-r--r--Userland/Libraries/LibWebView/ViewImplementation.h1
-rw-r--r--Userland/Libraries/LibWebView/WebContentClient.cpp5
-rw-r--r--Userland/Libraries/LibWebView/WebContentClient.h1
-rw-r--r--Userland/Services/WebContent/PageHost.cpp5
-rw-r--r--Userland/Services/WebContent/PageHost.h1
-rw-r--r--Userland/Services/WebContent/WebContentClient.ipc1
-rw-r--r--Userland/Utilities/headless-browser.cpp1
12 files changed, 46 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Page/EventHandler.cpp b/Userland/Libraries/LibWeb/Page/EventHandler.cpp
index 51ca89e1a3..a649d6b8bf 100644
--- a/Userland/Libraries/LibWeb/Page/EventHandler.cpp
+++ b/Userland/Libraries/LibWeb/Page/EventHandler.cpp
@@ -13,6 +13,7 @@
#include <LibWeb/HTML/HTMLAnchorElement.h>
#include <LibWeb/HTML/HTMLIFrameElement.h>
#include <LibWeb/HTML/HTMLImageElement.h>
+#include <LibWeb/HTML/HTMLVideoElement.h>
#include <LibWeb/Layout/Viewport.h>
#include <LibWeb/Page/EventHandler.h>
#include <LibWeb/Page/Page.h>
@@ -302,6 +303,17 @@ 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<HTML::HTMLVideoElement>(*node)) {
+ auto& video_element = verify_cast<HTML::HTMLVideoElement>(*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);
+
+ 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);
} 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 75264f2c9e..7a6cd69240 100644
--- a/Userland/Libraries/LibWeb/Page/Page.cpp
+++ b/Userland/Libraries/LibWeb/Page/Page.cpp
@@ -275,4 +275,10 @@ 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)
+{
+ 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);
+}
+
}
diff --git a/Userland/Libraries/LibWeb/Page/Page.h b/Userland/Libraries/LibWeb/Page/Page.h
index d78834cd38..ac0b9b073a 100644
--- a/Userland/Libraries/LibWeb/Page/Page.h
+++ b/Userland/Libraries/LibWeb/Page/Page.h
@@ -115,6 +115,8 @@ 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);
+
bool pdf_viewer_supported() const { return m_pdf_viewer_supported; }
private:
@@ -143,6 +145,8 @@ private:
Optional<bool> m_pending_confirm_response;
Optional<Optional<String>> m_pending_prompt_response;
+ Optional<int> m_video_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).
// Spec Note: This value also impacts the navigation processing model.
@@ -178,6 +182,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_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&) { }
diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp
index 0066e26744..8c47ff9f31 100644
--- a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp
+++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp
@@ -320,6 +320,12 @@ void OutOfProcessWebView::notify_server_did_request_image_context_menu(Badge<Web
on_image_context_menu_request(url, screen_relative_rect().location().translated(to_widget_position(content_position)), bitmap);
}
+void OutOfProcessWebView::notify_server_did_request_video_context_menu(Badge<WebContentClient>, Gfx::IntPoint content_position, const AK::URL& url, DeprecatedString const&, unsigned, bool is_playing, bool has_user_agent_controls, bool is_looping)
+{
+ if (on_video_context_menu_request)
+ on_video_context_menu_request(url, screen_relative_rect().location().translated(to_widget_position(content_position)), is_playing, has_user_agent_controls, is_looping);
+}
+
void OutOfProcessWebView::notify_server_did_request_alert(Badge<WebContentClient>, String const& message)
{
m_dialog = GUI::MessageBox::create(window(), message, "Alert"sv, GUI::MessageBox::Type::Information, GUI::MessageBox::InputType::OK).release_value_but_fixme_should_propagate_errors();
diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.h b/Userland/Libraries/LibWebView/OutOfProcessWebView.h
index b708d19940..8d8f3f9c31 100644
--- a/Userland/Libraries/LibWebView/OutOfProcessWebView.h
+++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.h
@@ -67,6 +67,7 @@ public:
Function<void(const AK::URL&, DeprecatedString const& target, unsigned modifiers)> on_link_click;
Function<void(const AK::URL&, Gfx::IntPoint screen_position)> on_link_context_menu_request;
Function<void(const AK::URL&, Gfx::IntPoint screen_position, Gfx::ShareableBitmap const&)> on_image_context_menu_request;
+ Function<void(const AK::URL&, Gfx::IntPoint screen_position, bool, bool, bool)> on_video_context_menu_request;
Function<void(const AK::URL&, DeprecatedString const& target, unsigned modifiers)> on_link_middle_click;
Function<void(const AK::URL&)> on_link_hover;
Function<void(DeprecatedString const&)> on_title_change;
@@ -148,6 +149,7 @@ private:
virtual void notify_server_did_request_context_menu(Badge<WebContentClient>, Gfx::IntPoint) override;
virtual void notify_server_did_request_link_context_menu(Badge<WebContentClient>, Gfx::IntPoint, const AK::URL&, DeprecatedString const& target, unsigned modifiers) override;
virtual void notify_server_did_request_image_context_menu(Badge<WebContentClient>, Gfx::IntPoint, const AK::URL&, DeprecatedString const& target, unsigned modifiers, Gfx::ShareableBitmap const&) override;
+ virtual void notify_server_did_request_video_context_menu(Badge<WebContentClient>, Gfx::IntPoint, const AK::URL&, DeprecatedString const& target, unsigned modifiers, bool is_playing, bool has_user_agent_controls, bool is_looping) override;
virtual void notify_server_did_request_alert(Badge<WebContentClient>, String const& message) override;
virtual void notify_server_did_request_confirm(Badge<WebContentClient>, String const& message) override;
virtual void notify_server_did_request_prompt(Badge<WebContentClient>, String const& message, String const& default_) override;
diff --git a/Userland/Libraries/LibWebView/ViewImplementation.h b/Userland/Libraries/LibWebView/ViewImplementation.h
index e73afc294d..21ec8de72a 100644
--- a/Userland/Libraries/LibWebView/ViewImplementation.h
+++ b/Userland/Libraries/LibWebView/ViewImplementation.h
@@ -93,6 +93,7 @@ public:
virtual void notify_server_did_request_context_menu(Badge<WebContentClient>, Gfx::IntPoint) = 0;
virtual void notify_server_did_request_link_context_menu(Badge<WebContentClient>, Gfx::IntPoint, const AK::URL&, DeprecatedString const& target, unsigned modifiers) = 0;
virtual void notify_server_did_request_image_context_menu(Badge<WebContentClient>, Gfx::IntPoint, const AK::URL&, DeprecatedString const& target, unsigned modifiers, Gfx::ShareableBitmap const&) = 0;
+ virtual void notify_server_did_request_video_context_menu(Badge<WebContentClient>, Gfx::IntPoint, const AK::URL&, DeprecatedString const& target, unsigned modifiers, bool is_playing, bool has_user_agent_controls, bool is_looping) = 0;
virtual void notify_server_did_request_alert(Badge<WebContentClient>, String const& message) = 0;
virtual void notify_server_did_request_confirm(Badge<WebContentClient>, String const& message) = 0;
virtual void notify_server_did_request_prompt(Badge<WebContentClient>, String const& message, String const& default_) = 0;
diff --git a/Userland/Libraries/LibWebView/WebContentClient.cpp b/Userland/Libraries/LibWebView/WebContentClient.cpp
index 01238a2357..4882817bfd 100644
--- a/Userland/Libraries/LibWebView/WebContentClient.cpp
+++ b/Userland/Libraries/LibWebView/WebContentClient.cpp
@@ -151,6 +151,11 @@ void WebContentClient::did_request_image_context_menu(Gfx::IntPoint content_posi
m_view.notify_server_did_request_image_context_menu({}, content_position, url, target, modifiers, bitmap);
}
+void WebContentClient::did_request_video_context_menu(Gfx::IntPoint content_position, AK::URL const& url, DeprecatedString const& target, unsigned modifiers, bool is_playing, bool has_user_agent_controls, bool is_looping)
+{
+ m_view.notify_server_did_request_video_context_menu({}, content_position, url, target, modifiers, is_playing, has_user_agent_controls, is_looping);
+}
+
void WebContentClient::did_get_source(AK::URL const& url, DeprecatedString const& source)
{
m_view.notify_server_did_get_source(url, source);
diff --git a/Userland/Libraries/LibWebView/WebContentClient.h b/Userland/Libraries/LibWebView/WebContentClient.h
index 295affda79..2d2b2227bc 100644
--- a/Userland/Libraries/LibWebView/WebContentClient.h
+++ b/Userland/Libraries/LibWebView/WebContentClient.h
@@ -52,6 +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_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/PageHost.cpp b/Userland/Services/WebContent/PageHost.cpp
index b4722cc970..0a505ee654 100644
--- a/Userland/Services/WebContent/PageHost.cpp
+++ b/Userland/Services/WebContent/PageHost.cpp
@@ -355,6 +355,11 @@ void PageHost::page_did_request_image_context_menu(Web::CSSPixelPoint content_po
m_client.async_did_request_image_context_menu({ content_position.x().value(), content_position.y().value() }, 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)
+{
+ m_client.async_did_request_video_context_menu({ content_position.x().value(), content_position.y().value() }, url, target, modifiers, is_playing, has_user_agent_controls, is_looping);
+}
+
Vector<Web::Cookie::Cookie> PageHost::page_did_request_all_cookies(URL const& url)
{
return m_client.did_request_all_cookies(url);
diff --git a/Userland/Services/WebContent/PageHost.h b/Userland/Services/WebContent/PageHost.h
index 07b07aedba..08c259f217 100644
--- a/Userland/Services/WebContent/PageHost.h
+++ b/Userland/Services/WebContent/PageHost.h
@@ -94,6 +94,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 Vector<Web::Cookie::Cookie> page_did_request_all_cookies(URL const&) override;
virtual Optional<Web::Cookie::Cookie> 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 06f0516a30..3cde0db35f 100644
--- a/Userland/Services/WebContent/WebContentClient.ipc
+++ b/Userland/Services/WebContent/WebContentClient.ipc
@@ -30,6 +30,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_alert(String message) =|
did_request_confirm(String message) =|
did_request_prompt(String message, String default_) =|
diff --git a/Userland/Utilities/headless-browser.cpp b/Userland/Utilities/headless-browser.cpp
index 2549a4d19d..75a1ffa299 100644
--- a/Userland/Utilities/headless-browser.cpp
+++ b/Userland/Utilities/headless-browser.cpp
@@ -113,6 +113,7 @@ private:
void notify_server_did_request_context_menu(Badge<WebView::WebContentClient>, Gfx::IntPoint) override { }
void notify_server_did_request_link_context_menu(Badge<WebView::WebContentClient>, Gfx::IntPoint, const URL&, DeprecatedString const&, unsigned) override { }
void notify_server_did_request_image_context_menu(Badge<WebView::WebContentClient>, Gfx::IntPoint, const URL&, DeprecatedString const&, unsigned, Gfx::ShareableBitmap const&) override { }
+ void notify_server_did_request_video_context_menu(Badge<WebView::WebContentClient>, Gfx::IntPoint, const URL&, DeprecatedString const&, unsigned, bool, bool, bool) override { }
void notify_server_did_request_alert(Badge<WebView::WebContentClient>, String const&) override { }
void notify_server_did_request_confirm(Badge<WebView::WebContentClient>, String const&) override { }
void notify_server_did_request_prompt(Badge<WebView::WebContentClient>, String const&, String const&) override { }