[desktop_webview_window] Add support for registerJavaScriptMessageHandler on Linux#452
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for registerJavaScriptMessageHandler and unregisterJavaScriptMessageHandler on Linux, allowing JavaScript in webviews to communicate with Flutter code using the WebKit message handler API (window.webkit.messageHandlers.<handlerName>.postMessage()).
Key changes:
- Implemented Linux platform support for JavaScript message handlers in C++ using WebKit's user content manager API
- Updated Dart code to enable these methods on Linux in addition to macOS
- Bumped package version from 0.2.4 to 0.2.5
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/desktop_webview_window/lib/src/webview_impl.dart | Modified platform checks to enable JavaScript message handlers on Linux; attempted to clean up null safety code |
| packages/desktop_webview_window/linux/webview_window.h | Added method declarations for RegisterJavaScriptChannel and UnregisterJavaScriptChannel |
| packages/desktop_webview_window/linux/webview_window.cc | Implemented JavaScript message handler registration/unregistration using WebKit APIs |
| packages/desktop_webview_window/linux/desktop_webview_window_plugin.cc | Added method call handlers for registerJavaScripInterface and unregisterJavaScripInterface |
| packages/desktop_webview_window/pubspec.yaml | Bumped version to 0.2.5 and relaxed flutter_lints constraint |
| packages/desktop_webview_window/CHANGELOG.md | Documented the new Linux support for JavaScript message handlers |
| packages/desktop_webview_window/example/pubspec.lock | Updated dependency versions |
| packages/desktop_webview_window/example/macos/Flutter/GeneratedPluginRegistrant.swift | Updated plugin import from path_provider_macos to path_provider_foundation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| void WebviewWindow::UnregisterJavaScriptChannel(const std::string &name) { | ||
| WebKitUserContentManager *manager = | ||
| webkit_web_view_get_user_content_manager(WEBKIT_WEB_VIEW(webview_)); | ||
|
|
||
| webkit_user_content_manager_unregister_script_message_handler(manager, name.c_str()); | ||
| } |
There was a problem hiding this comment.
When unregistering a JavaScript channel, the signal handler connected in RegisterJavaScriptChannel is not disconnected, leading to a memory leak. The HandlerData allocated on line 383 will never be freed after unregistration because the destroy notify callback on line 419-421 will not be invoked.
Consider storing the signal handler ID returned by g_signal_connect_data and calling g_signal_handler_disconnect in UnregisterJavaScriptChannel before unregistering the script message handler.
|
LGTM, Thanks for the PR |
|
@boyan01 When will you publish the version on pub.dev? |
registerJavaScriptMessageHandlerandunregisterJavaScriptMessageHandleron LinuxExample of usage
Reopen #428