Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit d2bd4f7

Browse files
committed
fuchsia fixes
1 parent 1745e82 commit d2bd4f7

File tree

4 files changed

+33
-27
lines changed

4 files changed

+33
-27
lines changed

shell/platform/fuchsia/flutter/fuchsia_intl.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace flutter_runner {
2727

2828
using fuchsia::intl::Profile;
2929

30-
std::vector<uint8_t> MakeLocalizationPlatformMessageData(
30+
fml::MallocMapping MakeLocalizationPlatformMessageData(
3131
const Profile& intl_profile) {
3232
rapidjson::Document document;
3333
auto& allocator = document.GetAllocator();
@@ -66,7 +66,7 @@ std::vector<uint8_t> MakeLocalizationPlatformMessageData(
6666
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
6767
document.Accept(writer);
6868
auto data = reinterpret_cast<const uint8_t*>(buffer.GetString());
69-
return std::vector<uint8_t>(data, data + buffer.GetSize());
69+
return fml::MallocMapping::Copy(data, data + buffer.GetSize());
7070
}
7171

7272
} // namespace flutter_runner

shell/platform/fuchsia/flutter/fuchsia_intl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define FLUTTER_SHELL_PLATFORM_FUCHSIA_FUCHSIA_INTL_H_
77

88
#include <fuchsia/intl/cpp/fidl.h>
9+
#include "flutter/fml/mapping.h"
910

1011
namespace flutter_runner {
1112

@@ -15,7 +16,7 @@ namespace flutter_runner {
1516
// This method does not return a `std::unique_ptr<flutter::PlatformMessage>` for
1617
// testing convenience; that would require an unreasonably large set of
1718
// dependencies for the unit tests.
18-
std::vector<uint8_t> MakeLocalizationPlatformMessageData(
19+
fml::MallocMapping MakeLocalizationPlatformMessageData(
1920
const fuchsia::intl::Profile& intl_profile);
2021

2122
} // namespace flutter_runner

shell/platform/fuchsia/flutter/platform_view.cc

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ void PlatformView::DidUpdateState(
177177

178178
const uint8_t* data = reinterpret_cast<const uint8_t*>(buffer.GetString());
179179
DispatchPlatformMessage(std::make_unique<flutter::PlatformMessage>(
180-
kTextInputChannel, // channel
181-
std::vector<uint8_t>(data, data + buffer.GetSize()), // message
182-
nullptr) // response
180+
kTextInputChannel, // channel
181+
fml::MallocMapping::Copy(data, data + buffer.GetSize()), // message
182+
nullptr) // response
183183
);
184184
last_text_state_ =
185185
std::make_unique<fuchsia::ui::input::TextInputState>(state);
@@ -207,9 +207,9 @@ void PlatformView::OnAction(fuchsia::ui::input::InputMethodAction action) {
207207

208208
const uint8_t* data = reinterpret_cast<const uint8_t*>(buffer.GetString());
209209
DispatchPlatformMessage(std::make_unique<flutter::PlatformMessage>(
210-
kTextInputChannel, // channel
211-
std::vector<uint8_t>(data, data + buffer.GetSize()), // message
212-
nullptr) // response
210+
kTextInputChannel, // channel
211+
fml::MallocMapping::Copy(data, data + buffer.GetSize()), // message
212+
nullptr) // response
213213
);
214214
}
215215

@@ -446,7 +446,8 @@ bool PlatformView::OnChildViewConnected(scenic::ResourceId view_holder_id) {
446446
std::unique_ptr<flutter::PlatformMessage> message =
447447
std::make_unique<flutter::PlatformMessage>(
448448
"flutter/platform_views",
449-
std::vector<uint8_t>(call.begin(), call.end()), nullptr);
449+
fml::MallocMapping::Copy(call.c_str(), call.c_str() + call.size()),
450+
nullptr);
450451
DispatchPlatformMessage(std::move(message));
451452

452453
return true;
@@ -470,7 +471,8 @@ bool PlatformView::OnChildViewDisconnected(scenic::ResourceId view_holder_id) {
470471
std::unique_ptr<flutter::PlatformMessage> message =
471472
std::make_unique<flutter::PlatformMessage>(
472473
"flutter/platform_views",
473-
std::vector<uint8_t>(call.begin(), call.end()), nullptr);
474+
fml::MallocMapping::Copy(call.c_str(), call.c_str() + call.size()),
475+
nullptr);
474476
DispatchPlatformMessage(std::move(message));
475477

476478
return true;
@@ -497,7 +499,8 @@ bool PlatformView::OnChildViewStateChanged(scenic::ResourceId view_holder_id,
497499
std::unique_ptr<flutter::PlatformMessage> message =
498500
std::make_unique<flutter::PlatformMessage>(
499501
"flutter/platform_views",
500-
std::vector<uint8_t>(call.begin(), call.end()), nullptr);
502+
fml::MallocMapping::Copy(call.c_str(), call.c_str() + call.size()),
503+
nullptr);
501504
DispatchPlatformMessage(std::move(message));
502505

503506
return true;
@@ -646,9 +649,9 @@ void PlatformView::OnKeyEvent(
646649

647650
const uint8_t* data = reinterpret_cast<const uint8_t*>(buffer.GetString());
648651
DispatchPlatformMessage(std::make_unique<flutter::PlatformMessage>(
649-
kKeyEventChannel, // channel
650-
std::vector<uint8_t>(data, data + buffer.GetSize()), // data
651-
nullptr) // response
652+
kKeyEventChannel, // channel
653+
fml::MallocMapping::Copy(data, data + buffer.GetSize()), // data
654+
nullptr) // response
652655
);
653656
callback(fuchsia::ui::input3::KeyEventStatus::HANDLED);
654657
}
@@ -766,7 +769,7 @@ void PlatformView::HandleAccessibilityChannelPlatformMessage(
766769
const flutter::StandardMessageCodec& standard_message_codec =
767770
flutter::StandardMessageCodec::GetInstance(nullptr);
768771
std::unique_ptr<flutter::EncodableValue> decoded =
769-
standard_message_codec.DecodeMessage(message->data());
772+
standard_message_codec.DecodeMessage(message->releaseData());
770773

771774
flutter::EncodableMap map = std::get<flutter::EncodableMap>(*decoded);
772775
std::string type =

shell/platform/fuchsia/flutter/platform_view_unittest.cc

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class MockPlatformViewDelegate : public flutter::PlatformView::Delegate {
9696
// |flutter::PlatformView::Delegate|
9797
void OnPlatformViewDispatchSemanticsAction(int32_t id,
9898
flutter::SemanticsAction action,
99-
std::vector<uint8_t> args) {}
99+
fml::MallocMapping args) {}
100100
// |flutter::PlatformView::Delegate|
101101
void OnPlatformViewSetSemanticsEnabled(bool enabled) {
102102
semantics_enabled_ = enabled;
@@ -571,7 +571,7 @@ TEST_F(PlatformViewTests, EnableWireframeTest) {
571571
std::unique_ptr<flutter::PlatformMessage> message =
572572
std::make_unique<flutter::PlatformMessage>(
573573
"flutter/platform_views",
574-
std::vector<uint8_t>(txt, txt + sizeof(txt)),
574+
fml::MallocMapping::Copy(txt, txt + sizeof(txt)),
575575
fml::RefPtr<flutter::PlatformMessageResponse>());
576576
base_view->HandlePlatformMessage(std::move(message));
577577

@@ -631,7 +631,7 @@ TEST_F(PlatformViewTests, CreateViewTest) {
631631
std::unique_ptr<flutter::PlatformMessage> message =
632632
std::make_unique<flutter::PlatformMessage>(
633633
"flutter/platform_views",
634-
std::vector<uint8_t>(txt, txt + sizeof(txt)),
634+
fml::MallocMapping::Copy(txt, txt + sizeof(txt)),
635635
fml::RefPtr<flutter::PlatformMessageResponse>());
636636
base_view->HandlePlatformMessage(std::move(message));
637637

@@ -681,7 +681,7 @@ TEST_F(PlatformViewTests, UpdateViewTest) {
681681
std::unique_ptr<flutter::PlatformMessage> message =
682682
std::make_unique<flutter::PlatformMessage>(
683683
"flutter/platform_views",
684-
std::vector<uint8_t>(txt, txt + sizeof(txt)),
684+
fml::MallocMapping::Copy(txt, txt + sizeof(txt)),
685685
fml::RefPtr<flutter::PlatformMessageResponse>());
686686
base_view->HandlePlatformMessage(std::move(message));
687687

@@ -738,7 +738,7 @@ TEST_F(PlatformViewTests, DestroyViewTest) {
738738
std::unique_ptr<flutter::PlatformMessage> message =
739739
std::make_unique<flutter::PlatformMessage>(
740740
"flutter/platform_views",
741-
std::vector<uint8_t>(txt, txt + sizeof(txt)),
741+
fml::MallocMapping::Copy(txt, txt + sizeof(txt)),
742742
fml::RefPtr<flutter::PlatformMessageResponse>());
743743
base_view->HandlePlatformMessage(std::move(message));
744744

@@ -826,8 +826,9 @@ TEST_F(PlatformViewTests, ViewEventsTest) {
826826
<< " }"
827827
<< "}";
828828
EXPECT_EQ(view_connected_expected_out.str(),
829-
std::string(view_connected_msg->data().begin(),
830-
view_connected_msg->data().end()));
829+
std::string(view_connected_msg->GetMapping(),
830+
view_connected_msg->GetMapping() +
831+
view_connected_msg->GetSize()));
831832

832833
// ViewDisconnected event.
833834
delegate.Reset();
@@ -938,7 +939,7 @@ TEST_F(PlatformViewTests, RequestFocusTest) {
938939
std::unique_ptr<flutter::PlatformMessage> message =
939940
std::make_unique<flutter::PlatformMessage>(
940941
"flutter/platform_views",
941-
std::vector<uint8_t>(buff, buff + sizeof(buff)), response);
942+
fml::MallocMapping::Copy(buff, buff + sizeof(buff)), response);
942943
base_view->HandlePlatformMessage(std::move(message));
943944

944945
RunLoopUntilIdle();
@@ -1001,7 +1002,7 @@ TEST_F(PlatformViewTests, RequestFocusFailTest) {
10011002
std::unique_ptr<flutter::PlatformMessage> message =
10021003
std::make_unique<flutter::PlatformMessage>(
10031004
"flutter/platform_views",
1004-
std::vector<uint8_t>(buff, buff + sizeof(buff)), response);
1005+
fml::MallocMapping::Copy(buff, buff + sizeof(buff)), response);
10051006
base_view->HandlePlatformMessage(std::move(message));
10061007

10071008
RunLoopUntilIdle();
@@ -1093,8 +1094,9 @@ TEST_F(PlatformViewTests, OnKeyEvent) {
10931094
key_event_status = status;
10941095
});
10951096
RunLoopUntilIdle();
1096-
const std::vector<uint8_t> data = delegate.message()->data();
1097-
const std::string message = std::string(data.begin(), data.end());
1097+
const fml::MallocMapping data = delegate.message()->releaseData();
1098+
const std::string message =
1099+
std::string(data.GetMapping(), data.GetMapping() + data.GetSize());
10981100

10991101
EXPECT_EQ(event.expected_platform_message, message);
11001102
EXPECT_EQ(key_event_status, event.expected_key_event_status);

0 commit comments

Comments
 (0)