mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-05 02:33:03 +00:00
LibWeb: Support loading data: URLs transparently via ResourceLoader
This is pretty darn cool! :^)
This commit is contained in:
parent
50c1eca9d4
commit
e3232eb25b
Notes:
sideshowbarker
2024-07-19 07:15:34 +09:00
Author: https://github.com/awesomekling
Commit: e3232eb25b
2 changed files with 24 additions and 0 deletions
|
@ -24,6 +24,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <AK/Base64.h>
|
||||
#include <AK/SharedBuffer.h>
|
||||
#include <LibCore/EventLoop.h>
|
||||
#include <LibCore/File.h>
|
||||
|
@ -72,6 +73,21 @@ void ResourceLoader::load(const URL& url, Function<void(const ByteBuffer&)> succ
|
|||
return;
|
||||
}
|
||||
|
||||
if (url.protocol() == "data") {
|
||||
dbg() << "ResourceLoader loading a data URL with mime-type: '" << url.data_mime_type() << "', base64=" << url.data_payload_is_base64() << ", payload='" << url.data_payload() << "'";
|
||||
|
||||
ByteBuffer data;
|
||||
if (url.data_payload_is_base64())
|
||||
data = decode_base64(url.data_payload());
|
||||
else
|
||||
data = url.data_payload().to_byte_buffer();
|
||||
|
||||
deferred_invoke([data = move(data), success_callback = move(success_callback)](auto&) {
|
||||
success_callback(data);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (url.protocol() == "file") {
|
||||
auto f = Core::File::construct();
|
||||
f->set_filename(url.path());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue