Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3694)

Unified Diff: runtime/bin/vmservice/loader.dart

Issue 1028453002: Support percent encoded data URIs in the standalone embedder. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/builtin.dart ('k') | runtime/tests/vm/dart/data_uri_failures_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/vmservice/loader.dart
diff --git a/runtime/bin/vmservice/loader.dart b/runtime/bin/vmservice/loader.dart
index 6d81f0454a0da3d6f6e475c6f922ec24cdd9f37a..1c4ae95e74a41261285a3e3627ee17c4fd585c91 100644
--- a/runtime/bin/vmservice/loader.dart
+++ b/runtime/bin/vmservice/loader.dart
@@ -47,6 +47,37 @@ void _loadFile(sendPort, path) {
});
}
+var dataUriRegex = new RegExp(
+ r"data:([\w-]+/[\w-]+)?(;charset=([\w-]+))?(;base64)?,(.*)");
+
+void _loadDataUri(sendPort, uri) {
+ try {
+ var match = dataUriRegex.firstMatch(uri.toString());
+ if (match == null) throw "Malformed data uri";
+
+ var mimeType = match.group(1);
+ var encoding = match.group(3);
+ var maybeBase64 = match.group(4);
+ var encodedData = match.group(5);
+
+ if (mimeType != "application/dart") {
+ throw "MIME-type must be application/dart";
+ }
+ if (encoding != "utf-8") {
+ // Default is ASCII. The C++ portion of the embedder assumes UTF-8.
+ throw "Only utf-8 encoding is supported";
+ }
+ if (maybeBase64 != null) {
+ throw "Only percent encoding is supported";
+ }
+
+ var data = UTF8.encode(Uri.decodeComponent(encodedData));
+ sendPort.send(data);
+ } catch (e) {
+ sendPort.send("Invalid data uri ($uri) $e");
+ }
+}
+
_processLoadRequest(request) {
var sp = request[0];
var uri = Uri.parse(request[1]);
@@ -54,6 +85,8 @@ _processLoadRequest(request) {
_loadFile(sp, uri.toFilePath());
} else if ((uri.scheme == 'http') || (uri.scheme == 'https')) {
_loadHttp(sp, uri);
+ } else if ((uri.scheme == 'data')) {
+ _loadDataUri(sp, uri);
} else {
sp.send('Unknown scheme for $uri');
}
« no previous file with comments | « runtime/bin/builtin.dart ('k') | runtime/tests/vm/dart/data_uri_failures_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698