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

fix: properly determine if WebContents is offscreen in WebContentsDelegate #16329

Merged
merged 1 commit into from Jan 9, 2019

Conversation

BinaryMuse
Copy link
Contributor

@BinaryMuse BinaryMuse commented Jan 8, 2019

Description of Change

WebContentsDelegate::InitWithWebContents previously used the following code to set offscreen_:

  // Determien whether the WebContents is offscreen.
  auto* web_preferences = WebContentsPreferences::From(web_contents);
  offscreen_ =
      !web_preferences || web_preferences->IsEnabled(options::kOffscreen);

However, options::kOffscreen defaults to false when its not set, so when web_preferences was null, offscreen_ would be set to true. The most immediate result of this is that RunModalDialog would have settings.force_detached set in the following code, causing the dialog to be shown as a regular modal instead of a sheet:

// Run modal dialog with parent window and return user's choice.
int RunModalDialog(NSSavePanel* dialog, const DialogSettings& settings) {
  __block int chosen = NSFileHandlingPanelCancelButton;
  if (!settings.parent_window || !settings.parent_window->GetNativeWindow() ||
      settings.force_detached) {
    chosen = [dialog runModal];
  } else {
    NSWindow* window = settings.parent_window->GetNativeWindow();

    [dialog beginSheetModalForWindow:window
                   completionHandler:^(NSInteger c) {
                     chosen = c;
                     [NSApp stopModal];
                   }];
    [NSApp runModalForWindow:window];
  }

  return chosen;
}

This change defaults offscreen_ to false when web_preferences is null.

/cc @VishwasShashidhar

Fixes #16300

Checklist

Release Notes

Notes: Changed the file dialog presented by inputs with the type file to use sheets on macOS instead of detached modals.

@BinaryMuse BinaryMuse requested a review from a team January 8, 2019 20:54
@BinaryMuse
Copy link
Contributor Author

Interestingly, I'm seeing web_preferences being null even though I set webPreferences when I created the BrowserWindow. This seems unexpected to me, but I may be missing something.

Copy link
Member

@codebytere codebytere left a comment

Choose a reason for hiding this comment

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

unsure if there's a way to test for this, but it'd be awesome if there way 🤔

@BinaryMuse BinaryMuse merged commit 744f737 into master Jan 9, 2019
@release-clerk
Copy link

release-clerk bot commented Jan 9, 2019

Release Notes Persisted

Changed the file dialog presented by inputs with the type file to use sheets on macOS instead of detached modals.

@trop
Copy link
Contributor

trop bot commented Jan 9, 2019

I have automatically backported this PR to "3-1-x", please check out #16341

@trop
Copy link
Contributor

trop bot commented Jan 9, 2019

I have automatically backported this PR to "4-0-x", please check out #16340

@VishwasShashidhar
Copy link

Confirmed that it is fixed on master and we see a sheet. Thanks @BinaryMuse @codebytere

akisctx pushed a commit to akisctx/electron that referenced this pull request Jan 22, 2019
@sofianguy sofianguy added this to Fixed in 3.1.1 in 3.1.x Jan 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
3.1.x
Fixed in 3.1.1
Development

Successfully merging this pull request may close these issues.

None yet

3 participants