Merge pull request #1569 from jason-simmons/mojo_merge_client

Update to mojo 4fe7bc6c228b3a2939cd3635ebd701f88eeca55d
This commit is contained in:
Jason Simmons
2015-10-12 10:10:45 -07:00
116 changed files with 3892 additions and 3442 deletions
+2 -2
View File
@@ -19,7 +19,7 @@
vars = {
'chromium_git': 'https://chromium.googlesource.com',
'mojo_sdk_revision': '033ebba671eced78b155862a1484ec1087b111e0',
'mojo_sdk_revision': '56e62e2ecf2052becf04a321fdc80e90600a75bd',
'mojo_devtools_revision': '49879d78ce4486e10c2214a101d9b2e82794b2f4',
'skia_revision': '0d39d37ddcfb3847795639eaef513f1112eba627',
@@ -29,7 +29,7 @@ vars = {
'dart_observatory_packages_revision': 'a731d3b1caf27b45aecdce9378b87a510240264d',
'dart_root_certificates_revision': 'c3a41df63afacec62fcb8135196177e35fe72f71',
'buildtools_revision': '5215ee866bc3e8eb4a7f124212845abf4029e60b',
'buildtools_revision': '565d04e8741429fb1b4f26d102f2c6c3b849edeb',
}
# Only these hosts are allowed for dependencies in this DEPS file.
-1
View File
@@ -102,7 +102,6 @@ android_library("mojo_javatests") {
"//base:base_java",
"//base:base_java_test_support",
"//mojo/public/interfaces/bindings/tests:test_interfaces_java",
"//mojo/public/interfaces/bindings/tests:test_interfaces_experimental_java",
"//mojo/public/java:bindings",
"//mojo/public/java:system",
]
+32 -18
View File
@@ -24,6 +24,7 @@ const traceEventPhaseBegin = "B";
const traceEventPhaseEnd = "E";
const traceEventPhaseAsyncBegin = "S";
const traceEventPhaseAsyncEnd = "F";
const traceEventDuration = "X";
// TracingHelper is used by Dart code running in the Mojo shell in order
// to perform tracing.
@@ -36,8 +37,10 @@ class TracingHelper {
// for use in trace messages. If |appName| is longer than 20 characters then
// only the last 20 characters of |appName| will be used.
TracingHelper.fromApplication(Application app, String appName) {
_tid = [appName, Isolate.current].fold(7,
(hash, element) => 31 * hash + element.hashCode);
// Masked because the tid is expected to be a 32-bit int.
_tid = [appName, Isolate.current]
.fold(7, (hash, element) => 31 * hash + element.hashCode) &
0x7fffffff;
_impl = new TraceProviderImpl();
ApplicationConnection connection = app.connectToApplication("mojo:tracing");
connection.provideService(TraceProviderName, (e) {
@@ -80,33 +83,44 @@ class TracingHelper {
_sendTraceMessage(name, categories, traceEventInstant, 0, args: args);
}
FunctionTrace _beginFunction(String functionName, String categories,
String phase, {Map<String, String> args}) {
void traceDuration(String name, String categories, int start, int end,
{Map<String, String> args}) {
_sendTraceMessage(name, categories, traceEventDuration, 0,
args: args, start: start, duration: end - start);
}
FunctionTrace _beginFunction(
String functionName, String categories, String phase,
{Map<String, String> args}) {
assert(functionName != null);
final trace =
new _FunctionTraceImpl(this, isActive() ? functionName : null,
categories, phase);
final trace = new _FunctionTraceImpl(
this, isActive() ? functionName : null, categories, phase);
_sendTraceMessage(functionName, categories, phase, trace.hashCode,
args: args);
return trace;
}
void _endFunction(String functionName, String categories, String phase,
int traceId) {
void _endFunction(
String functionName, String categories, String phase, int traceId) {
_sendTraceMessage(functionName, categories, phase, traceId);
}
void _sendTraceMessage(String name, String categories, String phase,
int traceId, {Map<String, String> args}) {
void _sendTraceMessage(
String name, String categories, String phase, int traceId,
{Map<String, String> args, int start, int duration}) {
if (isActive()) {
var time = (start != null) ? start : getTimeTicksNow();
var map = {};
map["name"] = name;
map["cat"] = categories;
map["ph"] = phase;
map["ts"] = getTimeTicksNow();
map["ts"] = time;
map["pid"] = pid;
map["tid"] = _tid;
map["id"] = traceId;
if (duration != null) {
map["dur"] = duration;
}
if (args != null) {
map["args"] = args;
}
@@ -148,8 +162,8 @@ class _FunctionTraceImpl implements FunctionTrace {
String _categories;
String _beginPhase;
_FunctionTraceImpl(this._tracing, this._functionName, this._categories,
this._beginPhase) {
_FunctionTraceImpl(
this._tracing, this._functionName, this._categories, this._beginPhase) {
assert(_beginPhase == traceEventPhaseBegin ||
_beginPhase == traceEventPhaseAsyncBegin);
}
@@ -158,11 +172,11 @@ class _FunctionTraceImpl implements FunctionTrace {
void end() {
if (_functionName != null) {
if (_beginPhase == traceEventPhaseBegin) {
_tracing._endFunction(_functionName, _categories, traceEventPhaseEnd,
hashCode);
_tracing._endFunction(
_functionName, _categories, traceEventPhaseEnd, hashCode);
} else if (_beginPhase == traceEventPhaseAsyncBegin) {
_tracing._endFunction(_functionName, _categories,
traceEventPhaseAsyncEnd, hashCode);
_tracing._endFunction(
_functionName, _categories, traceEventPhaseAsyncEnd, hashCode);
}
}
}
@@ -21,23 +21,24 @@ namespace {
ui::EventType MojoMouseEventTypeToUIEvent(const EventPtr& event) {
DCHECK(!event->pointer_data.is_null());
DCHECK_EQ(POINTER_KIND_MOUSE, event->pointer_data->kind);
DCHECK_EQ(PointerKind::MOUSE, event->pointer_data->kind);
switch (event->action) {
case EVENT_TYPE_POINTER_DOWN:
case EventType::POINTER_DOWN:
return ui::ET_MOUSE_PRESSED;
case EVENT_TYPE_POINTER_UP:
case EventType::POINTER_UP:
return ui::ET_MOUSE_RELEASED;
case EVENT_TYPE_POINTER_MOVE:
case EventType::POINTER_MOVE:
DCHECK(event->pointer_data);
if (event->pointer_data->horizontal_wheel != 0 ||
event->pointer_data->vertical_wheel != 0) {
return ui::ET_MOUSEWHEEL;
}
if (event->flags &
(EVENT_FLAGS_LEFT_MOUSE_BUTTON | EVENT_FLAGS_MIDDLE_MOUSE_BUTTON |
EVENT_FLAGS_RIGHT_MOUSE_BUTTON)) {
if (static_cast<uint32_t>(event->flags) &
(static_cast<uint32_t>(EventFlags::LEFT_MOUSE_BUTTON) |
static_cast<uint32_t>(EventFlags::MIDDLE_MOUSE_BUTTON) |
static_cast<uint32_t>(EventFlags::RIGHT_MOUSE_BUTTON))) {
return ui::ET_MOUSE_DRAGGED;
}
return ui::ET_MOUSE_MOVED;
@@ -51,18 +52,18 @@ ui::EventType MojoMouseEventTypeToUIEvent(const EventPtr& event) {
ui::EventType MojoTouchEventTypeToUIEvent(const EventPtr& event) {
DCHECK(!event->pointer_data.is_null());
DCHECK_EQ(POINTER_KIND_TOUCH, event->pointer_data->kind);
DCHECK_EQ(PointerKind::TOUCH, event->pointer_data->kind);
switch (event->action) {
case EVENT_TYPE_POINTER_DOWN:
case EventType::POINTER_DOWN:
return ui::ET_TOUCH_PRESSED;
case EVENT_TYPE_POINTER_UP:
case EventType::POINTER_UP:
return ui::ET_TOUCH_RELEASED;
case EVENT_TYPE_POINTER_MOVE:
case EventType::POINTER_MOVE:
return ui::ET_TOUCH_MOVED;
case EVENT_TYPE_POINTER_CANCEL:
case EventType::POINTER_CANCEL:
return ui::ET_TOUCH_CANCELLED;
default:
@@ -82,43 +83,43 @@ void SetPointerDataLocationFromEvent(const ui::LocatedEvent& located_event,
} // namespace
COMPILE_ASSERT(static_cast<int32>(EVENT_FLAGS_NONE) ==
COMPILE_ASSERT(static_cast<int32>(EventFlags::NONE) ==
static_cast<int32>(ui::EF_NONE),
event_flags_should_match);
COMPILE_ASSERT(static_cast<int32>(EVENT_FLAGS_CAPS_LOCK_DOWN) ==
COMPILE_ASSERT(static_cast<int32>(EventFlags::CAPS_LOCK_DOWN) ==
static_cast<int32>(ui::EF_CAPS_LOCK_DOWN),
event_flags_should_match);
COMPILE_ASSERT(static_cast<int32>(EVENT_FLAGS_SHIFT_DOWN) ==
COMPILE_ASSERT(static_cast<int32>(EventFlags::SHIFT_DOWN) ==
static_cast<int32>(ui::EF_SHIFT_DOWN),
event_flags_should_match);
COMPILE_ASSERT(static_cast<int32>(EVENT_FLAGS_CONTROL_DOWN) ==
COMPILE_ASSERT(static_cast<int32>(EventFlags::CONTROL_DOWN) ==
static_cast<int32>(ui::EF_CONTROL_DOWN),
event_flags_should_match);
COMPILE_ASSERT(static_cast<int32>(EVENT_FLAGS_ALT_DOWN) ==
COMPILE_ASSERT(static_cast<int32>(EventFlags::ALT_DOWN) ==
static_cast<int32>(ui::EF_ALT_DOWN),
event_flags_should_match);
COMPILE_ASSERT(static_cast<int32>(EVENT_FLAGS_LEFT_MOUSE_BUTTON) ==
COMPILE_ASSERT(static_cast<int32>(EventFlags::LEFT_MOUSE_BUTTON) ==
static_cast<int32>(ui::EF_LEFT_MOUSE_BUTTON),
event_flags_should_match);
COMPILE_ASSERT(static_cast<int32>(EVENT_FLAGS_MIDDLE_MOUSE_BUTTON) ==
COMPILE_ASSERT(static_cast<int32>(EventFlags::MIDDLE_MOUSE_BUTTON) ==
static_cast<int32>(ui::EF_MIDDLE_MOUSE_BUTTON),
event_flags_should_match);
COMPILE_ASSERT(static_cast<int32>(EVENT_FLAGS_RIGHT_MOUSE_BUTTON) ==
COMPILE_ASSERT(static_cast<int32>(EventFlags::RIGHT_MOUSE_BUTTON) ==
static_cast<int32>(ui::EF_RIGHT_MOUSE_BUTTON),
event_flags_should_match);
COMPILE_ASSERT(static_cast<int32>(EVENT_FLAGS_COMMAND_DOWN) ==
COMPILE_ASSERT(static_cast<int32>(EventFlags::COMMAND_DOWN) ==
static_cast<int32>(ui::EF_COMMAND_DOWN),
event_flags_should_match);
COMPILE_ASSERT(static_cast<int32>(EVENT_FLAGS_EXTENDED) ==
COMPILE_ASSERT(static_cast<int32>(EventFlags::EXTENDED) ==
static_cast<int32>(ui::EF_EXTENDED),
event_flags_should_match);
COMPILE_ASSERT(static_cast<int32>(EVENT_FLAGS_IS_SYNTHESIZED) ==
COMPILE_ASSERT(static_cast<int32>(EventFlags::IS_SYNTHESIZED) ==
static_cast<int32>(ui::EF_IS_SYNTHESIZED),
event_flags_should_match);
COMPILE_ASSERT(static_cast<int32>(EVENT_FLAGS_ALTGR_DOWN) ==
COMPILE_ASSERT(static_cast<int32>(EventFlags::ALTGR_DOWN) ==
static_cast<int32>(ui::EF_ALTGR_DOWN),
event_flags_should_match);
COMPILE_ASSERT(static_cast<int32>(EVENT_FLAGS_MOD3_DOWN) ==
COMPILE_ASSERT(static_cast<int32>(EventFlags::MOD3_DOWN) ==
static_cast<int32>(ui::EF_MOD3_DOWN),
event_flags_should_match);
@@ -128,7 +129,7 @@ EventType TypeConverter<EventType, ui::EventType>::Convert(ui::EventType type) {
switch (type) {
case ui::ET_MOUSE_PRESSED:
case ui::ET_TOUCH_PRESSED:
return EVENT_TYPE_POINTER_DOWN;
return EventType::POINTER_DOWN;
case ui::ET_MOUSE_DRAGGED:
case ui::ET_MOUSE_MOVED:
@@ -136,30 +137,30 @@ EventType TypeConverter<EventType, ui::EventType>::Convert(ui::EventType type) {
case ui::ET_MOUSE_EXITED:
case ui::ET_TOUCH_MOVED:
case ui::ET_MOUSEWHEEL:
return EVENT_TYPE_POINTER_MOVE;
return EventType::POINTER_MOVE;
case ui::ET_MOUSE_RELEASED:
case ui::ET_TOUCH_RELEASED:
return EVENT_TYPE_POINTER_UP;
return EventType::POINTER_UP;
case ui::ET_TOUCH_CANCELLED:
return EVENT_TYPE_POINTER_CANCEL;
return EventType::POINTER_CANCEL;
case ui::ET_KEY_PRESSED:
return EVENT_TYPE_KEY_PRESSED;
return EventType::KEY_PRESSED;
case ui::ET_KEY_RELEASED:
return EVENT_TYPE_KEY_RELEASED;
return EventType::KEY_RELEASED;
default:
break;
}
return EVENT_TYPE_UNKNOWN;
return EventType::UNKNOWN;
}
EventPtr TypeConverter<EventPtr, ui::Event>::Convert(const ui::Event& input) {
const EventType type = ConvertTo<EventType>(input.type());
if (type == EVENT_TYPE_UNKNOWN)
if (type == EventType::UNKNOWN)
return nullptr;
EventPtr event = Event::New();
@@ -174,7 +175,7 @@ EventPtr TypeConverter<EventPtr, ui::Event>::Convert(const ui::Event& input) {
PointerDataPtr pointer_data(PointerData::New());
// TODO(sky): come up with a better way to handle this.
pointer_data->pointer_id = std::numeric_limits<int32>::max();
pointer_data->kind = POINTER_KIND_MOUSE;
pointer_data->kind = PointerKind::MOUSE;
SetPointerDataLocationFromEvent(*located_event, pointer_data.get());
if (input.IsMouseWheelEvent()) {
const ui::MouseWheelEvent* wheel_event =
@@ -192,7 +193,7 @@ EventPtr TypeConverter<EventPtr, ui::Event>::Convert(const ui::Event& input) {
static_cast<const ui::TouchEvent*>(&input);
PointerDataPtr pointer_data(PointerData::New());
pointer_data->pointer_id = touch_event->touch_id();
pointer_data->kind = POINTER_KIND_TOUCH;
pointer_data->kind = PointerKind::TOUCH;
SetPointerDataLocationFromEvent(*touch_event, pointer_data.get());
pointer_data->radius_major = touch_event->radius_x();
pointer_data->radius_minor = touch_event->radius_y();
@@ -244,22 +245,26 @@ scoped_ptr<ui::Event> TypeConverter<scoped_ptr<ui::Event>, EventPtr>::Convert(
}
switch (input->action) {
case EVENT_TYPE_KEY_PRESSED:
case EVENT_TYPE_KEY_RELEASED: {
case EventType::KEY_PRESSED:
case EventType::KEY_RELEASED: {
scoped_ptr<ui::KeyEvent> key_event;
if (input->key_data->is_char) {
// TODO(johngro) : Need to verify that input->flags (a mojom generated
// enum) is a valid set of flags for a ui::KeyEvent
key_event.reset(new ui::KeyEvent(
static_cast<base::char16>(input->key_data->character),
static_cast<ui::KeyboardCode>(
input->key_data->key_code),
input->flags));
static_cast<int32_t>(input->flags)));
} else {
// TODO(johngro) : Need to verify that input->flags (a mojom generated
// enum) is a valid set of flags for a ui::KeyEvent
key_event.reset(new ui::KeyEvent(
input->action == EVENT_TYPE_KEY_PRESSED ? ui::ET_KEY_PRESSED
input->action == EventType::KEY_PRESSED ? ui::ET_KEY_PRESSED
: ui::ET_KEY_RELEASED,
static_cast<ui::KeyboardCode>(input->key_data->key_code),
input->flags));
static_cast<int32_t>(input->flags)));
}
key_event->SetExtendedKeyEventData(scoped_ptr<ui::ExtendedKeyEventData>(
new MojoExtendedKeyEventData(
@@ -269,11 +274,11 @@ scoped_ptr<ui::Event> TypeConverter<scoped_ptr<ui::Event>, EventPtr>::Convert(
key_event->set_platform_keycode(input->key_data->native_key_code);
return key_event.Pass();
}
case EVENT_TYPE_POINTER_DOWN:
case EVENT_TYPE_POINTER_UP:
case EVENT_TYPE_POINTER_MOVE:
case EVENT_TYPE_POINTER_CANCEL: {
if (input->pointer_data->kind == POINTER_KIND_MOUSE) {
case EventType::POINTER_DOWN:
case EventType::POINTER_UP:
case EventType::POINTER_MOVE:
case EventType::POINTER_CANCEL: {
if (input->pointer_data->kind == PointerKind::MOUSE) {
// TODO: last flags isn't right. Need to send changed_flags.
scoped_ptr<ui::MouseEvent> event(new ui::MouseEvent(
MojoMouseEventTypeToUIEvent(input), location, screen_location,
@@ -21,9 +21,9 @@
namespace mojo {
#define ASSERT_ENUM_VALUES_EQUAL(value) \
COMPILE_ASSERT(cc::DrawQuad::value == static_cast<cc::DrawQuad::Material>( \
MATERIAL_##value), \
#define ASSERT_ENUM_VALUES_EQUAL(value) \
COMPILE_ASSERT(static_cast<int32_t>(cc::DrawQuad::value) == \
static_cast<int32_t>(Material::value), \
value##_enum_value_matches)
ASSERT_ENUM_VALUES_EQUAL(CHECKERBOARD);
@@ -39,11 +39,11 @@ ASSERT_ENUM_VALUES_EQUAL(YUV_VIDEO_CONTENT);
COMPILE_ASSERT(
cc::YUVVideoDrawQuad::REC_601 ==
static_cast<cc::YUVVideoDrawQuad::ColorSpace>(YUV_COLOR_SPACE_REC_601),
static_cast<cc::YUVVideoDrawQuad::ColorSpace>(YUVColorSpace::REC_601),
rec_601_enum_matches);
COMPILE_ASSERT(cc::YUVVideoDrawQuad::JPEG ==
static_cast<cc::YUVVideoDrawQuad::ColorSpace>(
YUV_COLOR_SPACE_JPEG),
YUVColorSpace::JPEG),
rec_601_jpeg_enum_matches);
namespace {
@@ -66,7 +66,7 @@ bool ConvertDrawQuad(const QuadPtr& input,
cc::SharedQuadState* sqs,
cc::RenderPass* render_pass) {
switch (input->material) {
case MATERIAL_RENDER_PASS: {
case Material::RENDER_PASS: {
cc::RenderPassDrawQuad* render_pass_quad =
render_pass->CreateAndAppendDrawQuad<cc::RenderPassDrawQuad>();
RenderPassQuadState* render_pass_quad_state =
@@ -90,7 +90,7 @@ bool ConvertDrawQuad(const QuadPtr& input,
cc::FilterOperations()); // TODO(jamesr): background_filters
break;
}
case MATERIAL_SOLID_COLOR: {
case Material::SOLID_COLOR: {
if (input->solid_color_quad_state.is_null())
return false;
cc::SolidColorDrawQuad* color_quad =
@@ -105,7 +105,7 @@ bool ConvertDrawQuad(const QuadPtr& input,
input->solid_color_quad_state->force_anti_aliasing_off);
break;
}
case MATERIAL_SURFACE_CONTENT: {
case Material::SURFACE_CONTENT: {
if (input->surface_quad_state.is_null())
return false;
cc::SurfaceDrawQuad* surface_quad =
@@ -119,7 +119,7 @@ bool ConvertDrawQuad(const QuadPtr& input,
input->surface_quad_state->surface.To<cc::SurfaceId>());
break;
}
case MATERIAL_TEXTURE_CONTENT: {
case Material::TEXTURE_CONTENT: {
TextureQuadStatePtr& texture_quad_state =
input->texture_quad_state;
if (texture_quad_state.is_null() ||
@@ -144,7 +144,7 @@ bool ConvertDrawQuad(const QuadPtr& input,
texture_quad_state->nearest_neighbor);
break;
}
case MATERIAL_TILED_CONTENT: {
case Material::TILED_CONTENT: {
TileQuadStatePtr& tile_state = input->tile_quad_state;
if (tile_state.is_null())
return false;
@@ -162,7 +162,7 @@ bool ConvertDrawQuad(const QuadPtr& input,
tile_state->nearest_neighbor);
break;
}
case MATERIAL_YUV_VIDEO_CONTENT: {
case Material::YUV_VIDEO_CONTENT: {
YUVVideoQuadStatePtr& yuv_state = input->yuv_video_quad_state;
if (yuv_state.is_null())
return false;
@@ -71,7 +71,7 @@ TEST_F(SurfaceLibQuadTest, ColorQuad) {
QuadPtr mojo_quad = Quad::From<cc::DrawQuad>(*color_quad);
ASSERT_FALSE(mojo_quad.is_null());
EXPECT_EQ(MATERIAL_SOLID_COLOR, mojo_quad->material);
EXPECT_EQ(Material::SOLID_COLOR, mojo_quad->material);
EXPECT_EQ(Rect::From(rect), mojo_quad->rect);
EXPECT_EQ(Rect::From(opaque_rect), mojo_quad->opaque_rect);
EXPECT_EQ(Rect::From(visible_rect), mojo_quad->visible_rect);
@@ -91,7 +91,7 @@ TEST_F(SurfaceLibQuadTest, SurfaceQuad) {
QuadPtr mojo_quad = Quad::From<cc::DrawQuad>(*surface_quad);
ASSERT_FALSE(mojo_quad.is_null());
EXPECT_EQ(MATERIAL_SURFACE_CONTENT, mojo_quad->material);
EXPECT_EQ(Material::SURFACE_CONTENT, mojo_quad->material);
ASSERT_TRUE(mojo_quad->surface_quad_state);
SurfaceQuadStatePtr& mojo_surface_state = mojo_quad->surface_quad_state;
EXPECT_EQ(SurfaceId::From(arbitrary_id),
@@ -125,7 +125,7 @@ TEST_F(SurfaceLibQuadTest, TextureQuad) {
QuadPtr mojo_quad = Quad::From<cc::DrawQuad>(*texture_quad);
ASSERT_FALSE(mojo_quad.is_null());
EXPECT_EQ(MATERIAL_TEXTURE_CONTENT, mojo_quad->material);
EXPECT_EQ(Material::TEXTURE_CONTENT, mojo_quad->material);
ASSERT_TRUE(mojo_quad->texture_quad_state);
TextureQuadStatePtr& mojo_texture_state = mojo_quad->texture_quad_state;
EXPECT_EQ(resource_id, mojo_texture_state->resource_id);
@@ -142,7 +142,7 @@ TEST_F(SurfaceLibQuadTest, TextureQuad) {
TEST_F(SurfaceLibQuadTest, TextureQuadEmptyVertexOpacity) {
QuadPtr mojo_texture_quad = Quad::New();
mojo_texture_quad->material = MATERIAL_TEXTURE_CONTENT;
mojo_texture_quad->material = Material::TEXTURE_CONTENT;
TextureQuadStatePtr mojo_texture_state = TextureQuadState::New();
mojo_texture_state->background_color = Color::New();
mojo_texture_quad->texture_quad_state = mojo_texture_state.Pass();
@@ -158,7 +158,7 @@ TEST_F(SurfaceLibQuadTest, TextureQuadEmptyVertexOpacity) {
TEST_F(SurfaceLibQuadTest, TextureQuadEmptyBackgroundColor) {
QuadPtr mojo_texture_quad = Quad::New();
mojo_texture_quad->material = MATERIAL_TEXTURE_CONTENT;
mojo_texture_quad->material = Material::TEXTURE_CONTENT;
TextureQuadStatePtr mojo_texture_state = TextureQuadState::New();
mojo_texture_state->vertex_opacity = mojo::Array<float>::New(4);
mojo_texture_quad->texture_quad_state = mojo_texture_state.Pass();
+1 -1
View File
@@ -23,7 +23,7 @@ void InitDartVM() {
CHECK(Dart_SetVMFlags(arraysize(kDartArgs), kDartArgs));
CHECK(Dart_Initialize(mojo::dart::vm_isolate_snapshot_buffer, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr));
nullptr, nullptr, nullptr) == nullptr);
}
Dart_Isolate CreateDartIsolate() {
+2
View File
@@ -121,6 +121,7 @@ action_foreach("dart_embedder_package_sdk") {
"//mojo/public/dart/mojo/sdk_ext/src/handle_watcher.dart",
"//mojo/public/dart/mojo/sdk_ext/src/natives.dart",
"//mojo/public/dart/mojo/sdk_ext/src/timer_queue.dart",
"//mojo/public/dart/mojo/sdk_ext/src/wait_many_state.dart",
]
outputs = [
"$root_gen_dir/dart_embedder_packages/{{source_root_relative_dir}}/{{source_file_part}}",
@@ -302,6 +303,7 @@ action("generate_snapshot_bin") {
"//mojo/public/dart/mojo/sdk_ext/src/handle_watcher.dart",
"//mojo/public/dart/mojo/sdk_ext/src/natives.dart",
"//mojo/public/dart/mojo/sdk_ext/src/timer_queue.dart",
"//mojo/public/dart/mojo/sdk_ext/src/wait_many_state.dart",
]
vm_isolate_snapshot = "$target_gen_dir/vm_isolate_snapshot.bin"
isolate_snapshot = "$target_gen_dir/isolate_snapshot.bin"
+39 -13
View File
@@ -40,6 +40,16 @@ static const char* kInternalLibURL = "dart:_internal";
static const char* kIsolateLibURL = "dart:isolate";
static const char* kCoreLibURL = "dart:core";
// Notes on isolate startup order:
// 1) vm-service isolate is spawned by the VM when Dart_Initialize is called.
// 2) mojo-handle-watcher is spawned by from the vm-service isolate.
// 3) ... application isolates ...
// 4) stop-handle-watcher is spawned to shutdown the handle watcher isolate
// before the controller exits.
static const char* kVmServiceIsolateUri = "vm-service";
static const char* kStopHandleWatcherIsolateUri = "stop-handle-watcher";
static const char* kHandleWatcherIsolateUri = "mojo-handle-watcher";
static uint8_t snapshot_magic_number[] = { 0xf5, 0xf5, 0xdc, 0xdc };
static Dart_Handle SetWorkingDirectory(Dart_Handle builtin_lib) {
@@ -267,10 +277,15 @@ Dart_Isolate DartController::CreateIsolateHelper(
void* dart_app,
bool strict_compilation,
IsolateCallbacks callbacks,
const std::string& script_uri,
std::string script_uri,
const std::string& package_root,
char** error,
bool use_network_loader) {
if ((script_uri == kVmServiceIsolateUri) && service_isolate_spawned_) {
// Rewrite the uri so that it is easier to differentiate the actual service
// isolate from the handle watcher isolate.
script_uri = kHandleWatcherIsolateUri;
}
auto isolate_data = new MojoDartState(dart_app,
strict_compilation,
callbacks,
@@ -326,6 +341,7 @@ Dart_Isolate DartController::CreateIsolateHelper(
// The VM is creating the service isolate.
if (Dart_IsServiceIsolate(isolate)) {
service_isolate_spawned_ = true;
const intptr_t port = SupportDartMojoIo() ? 0 : -1;
InitializeDartMojoIo();
StartHandleWatcherIsolate();
@@ -336,7 +352,8 @@ Dart_Isolate DartController::CreateIsolateHelper(
return isolate;
}
if ((script_uri == "vm-service") || (script_uri == "stop-handle-watcher")) {
if ((script_uri == kHandleWatcherIsolateUri) ||
(script_uri == kStopHandleWatcherIsolateUri)) {
// Special case for starting and stopping the the handle watcher isolate.
LoadEmptyScript(script_uri);
} else {
@@ -397,7 +414,7 @@ Dart_Isolate DartController::IsolateCreateCallback(const char* script_uri,
}
// Inherit parameters from parent isolate (if any).
void* dart_app = nullptr;
bool strict_compilation = true;
bool strict_compilation = false;
// TODO(johnmccutchan): Use parent's setting?
bool use_network_loader = false;
IsolateCallbacks callbacks;
@@ -444,6 +461,7 @@ void DartController::UnhandledExceptionCallback(Dart_Handle error) {
bool DartController::initialized_ = false;
bool DartController::service_isolate_running_ = false;
bool DartController::service_isolate_spawned_ = false;
bool DartController::strict_compilation_ = false;
DartControllerServiceConnector* DartController::service_connector_ = nullptr;
base::Lock DartController::lock_;
@@ -531,7 +549,13 @@ void DartController::StopHandleWatcherIsolate() {
IsolateCallbacks callbacks;
char* error;
Dart_Isolate shutdown_isolate = CreateIsolateHelper(
nullptr, false, callbacks, "stop-handle-watcher", "", &error, false);
nullptr,
false,
callbacks,
kStopHandleWatcherIsolateUri,
"",
&error,
false);
CHECK(shutdown_isolate);
Dart_EnterIsolate(shutdown_isolate);
@@ -594,15 +618,17 @@ void DartController::InitVmIfNeeded(Dart_EntropySource entropy,
// This should be called before calling Dart_Initialize.
tonic::DartDebugger::InitDebugger();
result = Dart_Initialize(vm_isolate_snapshot_buffer,
IsolateCreateCallback,
nullptr, // Isolate interrupt callback.
UnhandledExceptionCallback,
IsolateShutdownCallback,
// File IO callbacks.
nullptr, nullptr, nullptr, nullptr,
entropy);
CHECK(result);
const char* error = Dart_Initialize(
vm_isolate_snapshot_buffer,
nullptr, // Precompiled instructions
IsolateCreateCallback,
nullptr, // Isolate interrupt callback.
UnhandledExceptionCallback,
IsolateShutdownCallback,
// File IO callbacks.
nullptr, nullptr, nullptr, nullptr,
entropy);
CHECK(error == nullptr);
initialized_ = true;
}
+2 -1
View File
@@ -147,7 +147,7 @@ class DartController {
static Dart_Isolate CreateIsolateHelper(void* dart_app,
bool strict_compilation,
IsolateCallbacks callbacks,
const std::string& script_uri,
std::string script_uri,
const std::string& package_root,
char** error,
bool use_network_loader);
@@ -166,6 +166,7 @@ class DartController {
static bool initialized_;
static bool strict_compilation_;
static bool service_isolate_running_;
static bool service_isolate_spawned_;
static DartControllerServiceConnector* service_connector_;
};
@@ -245,46 +245,6 @@ class _MojoRawServerSocket extends Stream<RawSocket>
_resume();
}
}
RawServerSocketReference get reference {
if (_referencePort == null) {
_referencePort = new ReceivePort();
_referencePort.listen((sendPort) {
sendPort.send(
[_socket.address,
_socket.port,
_v6Only]);
});
}
return new _MojoRawServerSocketReference(_referencePort.sendPort);
}
Map _toJSON(bool ref) => {};
}
class _MojoRawServerSocketReference implements RawServerSocketReference {
final SendPort _sendPort;
_MojoRawServerSocketReference(this._sendPort);
Future<RawServerSocket> create() {
var port = new ReceivePort();
_sendPort.send(port.sendPort);
return port.first.then((List args) {
port.close();
InternetAddress address = args[0];
int tcpPort = args[1];
bool v6Only = args[2];
return
RawServerSocket.bind(address, tcpPort, v6Only: v6Only, shared: true);
});
}
int get hashCode => _sendPort.hashCode;
bool operator==(Object other)
=> other is _MojoServerSocketReference && _sendPort == other._sendPort;
}
class _MojoServerSocket extends Stream<Socket>
@@ -323,21 +283,7 @@ class _MojoServerSocket extends Stream<Socket>
Future close() => _socket.close().then((_) => this);
ServerSocketReference get reference {
return new _MojoServerSocketReference(_socket.reference);
}
Map _toJSON(bool ref) => _socket._toJSON(ref);
void set _owner(owner) { _socket._owner = owner; }
}
class _MojoServerSocketReference implements ServerSocketReference {
final RawServerSocketReference _rawReference;
_MojoServerSocketReference(this._rawReference);
Future<ServerSocket> create() {
return _rawReference.create().then((raw) => new _MojoServerSocket(raw));
}
}
+95
View File
@@ -39,6 +39,8 @@ namespace dart {
V(MojoHandle_Wait, 3) \
V(MojoHandle_Register, 2) \
V(MojoHandle_WaitMany, 3) \
V(MojoHandleWatcher_GrowStateArrays, 1) \
V(MojoHandleWatcher_WaitMany, 2) \
V(MojoHandleWatcher_SendControlData, 4) \
V(MojoHandleWatcher_RecvControlData, 1) \
V(MojoHandleWatcher_SetControlHandle, 1) \
@@ -720,6 +722,99 @@ void MojoMessagePipe_Read(Dart_NativeArguments arguments) {
Dart_SetReturnValue(arguments, list);
}
struct MojoWaitManyState {
std::vector<uint32_t> handles;
std::vector<uint32_t> signals;
std::vector<uint32_t> out_index;
std::vector<MojoHandleSignalsState> out_signals;
};
// This global is safe because it is only accessed by the single handle watcher
// isolate. If multiple handle watcher isolates are ever needed, it will need
// to be replicated.
static MojoWaitManyState handle_watcher_wait_state;
void MojoHandleWatcher_GrowStateArrays(Dart_NativeArguments arguments) {
int64_t new_length;
CHECK_INTEGER_ARGUMENT(arguments, 0, &new_length, InvalidArgument);
handle_watcher_wait_state.handles.resize(new_length);
handle_watcher_wait_state.signals.resize(new_length);
handle_watcher_wait_state.out_index.resize(1);
handle_watcher_wait_state.out_signals.resize(new_length);
Dart_Handle dart_handles = Dart_NewExternalTypedData(
Dart_TypedData_kUint32, handle_watcher_wait_state.handles.data(),
handle_watcher_wait_state.handles.size());
if (Dart_IsError(dart_handles)) {
Dart_PropagateError(dart_handles);
}
if (Dart_IsNull(dart_handles)) {
SetNullReturn(arguments);
return;
}
Dart_Handle dart_signals = Dart_NewExternalTypedData(
Dart_TypedData_kUint32, handle_watcher_wait_state.signals.data(),
handle_watcher_wait_state.signals.size());
if (Dart_IsError(dart_signals)) {
Dart_PropagateError(dart_signals);
}
if (Dart_IsNull(dart_signals)) {
SetNullReturn(arguments);
return;
}
Dart_Handle dart_out_index = Dart_NewExternalTypedData(
Dart_TypedData_kUint32, handle_watcher_wait_state.out_index.data(),
handle_watcher_wait_state.out_index.size());
if (Dart_IsError(dart_out_index)) {
Dart_PropagateError(dart_out_index);
}
if (Dart_IsNull(dart_out_index)) {
SetNullReturn(arguments);
return;
}
Dart_Handle dart_out_signals = Dart_NewExternalTypedData(
Dart_TypedData_kUint64, handle_watcher_wait_state.out_signals.data(),
handle_watcher_wait_state.out_signals.size());
if (Dart_IsError(dart_out_signals)) {
Dart_PropagateError(dart_out_signals);
}
if (Dart_IsNull(dart_out_signals)) {
SetNullReturn(arguments);
return;
}
Dart_Handle list = Dart_NewList(4);
Dart_ListSetAt(list, 0, dart_handles);
Dart_ListSetAt(list, 1, dart_signals);
Dart_ListSetAt(list, 2, dart_out_index);
Dart_ListSetAt(list, 3, dart_out_signals);
Dart_SetReturnValue(arguments, list);
}
void MojoHandleWatcher_WaitMany(Dart_NativeArguments arguments) {
int64_t handles_len = 0;
int64_t deadline = 0;
CHECK_INTEGER_ARGUMENT(arguments, 0, &handles_len, InvalidArgument);
CHECK_INTEGER_ARGUMENT(arguments, 1, &deadline, InvalidArgument);
uint32_t* handles = handle_watcher_wait_state.handles.data();
uint32_t* signals = handle_watcher_wait_state.signals.data();
uint32_t* out_index = handle_watcher_wait_state.out_index.data();
MojoHandleSignalsState* out_signals =
handle_watcher_wait_state.out_signals.data();
Dart_IsolateBlocked();
MojoResult mojo_result = MojoWaitMany(handles, signals, handles_len, deadline,
out_index, out_signals);
Dart_IsolateUnblocked();
Dart_SetIntegerReturnValue(arguments, static_cast<int64_t>(mojo_result));
}
struct ControlData {
int64_t handle;
Dart_Port port;
-1
View File
@@ -52,7 +52,6 @@ source_set("dart_to_cpp_unittests") {
"//mojo/public/cpp/bindings",
"//mojo/public/cpp/system",
"//mojo/public/interfaces/bindings/tests:test_interfaces",
"//mojo/public/interfaces/bindings/tests:test_interfaces_experimental",
"//testing/gtest",
]
}
+1 -1
View File
@@ -8,7 +8,7 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:isolate';
import 'dart:vmservice';
import 'dart:_vmservice';
part 'loader.dart';
part 'resources.dart';
+4
View File
@@ -1,3 +1,7 @@
## 0.2.0
- 92 changes: https://github.com/domokit/mojo/compare/c1d7bc9...0894421
## 0.1.0
- 0 changes: https://github.com/domokit/mojo/compare/86d3dc4...86d3dc4
+1 -1
View File
@@ -5,4 +5,4 @@ dependencies:
description: Generated bindings for mojo services
homepage: https://github.com/domokit/mojo
name: mojo_services
version: 0.1.0
version: 0.2.0
+37 -5
View File
@@ -15,6 +15,7 @@ import 'package:mojom/mojo/test/test_structs.mojom.dart' as structs;
import 'package:mojom/mojo/test/test_unions.mojom.dart' as unions;
import 'package:mojom/mojo/test/rect.mojom.dart' as rect;
import 'package:mojom/mojo/test/serialization_test_structs.mojom.dart' as serialization;
import 'package:mojom/regression_tests/regression_tests.mojom.dart' as regression;
class ProviderImpl implements sample.Provider {
sample.ProviderStub _stub;
@@ -51,8 +52,9 @@ Future<bool> testCallResponse() {
client.ptr.echoStrings("hello", "mojo!").then((echoStringsResponse) {
Expect.equals("hello", echoStringsResponse.a);
Expect.equals("mojo!", echoStringsResponse.b);
client.close();
c.complete(true);
client.close().then((_) {
c.complete(true);
});
});
});
});
@@ -71,7 +73,7 @@ Future testAwaitCallResponse() async {
Expect.equals("hello", echoStringsResponse.a);
Expect.equals("mojo!", echoStringsResponse.b);
client.close();
await client.close();
}
bindings.ServiceMessage messageOfStruct(bindings.Struct s) =>
@@ -250,6 +252,35 @@ testUnions() {
testUnionsToString();
}
class CheckEnumCapsImpl implements regression.CheckEnumCaps {
regression.CheckEnumCapsStub _stub;
CheckEnumCapsImpl(core.MojoMessagePipeEndpoint endpoint) {
_stub = new regression.CheckEnumCapsStub.fromEndpoint(endpoint, this);
}
setEnumWithInternalAllCaps(regression.EnumWithInternalAllCaps e) {}
}
checkEnumCapsIsolate(core.MojoMessagePipeEndpoint endpoint) {
new CheckEnumCapsImpl(endpoint);
}
testCheckEnumCapsImpl() {
var pipe = new core.MojoMessagePipe();
var client =
new regression.CheckEnumCapsProxy.fromEndpoint(pipe.endpoints[0]);
var c = new Completer();
Isolate.spawn(checkEnumCapsIsolate, pipe.endpoints[1]).then((_) {
client.ptr.setEnumWithInternalAllCaps(
regression.EnumWithInternalAllCaps.STANDARD);
client.close().then((_) {
c.complete(null);
});
});
return c.future;
}
testSerializeEnum() {
var constants = new structs.ScopedConstants();
constants.f4 = structs.ScopedConstantsEType.E0;
@@ -258,8 +289,9 @@ testSerializeEnum() {
Expect.equals(constants.f4.value, constants2.f4.value);
}
testEnums() {
testEnums() async {
testSerializeEnum();
await testCheckEnumCapsImpl();
}
void closingProviderIsolate(core.MojoMessagePipeEndpoint endpoint) {
@@ -281,7 +313,7 @@ Future<bool> runOnClosedTest() {
main() async {
testSerializeStructs();
testUnions();
testEnums();
await testEnums();
await testCallResponse();
await testAwaitCallResponse();
await runOnClosedTest();
+3 -3
View File
@@ -131,7 +131,7 @@ class ScopedTestChannel {
class EmbedderTest : public testing::Test {
public:
EmbedderTest() : test_io_thread_(TestIOThread::kAutoStart) {}
EmbedderTest() : test_io_thread_(TestIOThread::StartMode::AUTO) {}
~EmbedderTest() override {}
protected:
@@ -477,7 +477,7 @@ MOJO_MULTIPROCESS_TEST_CHILD_TEST(MultiprocessMasterSlave) {
mojo::test::MultiprocessTestHelper::client_platform_handle.Pass();
EXPECT_TRUE(client_platform_handle.is_valid());
TestIOThread test_io_thread(TestIOThread::kAutoStart);
TestIOThread test_io_thread(TestIOThread::StartMode::AUTO);
test::InitWithSimplePlatformSupport();
{
@@ -672,7 +672,7 @@ MOJO_MULTIPROCESS_TEST_CHILD_TEST(MultiprocessChannelsClient) {
mojo::test::MultiprocessTestHelper::client_platform_handle.Pass();
EXPECT_TRUE(client_platform_handle.is_valid());
TestIOThread test_io_thread(TestIOThread::kAutoStart);
TestIOThread test_io_thread(TestIOThread::StartMode::AUTO);
test::InitWithSimplePlatformSupport();
{
-68
View File
@@ -1,68 +0,0 @@
# Copyright 2014 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("../mojo_edk.gni")
# TODO(hansmuller): The organization of tests in this directory is weird:
# * Really, js_unittests tests public stuff, so that should live in public
# and be reworked as some sort of apptest.
# * Both js_unittests and js_integration_tests should auto-generate their
# tests somehow. The .cc files are just test runner stubs, including
# explicit lists of .js files.
group("tests") {
testonly = true
deps = [
"test:js_unittests",
"test:js_integration_tests",
]
}
mojo_edk_source_set("js") {
sources = [
"core.cc",
"core.h",
"drain_data.cc",
"drain_data.h",
"handle.cc",
"handle.h",
"handle_close_observer.h",
"mojo_runner_delegate.cc",
"mojo_runner_delegate.h",
"support.cc",
"support.h",
"threading.cc",
"threading.h",
"waiting_callback.cc",
"waiting_callback.h",
]
public_deps = [
"//base",
"//gin",
"//v8",
]
mojo_sdk_deps = [
"mojo/public/cpp/environment",
"mojo/public/cpp/system",
]
}
mojo_edk_source_set("js_unittests") {
testonly = true
sources = [
"handle_unittest.cc",
]
deps = [
"//testing/gtest",
]
mojo_edk_deps = [
"mojo/edk/js",
"mojo/edk/test:test_support",
]
mojo_sdk_deps = [ "mojo/public/cpp/system" ]
}
-379
View File
@@ -1,379 +0,0 @@
// Copyright 2014 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.
#include "mojo/edk/js/core.h"
#include "base/bind.h"
#include "base/logging.h"
#include "gin/arguments.h"
#include "gin/array_buffer.h"
#include "gin/converter.h"
#include "gin/dictionary.h"
#include "gin/function_template.h"
#include "gin/handle.h"
#include "gin/object_template_builder.h"
#include "gin/per_isolate_data.h"
#include "gin/public/wrapper_info.h"
#include "gin/wrappable.h"
#include "mojo/edk/js/drain_data.h"
#include "mojo/edk/js/handle.h"
namespace mojo {
namespace js {
namespace {
MojoResult CloseHandle(gin::Handle<HandleWrapper> handle) {
if (!handle->get().is_valid())
return MOJO_RESULT_INVALID_ARGUMENT;
handle->Close();
return MOJO_RESULT_OK;
}
gin::Dictionary WaitHandle(const gin::Arguments& args,
mojo::Handle handle,
MojoHandleSignals signals,
MojoDeadline deadline) {
v8::Isolate* isolate = args.isolate();
gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(isolate);
MojoHandleSignalsState signals_state;
MojoResult result = mojo::Wait(handle, signals, deadline, &signals_state);
dictionary.Set("result", result);
mojo::WaitManyResult wmv(result, 0);
if (!wmv.AreSignalsStatesValid()) {
dictionary.Set("signalsState", v8::Null(isolate).As<v8::Value>());
} else {
gin::Dictionary signalsStateDict = gin::Dictionary::CreateEmpty(isolate);
signalsStateDict.Set("satisfiedSignals", signals_state.satisfied_signals);
signalsStateDict.Set("satisfiableSignals",
signals_state.satisfiable_signals);
dictionary.Set("signalsState", signalsStateDict);
}
return dictionary;
}
gin::Dictionary WaitMany(const gin::Arguments& args,
const std::vector<mojo::Handle>& handles,
const std::vector<MojoHandleSignals>& signals,
MojoDeadline deadline) {
v8::Isolate* isolate = args.isolate();
gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(isolate);
std::vector<MojoHandleSignalsState> signals_states(signals.size());
mojo::WaitManyResult wmv =
mojo::WaitMany(handles, signals, deadline, &signals_states);
dictionary.Set("result", wmv.result);
if (wmv.IsIndexValid()) {
dictionary.Set("index", wmv.index);
} else {
dictionary.Set("index", v8::Null(isolate).As<v8::Value>());
}
if (wmv.AreSignalsStatesValid()) {
std::vector<gin::Dictionary> vec;
for (size_t i = 0; i < handles.size(); ++i) {
gin::Dictionary signalsStateDict = gin::Dictionary::CreateEmpty(isolate);
signalsStateDict.Set("satisfiedSignals",
signals_states[i].satisfied_signals);
signalsStateDict.Set("satisfiableSignals",
signals_states[i].satisfiable_signals);
vec.push_back(signalsStateDict);
}
dictionary.Set("signalsState", vec);
} else {
dictionary.Set("signalsState", v8::Null(isolate).As<v8::Value>());
}
return dictionary;
}
gin::Dictionary CreateMessagePipe(const gin::Arguments& args) {
gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate());
dictionary.Set("result", MOJO_RESULT_INVALID_ARGUMENT);
MojoHandle handle0 = MOJO_HANDLE_INVALID;
MojoHandle handle1 = MOJO_HANDLE_INVALID;
MojoResult result = MOJO_RESULT_OK;
v8::Handle<v8::Value> options_value = args.PeekNext();
if (options_value.IsEmpty() || options_value->IsNull() ||
options_value->IsUndefined()) {
result = MojoCreateMessagePipe(NULL, &handle0, &handle1);
} else if (options_value->IsObject()) {
gin::Dictionary options_dict(args.isolate(), options_value->ToObject());
MojoCreateMessagePipeOptions options;
// For future struct_size, we can probably infer that from the presence of
// properties in options_dict. For now, it's always 8.
options.struct_size = 8;
// Ideally these would be optional. But the interface makes it hard to
// typecheck them then.
if (!options_dict.Get("flags", &options.flags)) {
return dictionary;
}
result = MojoCreateMessagePipe(&options, &handle0, &handle1);
} else {
return dictionary;
}
CHECK_EQ(MOJO_RESULT_OK, result);
dictionary.Set("result", result);
dictionary.Set("handle0", mojo::Handle(handle0));
dictionary.Set("handle1", mojo::Handle(handle1));
return dictionary;
}
MojoResult WriteMessage(
mojo::Handle handle,
const gin::ArrayBufferView& buffer,
const std::vector<gin::Handle<HandleWrapper> >& handles,
MojoWriteMessageFlags flags) {
std::vector<MojoHandle> raw_handles(handles.size());
for (size_t i = 0; i < handles.size(); ++i)
raw_handles[i] = handles[i]->get().value();
MojoResult rv = MojoWriteMessage(handle.value(),
buffer.bytes(),
static_cast<uint32_t>(buffer.num_bytes()),
raw_handles.empty() ? NULL : &raw_handles[0],
static_cast<uint32_t>(raw_handles.size()),
flags);
// MojoWriteMessage takes ownership of the handles upon success, so
// release them here.
if (rv == MOJO_RESULT_OK) {
for (size_t i = 0; i < handles.size(); ++i)
ignore_result(handles[i]->release());
}
return rv;
}
gin::Dictionary ReadMessage(const gin::Arguments& args,
mojo::Handle handle,
MojoReadMessageFlags flags) {
uint32_t num_bytes = 0;
uint32_t num_handles = 0;
MojoResult result = MojoReadMessage(
handle.value(), NULL, &num_bytes, NULL, &num_handles, flags);
if (result != MOJO_RESULT_RESOURCE_EXHAUSTED) {
gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate());
dictionary.Set("result", result);
return dictionary;
}
v8::Handle<v8::ArrayBuffer> array_buffer =
v8::ArrayBuffer::New(args.isolate(), num_bytes);
std::vector<mojo::Handle> handles(num_handles);
gin::ArrayBuffer buffer;
ConvertFromV8(args.isolate(), array_buffer, &buffer);
CHECK(buffer.num_bytes() == num_bytes);
result = MojoReadMessage(handle.value(),
buffer.bytes(),
&num_bytes,
handles.empty() ? NULL :
reinterpret_cast<MojoHandle*>(&handles[0]),
&num_handles,
flags);
CHECK(buffer.num_bytes() == num_bytes);
CHECK(handles.size() == num_handles);
gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate());
dictionary.Set("result", result);
dictionary.Set("buffer", array_buffer);
dictionary.Set("handles", handles);
return dictionary;
}
gin::Dictionary CreateDataPipe(const gin::Arguments& args) {
gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate());
dictionary.Set("result", MOJO_RESULT_INVALID_ARGUMENT);
MojoHandle producer_handle = MOJO_HANDLE_INVALID;
MojoHandle consumer_handle = MOJO_HANDLE_INVALID;
MojoResult result = MOJO_RESULT_OK;
v8::Handle<v8::Value> options_value = args.PeekNext();
if (options_value.IsEmpty() || options_value->IsNull() ||
options_value->IsUndefined()) {
result = MojoCreateDataPipe(NULL, &producer_handle, &consumer_handle);
} else if (options_value->IsObject()) {
gin::Dictionary options_dict(args.isolate(), options_value->ToObject());
MojoCreateDataPipeOptions options;
// For future struct_size, we can probably infer that from the presence of
// properties in options_dict. For now, it's always 16.
options.struct_size = 16;
// Ideally these would be optional. But the interface makes it hard to
// typecheck them then.
if (!options_dict.Get("flags", &options.flags) ||
!options_dict.Get("elementNumBytes", &options.element_num_bytes) ||
!options_dict.Get("capacityNumBytes", &options.capacity_num_bytes)) {
return dictionary;
}
result = MojoCreateDataPipe(&options, &producer_handle, &consumer_handle);
} else {
return dictionary;
}
CHECK_EQ(MOJO_RESULT_OK, result);
dictionary.Set("result", result);
dictionary.Set("producerHandle", mojo::Handle(producer_handle));
dictionary.Set("consumerHandle", mojo::Handle(consumer_handle));
return dictionary;
}
gin::Dictionary WriteData(const gin::Arguments& args,
mojo::Handle handle,
const gin::ArrayBufferView& buffer,
MojoWriteDataFlags flags) {
uint32_t num_bytes = static_cast<uint32_t>(buffer.num_bytes());
MojoResult result =
MojoWriteData(handle.value(), buffer.bytes(), &num_bytes, flags);
gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate());
dictionary.Set("result", result);
dictionary.Set("numBytes", num_bytes);
return dictionary;
}
gin::Dictionary ReadData(const gin::Arguments& args,
mojo::Handle handle,
MojoReadDataFlags flags) {
uint32_t num_bytes = 0;
MojoResult result = MojoReadData(
handle.value(), NULL, &num_bytes, MOJO_READ_DATA_FLAG_QUERY);
if (result != MOJO_RESULT_OK) {
gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate());
dictionary.Set("result", result);
return dictionary;
}
v8::Handle<v8::ArrayBuffer> array_buffer =
v8::ArrayBuffer::New(args.isolate(), num_bytes);
gin::ArrayBuffer buffer;
ConvertFromV8(args.isolate(), array_buffer, &buffer);
CHECK_EQ(num_bytes, buffer.num_bytes());
result = MojoReadData(handle.value(), buffer.bytes(), &num_bytes, flags);
CHECK_EQ(num_bytes, buffer.num_bytes());
gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate());
dictionary.Set("result", result);
dictionary.Set("buffer", array_buffer);
return dictionary;
}
// Asynchronously read all of the data available for the specified data pipe
// consumer handle until the remote handle is closed or an error occurs. A
// Promise is returned whose settled value is an object like this:
// {result: core.RESULT_OK, buffer: dataArrayBuffer}. If the read failed,
// then the Promise is rejected, the result will be the actual error code,
// and the buffer will contain whatever was read before the error occurred.
// The drainData data pipe handle argument is closed automatically.
v8::Handle<v8::Value> DoDrainData(gin::Arguments* args,
gin::Handle<HandleWrapper> handle) {
return (new DrainData(args->isolate(), handle->release()))->GetPromise();
}
bool IsHandle(gin::Arguments* args, v8::Handle<v8::Value> val) {
gin::Handle<mojo::js::HandleWrapper> ignore_handle;
return gin::Converter<gin::Handle<mojo::js::HandleWrapper>>::FromV8(
args->isolate(), val, &ignore_handle);
}
gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin };
} // namespace
const char Core::kModuleName[] = "mojo/public/js/core";
v8::Local<v8::Value> Core::GetModule(v8::Isolate* isolate) {
gin::PerIsolateData* data = gin::PerIsolateData::From(isolate);
v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate(
&g_wrapper_info);
if (templ.IsEmpty()) {
templ =
gin::ObjectTemplateBuilder(isolate)
// TODO(mpcomplete): Should these just be methods on the JS Handle
// object?
.SetMethod("close", CloseHandle)
.SetMethod("wait", WaitHandle)
.SetMethod("waitMany", WaitMany)
.SetMethod("createMessagePipe", CreateMessagePipe)
.SetMethod("writeMessage", WriteMessage)
.SetMethod("readMessage", ReadMessage)
.SetMethod("createDataPipe", CreateDataPipe)
.SetMethod("writeData", WriteData)
.SetMethod("readData", ReadData)
.SetMethod("drainData", DoDrainData)
.SetMethod("isHandle", IsHandle)
.SetValue("RESULT_OK", MOJO_RESULT_OK)
.SetValue("RESULT_CANCELLED", MOJO_RESULT_CANCELLED)
.SetValue("RESULT_UNKNOWN", MOJO_RESULT_UNKNOWN)
.SetValue("RESULT_INVALID_ARGUMENT", MOJO_RESULT_INVALID_ARGUMENT)
.SetValue("RESULT_DEADLINE_EXCEEDED", MOJO_RESULT_DEADLINE_EXCEEDED)
.SetValue("RESULT_NOT_FOUND", MOJO_RESULT_NOT_FOUND)
.SetValue("RESULT_ALREADY_EXISTS", MOJO_RESULT_ALREADY_EXISTS)
.SetValue("RESULT_PERMISSION_DENIED", MOJO_RESULT_PERMISSION_DENIED)
.SetValue("RESULT_RESOURCE_EXHAUSTED",
MOJO_RESULT_RESOURCE_EXHAUSTED)
.SetValue("RESULT_FAILED_PRECONDITION",
MOJO_RESULT_FAILED_PRECONDITION)
.SetValue("RESULT_ABORTED", MOJO_RESULT_ABORTED)
.SetValue("RESULT_OUT_OF_RANGE", MOJO_RESULT_OUT_OF_RANGE)
.SetValue("RESULT_UNIMPLEMENTED", MOJO_RESULT_UNIMPLEMENTED)
.SetValue("RESULT_INTERNAL", MOJO_RESULT_INTERNAL)
.SetValue("RESULT_UNAVAILABLE", MOJO_RESULT_UNAVAILABLE)
.SetValue("RESULT_DATA_LOSS", MOJO_RESULT_DATA_LOSS)
.SetValue("RESULT_BUSY", MOJO_RESULT_BUSY)
.SetValue("RESULT_SHOULD_WAIT", MOJO_RESULT_SHOULD_WAIT)
.SetValue("DEADLINE_INDEFINITE", MOJO_DEADLINE_INDEFINITE)
.SetValue("HANDLE_SIGNAL_NONE", MOJO_HANDLE_SIGNAL_NONE)
.SetValue("HANDLE_SIGNAL_READABLE", MOJO_HANDLE_SIGNAL_READABLE)
.SetValue("HANDLE_SIGNAL_WRITABLE", MOJO_HANDLE_SIGNAL_WRITABLE)
.SetValue("HANDLE_SIGNAL_PEER_CLOSED",
MOJO_HANDLE_SIGNAL_PEER_CLOSED)
.SetValue("CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE",
MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE)
.SetValue("WRITE_MESSAGE_FLAG_NONE", MOJO_WRITE_MESSAGE_FLAG_NONE)
.SetValue("READ_MESSAGE_FLAG_NONE", MOJO_READ_MESSAGE_FLAG_NONE)
.SetValue("READ_MESSAGE_FLAG_MAY_DISCARD",
MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)
.SetValue("CREATE_DATA_PIPE_OPTIONS_FLAG_NONE",
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE)
.SetValue("WRITE_DATA_FLAG_NONE", MOJO_WRITE_DATA_FLAG_NONE)
.SetValue("WRITE_DATA_FLAG_ALL_OR_NONE",
MOJO_WRITE_DATA_FLAG_ALL_OR_NONE)
.SetValue("READ_DATA_FLAG_NONE", MOJO_READ_DATA_FLAG_NONE)
.SetValue("READ_DATA_FLAG_ALL_OR_NONE",
MOJO_READ_DATA_FLAG_ALL_OR_NONE)
.SetValue("READ_DATA_FLAG_DISCARD", MOJO_READ_DATA_FLAG_DISCARD)
.SetValue("READ_DATA_FLAG_QUERY", MOJO_READ_DATA_FLAG_QUERY)
.SetValue("READ_DATA_FLAG_PEEK", MOJO_READ_DATA_FLAG_PEEK)
.Build();
data->SetObjectTemplate(&g_wrapper_info, templ);
}
return templ->NewInstance();
}
} // namespace js
} // namespace mojo

Some files were not shown because too many files have changed in this diff Show More