Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only register top level window message listener upon registering service binding #41733

Merged
merged 22 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions shell/platform/darwin/macos/framework/Source/FlutterEngine.mm
Expand Up @@ -1031,6 +1031,8 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
result(@{@"value" : @([self clipboardHasStrings])});
} else if ([call.method isEqualToString:@"System.exitApplication"]) {
[[self terminationHandler] handleRequestAppExitMethodCall:call.arguments result:result];
} else if ([call.method isEqualToString:@"System.registerBinding"]) {
result(nil);
loic-sharma marked this conversation as resolved.
Show resolved Hide resolved
} else {
result(FlutterMethodNotImplemented);
}
Expand Down
3 changes: 3 additions & 0 deletions shell/platform/linux/fl_platform_plugin.cc
Expand Up @@ -20,6 +20,7 @@ static constexpr char kSetClipboardDataMethod[] = "Clipboard.setData";
static constexpr char kClipboardHasStringsMethod[] = "Clipboard.hasStrings";
static constexpr char kExitApplicationMethod[] = "System.exitApplication";
static constexpr char kRequestAppExitMethod[] = "System.requestAppExit";
static constexpr char kRegisterBindingMethod[] = "System.registerBinding";
static constexpr char kPlaySoundMethod[] = "SystemSound.play";
static constexpr char kSystemNavigatorPopMethod[] = "SystemNavigator.pop";
static constexpr char kTextKey[] = "text";
Expand Down Expand Up @@ -335,6 +336,8 @@ static void method_call_cb(FlMethodChannel* channel,
response = system_sound_play(self, args);
} else if (strcmp(method, kSystemNavigatorPopMethod) == 0) {
response = system_navigator_pop(self);
} else if () {
response = FL_METHOD_RESPONSE(fl_method_success_response_new(fl_value_new_null()));
} else {
response = FL_METHOD_RESPONSE(fl_method_not_implemented_response_new());
}
Expand Down
25 changes: 14 additions & 11 deletions shell/platform/windows/flutter_windows_engine.cc
Expand Up @@ -204,17 +204,6 @@ FlutterWindowsEngine::FlutterWindowsEngine(
std::make_unique<FlutterWindowsTextureRegistrar>(this, gl_procs_);
surface_manager_ = AngleSurfaceManager::Create();
window_proc_delegate_manager_ = std::make_unique<WindowProcDelegateManager>();
window_proc_delegate_manager_->RegisterTopLevelWindowProcDelegate(
[](HWND hwnd, UINT msg, WPARAM wpar, LPARAM lpar, void* user_data,
LRESULT* result) {
BASE_DCHECK(user_data);
FlutterWindowsEngine* that =
static_cast<FlutterWindowsEngine*>(user_data);
BASE_DCHECK(that->lifecycle_manager_);
return that->lifecycle_manager_->WindowProc(hwnd, msg, wpar, lpar,
result);
},
static_cast<void*>(this));

// Set up internal channels.
// TODO: Replace this with an embedder.h API. See
Expand Down Expand Up @@ -778,4 +767,18 @@ void FlutterWindowsEngine::OnDwmCompositionChanged() {
view_->OnDwmCompositionChanged();
}

void FlutterWindowsEngine::OnServiceBindingsRegistered() {
yaakovschectman marked this conversation as resolved.
Show resolved Hide resolved
window_proc_delegate_manager_->RegisterTopLevelWindowProcDelegate(
[](HWND hwnd, UINT msg, WPARAM wpar, LPARAM lpar, void* user_data,
LRESULT* result) {
BASE_DCHECK(user_data);
FlutterWindowsEngine* that =
static_cast<FlutterWindowsEngine*>(user_data);
BASE_DCHECK(that->lifecycle_manager_);
return that->lifecycle_manager_->WindowProc(hwnd, msg, wpar, lpar,
result);
},
static_cast<void*>(this));
}

} // namespace flutter
4 changes: 4 additions & 0 deletions shell/platform/windows/flutter_windows_engine.h
Expand Up @@ -269,6 +269,10 @@ class FlutterWindowsEngine {
// Called when a WM_DWMCOMPOSITIONCHANGED message is received.
void OnDwmCompositionChanged();

// Called in response to the framework registering a ServiceBindings.
// Registers the top level handler for the WM_CLOSE window message.
void OnServiceBindingsRegistered();
Copy link
Member

Choose a reason for hiding this comment

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

Don't forget to update these names to reflect the latest framework message name :)


protected:
// Creates the keyboard key handler.
//
Expand Down
4 changes: 4 additions & 0 deletions shell/platform/windows/flutter_windows_engine_unittests.cc
Expand Up @@ -645,6 +645,7 @@ TEST_F(FlutterWindowsEngineTest, TestExit) {
MockFlutterWindowsView view(std::move(window_binding_handler));
view.SetEngine(builder.Build());
FlutterWindowsEngine* engine = view.GetEngine();
engine->OnServiceBindingsRegistered();
yaakovschectman marked this conversation as resolved.
Show resolved Hide resolved

EngineModifier modifier(engine);
modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
Expand Down Expand Up @@ -681,6 +682,7 @@ TEST_F(FlutterWindowsEngineTest, TestExitCancel) {
MockFlutterWindowsView view(std::move(window_binding_handler));
view.SetEngine(builder.Build());
FlutterWindowsEngine* engine = view.GetEngine();
engine->OnServiceBindingsRegistered();

EngineModifier modifier(engine);
modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
Expand Down Expand Up @@ -731,6 +733,7 @@ TEST_F(FlutterWindowsEngineTest, TestExitSecondCloseMessage) {
MockFlutterWindowsView view(std::move(window_binding_handler));
view.SetEngine(builder.Build());
FlutterWindowsEngine* engine = view.GetEngine();
engine->OnServiceBindingsRegistered();

EngineModifier modifier(engine);
modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
Expand Down Expand Up @@ -792,6 +795,7 @@ TEST_F(FlutterWindowsEngineTest, TestExitCloseMultiWindow) {
MockFlutterWindowsView view(std::move(window_binding_handler));
view.SetEngine(builder.Build());
FlutterWindowsEngine* engine = view.GetEngine();
engine->OnServiceBindingsRegistered();

EngineModifier modifier(engine);
modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; };
Expand Down
4 changes: 4 additions & 0 deletions shell/platform/windows/platform_handler.cc
Expand Up @@ -23,6 +23,7 @@ static constexpr char kHasStringsClipboardMethod[] = "Clipboard.hasStrings";
static constexpr char kSetClipboardDataMethod[] = "Clipboard.setData";
static constexpr char kExitApplicationMethod[] = "System.exitApplication";
static constexpr char kRequestAppExitMethod[] = "System.requestAppExit";
static constexpr char kRegisterBindingMethod[] = "System.registerBinding";
static constexpr char kPlaySoundMethod[] = "SystemSound.play";

static constexpr char kExitCodeKey[] = "exitCode";
Expand Down Expand Up @@ -495,6 +496,9 @@ void PlatformHandler::HandleMethodCall(
const rapidjson::Value& sound_type = method_call.arguments()[0];

SystemSoundPlay(sound_type.GetString(), std::move(result));
} else if (method.compare(kRegisterBindingMethod) == 0) {
engine_->OnServiceBindingsRegistered();
result->Success();
} else {
result->NotImplemented();
}
Expand Down