Page MenuHomePhabricator

Bug 1625513 - Part 1: Perform onMayChangeProcess handling within DocumentLoadListener,
ClosedPublic

Authored by nika on Mar 27 2020, 4:49 PM.

Details

Summary

When I first added this method last year, I added it in JS, handled from within
SessionStore.jsm, as that was the easiest place to do it. Now that
DocumentLoadListener exists, it makes more sense to handle this logic directly
from within that code.

Many parts of the process switch are still handled by frontend JS, such as
selecting remote types, and performing toplevel process switches.

Diff Detail

Repository
rMOZILLACENTRAL mozilla-central
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

phab-bot changed the visibility from "Custom Policy" to "Public (No Login Required)".
phab-bot changed the edit policy from "Custom Policy" to "Restricted Project (Project)".
phab-bot removed a project: secure-revision.

Looks awesome! Thanks for doing this.

dom/interfaces/base/nsIBrowser.idl
202

Would be nice to elaborate a bit more on what/why.

netwerk/base/nsIProcessSwitchRequestor.idl
37

I think we can drop this entire .idl file now.

The only users were the SessionStore code accessing DocumentLoadListener's impl, and DocumentLoadListener's impl accessing nsHttpChannel (which uses the concrete class and doesn't need an interface).

I think we still need the two COOP functions implemented on both classes, but we could de-COM-taminate them.

netwerk/ipc/DocumentLoadListener.cpp
1011

Missing a word?

1057

Existing issue, but it's weird that this lambda captures self and this, whereas all the others don't.

netwerk/ipc/DocumentLoadListener.h
206

It feels like having both 'cross' and 'switch' in this name is a bit redundant (which isn't new to this patch). I'd be ok if you wanted to drop one of them while you're at it.

toolkit/content/widgets/browser-custom-element.js
2057

Is there a way to make this extensible for non-tabbrowser-users (like the reftest harness, xpcshell-test, layout debugger etc)?

I know you have plans to modify this further in the future, so it's fine if it makes sense to wait until then before worrying about other consumers.

nika added a subscriber: droeh.

Adding @droeh as a reviewer, as I realize that my changes here might screw with their plans to use DocumentChannel for GeckoView a bit.

We should probably make sure that this doesn't create too much extra work for @droeh, (and perhaps makes their work easier!)

toolkit/content/widgets/browser-custom-element.js
2057

That's my plan, to make it possible for all clients to control this behaviour. I intend for process switching to eventually be universally available, and to allow clients to add callbacks for handling special pre-switch and post-switch actions.

This looks good to me. Thanks Nika.

browser/components/sessionstore/SessionStore.jsm
3054

I couldn't figure out how to move this to C++ yet. That's why I had two bugs to solve this part later. I'm interested in your solution.

netwerk/ipc/DocumentLoadListener.cpp
1113

I think we can do something better before this patch lands. It'll save us the time of having to debug weird doubled up / skipped identifiers. Or can this only happen on the main thread? Do we have a way of saying that this is only accessaible from the main thread and let the compiler check that? (I've seen that in SpiderMonkey code.)

netwerk/ipc/DocumentLoadListener.cpp
1011

I'm unclear on how this works. I thought that the original JS code didn't have access to browser tabs and so this would have to remain in JS. But it's in C++ with this change and on re-reading it I'm not really following.

I thought that a top level load _is_ one that's in a tab, rather than an iframe. When coudl something be top-level but not in an tab?

I also thought that the JS code that this comes from handled tabs, and couldn't be converted to JS (yet). Which is why I had two seperate bugs. But I'm misunderstanding something about that. @nika could you help me by explaining?

Thanks.

nika marked 4 inline comments as done.Mar 31 2020, 3:34 PM
nika added inline comments.
browser/components/sessionstore/SessionStore.jsm
3054

I didn't move exactly this into c++, but instead I added a method to nsIBrowser which implements the intention behind that check, and call that method instead. In the long-run, I intend to remove the need to get the tabbrowser from our embedder element entirely.

netwerk/ipc/DocumentLoadListener.cpp
1011

I thought that a top level load _is_ one that's in a tab, rather than an iframe. When coudl something be top-level but not in an tab?

There are a number of <browser>s in gecko which aren't loaded in tabs, such as devtools, webextension pop-ups, the browser sidebar, and webextension settings. These browsers are just <browser> elements, and don't have a corresponding tab.

If the call to getTabbrowser() from the old code failed, that meant that the browser which was considering doing a process switch was not loaded within a tab.

I also thought that the JS code that this comes from handled tabs, and couldn't be converted to JS (yet). Which is why I had two seperate bugs. But I'm misunderstanding something about that. @nika could you help me by explaining?

The bits which couldn't be switched from JS to C++ yet are still in JS. I added a couple of extra methods to the nsIBrowser interface, which is implemented in JS, which will perform the relevant checks for us.

GetCanPerformProcessSwitch is the equivalent of checking getTabbrowser() for being non-null, and PerformProcessSwitch is equivalent to SessionStore._doTabProcessSwitch.

I also use the nsIBrowser interface for the getRemoteTypeForPrincipal method, as that is still implemented in JS, and needs to be refactored to be accessible without a nsIBrowser in the future.

1113

This can only happen on the main thread. I can add a MOZ_ASSERT(NS_IsMainThread()), but DocumentLoadListener's methods, in general, are tied to the main thread.

This solution is mainly not-great because I'm just declaring the static inline in this method, and I think it would be nicer if I factored this logic out somewhere where it's easier to follow.

Thanks for flagging me, it doesn't look like the changes should impact my patch for 1619798.

This revision is now accepted and ready to land.Mar 31 2020, 6:58 PM
nika retitled this revision from Bug 1625513 - Perform onMayChangeProcess handling within DocumentLoadListener, to Bug 1625513 - Part 1: Perform onMayChangeProcess handling within DocumentLoadListener,.
nika marked 7 inline comments as done.

Thanks for answering that Nika, that's helpful.

This revision is now accepted and ready to land.Apr 6 2020, 5:21 PM
This revision is now accepted and ready to land.Apr 8 2020, 10:15 PM
This revision now requires review to proceed.Apr 17 2020, 7:12 PM
This revision is now accepted and ready to land.Apr 20 2020, 2:16 PM
This revision is now accepted and ready to land.Apr 20 2020, 7:54 PM
This revision is now accepted and ready to land.Apr 21 2020, 9:20 PM