LibWeb: Support loading data: URLs transparently via ResourceLoader

This is pretty darn cool! :^)
This commit is contained in:
Andreas Kling 2020-04-26 22:52:30 +02:00
parent 50c1eca9d4
commit e3232eb25b
Notes: sideshowbarker 2024-07-19 07:15:34 +09:00
2 changed files with 24 additions and 0 deletions

View file

@ -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());