-
Notifications
You must be signed in to change notification settings - Fork 6k
Allow embedders to add callbacks for responses to platform messages from the framework. #9655
Allow embedders to add callbacks for responses to platform messages from the framework. #9655
Conversation
shell/platform/embedder/embedder.cc
Outdated
| return LOG_EMBEDDER_ERROR(kInvalidArguments); | ||
| } | ||
|
|
||
| flutter::EmbedderPlatformMessageResponse::Callback response = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it naming this "response_callback" would make it a bit more clear since this is just the callback, not the whole response.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
shell/platform/embedder/embedder.cc
Outdated
|
|
||
| auto handle = new FlutterPlatformMessageResponseHandle(); | ||
| handle->message = fml::MakeRefCounted<flutter::PlatformMessage>( | ||
| "", fml::MakeRefCounted<flutter::EmbedderPlatformMessageResponse>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to add a comment explaining why we are sending an empty channel, or is that obvious?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
shell/platform/embedder/embedder.cc
Outdated
| return kSuccess; | ||
| } | ||
|
|
||
| FLUTTER_EXPORT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
|
||
| namespace flutter { | ||
|
|
||
| class EmbedderPlatformMessageResponse : public PlatformMessageResponse { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add class definition documentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
|
||
|
|
||
| @pragma('vm:entry-point') | ||
| void platform_messages_response() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these messages have documentation relating to the tests using them?
| kill_latch.Wait(); | ||
| } | ||
|
|
||
| TEST_F(EmbedderTest, ShouldBeAbleToCreateAndCollectCallbacks) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this test be called CanCreateAndCollectcallbacks, for consistency with the test PlatformMessagesCanReceiveResponse below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| kill_latch.Wait(); | ||
| } | ||
|
|
||
| TEST_F(EmbedderTest, ShouldBeAbleToCreateAndCollectCallbacks) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion for this and future tests: We should have a brief comment explaining what the test does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
shell/platform/embedder/embedder.cc
Outdated
| return LOG_EMBEDDER_ERROR(kInvalidArguments); | ||
| } | ||
|
|
||
| auto response_handle = SAFE_ACCESS(flutter_message, response_handle, nullptr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer auto* to auto here. (I'd actually suggest FlutterPlatformMessageResponseHandle* since I don't think the type is obvious in immediate context, and it's used in a way other than just passing off to something else, so this is a case where the guide prefers explicit type).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point. Done.
shell/platform/embedder/embedder.h
Outdated
| FlutterEngine engine, | ||
| const FlutterPlatformMessage* message); | ||
|
|
||
| // Create a platform message response handle that allows the embedder to set a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Create/Creates/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
shell/platform/embedder/embedder.h
Outdated
|
|
||
| // Create a platform message response handle that allows the embedder to set a | ||
| // native callback for a response to a message. This handle may be set on the | ||
| // |response_handle| field of any |FlutterPlatformMessage|. The handle must be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/any |FlutterPlatformMessage|/any |FlutterPlatformMessage| sent to the engine/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
shell/platform/embedder/embedder.h
Outdated
| // Create a platform message response handle that allows the embedder to set a | ||
| // native callback for a response to a message. This handle may be set on the | ||
| // |response_handle| field of any |FlutterPlatformMessage|. The handle must be | ||
| // collected via a call to |FlutterPlatformMessageReleaseResponseHandle|. This |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear to me why we need this step; why not just do the cleanup internally, and make it an error not to send the message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The memory management is cleaner and more explicit than deleting objects in obscure struct fields on specific calls that don't even operate on that object directly. I strongly think this makes the lifecycle of these resources easier to reason about.
shell/platform/embedder/embedder.h
Outdated
| void* user_data, | ||
| FlutterPlatformMessageResponseHandle** response_out); | ||
|
|
||
| // Collect the handle created using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Collect/Collects/ (if this function is kept)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
chinmaygarde
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed all PR comments.
shell/platform/embedder/embedder.cc
Outdated
| return LOG_EMBEDDER_ERROR(kInvalidArguments); | ||
| } | ||
|
|
||
| auto response_handle = SAFE_ACCESS(flutter_message, response_handle, nullptr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point. Done.
shell/platform/embedder/embedder.cc
Outdated
| return LOG_EMBEDDER_ERROR(kInvalidArguments); | ||
| } | ||
|
|
||
| flutter::EmbedderPlatformMessageResponse::Callback response = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
shell/platform/embedder/embedder.cc
Outdated
|
|
||
| auto handle = new FlutterPlatformMessageResponseHandle(); | ||
| handle->message = fml::MakeRefCounted<flutter::PlatformMessage>( | ||
| "", fml::MakeRefCounted<flutter::EmbedderPlatformMessageResponse>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
shell/platform/embedder/embedder.cc
Outdated
| return kSuccess; | ||
| } | ||
|
|
||
| FLUTTER_EXPORT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
shell/platform/embedder/embedder.h
Outdated
| // Create a platform message response handle that allows the embedder to set a | ||
| // native callback for a response to a message. This handle may be set on the | ||
| // |response_handle| field of any |FlutterPlatformMessage|. The handle must be | ||
| // collected via a call to |FlutterPlatformMessageReleaseResponseHandle|. This |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The memory management is cleaner and more explicit than deleting objects in obscure struct fields on specific calls that don't even operate on that object directly. I strongly think this makes the lifecycle of these resources easier to reason about.
shell/platform/embedder/embedder.h
Outdated
| void* user_data, | ||
| FlutterPlatformMessageResponseHandle** response_out); | ||
|
|
||
| // Collect the handle created using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
|
||
| namespace flutter { | ||
|
|
||
| class EmbedderPlatformMessageResponse : public PlatformMessageResponse { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| kill_latch.Wait(); | ||
| } | ||
|
|
||
| TEST_F(EmbedderTest, ShouldBeAbleToCreateAndCollectCallbacks) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| kill_latch.Wait(); | ||
| } | ||
|
|
||
| TEST_F(EmbedderTest, ShouldBeAbleToCreateAndCollectCallbacks) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
stuartmorgan-g
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with some nits and one API type question.
|
|
||
| //---------------------------------------------------------------------------- | ||
| /// @brief Destroys the message response. Can be called on any thread. | ||
| /// Does no execute unfulfilled callbacks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: no->not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| //---------------------------------------------------------------------------- | ||
| /// @brief Destroys the message response. Can be called on any thread. | ||
| /// Does no execute unfulfilled callbacks. | ||
| /// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: remove blank comment line.
| // Creates a platform message response handle that allows the embedder to set a | ||
| // native callback for a response to a message. This handle may be set on the | ||
| // |response_handle| field of any |FlutterPlatformMessage| sent to the engine. | ||
| // The handle must be collected via a call to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: consider adding a blank line above this, and another before the "The user data baton [...]" to break this long comment up into different conceptual sections (overview, memory management, argument details).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. At some point, we should move over to using doxygen style header docs too.
shell/platform/embedder/embedder.h
Outdated
| const FlutterPlatformMessage* /* message*/, | ||
| void* /* user data */); | ||
|
|
||
| typedef void (*FlutterDataCallback)(const void* /* data */, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed this before: why is data a void* rather than a uint8_t* like the data in a message and the data in a response going the other way? It seems like an odd/confusing mismatch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, it should be uint8_t*. Updated. Ditto for EmbedderPlatformMessageResponse::Callback.
…rom the framework. Fixes flutter/flutter#18852
a06c665 to
c2bfb97
Compare
chinmaygarde
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed all comments.
shell/platform/embedder/embedder.h
Outdated
| const FlutterPlatformMessage* /* message*/, | ||
| void* /* user data */); | ||
|
|
||
| typedef void (*FlutterDataCallback)(const void* /* data */, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, it should be uint8_t*. Updated. Ditto for EmbedderPlatformMessageResponse::Callback.
| // Creates a platform message response handle that allows the embedder to set a | ||
| // native callback for a response to a message. This handle may be set on the | ||
| // |response_handle| field of any |FlutterPlatformMessage| sent to the engine. | ||
| // The handle must be collected via a call to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. At some point, we should move over to using doxygen style header docs too.
|
|
||
| //---------------------------------------------------------------------------- | ||
| /// @brief Destroys the message response. Can be called on any thread. | ||
| /// Does no execute unfulfilled callbacks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
…ssages from the framework. (flutter/engine#9655)
…ssages from the framework. (flutter/engine#9655)
…ssages from the framework. (flutter/engine#9655)
…ssages from the framework. (flutter/engine#9655)
…ssages from the framework. (flutter/engine#9655)
…ssages from the framework. (flutter/engine#9655)
flutter/engine@7d3e722...3c51a7b git log 7d3e722..3c51a7b --no-merges --oneline 3c51a7b Roll src/third_party/skia 11eb847a2080..857c9f955edb (2 commits) (flutter/engine#9676) 7f828dd Raster now returns an enum rather than boolean (flutter/engine#9661) 11b6afe Roll src/third_party/dart 67ab3be10d...b5aeaa6796 (flutter/engine#9675) 3c4dbe2 Revert " Roll src/third_party/dart 67ab3be10d...43891316ca (#9670)" (flutter/engine#9673) 5e596f2 Roll src/third_party/dart 67ab3be10d...43891316ca (flutter/engine#9670) 46a2239 Roll src/third_party/skia 5b52c52141ac..11eb847a2080 (6 commits) (flutter/engine#9671) b84f89b Allow embedders to add callbacks for responses to platform messages from the framework. (flutter/engine#9655) 8dac2e9 Begin separating macOS engine from view controller (flutter/engine#9654) d3616c7 Roll src/third_party/skia 0e0113dcbd9a..5b52c52141ac (8 commits) (flutter/engine#9665) cea2c36 Mutators Stack refactoring (flutter/engine#9663) 6a8782f Roll src/third_party/skia 93eeff578b08..0e0113dcbd9a (9 commits) (flutter/engine#9662) 791143f ExternalViewEmbedder can CancelFrame after pre-roll (flutter/engine#9660) d637f29 External view embedder can tell if embedded views have mutated (flutter/engine#9653) ceee3d7 Roll src/third_party/skia 38ae3f42fec1..93eeff578b08 (1 commits) (flutter/engine#9659) d757290 Roll src/third_party/skia febc162c7898..38ae3f42fec1 (3 commits) (flutter/engine#9658) 58133ab Roll src/third_party/skia 3de5c6388142..febc162c7898 (2 commits) (flutter/engine#9657) 29342dd Roll src/third_party/skia 1e2cb444e0c1..3de5c6388142 (8 commits) (flutter/engine#9656) b547356 Pipeline allows continuations that can produce to front (flutter/engine#9652) 8306ee6 Move the mutators stack handling to preroll (flutter/engine#9651) 511b9f2 Roll src/third_party/skia 215ff3325230..1e2cb444e0c1 (12 commits) (flutter/engine#9650) The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+/master/autoroll/README.md If the roll is causing failures, please contact the current sheriff (jsimmons@google.com), and stop the roller if necessary.
Fixes flutter/flutter#18852