mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Merge pull request #2028 from johnmccutchan/upgrade_dart
Switch to using callback to get observatory data (working)
This commit is contained in:
commit
5c0bd1daee
@ -47,17 +47,12 @@ source_set("prerequisites") {
|
||||
}
|
||||
|
||||
dart_embedder_resources("generate_sky_embedder_service_isolate_resources_cc") {
|
||||
deps = [
|
||||
"//mojo/dart/observatory:deploy_observatory",
|
||||
]
|
||||
inputs = [
|
||||
"//sky/engine/core/script/dart_service_isolate/loader.dart",
|
||||
"//sky/engine/core/script/dart_service_isolate/main.dart",
|
||||
"//sky/engine/core/script/dart_service_isolate/resources.dart",
|
||||
"//sky/engine/core/script/dart_service_isolate/server.dart",
|
||||
]
|
||||
root_prefix = "//sky/engine/core/script/"
|
||||
input_directory = "$root_out_dir/observatory/deployed/web/"
|
||||
output = "$target_gen_dir/sky_embedder_service_isolate_resources.cc"
|
||||
table_name = "sky_embedder_service_isolate"
|
||||
}
|
||||
@ -74,6 +69,7 @@ static_library("core") {
|
||||
"//sky/services/pointer:interfaces",
|
||||
"//dart/runtime/bin:embedded_dart_io",
|
||||
"//dart/runtime:libdart",
|
||||
"//dart/runtime/observatory:embedded_observatory_archive",
|
||||
"//dart/runtime/vm:libdart_platform",
|
||||
"//mojo/services/navigation/interfaces",
|
||||
]
|
||||
|
||||
@ -30,6 +30,19 @@
|
||||
#include "sky/engine/tonic/dart_snapshot_loader.h"
|
||||
#include "sky/engine/tonic/dart_state.h"
|
||||
#include "sky/engine/tonic/dart_wrappable.h"
|
||||
#include "sky/engine/tonic/uint8_list.h"
|
||||
|
||||
namespace dart {
|
||||
namespace observatory {
|
||||
|
||||
// These two symbols are defined in |observatory_archive.cc| which is generated
|
||||
// by the |//dart/runtime/observatory:archive_observatory| rule. Both of these
|
||||
// symbols will be part of the data segment and therefore are read only.
|
||||
extern unsigned int observatory_assets_archive_len;
|
||||
extern const uint8_t* observatory_assets_archive;
|
||||
|
||||
} // namespace observatory
|
||||
} // namespace dart
|
||||
|
||||
namespace blink {
|
||||
|
||||
@ -175,6 +188,12 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri,
|
||||
return isolate;
|
||||
}
|
||||
|
||||
Dart_Handle GetVMServiceAssetsArchiveCallback() {
|
||||
return DartConverter<Uint8List>::ToDart(
|
||||
::dart::observatory::observatory_assets_archive,
|
||||
::dart::observatory::observatory_assets_archive_len);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
#if DART_ALLOW_DYNAMIC_RESOLUTION
|
||||
@ -270,7 +289,7 @@ void InitDartVM() {
|
||||
// Entroy source
|
||||
nullptr,
|
||||
// VM service assets archive
|
||||
nullptr) == nullptr);
|
||||
GetVMServiceAssetsArchiveCallback) == nullptr);
|
||||
// Wait for load port- ensures handle watcher and service isolates are
|
||||
// running.
|
||||
Dart_ServiceWaitForLoadPort();
|
||||
|
||||
@ -11,7 +11,6 @@ import 'dart:isolate';
|
||||
import 'dart:_vmservice';
|
||||
|
||||
part 'loader.dart';
|
||||
part 'resources.dart';
|
||||
part 'server.dart';
|
||||
|
||||
// The TCP ip/port that the HTTP server listens on.
|
||||
@ -22,6 +21,7 @@ bool _autoStart;
|
||||
|
||||
// HTTP server.
|
||||
Server server;
|
||||
Map<String, Asset> assets;
|
||||
|
||||
_onShutdown() {
|
||||
if (server != null) {
|
||||
@ -34,8 +34,11 @@ _onShutdown() {
|
||||
}
|
||||
|
||||
void _bootServer() {
|
||||
// Load resources.
|
||||
_triggerResourceLoad();
|
||||
try {
|
||||
assets = Asset.request();
|
||||
} catch (e) {
|
||||
print('Could not load Observatory assets: $e');
|
||||
}
|
||||
// Lazily create service.
|
||||
var service = new VMService();
|
||||
service.onShutdown = _onShutdown;
|
||||
|
||||
@ -1,50 +0,0 @@
|
||||
// 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.
|
||||
|
||||
part of sky_shell_dart_controller_service_isolate;
|
||||
|
||||
String detectMimeType(String name) {
|
||||
var extensionStart = name.lastIndexOf('.');
|
||||
var extension = name.substring(extensionStart+1);
|
||||
switch (extension) {
|
||||
case 'html':
|
||||
return 'text/html; charset=UTF-8';
|
||||
case 'dart':
|
||||
return 'application/dart; charset=UTF-8';
|
||||
case 'js':
|
||||
return 'application/javascript; charset=UTF-8';
|
||||
case 'css':
|
||||
return 'text/css; charset=UTF-8';
|
||||
case 'gif':
|
||||
return 'image/gif';
|
||||
case 'png':
|
||||
return 'image/png';
|
||||
case 'jpg':
|
||||
return 'image/jpeg';
|
||||
case 'jpeg':
|
||||
return 'image/jpeg';
|
||||
case 'svg':
|
||||
return 'image/svg+xml';
|
||||
default:
|
||||
return 'text/plain';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Resource {
|
||||
final String name;
|
||||
final String mimeType;
|
||||
final List<int> data;
|
||||
Resource(this.name, this.mimeType, this.data);
|
||||
static final Map<String, Resource> resources = new Map<String, Resource>();
|
||||
}
|
||||
|
||||
|
||||
_addResource(String name, List<int> data) {
|
||||
var mimeType = detectMimeType(name);
|
||||
Resource resource = new Resource(name, mimeType, data);
|
||||
Resource.resources[name] = resource;
|
||||
}
|
||||
|
||||
_triggerResourceLoad() native "ServiceIsolate_TriggerResourceLoad";
|
||||
@ -138,16 +138,16 @@ class Server {
|
||||
return;
|
||||
}
|
||||
|
||||
var resource = Resource.resources[path];
|
||||
if (resource == null && _shouldServeObservatory(request)) {
|
||||
resource = Resource.resources[ROOT_REDIRECT_PATH];
|
||||
assert(resource != null);
|
||||
Asset asset = assets[path];
|
||||
if (asset == null && _shouldServeObservatory(request)) {
|
||||
asset = assets[ROOT_REDIRECT_PATH];
|
||||
assert(asset != null);
|
||||
}
|
||||
if (resource != null) {
|
||||
if (asset != null) {
|
||||
// Serving up a static resource (e.g. .css, .html, .png).
|
||||
request.response.headers.contentType =
|
||||
ContentType.parse(resource.mimeType);
|
||||
request.response.add(resource.data);
|
||||
ContentType.parse(asset.mimeType);
|
||||
request.response.add(asset.data);
|
||||
request.response.close();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -48,4 +48,23 @@ void DartConverter<Uint8List>::SetReturnValue(Dart_NativeArguments args,
|
||||
Dart_SetReturnValue(args, val.dart_handle());
|
||||
}
|
||||
|
||||
Dart_Handle DartConverter<Uint8List>::ToDart(const uint8_t* buffer,
|
||||
unsigned int length) {
|
||||
const intptr_t buffer_length = static_cast<intptr_t>(length);
|
||||
Dart_Handle array = Dart_NewTypedData(Dart_TypedData_kUint8, buffer_length);
|
||||
DCHECK(!LogIfError(array));
|
||||
{
|
||||
Dart_TypedData_Type type;
|
||||
void* data = nullptr;
|
||||
intptr_t data_length = 0;
|
||||
Dart_TypedDataAcquireData(array, &type, &data, &data_length);
|
||||
CHECK_EQ(type, Dart_TypedData_kUint8);
|
||||
CHECK(data);
|
||||
CHECK_EQ(data_length, buffer_length);
|
||||
memmove(data, buffer, data_length);
|
||||
Dart_TypedDataReleaseData(array);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
} // namespace blink
|
||||
|
||||
@ -54,6 +54,8 @@ struct DartConverter<Uint8List> {
|
||||
static Uint8List FromArgumentsWithNullCheck(Dart_NativeArguments args,
|
||||
int index,
|
||||
Dart_Handle& exception);
|
||||
|
||||
static Dart_Handle ToDart(const uint8_t* buffer, unsigned int length);
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
@ -32,7 +32,6 @@ dart_pkg("sky_engine") {
|
||||
"//sky/engine/bindings/internals.dart",
|
||||
"$service_isolate_dir/main.dart",
|
||||
"$service_isolate_dir/loader.dart",
|
||||
"$service_isolate_dir/resources.dart",
|
||||
"$service_isolate_dir/server.dart",
|
||||
]
|
||||
sdk_ext_mappings = [
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user