Sitelet https://github.com/flutter/flutter/pull/191855
Skip to content

iOS: Key the platform view factory registries by NSString - #191855

Merged
auto-submit[bot] merged 1 commit into
flutter:masterfrom
cbracken:use-nsdict-for-pv-factories
Aug 28, 2026
Merged

auto-submit[bot] merged 1 commit into
flutter:masterfrom
cbracken:use-nsdict-for-pv-factories

Conversation

@cbracken

Copy link
Copy Markdown
Member

FlutterPlatformViewsController was holding its view factories and their gesture blocking policies in std::unordered_maps keyed by std::string, so both the registration path and the create path converted an NSString to a std::string first. But all the mapped values are Obj-C types so we can migrate to na NSMutableDictionary. This matches how we do it in the macOS embedder.

This removes the last of the UTF8String conversions in this file. As noted in #191853 and #191854 std::string's const char* constructor determines the length using strlen, so it truncates at an embedded NUL and dereferences null if UTF8String ever returns NULL, which it does for a nil receiver.

Spotted while working on: #191616

No new tests since this just changes the implementation without changing any semantics.

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

`FlutterPlatformViewsController` was holding its view factories and
their gesture blocking policies in `std::unordered_map`s keyed by
`std::string`, so both the registration path and the create path
converted an `NSString` to a `std::string` first. But all the mapped
values are Obj-C types so we can migrate to na `NSMutableDictionary`.
This matches how we do it in the macOS embedder.

This removes the last of the `UTF8String` conversions in this file. As
noted in flutter#191853 and flutter#191854 `std::string`'s `const char*` constructor
determines the length using `strlen`, so it truncates at an embedded NUL
and dereferences null if `UTF8String` ever returns NULL, which it does
for a nil receiver.

Spotted while working on: flutter#191616

No new tests since this just changes the implementation without changing
any semantics.
@cbracken
cbracken requested a review from a team as a code owner August 27, 2026 04:01
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Aug 27, 2026
@flutter-dashboard

Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@github-actions github-actions Bot added platform-ios iOS applications specifically engine flutter/engine related. See also e: labels. team-ios Owned by iOS platform team labels Aug 27, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors FlutterPlatformViewsController by replacing C++ std::unordered_map with Objective-C NSMutableDictionary for managing platform view factories and gesture blocking policies. Feedback recommends adding defensive FML_CHECK assertions to verify that both factoryId and factory are not nil before inserting them into the dictionary, which prevents potential runtime exceptions.

@stuartmorgan-g

Copy link
Copy Markdown
Contributor

test-exempt: code refactor with no semantic change

@stuartmorgan-g stuartmorgan-g left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

int64_t viewId = [args[@"id"] longLongValue];
// A missing argument arrives as nil and an explicit Dart null as NSNull, neither of which can be
// converted to a view type.
NSString* viewTypeString = args[@"viewType"];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional nit: you could rename this viewType, since it looks like calling it viewTypeString was probably just to give it a distinct name from viewType (although that's arguably the least useful suffix that could have been added...)

} else if ([gestureBlockingPolicyValue
isEqualToString:kGestureBlockingPolicyFallbackToPluginDefault]) {
gestureBlockingPolicy = self.gestureRecognizersBlockingPoliciesByType[viewType];
gestureBlockingPolicy = static_cast<FlutterPlatformViewGestureRecognizersBlockingPolicy>(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(It's a shame we're losing type information on the value, but that's worth avoiding the actual data conversion on the key. If only there were some language we could use for this file where we didn't have to make that tradeoff 😉 )

@cbracken cbracken added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 27, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Aug 27, 2026
Merged via the queue into flutter:master with commit ff663c6 Aug 28, 2026
28 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 28, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Aug 28, 2026
flutter/flutter@e8dca90...8d8c1aa

2026-08-28 engine-flutter-autoroll@skia.org Roll Packages from bd3cbc1 to cd4cdd0 (15 revisions) (flutter/flutter#191965)
2026-08-28 matthiasngeo@gmail.com Bump customer testing version to pick up forui tests (flutter/flutter#191931)
2026-08-28 victorsanniay@gmail.com Use leading scroll offset instead of infinite offset to reveal pinned slivers (flutter/flutter#191329)
2026-08-28 engine-flutter-autoroll@skia.org Roll Skia from 21f71051e749 to fe0b9a5261f9 (1 revision) (flutter/flutter#191960)
2026-08-28 robert.ancell@canonical.com Share the common Linux window controller code in mixins (flutter/flutter#191930)
2026-08-28 engine-flutter-autoroll@skia.org Roll Dart SDK from 2cf2f69fd9f0 to ae63a6eca3f1 (1 revision) (flutter/flutter#191953)
2026-08-28 engine-flutter-autoroll@skia.org Roll Skia from 11e3a7cb0fd0 to 21f71051e749 (3 revisions) (flutter/flutter#191942)
2026-08-28 engine-flutter-autoroll@skia.org Roll Dart SDK from e030e77d5413 to 2cf2f69fd9f0 (2 revisions) (flutter/flutter#191934)
2026-08-28 32538273+ValentinVignal@users.noreply.github.com Remove no-shuffle in flutter tools overall experience test (flutter/flutter#191861)
2026-08-28 bkonyi@google.com [flutter_tools] Gracefully handle Windows Application Control and security policy execution blocks (flutter/flutter#191912)
2026-08-28 bkonyi@google.com [tool] Migrate ConfigCommand to modular dependency injection (flutter/flutter#190743)
2026-08-28 engine-flutter-autoroll@skia.org Roll Skia from 37459da0a755 to 11e3a7cb0fd0 (9 revisions) (flutter/flutter#191929)
2026-08-28 robert.ancell@canonical.com Connect to moved-to-rect after the window is realized (flutter/flutter#191773)
2026-08-28 chris@bracken.jp macOS: Compare accessibility strings as NSStrings in tests (flutter/flutter#191853)
2026-08-28 chris@bracken.jp macOS: Record test accessibility notifications in a dictionary (flutter/flutter#191854)
2026-08-28 engine-flutter-autoroll@skia.org Roll Fuchsia Test Scripts from 6SXRz6wsA2Zm_rAqP... to u_fSMsPU22VvUsvSo... (flutter/flutter#191927)
2026-08-28 engine-flutter-autoroll@skia.org Roll Dart SDK from cb4c39d067f3 to e030e77d5413 (3 revisions) (flutter/flutter#191923)
2026-08-27 okorohelijah@google.com Migrate ios driver tests batch 2 to simulators (flutter/flutter#190930)
2026-08-27 bkonyi@google.com [flutter_test] Ensure LiveTestWidgetsFlutterBinding executes frame and pointer callbacks in the test zone (flutter/flutter#191595)
2026-08-27 36861262+QuncCccccc@users.noreply.github.com Deprecate legacy gen_defaults tool (flutter/flutter#191911)
2026-08-27 robert.ancell@canonical.com Fix black window in the subsurface view renderer (flutter/flutter#191850)
2026-08-27 engine-flutter-autoroll@skia.org Roll Skia from 82e972ea84b1 to 37459da0a755 (10 revisions) (flutter/flutter#191906)
2026-08-27 chris@bracken.jp iOS: Key the platform view factory registries by NSString (flutter/flutter#191855)
2026-08-27 154381524+flutteractionsbot@users.noreply.github.com Sync CHANGELOG.md from stable (flutter/flutter#191895)
2026-08-27 bkonyi@google.com [flutter_tools] Honor configured build-dir across flutter project and build targets (flutter/flutter#191592)
2026-08-27 154381524+flutteractionsbot@users.noreply.github.com Revert: Handle linear and radial gradients in UberSDF (flutter/flutter#191913)
2026-08-27 34871572+gmackall@users.noreply.github.com Explicitly disable HCPP in hybrid_android_views integration test (flutter/flutter#191894)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC bmparr@google.com,stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
victorsanni pushed a commit to victorsanni/packages that referenced this pull request Sep 9, 2026
…r#12679)

flutter/flutter@e8dca90...8d8c1aa

2026-08-28 engine-flutter-autoroll@skia.org Roll Packages from bd3cbc1 to cd4cdd0 (15 revisions) (flutter/flutter#191965)
2026-08-28 matthiasngeo@gmail.com Bump customer testing version to pick up forui tests (flutter/flutter#191931)
2026-08-28 victorsanniay@gmail.com Use leading scroll offset instead of infinite offset to reveal pinned slivers (flutter/flutter#191329)
2026-08-28 engine-flutter-autoroll@skia.org Roll Skia from 21f71051e749 to fe0b9a5261f9 (1 revision) (flutter/flutter#191960)
2026-08-28 robert.ancell@canonical.com Share the common Linux window controller code in mixins (flutter/flutter#191930)
2026-08-28 engine-flutter-autoroll@skia.org Roll Dart SDK from 2cf2f69fd9f0 to ae63a6eca3f1 (1 revision) (flutter/flutter#191953)
2026-08-28 engine-flutter-autoroll@skia.org Roll Skia from 11e3a7cb0fd0 to 21f71051e749 (3 revisions) (flutter/flutter#191942)
2026-08-28 engine-flutter-autoroll@skia.org Roll Dart SDK from e030e77d5413 to 2cf2f69fd9f0 (2 revisions) (flutter/flutter#191934)
2026-08-28 32538273+ValentinVignal@users.noreply.github.com Remove no-shuffle in flutter tools overall experience test (flutter/flutter#191861)
2026-08-28 bkonyi@google.com [flutter_tools] Gracefully handle Windows Application Control and security policy execution blocks (flutter/flutter#191912)
2026-08-28 bkonyi@google.com [tool] Migrate ConfigCommand to modular dependency injection (flutter/flutter#190743)
2026-08-28 engine-flutter-autoroll@skia.org Roll Skia from 37459da0a755 to 11e3a7cb0fd0 (9 revisions) (flutter/flutter#191929)
2026-08-28 robert.ancell@canonical.com Connect to moved-to-rect after the window is realized (flutter/flutter#191773)
2026-08-28 chris@bracken.jp macOS: Compare accessibility strings as NSStrings in tests (flutter/flutter#191853)
2026-08-28 chris@bracken.jp macOS: Record test accessibility notifications in a dictionary (flutter/flutter#191854)
2026-08-28 engine-flutter-autoroll@skia.org Roll Fuchsia Test Scripts from 6SXRz6wsA2Zm_rAqP... to u_fSMsPU22VvUsvSo... (flutter/flutter#191927)
2026-08-28 engine-flutter-autoroll@skia.org Roll Dart SDK from cb4c39d067f3 to e030e77d5413 (3 revisions) (flutter/flutter#191923)
2026-08-27 okorohelijah@google.com Migrate ios driver tests batch 2 to simulators (flutter/flutter#190930)
2026-08-27 bkonyi@google.com [flutter_test] Ensure LiveTestWidgetsFlutterBinding executes frame and pointer callbacks in the test zone (flutter/flutter#191595)
2026-08-27 36861262+QuncCccccc@users.noreply.github.com Deprecate legacy gen_defaults tool (flutter/flutter#191911)
2026-08-27 robert.ancell@canonical.com Fix black window in the subsurface view renderer (flutter/flutter#191850)
2026-08-27 engine-flutter-autoroll@skia.org Roll Skia from 82e972ea84b1 to 37459da0a755 (10 revisions) (flutter/flutter#191906)
2026-08-27 chris@bracken.jp iOS: Key the platform view factory registries by NSString (flutter/flutter#191855)
2026-08-27 154381524+flutteractionsbot@users.noreply.github.com Sync CHANGELOG.md from stable (flutter/flutter#191895)
2026-08-27 bkonyi@google.com [flutter_tools] Honor configured build-dir across flutter project and build targets (flutter/flutter#191592)
2026-08-27 154381524+flutteractionsbot@users.noreply.github.com Revert: Handle linear and radial gradients in UberSDF (flutter/flutter#191913)
2026-08-27 34871572+gmackall@users.noreply.github.com Explicitly disable HCPP in hybrid_android_views integration test (flutter/flutter#191894)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC bmparr@google.com,stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
victorsanni pushed a commit to victorsanni/packages that referenced this pull request Sep 9, 2026
…r#12679)

flutter/flutter@e8dca90...8d8c1aa

2026-08-28 engine-flutter-autoroll@skia.org Roll Packages from bd3cbc1 to cd4cdd0 (15 revisions) (flutter/flutter#191965)
2026-08-28 matthiasngeo@gmail.com Bump customer testing version to pick up forui tests (flutter/flutter#191931)
2026-08-28 victorsanniay@gmail.com Use leading scroll offset instead of infinite offset to reveal pinned slivers (flutter/flutter#191329)
2026-08-28 engine-flutter-autoroll@skia.org Roll Skia from 21f71051e749 to fe0b9a5261f9 (1 revision) (flutter/flutter#191960)
2026-08-28 robert.ancell@canonical.com Share the common Linux window controller code in mixins (flutter/flutter#191930)
2026-08-28 engine-flutter-autoroll@skia.org Roll Dart SDK from 2cf2f69fd9f0 to ae63a6eca3f1 (1 revision) (flutter/flutter#191953)
2026-08-28 engine-flutter-autoroll@skia.org Roll Skia from 11e3a7cb0fd0 to 21f71051e749 (3 revisions) (flutter/flutter#191942)
2026-08-28 engine-flutter-autoroll@skia.org Roll Dart SDK from e030e77d5413 to 2cf2f69fd9f0 (2 revisions) (flutter/flutter#191934)
2026-08-28 32538273+ValentinVignal@users.noreply.github.com Remove no-shuffle in flutter tools overall experience test (flutter/flutter#191861)
2026-08-28 bkonyi@google.com [flutter_tools] Gracefully handle Windows Application Control and security policy execution blocks (flutter/flutter#191912)
2026-08-28 bkonyi@google.com [tool] Migrate ConfigCommand to modular dependency injection (flutter/flutter#190743)
2026-08-28 engine-flutter-autoroll@skia.org Roll Skia from 37459da0a755 to 11e3a7cb0fd0 (9 revisions) (flutter/flutter#191929)
2026-08-28 robert.ancell@canonical.com Connect to moved-to-rect after the window is realized (flutter/flutter#191773)
2026-08-28 chris@bracken.jp macOS: Compare accessibility strings as NSStrings in tests (flutter/flutter#191853)
2026-08-28 chris@bracken.jp macOS: Record test accessibility notifications in a dictionary (flutter/flutter#191854)
2026-08-28 engine-flutter-autoroll@skia.org Roll Fuchsia Test Scripts from 6SXRz6wsA2Zm_rAqP... to u_fSMsPU22VvUsvSo... (flutter/flutter#191927)
2026-08-28 engine-flutter-autoroll@skia.org Roll Dart SDK from cb4c39d067f3 to e030e77d5413 (3 revisions) (flutter/flutter#191923)
2026-08-27 okorohelijah@google.com Migrate ios driver tests batch 2 to simulators (flutter/flutter#190930)
2026-08-27 bkonyi@google.com [flutter_test] Ensure LiveTestWidgetsFlutterBinding executes frame and pointer callbacks in the test zone (flutter/flutter#191595)
2026-08-27 36861262+QuncCccccc@users.noreply.github.com Deprecate legacy gen_defaults tool (flutter/flutter#191911)
2026-08-27 robert.ancell@canonical.com Fix black window in the subsurface view renderer (flutter/flutter#191850)
2026-08-27 engine-flutter-autoroll@skia.org Roll Skia from 82e972ea84b1 to 37459da0a755 (10 revisions) (flutter/flutter#191906)
2026-08-27 chris@bracken.jp iOS: Key the platform view factory registries by NSString (flutter/flutter#191855)
2026-08-27 154381524+flutteractionsbot@users.noreply.github.com Sync CHANGELOG.md from stable (flutter/flutter#191895)
2026-08-27 bkonyi@google.com [flutter_tools] Honor configured build-dir across flutter project and build targets (flutter/flutter#191592)
2026-08-27 154381524+flutteractionsbot@users.noreply.github.com Revert: Handle linear and radial gradients in UberSDF (flutter/flutter#191913)
2026-08-27 34871572+gmackall@users.noreply.github.com Explicitly disable HCPP in hybrid_android_views integration test (flutter/flutter#191894)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC bmparr@google.com,stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD engine flutter/engine related. See also e: labels. platform-ios iOS applications specifically team-ios Owned by iOS platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants