John McCutchan b017dfd995 Rationalize Dart mojo and sky package structure.
NOTE: This CL appears far larger than it actually is for two reasons:

1) Many files were moved around to use the Dart package directory structure.
2) Many .dart files had to have import paths updated.

- Organize mojo/public/dart so that it uses standard Dart package layout
- Organize mojo/dart/apptest so that it uses a standard Dart package layout
- Organize sky/sdk so that it uses a standard Dart package layout
- Create a mojo/testing package (used by unittests)
- Introduce the 'dart_pkg' gn rule which populates gen/Config/dart-pkg
- All internally vended Dart packages must have a corresponding dart_pkg rule
- It is now possible to use dependency_overrides: in pubspec.yaml to mix internal and external package dependencies (enables analyzer, editor, webstorm usage for internal developers).
- Package root for dart content handler ends with "packages/"
- Imports of mojo package uris no longer need the "public/dart"
- mojo/public/tools/dart_package.py is a clone of mojo/public/tools/gn/zip.py
- Sky tests no longer run 'deploy_sdk' script.

R=eseidel@chromium.org

Review URL: https://codereview.chromium.org/1132063007
2015-05-18 14:41:39 -07:00

45 lines
1.2 KiB
Dart

// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import '../shell.dart' as shell;
import 'dart:async';
import 'dart:sky' as sky;
import 'dart:typed_data';
import 'package:mojo/core.dart' as core;
import 'package:mojom/mojo/network_service.mojom.dart';
import 'package:mojom/mojo/url_loader.mojom.dart';
class Response {
ByteData body;
Response(this.body);
String bodyAsString() {
return new String.fromCharCodes(new Uint8List.view(body.buffer));
}
}
Future<Response> fetch(String relativeUrl) async {
String url = new sky.URL(relativeUrl, sky.document.baseURI).href;
var net = new NetworkServiceProxy.unbound();
shell.requestService("mojo:network_service", net);
var loader = new UrlLoaderProxy.unbound();
net.ptr.createUrlLoader(loader);
var request = new UrlRequest()
..url = url
..autoFollowRedirects = true;
var response = (await loader.ptr.start(request)).response;
loader.close();
net.close();
if (response.body == null) return new Response(null);
ByteData data = await core.DataPipeDrainer.drainHandle(response.body);
return new Response(data);
}