mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:37:43 +00:00
LibWeb: Start building a new Resource class to share more resources
A Resource represents a resource that we're loading, have loaded or will soon load. Basically, it's a downloadable resource that can be shared by multiple clients. A typical usecase is multiple <img> elements with the same src. In a future patch, we will try to make sure that those <img> elements get the same Resource if possible. This will reduce network usage, memory usage, and CPU usage. :^) For now, this first patch simply introduces the mechanism. You get a Resource by calling ResourceLoader::load_resource(). To get notified about changes to a Resource's load status, you inherit from ResourceClient and implement the callbacks you're interested in. This patch turns HTMLImageElement into a ResourceClient.
This commit is contained in:
parent
7be9cf8d36
commit
5ed66cb8d9
8 changed files with 274 additions and 23 deletions
|
@ -29,6 +29,7 @@
|
|||
#include <AK/Function.h>
|
||||
#include <AK/URL.h>
|
||||
#include <LibCore/Object.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Protocol {
|
||||
class Client;
|
||||
|
@ -41,6 +42,8 @@ class ResourceLoader : public Core::Object {
|
|||
public:
|
||||
static ResourceLoader& the();
|
||||
|
||||
RefPtr<Resource> load_resource(const URL&);
|
||||
|
||||
void load(const URL&, Function<void(const ByteBuffer&, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers)> success_callback, Function<void(const String&)> error_callback = nullptr);
|
||||
void load_sync(const URL&, Function<void(const ByteBuffer&, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers)> success_callback, Function<void(const String&)> error_callback = nullptr);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue