Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library resource; | 5 library resource; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:io' as io; | 9 import 'dart:io' as io; |
| 10 | 10 |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 452 return new _PhysicalFolder(directory); | 452 return new _PhysicalFolder(directory); |
| 453 } else { | 453 } else { |
| 454 io.File file = new io.File(path); | 454 io.File file = new io.File(path); |
| 455 return new _PhysicalFile(file); | 455 return new _PhysicalFile(file); |
| 456 } | 456 } |
| 457 } | 457 } |
| 458 | 458 |
| 459 @override | 459 @override |
| 460 Context get pathContext => io.Platform.isWindows ? windows : posix; | 460 Context get pathContext => io.Platform.isWindows ? windows : posix; |
| 461 } | 461 } |
| 462 | |
| 463 | |
| 464 /** | |
| 465 * A [UriResolver] for [Resource]s. | |
| 466 */ | |
| 467 class ResourceUriResolver extends UriResolver { | |
| 468 /** | |
| 469 * The name of the `file` scheme. | |
| 470 */ | |
| 471 static String _FILE_SCHEME = "file"; | |
| 472 | |
| 473 final MemoryResourceProvider _provider; | |
|
Paul Berry
2014/06/24 15:49:59
It doesn't look like we're making use of any funct
scheglov
2014/06/24 18:07:46
Done.
| |
| 474 | |
| 475 ResourceUriResolver(this._provider); | |
| 476 | |
| 477 @override | |
| 478 Source fromEncoding(UriKind kind, Uri uri) { | |
| 479 if (kind == UriKind.FILE_URI) { | |
| 480 Resource resource = _provider.getResource(uri.path); | |
| 481 if (resource is File) { | |
| 482 return resource.createSource(kind); | |
| 483 } | |
| 484 } | |
| 485 return null; | |
| 486 } | |
| 487 | |
| 488 @override | |
| 489 Source resolveAbsolute(Uri uri) { | |
| 490 if (!_isFileUri(uri)) { | |
| 491 return null; | |
| 492 } | |
| 493 Resource resource = _provider.getResource(uri.path); | |
| 494 if (resource is File) { | |
| 495 return resource.createSource(UriKind.FILE_URI); | |
| 496 } | |
| 497 return null; | |
| 498 } | |
| 499 | |
| 500 /** | |
| 501 * Return `true` if the given URI is a `file` URI. | |
| 502 * | |
| 503 * @param uri the URI being tested | |
| 504 * @return `true` if the given URI is a `file` URI | |
| 505 */ | |
| 506 static bool _isFileUri(Uri uri) => uri.scheme == _FILE_SCHEME; | |
| 507 } | |
| OLD | NEW |