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 _sanitizeWindowsPath(path) { | 7 _sanitizeWindowsPath(path) { |
8 // For Windows we need to massage the paths a bit according to | 8 // For Windows we need to massage the paths a bit according to |
9 // http://blogs.msdn.com/b/ie/archive/2006/12/06/file-uris-in-windows.aspx | 9 // http://blogs.msdn.com/b/ie/archive/2006/12/06/file-uris-in-windows.aspx |
10 // | 10 // |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 _log(msg) { | 312 _log(msg) { |
313 print("% $msg"); | 313 print("% $msg"); |
314 } | 314 } |
315 | 315 |
316 var _httpClient; | 316 var _httpClient; |
317 | 317 |
318 // Send a response to the requesting isolate. | 318 // Send a response to the requesting isolate. |
319 void _sendResourceResponse(SendPort sp, | 319 void _sendResourceResponse(SendPort sp, |
320 int tag, | 320 int tag, |
321 Uri uri, | 321 Uri uri, |
| 322 Uri resolvedUri, |
322 String libraryUrl, | 323 String libraryUrl, |
323 dynamic data) { | 324 dynamic data) { |
324 assert((data is List<int>) || (data is String)); | 325 assert((data is List<int>) || (data is String)); |
325 var msg = new List(4); | 326 var msg = new List(5); |
326 if (data is String) { | 327 if (data is String) { |
327 // We encountered an error, flip the sign of the tag to indicate that. | 328 // We encountered an error, flip the sign of the tag to indicate that. |
328 tag = -tag; | 329 tag = -tag; |
329 if (libraryUrl == null) { | 330 if (libraryUrl == null) { |
330 data = 'Could not load "$uri": $data'; | 331 data = 'Could not load "$uri": $data'; |
331 } else { | 332 } else { |
332 data = 'Could not import "$uri" from "$libraryUrl": $data'; | 333 data = 'Could not import "$uri" from "$libraryUrl": $data'; |
333 } | 334 } |
334 } | 335 } |
335 msg[0] = tag; | 336 msg[0] = tag; |
336 msg[1] = uri.toString(); | 337 msg[1] = uri.toString(); |
337 msg[2] = libraryUrl; | 338 msg[2] = resolvedUri.toString(); |
338 msg[3] = data; | 339 msg[3] = libraryUrl; |
| 340 msg[4] = data; |
339 sp.send(msg); | 341 sp.send(msg); |
340 } | 342 } |
341 | 343 |
342 // Send a response to the requesting isolate. | 344 // Send a response to the requesting isolate. |
343 void _sendExtensionImportResponse(SendPort sp, | 345 void _sendExtensionImportResponse(SendPort sp, |
344 Uri uri, | 346 Uri uri, |
345 String libraryUrl, | 347 String libraryUrl, |
346 String resolvedUri) { | 348 String resolvedUri) { |
347 var msg = new List(4); | 349 var msg = new List(4); |
348 int tag = _Dart_kImportExtension; | 350 int tag = _Dart_kImportExtension; |
(...skipping 20 matching lines...) Expand all Loading... |
369 _httpClient.getUrl(resolvedUri) | 371 _httpClient.getUrl(resolvedUri) |
370 .then((HttpClientRequest request) => request.close()) | 372 .then((HttpClientRequest request) => request.close()) |
371 .then((HttpClientResponse response) { | 373 .then((HttpClientResponse response) { |
372 var builder = new BytesBuilder(copy: false); | 374 var builder = new BytesBuilder(copy: false); |
373 response.listen( | 375 response.listen( |
374 builder.add, | 376 builder.add, |
375 onDone: () { | 377 onDone: () { |
376 if (response.statusCode != 200) { | 378 if (response.statusCode != 200) { |
377 var msg = "Failure getting $resolvedUri:\n" | 379 var msg = "Failure getting $resolvedUri:\n" |
378 " ${response.statusCode} ${response.reasonPhrase}"; | 380 " ${response.statusCode} ${response.reasonPhrase}"; |
379 _sendResourceResponse(sp, tag, uri, libraryUrl, msg); | 381 _sendResourceResponse(sp, tag, uri, resolvedUri, libraryUrl, msg); |
380 } else { | 382 } else { |
381 _sendResourceResponse(sp, tag, uri, libraryUrl, | 383 _sendResourceResponse(sp, tag, uri, resolvedUri, libraryUrl, |
382 builder.takeBytes()); | 384 builder.takeBytes()); |
383 } | 385 } |
384 }, | 386 }, |
385 onError: (e) { | 387 onError: (e) { |
386 _sendResourceResponse(sp, tag, uri, libraryUrl, e.toString()); | 388 _sendResourceResponse( |
| 389 sp, tag, uri, resolvedUri, libraryUrl, e.toString()); |
387 }); | 390 }); |
388 }) | 391 }) |
389 .catchError((e) { | 392 .catchError((e) { |
390 _sendResourceResponse(sp, tag, uri, libraryUrl, e.toString()); | 393 _sendResourceResponse( |
| 394 sp, tag, uri, resolvedUri, libraryUrl, e.toString()); |
391 }); | 395 }); |
392 // It's just here to push an event on the event loop so that we invoke the | 396 // It's just here to push an event on the event loop so that we invoke the |
393 // scheduled microtasks. | 397 // scheduled microtasks. |
394 Timer.run(() {}); | 398 Timer.run(() {}); |
395 } | 399 } |
396 | 400 |
397 void _loadFile(SendPort sp, | 401 void _loadFile(SendPort sp, |
398 int tag, | 402 int tag, |
399 Uri uri, | 403 Uri uri, |
400 Uri resolvedUri, | 404 Uri resolvedUri, |
401 String libraryUrl) { | 405 String libraryUrl) { |
402 var path = resolvedUri.toFilePath(); | 406 var path = resolvedUri.toFilePath(); |
403 var sourceFile = new File(path); | 407 var sourceFile = new File(path); |
404 sourceFile.readAsBytes().then((data) { | 408 sourceFile.readAsBytes().then((data) { |
405 _sendResourceResponse(sp, tag, uri, libraryUrl, data); | 409 _sendResourceResponse(sp, tag, uri, resolvedUri, libraryUrl, data); |
406 }, | 410 }, |
407 onError: (e) { | 411 onError: (e) { |
408 _sendResourceResponse(sp, tag, uri, libraryUrl, e.toString()); | 412 _sendResourceResponse(sp, tag, uri, resolvedUri, libraryUrl, e.toString()); |
409 }); | 413 }); |
410 } | 414 } |
411 | 415 |
412 void _loadDataUri(SendPort sp, | 416 void _loadDataUri(SendPort sp, |
413 int tag, | 417 int tag, |
414 Uri uri, | 418 Uri uri, |
415 Uri resolvedUri, | 419 Uri resolvedUri, |
416 String libraryUrl) { | 420 String libraryUrl) { |
417 try { | 421 try { |
418 var mime = uri.data.mimeType; | 422 var mime = uri.data.mimeType; |
419 if ((mime != "application/dart") && | 423 if ((mime != "application/dart") && |
420 (mime != "text/plain")) { | 424 (mime != "text/plain")) { |
421 throw "MIME-type must be application/dart or text/plain: $mime given."; | 425 throw "MIME-type must be application/dart or text/plain: $mime given."; |
422 } | 426 } |
423 var charset = uri.data.charset; | 427 var charset = uri.data.charset; |
424 if ((charset != "utf-8") && | 428 if ((charset != "utf-8") && |
425 (charset != "US-ASCII")) { | 429 (charset != "US-ASCII")) { |
426 // The C++ portion of the embedder assumes UTF-8. | 430 // The C++ portion of the embedder assumes UTF-8. |
427 throw "Only utf-8 or US-ASCII encodings are supported: $charset given."; | 431 throw "Only utf-8 or US-ASCII encodings are supported: $charset given."; |
428 } | 432 } |
429 _sendResourceResponse(sp, tag, uri, libraryUrl, uri.data.contentAsBytes()); | 433 _sendResourceResponse( |
| 434 sp, tag, uri, resolvedUri, libraryUrl, uri.data.contentAsBytes()); |
430 } catch (e) { | 435 } catch (e) { |
431 _sendResourceResponse(sp, tag, uri, libraryUrl, | 436 _sendResourceResponse(sp, tag, uri, resolvedUri, libraryUrl, |
432 "Invalid data uri ($uri):\n $e"); | 437 "Invalid data uri ($uri):\n $e"); |
433 } | 438 } |
434 } | 439 } |
435 | 440 |
436 // Loading a package URI needs to first map the package name to a loadable | 441 // Loading a package URI needs to first map the package name to a loadable |
437 // URI. | 442 // URI. |
438 _loadPackage(IsolateLoaderState loaderState, | 443 _loadPackage(IsolateLoaderState loaderState, |
439 SendPort sp, | 444 SendPort sp, |
440 bool traceLoading, | 445 bool traceLoading, |
441 int tag, | 446 int tag, |
442 Uri uri, | 447 Uri uri, |
443 Uri resolvedUri, | 448 Uri resolvedUri, |
444 String libraryUrl) { | 449 String libraryUrl) { |
445 if (loaderState._packagesReady) { | 450 if (loaderState._packagesReady) { |
446 var resolvedUri; | 451 var resolvedUri; |
447 try { | 452 try { |
448 resolvedUri = loaderState._resolvePackageUri(uri); | 453 resolvedUri = loaderState._resolvePackageUri(uri); |
449 } catch (e, s) { | 454 } catch (e, s) { |
450 if (traceLoading) { | 455 if (traceLoading) { |
451 _log("Exception ($e) when resolving package URI: $uri"); | 456 _log("Exception ($e) when resolving package URI: $uri"); |
452 } | 457 } |
453 // Report error. | 458 // Report error. |
454 _sendResourceResponse(sp, | 459 _sendResourceResponse(sp, |
455 tag, | 460 tag, |
456 uri, | 461 uri, |
| 462 resolvedUri, |
457 libraryUrl, | 463 libraryUrl, |
458 e.toString()); | 464 e.toString()); |
459 return; | 465 return; |
460 } | 466 } |
461 // Recursively call with the new resolved uri. | 467 // Recursively call with the new resolved uri. |
462 _handleResourceRequest(loaderState, | 468 _handleResourceRequest(loaderState, |
463 sp, | 469 sp, |
464 traceLoading, | 470 traceLoading, |
465 tag, | 471 tag, |
466 uri, | 472 uri, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 _loadPackage(loaderState, | 516 _loadPackage(loaderState, |
511 sp, | 517 sp, |
512 traceLoading, | 518 traceLoading, |
513 tag, | 519 tag, |
514 uri, | 520 uri, |
515 resolvedUri, | 521 resolvedUri, |
516 libraryUrl); | 522 libraryUrl); |
517 } else { | 523 } else { |
518 _sendResourceResponse(sp, tag, | 524 _sendResourceResponse(sp, tag, |
519 uri, | 525 uri, |
| 526 resolvedUri, |
520 libraryUrl, | 527 libraryUrl, |
521 'Unknown scheme (${resolvedUri.scheme}) for ' | 528 'Unknown scheme (${resolvedUri.scheme}) for ' |
522 '$resolvedUri'); | 529 '$resolvedUri'); |
523 } | 530 } |
524 } | 531 } |
525 | 532 |
526 // Handling of packages requests. Finding and parsing of .packages file or | 533 // Handling of packages requests. Finding and parsing of .packages file or |
527 // packages/ directories. | 534 // packages/ directories. |
528 const _LF = 0x0A; | 535 const _LF = 0x0A; |
529 const _CR = 0x0D; | 536 const _CR = 0x0D; |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1058 _log('Unknown scheme (${pathUri.scheme}) in $pathUri.'); | 1065 _log('Unknown scheme (${pathUri.scheme}) in $pathUri.'); |
1059 } | 1066 } |
1060 _sendExtensionImportResponse(sp, uri, libraryUri, null); | 1067 _sendExtensionImportResponse(sp, uri, libraryUri, null); |
1061 break; | 1068 break; |
1062 } | 1069 } |
1063 break; | 1070 break; |
1064 default: | 1071 default: |
1065 _log('Unknown loader request tag=$tag from $isolateId'); | 1072 _log('Unknown loader request tag=$tag from $isolateId'); |
1066 } | 1073 } |
1067 } | 1074 } |
OLD | NEW |