mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
LibHTML: Use LibProtocol for HTTP requests :^)
This moves all of the browser networking to ProtocolServer.
This commit is contained in:
parent
653e61d9cf
commit
0d2659c0a2
Notes:
sideshowbarker
2024-07-19 11:05:52 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/0d2659c0a2c
4 changed files with 26 additions and 22 deletions
|
@ -3,7 +3,7 @@ DEFINES += -DUSERLAND
|
|||
all: $(APP)
|
||||
|
||||
$(APP): $(OBJS)
|
||||
$(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lmarkdown -lhtml -laudio -lipc -lvt -lpcidb -lgui -ldraw -lthread -lpthread -lcore -lc
|
||||
$(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lmarkdown -lhtml -laudio -lipc -lvt -lpcidb -lgui -ldraw -lprotocol -lipc -lthread -lpthread -lcore -lc
|
||||
|
||||
.cpp.o:
|
||||
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
|
||||
|
|
|
@ -25,7 +25,7 @@ DEFINES += -DUSERLAND
|
|||
all: $(APP)
|
||||
|
||||
$(APP): $(OBJS)
|
||||
$(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lvt -lhtml -lmarkdown -lgui -ldraw -lthread -lpthread -lcore -lc
|
||||
$(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lvt -lhtml -lprotocol -lipc -lmarkdown -lgui -ldraw -lthread -lpthread -lcore -lc
|
||||
|
||||
.cpp.o:
|
||||
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include <LibC/SharedBuffer.h>
|
||||
#include <LibCore/CFile.h>
|
||||
#include <LibCore/CHttpJob.h>
|
||||
#include <LibCore/CHttpRequest.h>
|
||||
#include <LibCore/CNetworkResponse.h>
|
||||
#include <LibHTML/ResourceLoader.h>
|
||||
#include <LibProtocol/Client.h>
|
||||
#include <LibProtocol/Download.h>
|
||||
|
||||
ResourceLoader& ResourceLoader::the()
|
||||
{
|
||||
|
@ -12,6 +12,11 @@ ResourceLoader& ResourceLoader::the()
|
|||
return *s_the;
|
||||
}
|
||||
|
||||
ResourceLoader::ResourceLoader()
|
||||
: m_protocol_client(LibProtocol::Client::construct())
|
||||
{
|
||||
}
|
||||
|
||||
void ResourceLoader::load(const URL& url, Function<void(const ByteBuffer&)> callback)
|
||||
{
|
||||
if (url.protocol() == "file") {
|
||||
|
@ -31,25 +36,17 @@ void ResourceLoader::load(const URL& url, Function<void(const ByteBuffer&)> call
|
|||
}
|
||||
|
||||
if (url.protocol() == "http") {
|
||||
CHttpRequest request;
|
||||
request.set_url(url);
|
||||
request.set_method(CHttpRequest::Method::GET);
|
||||
auto job = request.schedule();
|
||||
auto download = protocol_client().start_download(url.to_string());
|
||||
download->on_finish = [callback = move(callback)](bool success, const ByteBuffer& payload, auto) {
|
||||
if (!success) {
|
||||
dbg() << "HTTP load failed!";
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
callback(ByteBuffer::copy(payload.data(), payload.size()));
|
||||
};
|
||||
++m_pending_loads;
|
||||
if (on_load_counter_change)
|
||||
on_load_counter_change();
|
||||
job->on_finish = [this, job, callback = move(callback)](bool success) {
|
||||
--m_pending_loads;
|
||||
if (on_load_counter_change)
|
||||
on_load_counter_change();
|
||||
if (!success) {
|
||||
dbg() << "HTTP job failed!";
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
auto* response = job->response();
|
||||
ASSERT(response);
|
||||
callback(response->payload());
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,10 @@
|
|||
#include <AK/URL.h>
|
||||
#include <LibCore/CObject.h>
|
||||
|
||||
namespace LibProtocol {
|
||||
class Client;
|
||||
}
|
||||
|
||||
class ResourceLoader : public CObject {
|
||||
C_OBJECT(ResourceLoader)
|
||||
public:
|
||||
|
@ -16,7 +20,10 @@ public:
|
|||
int pending_loads() const { return m_pending_loads; }
|
||||
|
||||
private:
|
||||
ResourceLoader() {}
|
||||
ResourceLoader();
|
||||
|
||||
int m_pending_loads { 0 };
|
||||
|
||||
LibProtocol::Client& protocol_client() { return *m_protocol_client; }
|
||||
RefPtr<LibProtocol::Client> m_protocol_client;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue