1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-17 21:15:06 +00:00
serenity/Userland/Libraries/LibWeb/Loader/ResourceLoader.h
sin-ack 2e1bbcb0fa LibCore+LibIPC+Everywhere: Return Stream::LocalSocket from LocalServer
This change unfortunately cannot be atomically made without a single
commit changing everything.

Most of the important changes are in LibIPC/Connection.cpp,
LibIPC/ServerConnection.cpp and LibCore/LocalServer.cpp.

The notable changes are:
- IPCCompiler now generates the decode and decode_message functions such
  that they take a Core::Stream::LocalSocket instead of the socket fd.
- IPC::Decoder now uses the receive_fd method of LocalSocket instead of
  doing system calls directly on the fd.
- IPC::ConnectionBase and related classes now use the Stream API
  functions.
- IPC::ServerConnection no longer constructs the socket itself; instead,
  a convenience macro, IPC_CLIENT_CONNECTION, is used in place of
  C_OBJECT and will generate a static try_create factory function for
  the ServerConnection subclass. The subclass is now responsible for
  passing the socket constructed in this function to its
  ServerConnection base; the socket is passed as the first argument to
  the constructor (as a NonnullOwnPtr<Core::Stream::LocalServer>) before
  any other arguments.
- The functionality regarding taking over sockets from SystemServer has
  been moved to LibIPC/SystemServerTakeover.cpp. The Core::LocalSocket
  implementation of this functionality hasn't been deleted due to my
  intention of removing this class in the near future and to reduce
  noise on this (already quite noisy) PR.
2022-01-15 13:29:48 +03:30

67 lines
2.3 KiB
C++

/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Function.h>
#include <AK/URL.h>
#include <LibCore/Object.h>
#include <LibWeb/Loader/Resource.h>
namespace Protocol {
class RequestClient;
class Request;
}
namespace Web {
#if ARCH(I386)
# define CPU_STRING "x86"
#else
# define CPU_STRING "x86_64"
#endif
constexpr auto default_user_agent = "Mozilla/4.0 (SerenityOS; " CPU_STRING ") LibWeb+LibJS (Not KHTML, nor Gecko) LibWeb";
class ResourceLoader : public Core::Object {
C_OBJECT_ABSTRACT(ResourceLoader)
public:
static ResourceLoader& the();
RefPtr<Resource> load_resource(Resource::Type, LoadRequest&);
void load(LoadRequest&, Function<void(ReadonlyBytes, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers, Optional<u32> status_code)> success_callback, Function<void(const String&, Optional<u32> status_code)> error_callback = nullptr);
void load(const AK::URL&, Function<void(ReadonlyBytes, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers, Optional<u32> status_code)> success_callback, Function<void(const String&, Optional<u32> status_code)> error_callback = nullptr);
void load_sync(LoadRequest&, Function<void(ReadonlyBytes, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers, Optional<u32> status_code)> success_callback, Function<void(const String&, Optional<u32> status_code)> error_callback = nullptr);
void prefetch_dns(AK::URL const&);
void preconnect(AK::URL const&);
Function<void()> on_load_counter_change;
int pending_loads() const { return m_pending_loads; }
Protocol::RequestClient& protocol_client() { return *m_protocol_client; }
const String& user_agent() const { return m_user_agent; }
void set_user_agent(const String& user_agent) { m_user_agent = user_agent; }
void clear_cache();
private:
ResourceLoader(NonnullRefPtr<Protocol::RequestClient> protocol_client);
static ErrorOr<NonnullRefPtr<ResourceLoader>> try_create();
static bool is_port_blocked(int port);
int m_pending_loads { 0 };
HashTable<NonnullRefPtr<Protocol::Request>> m_active_requests;
RefPtr<Protocol::RequestClient> m_protocol_client;
String m_user_agent;
};
}