88
99#include " flutter/common/task_runners.h"
1010#include " flutter/fml/make_copyable.h"
11- #include " flutter/lib/ui/window/window.h"
1211#include " third_party/tonic/dart_state.h"
1312#include " third_party/tonic/logging/dart_invoke.h"
13+ #include " third_party/tonic/typed_data/dart_byte_data.h"
1414
1515namespace flutter {
1616
17- namespace {
18-
19- // Avoid copying the contents of messages beyond a certain size.
20- const int kMessageCopyThreshold = 1000 ;
21-
22- void MessageDataFinalizer (void * isolate_callback_data,
23- Dart_WeakPersistentHandle handle,
24- void * peer) {
25- std::vector<uint8_t >* data = reinterpret_cast <std::vector<uint8_t >*>(peer);
26- delete data;
27- }
28-
29- Dart_Handle WrapByteData (std::vector<uint8_t > data) {
30- if (data.size () < kMessageCopyThreshold ) {
31- return ToByteData (data);
32- } else {
33- std::vector<uint8_t >* heap_data = new std::vector<uint8_t >(std::move (data));
34- return Dart_NewExternalTypedDataWithFinalizer (
35- Dart_TypedData_kByteData, heap_data->data (), heap_data->size (),
36- heap_data, heap_data->size (), MessageDataFinalizer);
37- }
38- }
39-
40- Dart_Handle WrapByteData (std::unique_ptr<fml::Mapping> mapping) {
41- std::vector<uint8_t > data (mapping->GetSize ());
42- memcpy (data.data (), mapping->GetMapping (), mapping->GetSize ());
43- return WrapByteData (std::move (data));
44- }
45-
46- } // anonymous namespace
47-
4817PlatformMessageResponseDart::PlatformMessageResponseDart (
4918 tonic::DartPersistentValue callback,
5019 fml::RefPtr<fml::TaskRunner> ui_task_runner)
@@ -71,7 +40,8 @@ void PlatformMessageResponseDart::Complete(std::unique_ptr<fml::Mapping> data) {
7140 return ;
7241 tonic::DartState::Scope scope (dart_state);
7342
74- Dart_Handle byte_buffer = WrapByteData (std::move (data));
43+ Dart_Handle byte_buffer =
44+ tonic::DartByteData::Create (data->GetMapping (), data->GetSize ());
7545 tonic::DartInvoke (callback.Release (), {byte_buffer});
7646 }));
7747}
0 commit comments