1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:04:59 +00:00

Ladybird+LibWebView+WebContent: Make the screenshot IPCs async

These IPCs are different than other IPCs in that we can't just set up a
callback function to be invoked when WebContent sends us the screenshot
data. There are multiple places that would set that callback, and they
would step on each other's toes.

Instead, the screenshot APIs on ViewImplementation now return a Promise
which callers can interact with to receive the screenshot (or an error).
This commit is contained in:
Timothy Flynn 2023-12-31 09:51:02 -05:00 committed by Andreas Kling
parent 93db790974
commit d8fa226a8f
13 changed files with 121 additions and 47 deletions

View file

@ -310,19 +310,19 @@ Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, St
auto* take_visible_screenshot_action = new QAction("Take &Visible Screenshot", this);
take_visible_screenshot_action->setIcon(load_icon_from_uri("resource://icons/16x16/filetype-image.png"sv));
QObject::connect(take_visible_screenshot_action, &QAction::triggered, this, [this]() {
if (auto result = view().take_screenshot(WebView::ViewImplementation::ScreenshotType::Visible); result.is_error()) {
auto error = MUST(String::formatted("{}", result.error()));
QMessageBox::warning(this, "Ladybird", qstring_from_ak_string(error));
}
view().take_screenshot(WebView::ViewImplementation::ScreenshotType::Visible)->when_rejected([this](auto const& error) {
auto error_message = MUST(String::formatted("{}", error));
QMessageBox::warning(this, "Ladybird", qstring_from_ak_string(error_message));
});
});
auto* take_full_screenshot_action = new QAction("Take &Full Screenshot", this);
take_full_screenshot_action->setIcon(load_icon_from_uri("resource://icons/16x16/filetype-image.png"sv));
QObject::connect(take_full_screenshot_action, &QAction::triggered, this, [this]() {
if (auto result = view().take_screenshot(WebView::ViewImplementation::ScreenshotType::Full); result.is_error()) {
auto error = MUST(String::formatted("{}", result.error()));
QMessageBox::warning(this, "Ladybird", qstring_from_ak_string(error));
}
view().take_screenshot(WebView::ViewImplementation::ScreenshotType::Full)->when_rejected([this](auto const& error) {
auto error_message = MUST(String::formatted("{}", error));
QMessageBox::warning(this, "Ladybird", qstring_from_ak_string(error_message));
});
});
m_page_context_menu = new QMenu("Context menu", this);