/* * Copyright (c) 2018-2020, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include 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(ResourceLoader) public: static ResourceLoader& the(); RefPtr load_resource(Resource::Type, LoadRequest&); void load(LoadRequest&, Function& response_headers, Optional status_code)> success_callback, Function status_code)> error_callback = nullptr); void load(const AK::URL&, Function& response_headers, Optional status_code)> success_callback, Function status_code)> error_callback = nullptr); void load_sync(LoadRequest&, Function& response_headers, Optional status_code)> success_callback, Function status_code)> error_callback = nullptr); void prefetch_dns(AK::URL const&); void preconnect(AK::URL const&); Function 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(); static bool is_port_blocked(int port); int m_pending_loads { 0 }; HashTable> m_active_requests; RefPtr m_protocol_client; String m_user_agent; }; }