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

Side by Side Diff: runtime/bin/vmservice/loader.dart

Issue 1585103006: - Add support for passing data: based URIs as packageConfig to (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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 unified diff | Download patch
« no previous file with comments | « no previous file | runtime/tests/vm/vm.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 void _loadDataUri(SendPort sp, int id, Uri uri) { 65 void _loadDataUri(SendPort sp, int id, Uri uri) {
66 try { 66 try {
67 if (uri.data.mimeType != "application/dart") { 67 var mime = uri.data.mimeType;
68 throw "MIME-type must be application/dart"; 68 if ((mime != "application/dart") &&
69 (mime != "text/plain")) {
70 throw "MIME-type must be application/dart or text/plain: $mime given.";
69 } 71 }
70 if (uri.data.charset != "utf-8") { 72 var charset = uri.data.charset;
73 if ((charset != "utf-8") &&
74 (charset != "US-ASCII")) {
71 // The C++ portion of the embedder assumes UTF-8. 75 // The C++ portion of the embedder assumes UTF-8.
72 throw "Only utf-8 encoding is supported"; 76 throw "Only utf-8 or US-ASCII encodings are supported: $charset given.";
73 } 77 }
74 _sendResourceResponse(sp, id, uri.data.contentAsBytes()); 78 _sendResourceResponse(sp, id, uri.data.contentAsBytes());
75 } catch (e) { 79 } catch (e) {
76 _sendResourceResponse(sp, id, "Invalid data uri ($uri):\n $e"); 80 _sendResourceResponse(sp, id, "Invalid data uri ($uri):\n $e");
77 } 81 }
78 } 82 }
79 83
80 _handleResourceRequest(SendPort sp, bool traceLoading, int id, Uri resource) { 84 _handleResourceRequest(SendPort sp, bool traceLoading, int id, Uri resource) {
81 if (resource.scheme == 'file') { 85 if (resource.scheme == 'file') {
82 _loadFile(sp, id, resource); 86 _loadFile(sp, id, resource);
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 var data = await new File.fromUri(packagesFile).readAsBytes(); 259 var data = await new File.fromUri(packagesFile).readAsBytes();
256 if (traceLoading) { 260 if (traceLoading) {
257 _log("Loaded packages file from $packagesFile:\n" 261 _log("Loaded packages file from $packagesFile:\n"
258 "${new String.fromCharCodes(data)}"); 262 "${new String.fromCharCodes(data)}");
259 } 263 }
260 _parsePackagesFile(sp, traceLoading, packagesFile, data); 264 _parsePackagesFile(sp, traceLoading, packagesFile, data);
261 } catch (e, s) { 265 } catch (e, s) {
262 if (traceLoading) { 266 if (traceLoading) {
263 _log("Error loading packages: $e\n$s"); 267 _log("Error loading packages: $e\n$s");
264 } 268 }
265 sp.send("Uncaught error ($e) loading packags file."); 269 sp.send("Uncaught error ($e) loading packages file.");
266 } 270 }
267 } 271 }
268 272
269 _findPackagesFile(SendPort sp, bool traceLoading, Uri base) async { 273 _findPackagesFile(SendPort sp, bool traceLoading, Uri base) async {
270 try { 274 try {
271 // Walk up the directory hierarchy to check for the existence of 275 // Walk up the directory hierarchy to check for the existence of
272 // .packages files in parent directories and for the existense of a 276 // .packages files in parent directories and for the existense of a
273 // packages/ directory on the first iteration. 277 // packages/ directory on the first iteration.
274 var dir = new File.fromUri(base).parent; 278 var dir = new File.fromUri(base).parent;
275 var prev = null; 279 var prev = null;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 _parsePackagesFile(sp, traceLoading, resource, data); 361 _parsePackagesFile(sp, traceLoading, resource, data);
358 } catch (e, s) { 362 } catch (e, s) {
359 if (traceLoading) { 363 if (traceLoading) {
360 _log("Error loading packages file from '$resource': $e\n$s"); 364 _log("Error loading packages file from '$resource': $e\n$s");
361 } 365 }
362 sp.send("Uncaught error ($e) loading packages file from '$resource'."); 366 sp.send("Uncaught error ($e) loading packages file from '$resource'.");
363 } 367 }
364 return false; 368 return false;
365 } 369 }
366 370
371 _loadPackagesData(sp, traceLoading, resource){
372 try {
373 var data = resource.data;
374 var mime = data.mimeType;
375 if (mime != "text/plain") {
376 throw "MIME-type must be text/plain: $mime given.";
377 }
378 var charset = data.charset;
379 if ((charset != "utf-8") &&
380 (charset != "US-ASCII")) {
381 // The C++ portion of the embedder assumes UTF-8.
382 throw "Only utf-8 or US-ASCII encodings are supported: $charset given.";
383 }
384 _parsePackagesFile(sp, traceLoading, resource, data.contentAsBytes());
385 } catch (e) {
386 sp.send("Uncaught error ($e) loading packages data.");
387 }
388 }
389
390
367 _handlePackagesRequest(SendPort sp, 391 _handlePackagesRequest(SendPort sp,
368 bool traceLoading, 392 bool traceLoading,
369 int id, 393 int id,
370 Uri resource) async { 394 Uri resource) async {
371 try { 395 try {
372 if (id == -1) { 396 if (id == -1) {
373 if (resource.scheme == 'file') { 397 if (resource.scheme == 'file') {
374 _findPackagesFile(sp, traceLoading, resource); 398 _findPackagesFile(sp, traceLoading, resource);
375 } else if ((resource.scheme == 'http') || (resource.scheme == 'https')) { 399 } else if ((resource.scheme == 'http') || (resource.scheme == 'https')) {
376 // Try to load the .packages file next to the resource. 400 // Try to load the .packages file next to the resource.
(...skipping 18 matching lines...) Expand all
395 if (exists) { 419 if (exists) {
396 _loadPackagesFile(sp, traceLoading, resource); 420 _loadPackagesFile(sp, traceLoading, resource);
397 } else { 421 } else {
398 sp.send("Packages file '$resource' not found."); 422 sp.send("Packages file '$resource' not found.");
399 } 423 }
400 } else if ((resource.scheme == 'http') || (resource.scheme == 'https')) { 424 } else if ((resource.scheme == 'http') || (resource.scheme == 'https')) {
401 var exists = await _loadHttpPackagesFile(sp, traceLoading, resource); 425 var exists = await _loadHttpPackagesFile(sp, traceLoading, resource);
402 if (!exists) { 426 if (!exists) {
403 sp.send("Packages file '$resource' not found."); 427 sp.send("Packages file '$resource' not found.");
404 } 428 }
429 } else if (resource.scheme == 'data') {
430 _loadPackagesData(sp, traceLoading, resource);
405 } else { 431 } else {
406 sp.send("Unknown scheme (${resource.scheme}) for package file at " 432 sp.send("Unknown scheme (${resource.scheme}) for package file at "
407 "'$resource'."); 433 "'$resource'.");
408 } 434 }
409 } else { 435 } else {
410 sp.send("Unknown packages request id: $id for '$resource'."); 436 sp.send("Unknown packages request id: $id for '$resource'.");
411 } 437 }
412 } catch (e, s) { 438 } catch (e, s) {
413 if (traceLoading) { 439 if (traceLoading) {
414 _log("Error handling packages request: $e\n$s"); 440 _log("Error handling packages request: $e\n$s");
(...skipping 13 matching lines...) Expand all
428 assert(id != null); 454 assert(id != null);
429 String resource = request[3]; 455 String resource = request[3];
430 assert(resource != null); 456 assert(resource != null);
431 var uri = Uri.parse(resource); 457 var uri = Uri.parse(resource);
432 if (id >= 0) { 458 if (id >= 0) {
433 _handleResourceRequest(sp, traceLoading, id, uri); 459 _handleResourceRequest(sp, traceLoading, id, uri);
434 } else { 460 } else {
435 _handlePackagesRequest(sp, traceLoading, id, uri); 461 _handlePackagesRequest(sp, traceLoading, id, uri);
436 } 462 }
437 } 463 }
OLDNEW
« no previous file with comments | « no previous file | runtime/tests/vm/vm.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698