Skip to content

Commit

Permalink
Add API to send platform messages into engine through embedder API (f…
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishekamit authored and cbracken committed Sep 19, 2017
1 parent aa2437b commit 004d0bd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
30 changes: 30 additions & 0 deletions shell/platform/embedder/embedder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,33 @@ FlutterResult FlutterEngineSendPointerEvent(FlutterEngine engine,

return kSuccess;
}

FlutterResult FlutterEngineSendPlatformMessage(
FlutterEngine engine,
const FlutterPlatformMessage* flutter_message) {
if (engine == nullptr || flutter_message == nullptr) {
return kInvalidArguments;
}

if (SAFE_ACCESS(flutter_message, channel, nullptr) == nullptr ||
SAFE_ACCESS(flutter_message, message, nullptr) == nullptr) {
return kInvalidArguments;
}

auto holder = reinterpret_cast<PlatformViewHolder*>(engine);

auto message = fxl::MakeRefCounted<blink::PlatformMessage>(
flutter_message->channel,
std::vector<uint8_t>(
flutter_message->message,
flutter_message->message + flutter_message->message_size),
nullptr);

blink::Threads::UI()->PostTask(
[ weak_engine = holder->view()->engine().GetWeakPtr(), message ] {
if (auto engine = weak_engine) {
engine->DispatchPlatformMessage(message);
}
});
return kSuccess;
}
13 changes: 13 additions & 0 deletions shell/platform/embedder/embedder.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ typedef struct {
double y;
} FlutterPointerEvent;

typedef struct {
// The size of this struct. Must be sizeof(FlutterPlatformMessage).
size_t struct_size;
const char* channel;
const uint8_t* message;
const size_t message_size;
} FlutterPlatformMessage;

FLUTTER_EXPORT
FlutterResult FlutterEngineRun(size_t version,
const FlutterRendererConfig* config,
Expand All @@ -114,6 +122,11 @@ FlutterResult FlutterEngineSendPointerEvent(FlutterEngine engine,
const FlutterPointerEvent* events,
size_t events_count);

FLUTTER_EXPORT
FlutterResult FlutterEngineSendPlatformMessage(
FlutterEngine engine,
const FlutterPlatformMessage* message);

#if defined(__cplusplus)
} // extern "C"
#endif
Expand Down

0 comments on commit 004d0bd

Please sign in to comment.