diff --git a/components/remote_cocoa/app_shim/select_file_dialog_bridge.mm b/components/remote_cocoa/app_shim/select_file_dialog_bridge.mm index 6531f80a40c67..10171bf3d41c6 100644 --- a/components/remote_cocoa/app_shim/select_file_dialog_bridge.mm +++ b/components/remote_cocoa/app_shim/select_file_dialog_bridge.mm @@ -427,9 +427,14 @@ void SelectFileDialogBridge::Show( open_dialog.canChooseDirectories = NO; } - delegate_ = [[SelectFileDialogDelegate alloc] init]; - open_dialog.delegate = delegate_; } + + // Install the delegate on |panel_| for both the open *and* save cases so + // that -panel:validateURL:error: vetoes auto-repeated key events + // (https://crbug.com/40085079) on NSSavePanel as well as NSOpenPanel. + delegate_ = [[SelectFileDialogDelegate alloc] init]; + panel_.delegate = delegate_; + if (default_dir) { panel_.directoryURL = [NSURL fileURLWithPath:default_dir]; }