diff options
author | Andreas Kling <kling@serenityos.org> | 2020-04-26 22:52:30 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-26 22:57:00 +0200 |
commit | e3232eb25be06b5f0dbe94dc8850f8b02cc26c9f (patch) | |
tree | 33f05532c2af1396cedca2531648a871a0d94d6f /Libraries | |
parent | 50c1eca9d4aa2f90085dd510c9432a007b3400e2 (diff) | |
download | serenity-e3232eb25be06b5f0dbe94dc8850f8b02cc26c9f.zip |
LibWeb: Support loading data: URLs transparently via ResourceLoader
This is pretty darn cool! :^)
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibWeb/ResourceLoader.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Libraries/LibWeb/ResourceLoader.cpp b/Libraries/LibWeb/ResourceLoader.cpp index ed013daeae..a26ab27746 100644 --- a/Libraries/LibWeb/ResourceLoader.cpp +++ b/Libraries/LibWeb/ResourceLoader.cpp @@ -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()); |