2023-08-20 20:14:31 +00:00
|
|
|
/*
|
2024-07-30 18:01:05 +00:00
|
|
|
* Copyright (c) 2023-2024, Tim Flynn <trflynn89@serenityos.org>
|
2023-08-20 20:14:31 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2024-04-28 16:30:34 +00:00
|
|
|
#include <AK/Enumerate.h>
|
2024-05-31 08:54:11 +00:00
|
|
|
#include <Ladybird/DefaultSettings.h>
|
2024-04-04 20:13:14 +00:00
|
|
|
#include <Ladybird/MachPortServer.h>
|
2023-08-20 20:14:31 +00:00
|
|
|
#include <Ladybird/Utilities.h>
|
|
|
|
#include <LibGfx/Font/FontDatabase.h>
|
|
|
|
#include <LibMain/Main.h>
|
2024-06-30 04:24:01 +00:00
|
|
|
#include <LibWebView/Application.h>
|
2024-04-28 16:30:34 +00:00
|
|
|
#include <LibWebView/ChromeProcess.h>
|
2023-10-13 15:04:07 +00:00
|
|
|
#include <LibWebView/URL.h>
|
2024-06-20 18:34:51 +00:00
|
|
|
#include <LibWebView/ViewImplementation.h>
|
|
|
|
#include <LibWebView/WebContentClient.h>
|
2023-08-20 20:14:31 +00:00
|
|
|
|
|
|
|
#import <Application/Application.h>
|
|
|
|
#import <Application/ApplicationDelegate.h>
|
|
|
|
#import <Application/EventLoopImplementation.h>
|
|
|
|
#import <UI/Tab.h>
|
|
|
|
#import <UI/TabController.h>
|
|
|
|
|
|
|
|
#if !__has_feature(objc_arc)
|
|
|
|
# error "This project requires ARC"
|
|
|
|
#endif
|
|
|
|
|
2024-07-30 18:01:05 +00:00
|
|
|
static void open_urls_from_client(Vector<URL::URL> const& urls, WebView::NewWindow new_window)
|
2024-04-28 16:30:34 +00:00
|
|
|
{
|
|
|
|
ApplicationDelegate* delegate = [NSApp delegate];
|
2024-07-30 18:01:05 +00:00
|
|
|
Tab* tab = new_window == WebView::NewWindow::Yes ? nil : [delegate activeTab];
|
2024-04-28 16:30:34 +00:00
|
|
|
|
|
|
|
for (auto [i, url] : enumerate(urls)) {
|
|
|
|
auto activate_tab = i == 0 ? Web::HTML::ActivateTab::Yes : Web::HTML::ActivateTab::No;
|
|
|
|
|
|
|
|
auto* controller = [delegate createNewTab:url
|
|
|
|
fromTab:tab
|
|
|
|
activateTab:activate_tab];
|
|
|
|
|
|
|
|
tab = (Tab*)[controller window];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-20 20:14:31 +00:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|
|
|
{
|
2023-12-11 18:19:41 +00:00
|
|
|
AK::set_rich_debug_enabled(true);
|
|
|
|
|
2024-04-15 23:39:48 +00:00
|
|
|
Application* application = [Application sharedApplication];
|
2023-08-20 20:14:31 +00:00
|
|
|
|
|
|
|
Core::EventLoopManager::install(*new Ladybird::CFEventLoopManager);
|
2024-07-30 18:01:05 +00:00
|
|
|
[application setupWebViewApplication:arguments newTabPageURL:Browser::default_new_tab_url];
|
2023-08-20 20:14:31 +00:00
|
|
|
|
|
|
|
platform_init();
|
|
|
|
|
2024-10-07 17:36:17 +00:00
|
|
|
WebView::ChromeProcess chrome_process;
|
2024-07-30 18:01:05 +00:00
|
|
|
|
|
|
|
if (auto const& chrome_options = WebView::Application::chrome_options(); chrome_options.force_new_process == WebView::ForceNewProcess::No) {
|
|
|
|
auto disposition = TRY(chrome_process.connect(chrome_options.raw_urls, chrome_options.new_window));
|
|
|
|
|
|
|
|
if (disposition == WebView::ChromeProcess::ProcessDisposition::ExitProcess) {
|
|
|
|
outln("Opening in existing process");
|
|
|
|
return 0;
|
|
|
|
}
|
2024-04-28 16:30:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
chrome_process.on_new_tab = [&](auto const& raw_urls) {
|
2024-07-30 18:01:05 +00:00
|
|
|
open_urls_from_client(raw_urls, WebView::NewWindow::No);
|
2024-04-28 16:30:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
chrome_process.on_new_window = [&](auto const& raw_urls) {
|
2024-07-30 18:01:05 +00:00
|
|
|
open_urls_from_client(raw_urls, WebView::NewWindow::Yes);
|
2024-04-28 16:30:34 +00:00
|
|
|
};
|
|
|
|
|
2024-04-04 20:13:14 +00:00
|
|
|
auto mach_port_server = make<Ladybird::MachPortServer>();
|
|
|
|
set_mach_server_name(mach_port_server->server_port_name());
|
2024-07-30 18:01:05 +00:00
|
|
|
mach_port_server->on_receive_child_mach_port = [&](auto pid, auto port) {
|
|
|
|
WebView::Application::the().set_process_mach_port(pid, move(port));
|
2024-04-04 20:13:14 +00:00
|
|
|
};
|
2024-06-20 18:34:51 +00:00
|
|
|
mach_port_server->on_receive_backing_stores = [](Ladybird::MachPortServer::BackingStoresMessage message) {
|
2024-06-30 04:24:01 +00:00
|
|
|
if (auto view = WebView::WebContentClient::view_for_pid_and_page_id(message.pid, message.page_id); view.has_value())
|
|
|
|
view->did_allocate_iosurface_backing_stores(message.front_backing_store_id, move(message.front_backing_store_port), message.back_backing_store_id, move(message.back_backing_store_port));
|
2024-06-20 18:34:51 +00:00
|
|
|
};
|
2024-04-04 20:13:14 +00:00
|
|
|
|
2024-04-15 23:39:48 +00:00
|
|
|
// FIXME: Create an abstraction to re-spawn the RequestServer and re-hook up its client hooks to each tab on crash
|
2024-07-30 18:01:05 +00:00
|
|
|
TRY([application launchRequestServer]);
|
2024-04-15 23:39:48 +00:00
|
|
|
|
2024-06-26 19:44:42 +00:00
|
|
|
TRY([application launchImageDecoder]);
|
|
|
|
|
2024-09-05 22:19:51 +00:00
|
|
|
auto* delegate = [[ApplicationDelegate alloc] init];
|
2023-08-20 20:14:31 +00:00
|
|
|
[NSApp setDelegate:delegate];
|
|
|
|
|
2024-07-30 18:01:05 +00:00
|
|
|
return WebView::Application::the().execute();
|
2023-08-20 20:14:31 +00:00
|
|
|
}
|