| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of vmservice_io; | 5 part of vmservice_io; |
| 6 | 6 |
| 7 _log(msg) { | 7 _log(msg) { |
| 8 print("% $msg"); | 8 print("% $msg"); |
| 9 } | 9 } |
| 10 | 10 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 var sourceFile = new File(path); | 55 var sourceFile = new File(path); |
| 56 sourceFile.readAsBytes().then((data) { | 56 sourceFile.readAsBytes().then((data) { |
| 57 _sendResourceResponse(sp, id, data); | 57 _sendResourceResponse(sp, id, data); |
| 58 }, | 58 }, |
| 59 onError: (e) { | 59 onError: (e) { |
| 60 var err = "Error loading $uri:\n $e"; | 60 var err = "Error loading $uri:\n $e"; |
| 61 _sendResourceResponse(sp, id, err); | 61 _sendResourceResponse(sp, id, err); |
| 62 }); | 62 }); |
| 63 } | 63 } |
| 64 | 64 |
| 65 var dataUriRegex = new RegExp( | |
| 66 r"data:([\w-]+/[\w-]+)?(;charset=([\w-]+))?(;base64)?,(.*)"); | |
| 67 | |
| 68 void _loadDataUri(SendPort sp, int id, Uri uri) { | 65 void _loadDataUri(SendPort sp, int id, Uri uri) { |
| 69 try { | 66 try { |
| 70 var match = dataUriRegex.firstMatch(uri.toString()); | 67 if (uri.data.mimeType != "application/dart") { |
| 71 if (match == null) throw "Malformed data uri"; | |
| 72 | |
| 73 var mimeType = match.group(1); | |
| 74 var encoding = match.group(3); | |
| 75 var maybeBase64 = match.group(4); | |
| 76 var encodedData = match.group(5); | |
| 77 | |
| 78 if (mimeType != "application/dart") { | |
| 79 throw "MIME-type must be application/dart"; | 68 throw "MIME-type must be application/dart"; |
| 80 } | 69 } |
| 81 if (encoding != "utf-8") { | 70 if (uri.data.charset != "utf-8") { |
| 82 // Default is ASCII. The C++ portion of the embedder assumes UTF-8. | 71 // The C++ portion of the embedder assumes UTF-8. |
| 83 throw "Only utf-8 encoding is supported"; | 72 throw "Only utf-8 encoding is supported"; |
| 84 } | 73 } |
| 85 if (maybeBase64 != null) { | 74 _sendResourceResponse(sp, id, uri.data.contentAsBytes()); |
| 86 throw "Only percent encoding is supported"; | |
| 87 } | |
| 88 | |
| 89 var data = UTF8.encode(Uri.decodeComponent(encodedData)); | |
| 90 _sendResourceResponse(sp, id, data); | |
| 91 } catch (e) { | 75 } catch (e) { |
| 92 _sendResourceResponse(sp, id, "Invalid data uri ($uri):\n $e"); | 76 _sendResourceResponse(sp, id, "Invalid data uri ($uri):\n $e"); |
| 93 } | 77 } |
| 94 } | 78 } |
| 95 | 79 |
| 96 _handleResourceRequest(SendPort sp, bool traceLoading, int id, Uri resource) { | 80 _handleResourceRequest(SendPort sp, bool traceLoading, int id, Uri resource) { |
| 97 if (resource.scheme == 'file') { | 81 if (resource.scheme == 'file') { |
| 98 _loadFile(sp, id, resource); | 82 _loadFile(sp, id, resource); |
| 99 } else if ((resource.scheme == 'http') || (resource.scheme == 'https')) { | 83 } else if ((resource.scheme == 'http') || (resource.scheme == 'https')) { |
| 100 _loadHttp(sp, id, resource); | 84 _loadHttp(sp, id, resource); |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 assert(id != null); | 426 assert(id != null); |
| 443 String resource = request[3]; | 427 String resource = request[3]; |
| 444 assert(resource != null); | 428 assert(resource != null); |
| 445 var uri = Uri.parse(resource); | 429 var uri = Uri.parse(resource); |
| 446 if (id >= 0) { | 430 if (id >= 0) { |
| 447 _handleResourceRequest(sp, traceLoading, id, uri); | 431 _handleResourceRequest(sp, traceLoading, id, uri); |
| 448 } else { | 432 } else { |
| 449 _handlePackagesRequest(sp, traceLoading, id, uri); | 433 _handlePackagesRequest(sp, traceLoading, id, uri); |
| 450 } | 434 } |
| 451 } | 435 } |
| OLD | NEW |