Skip to content

Inherit webPreferences in windows opened via sandbox or nativeWindowOpen - #9972

Merged
kevinsawicki merged 13 commits into
masterfrom
merge-web-preferences
Jul 17, 2017
Merged

kevinsawicki merged 13 commits into
masterfrom
merge-web-preferences

Conversation

@kevinsawicki

@kevinsawicki kevinsawicki commented Jul 10, 2017 •

Copy link
Copy Markdown
Contributor

Previously both nativeWindowOpen and sandbox options did not support overriding webPreferences via new-window events. The preferences from the opener window were used instead when launching render processes for the new windows.

This pull request changes this behavior to set configured webPreferences when creating new windows with an existing webContents. These preferences are then used when the render process is launched for the webContents (if applicable).

  • Reset webContents web preferences with the configured options when creating a new window with an existing contents.
  • Track pending render process launches via RenderFrameHost instead of RenderProcessHost so that lookup via WebContents can be done later on.
  • Register sandbox as an inherited option in guest-window-manager.js so windows opened from sandboxed windows have it enabled by default.
  • Register nativeWindowOpen as an inherited option in guest-window-manager.js so windows opened from native window open windows have it enabled by default.
  • Add specs for inherited options behavior
  • Add specs new-window option overriding for sandbox/nativeWindowOpen windows.
  • Add spec for reload bug from turning on nativeWindowOpen leads to nodeIntegration-like behavior #9928

Refs #9961
Closes #9928

auto pending_process = (*new_instance)->GetProcess();
pending_processes_[pending_process->GetID()] = current_process->GetID();
pending_processes_[pending_process->GetID()] =
content::WebContents::FromRenderFrameHost(render_frame_host);;

@kevinsawicki kevinsawicki Jul 11, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@zcbenz I'm a little nervous about this change, I'm not sure if there are times when we would have a pending render process host but not a render frame host. Through my testing, it seemed like the render frame host for the proper web contents was passed in each time so it seemed okay to track the pending process to the originating contents.

Do you remember why initially this mapped process host to process host instead of using the frame host to track the web contents doing the navigation?

@zcbenz zcbenz Jul 17, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't remember the details, Chromium frequently changes how renderer process restarts, so some assumptions were no longer valid. If this change passes the tests, I think we can confidently do it.

@kevinsawicki
kevinsawicki requested a review from tarruda July 11, 2017 00:16
@kevinsawicki

Copy link
Copy Markdown
Contributor Author

@tarruda Wanted to get your feedback on this since this does change the sandbox behavior so preferences can be configured per-window via the new-window event instead of using the preferences from the initial windows.

Seemed nice to have that flexibility given the number of webPreferences that you may want to configure on a per-window basis.

@kevinsawicki
kevinsawicki requested a review from zcbenz July 11, 2017 00:45
}
if (!options.webPreferences.sandbox) {
// These events should only be handled when the guest window is opened by a
// non-sandboxed renderer for two reasons:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@tarruda I removed this because I was seeing a spec failure once options.webPreferences.sandbox was inherited by default from the parent window (line 16).

It looks like it was going down this path previously when a sandboxed window was opening a new window so I wasn't sure if this code was still needed.

Is this check only needed for opening sandboxed windows opened from non-sandbox windows?

On master, if you open a sandbox window then do window.open() the listeners did appear to be registered since the options have no web preferences by default so options.webPreferences.sandbox is false.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this check only needed for opening sandboxed windows opened from non-sandbox windows?

I think it was related to opening sandboxed windows, regardless of the parent. Could also apply to nativeWindowOpen.

On master, if you open a sandbox window then do window.open() the listeners did appear to be registered since the options have no web preferences by default so options.webPreferences.sandbox is false.

Since this code was first added, there were some changes to allow sandbox reuse code from non-sandbox, so it is possible that this is obsolete.

If I remember correctly, you could reproduce the crash by closing a window created by window.open and waiting a bit for the garbage collector. If you can't reproduce this now, I guess it should be fine to remove it.

@tarruda tarruda left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

}
if (!options.webPreferences.sandbox) {
// These events should only be handled when the guest window is opened by a
// non-sandboxed renderer for two reasons:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this check only needed for opening sandboxed windows opened from non-sandbox windows?

I think it was related to opening sandboxed windows, regardless of the parent. Could also apply to nativeWindowOpen.

On master, if you open a sandbox window then do window.open() the listeners did appear to be registered since the options have no web preferences by default so options.webPreferences.sandbox is false.

Since this code was first added, there were some changes to allow sandbox reuse code from non-sandbox, so it is possible that this is obsolete.

If I remember correctly, you could reproduce the crash by closing a window created by window.open and waiting a bit for the garbage collector. If you can't reproduce this now, I guess it should be fine to remove it.

@tarruda

tarruda commented Jul 11, 2017

Copy link
Copy Markdown
Contributor

@tarruda Wanted to get your feedback on this since this does change the sandbox behavior so preferences can be configured per-window via the new-window event instead of using the preferences from the initial windows.

Seemed nice to have that flexibility given the number of webPreferences that you may want to configure on a per-window basis.

Agreed, this is a nice improvement 👍

@zcbenz zcbenz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

@kevinsawicki kevinsawicki changed the title [WIP] Inherit webPreferences in windows opened via sandbox or nativeWindowOpen Inherit webPreferences in windows opened via sandbox or nativeWindowOpen Jul 17, 2017
@kevinsawicki
kevinsawicki force-pushed the merge-web-preferences branch from 238bec1 to a7c5de1 Compare July 17, 2017 16:50
@kevinsawicki
kevinsawicki force-pushed the merge-web-preferences branch from a7c5de1 to fc53ac3 Compare July 17, 2017 18:55
@kevinsawicki
kevinsawicki merged commit 65fe703 into master Jul 17, 2017
@kevinsawicki
kevinsawicki deleted the merge-web-preferences branch July 17, 2017 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants