Browse Source

LibWeb: Support loading data: URLs transparently via ResourceLoader

This is pretty darn cool! :^)
Andreas Kling 5 years ago
parent
commit
e3232eb25b
2 changed files with 21 additions and 0 deletions
  1. 5 0
      Base/home/anon/www/data-url.html
  2. 16 0
      Libraries/LibWeb/ResourceLoader.cpp

File diff suppressed because it is too large
+ 5 - 0
Base/home/anon/www/data-url.html


+ 16 - 0
Libraries/LibWeb/ResourceLoader.cpp

@@ -24,6 +24,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
  */
 
 
+#include <AK/Base64.h>
 #include <AK/SharedBuffer.h>
 #include <AK/SharedBuffer.h>
 #include <LibCore/EventLoop.h>
 #include <LibCore/EventLoop.h>
 #include <LibCore/File.h>
 #include <LibCore/File.h>
@@ -72,6 +73,21 @@ void ResourceLoader::load(const URL& url, Function<void(const ByteBuffer&)> succ
         return;
         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") {
     if (url.protocol() == "file") {
         auto f = Core::File::construct();
         auto f = Core::File::construct();
         f->set_filename(url.path());
         f->set_filename(url.path());

Some files were not shown because too many files changed in this diff