Skip to content

Commit

Permalink
headless-browser: Support loading local file:https:// URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
trflynn89 authored and linusg committed Mar 13, 2023
1 parent 31bdd8a commit 2845a8e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion Userland/Utilities/headless-browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <LibCore/ArgsParser.h>
#include <LibCore/DeprecatedFile.h>
#include <LibCore/EventLoop.h>
#include <LibCore/File.h>
#include <LibCore/Timer.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/Font/FontDatabase.h>
Expand All @@ -31,6 +32,7 @@
#include <LibGfx/Size.h>
#include <LibGfx/StandardCursor.h>
#include <LibGfx/SystemTheme.h>
#include <LibIPC/File.h>
#include <LibWeb/Cookie/Cookie.h>
#include <LibWeb/Cookie/ParsedCookie.h>
#include <LibWeb/Loader/FrameLoader.h>
Expand Down Expand Up @@ -124,7 +126,17 @@ class HeadlessWebContentView final : public WebView::ViewImplementation {
Gfx::IntRect notify_server_did_request_maximize_window() override { return {}; }
Gfx::IntRect notify_server_did_request_minimize_window() override { return {}; }
Gfx::IntRect notify_server_did_request_fullscreen_window() override { return {}; }
void notify_server_did_request_file(Badge<WebView::WebContentClient>, DeprecatedString const&, i32) override { }

void notify_server_did_request_file(Badge<WebView::WebContentClient>, DeprecatedString const& path, i32 request_id) override
{
auto file = Core::File::open(path, Core::File::OpenMode::Read);

if (file.is_error())
client().async_handle_file_return(file.error().code(), {}, request_id);
else
client().async_handle_file_return(0, IPC::File(*file.value()), request_id);
}

void notify_server_did_finish_handling_input_event(bool) override { }
void update_zoom() override { }
void create_client() override { }
Expand Down Expand Up @@ -162,6 +174,9 @@ static ErrorOr<NonnullRefPtr<Core::Timer>> load_page_for_screenshot_and_exit(Cor

static ErrorOr<URL> format_url(StringView url)
{
if (Core::DeprecatedFile::exists(url))
return URL::create_with_file_scheme(Core::DeprecatedFile::real_path_for(url));

URL formatted_url { url };
if (!formatted_url.is_valid())
formatted_url = TRY(String::formatted("http:https://{}", url));
Expand Down

0 comments on commit 2845a8e

Please sign in to comment.