Stop touching `content` in browser/base/content/tab-content.js
Categories
(Firefox :: General, enhancement, P2)
Tracking
()
Tracking | Status | |
---|---|---|
firefox90 | --- | fixed |
People
(Reporter: kmag, Assigned: nika)
References
(Blocks 1 open bug)
Details
(Whiteboard: [fxperf:p3])
Attachments
(1 file)
(deleted),
text/x-phabricator-request
|
Details |
Comment 1•6 years ago
|
||
Comment 2•6 years ago
|
||
Reporter | ||
Comment 3•6 years ago
|
||
Comment 4•6 years ago
|
||
Comment 5•6 years ago
|
||
Comment 6•6 years ago
|
||
Updated•6 years ago
|
Comment 7•6 years ago
|
||
Comment 8•6 years ago
|
||
Updated•6 years ago
|
Updated•6 years ago
|
Updated•6 years ago
|
Comment 9•6 years ago
|
||
Comment 10•6 years ago
|
||
Comment 11•6 years ago
|
||
Comment 12•6 years ago
|
||
Comment 13•6 years ago
|
||
Comment 14•6 years ago
|
||
Reporter | ||
Comment 15•6 years ago
|
||
Updated•6 years ago
|
Comment 16•6 years ago
|
||
Reporter | ||
Comment 17•6 years ago
|
||
Comment 18•6 years ago
|
||
Comment 19•6 years ago
|
||
Comment 20•4 years ago
|
||
I'll see if we can drop this altogether now that we're moving to fission-compatible actors and a lot of things have changed in the meantime...
Comment 21•4 years ago
|
||
Comment 22•4 years ago
|
||
I tried this for a bit, but the first hurdle is that we now have an assert in JSActorManager that checks IsSafeToRunScript
. We hit this in some tests, cf. https://treeherder.mozilla.org/#/jobs?repo=try&selectedTaskRun=USYZMgdASTaaDEQ-m8xGNg.0&revision=779f0cf76f6a0ab9c028984fa0df11301e285053
The reason appears to be that we get an onLocationChange
notification for the load of about:blank, and the tabbrowser code at https://searchfox.org/mozilla-central/rev/d25eb00ab4e90cc0130cd18f303a04cc2a2f8409/browser/base/content/browser.js#5411 attempts to create an actor at https://searchfox.org/mozilla-central/rev/d25eb00ab4e90cc0130cd18f303a04cc2a2f8409/browser/actors/AboutReaderParent.jsm#169-171 . This fails with the assert.
What I don't understand is why it is not safe to run script - we're already running script! The C++ stack looks like this on my local opt build:
* frame #0: 0x0000000104b896b9 XUL`mozilla::dom::JSActorManager::GetActor(this=0x0000000125984400, aCx=0x000000011b32f000, aName=0x00007ffeefbfa818, aRv=<unavailable>) at JSActorManager.cpp:18:3 [opt]
frame #1: 0x0000000103d25b7b XUL`mozilla::dom::WindowGlobalParent_Binding::getActor(cx=0x000000011b32f000, obj=<unavailable>, void_self=0x0000000125984400, args=0x00007ffeefbfa900) at WindowGlobalActorsBinding.cpp:2164:86 [opt]
frame #2: 0x0000000104028135 XUL`bool mozilla::dom::binding_detail::GenericMethod<mozilla::dom::binding_detail::NormalThisPolicy, mozilla::dom::binding_detail::ThrowExceptions>(cx=0x000000011b32f000, argc=1, vp=<unavailable>) at BindingUtils.cpp:3229:13 [opt]
frame #3: 0x00000001063671be XUL`js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) [inlined] CallJSNative(cx=0x000000011b32f000, native=(XUL`bool mozilla::dom::binding_detail::GenericMethod<mozilla::dom::binding_detail::NormalThisPolicy, mozilla::dom::binding_detail::ThrowExceptions>(JSContext*, unsigned int, JS::Value*) at BindingUtils.cpp:3203), reason=<unavailable>, args=0x00007ffeefbfaac8)(JSContext*, unsigned int, JS::Value*), js::CallReason, JS::CallArgs const&) at Interpreter.cpp:509:13 [opt]
frame #4: 0x0000000106367171 XUL`js::InternalCallOrConstruct(cx=0x000000011b32f000, args=0x00007ffeefbfaac8, construct=<unavailable>, reason=<unavailable>) at Interpreter.cpp:601 [opt]
frame #5: 0x00000001063607e9 XUL`Interpret(JSContext*, js::RunState&) [inlined] js::CallFromStack(cx=0x000000011b32f000, args=<unavailable>) at Interpreter.cpp:670:10 [opt]
frame #6: 0x00000001063607df XUL`Interpret(cx=0x000000011b32f000, state=<unavailable>) at Interpreter.cpp:3338 [opt]
plus some more JS/jit frames, so not particularly illuminating. :-(
Nika or Kris, can you shed some light on this?
Assignee | ||
Comment 23•4 years ago
|
||
I chatted with you a bit about this on Matrix. This isn't super high priority, and fully preventing creating the initial about:blank document would be very difficult, so I'm inclined to put this on the back burner for now.
Reporter | ||
Comment 24•4 years ago
|
||
(In reply to :Gijs (he/him) from comment #22)
What I don't understand is why it is not safe to run script - we're already running script! The C++ stack looks like this on my local opt build:
Unfortunately, it's still possible to run scripts at times when it isn't safe to run scripts, and in the past we've been fairly lenient about it for chrome scripts, despite how footgunny it is. It's fairly easy for those scripts to trigger code that really isn't safe to run when we have a script blocker. This probably isn't one of those cases, but those assertions are mainly in place to prevent native code from accidentally instantiating an actor when it isn't safe to run scripts.
We're winding up doing that here:
#45 0x000015554f0eb7fe in nsDocShell::CreateAboutBlankContentViewer(nsIPrincipal*, nsIPrincipal*, nsIContentSecurityPolicy*, nsIURI*, mozilla::Maybe<nsILoadInfo::CrossOriginEmbedderPolicy> const&, bool, bool, mozilla::dom::WindowGlobalChild*) (this=this@entry=0x155554d2ac00, aPrincipal=aPrincipal@entry=
0x0, aPartitionedPrincipal=aPartitionedPrincipal@entry=0x0, aCSP=<optimized out>, aBaseURI=<optimized out>, aCOEP=..., aTryToSaveOldPresentation=<optimized out>, aCheckPermitUnload=<optimized out>, aActor=0x0) at /home/kris/code/mozilla-central/docshell/base/nsDocShell.cpp:6758
#46 0x000015554f0d6d58 in nsDocShell::EnsureContentViewer() (this=0x155554d2ac00) at /home/kris/code/mozilla-central/docshell/base/nsDocShell.cpp:6575
#47 0x000015554f0e0148 in non-virtual thunk to nsDocShell::GetDocument() () at /home/kris/code/mozilla-central/docshell/base/nsDocShell.cpp:3179
#48 0x000015554e11c90c in mozilla::PresShell::GetPrimaryContentDocument() (this=<optimized out>) at /home/kris/code/mozilla-central/layout/base/PresShell.cpp:8005
#49 0x000015554e11be24 in mozilla::PresShell::Paint(nsView*, nsRegion const&, mozilla::PaintFlags) (this=0x155540907000, aViewToPaint=0x155540ed5b80, aDirtyRegion=..., aFlags=mozilla::PaintFlags::PaintLayers) at /home/kris/code/mozilla-central/layout/base/PresShell.cpp:6181
#50 0x000015554dedb73b in nsViewManager::ProcessPendingUpdatesPaint(nsIWidget*) (this=<optimized out>, this@entry=0x155540fa74c0, aWidget=aWidget@entry=0x15554164f400) at /home/kris/code/mozilla-central/view/nsViewManager.cpp:460
#51 0x000015554dedb3ea in nsViewManager::ProcessPendingUpdatesForView(nsView*, bool) (this=this@entry=0x155540fa74c0, aView=<optimized out>, aFlushDirtyRegion=false) at /home/kris/code/mozilla-central/view/nsViewManager.cpp:395
#52 0x000015554dedc76d in nsViewManager::ProcessPendingUpdates() (this=0x155540fa74c0) at /home/kris/code/mozilla-central/view/nsViewManager.cpp:1018
#53 0x000015554e0ed635 in nsRefreshDriver::Tick(mozilla::layers::BaseTransactionId<mozilla::VsyncIdType>, mozilla::TimeStamp) (this=0x155540e40800, aId=aId@entry=..., aNowTime=...) at /home/kris/code/mozilla-central/layout/base/nsRefreshDriver.cpp:2369
#54 0x000015554e0f23d0 in mozilla::RefreshDriverTimer::TickDriver(nsRefreshDriver*, mozilla::layers::BaseTransactionId<mozilla::VsyncIdType>, mozilla::TimeStamp) (driver=0x0, aId=..., now=...) at /home/kris/code/mozilla-central/layout/base/nsRefreshDriver.cpp:374
#55 mozilla::RefreshDriverTimer::TickRefreshDrivers(mozilla::layers::BaseTransactionId<mozilla::VsyncIdType>, mozilla::TimeStamp, nsTArray<RefPtr<nsRefreshDriver> >&) (this=this@entry=0x155540fee940, aId=aId@entry=..., aNow=aNow@entry=..., aDrivers=nsTArray<RefPtr<nsRefreshDriver> > & = {...})
at /home/kris/code/mozilla-central/layout/base/nsRefreshDriver.cpp:353
#56 0x000015554e0f21fd in mozilla::RefreshDriverTimer::Tick(mozilla::layers::BaseTransactionId<mozilla::VsyncIdType>, mozilla::TimeStamp) (this=this@entry=0x155540fee940, aId=..., now=now@entry=...) at /home/kris/code/mozilla-central/layout/base/nsRefreshDriver.cpp:368
#57 0x000015554e0f1d6a in mozilla::VsyncRefreshDriverTimer::RunRefreshDrivers(mozilla::layers::BaseTransactionId<mozilla::VsyncIdType>, mozilla::TimeStamp) (this=0x155540fee940, aId=..., aTimeStamp=...) at /home/kris/code/mozilla-central/layout/base/nsRefreshDriver.cpp:829
#58 mozilla::VsyncRefreshDriverTimer::RefreshDriverVsyncObserver::TickRefreshDriver(mozilla::layers::BaseTransactionId<mozilla::VsyncIdType>, mozilla::TimeStamp) (this=this@entry=0x155540dbe160, aId=..., aId@entry=..., aVsyncTimestamp=aVsyncTimestamp@entry=...) at /home/kris/code/mozilla-central/layout/base/nsRefreshDriver.cpp:747
#59 0x000015554e0f1ab9 in mozilla::VsyncRefreshDriverTimer::RefreshDriverVsyncObserver::NotifyParentProcessVsync() (this=0x155540dbe160) at /home/kris/code/mozilla-central/layout/base/nsRefreshDriver.cpp:649
#60 0x000015554e0f10b0 in mozilla::VsyncRefreshDriverTimer::RefreshDriverVsyncObserver::ParentProcessVsyncNotifier::Run() (this=0x155542ba46d0) at /home/kris/code/mozilla-central/layout/base/nsRefreshDriver.cpp:539
We definitely don't want to be creating new content viewers in the middle of layout/painting. There are lots of ways that could trigger unsafe code... Which means I think we want that code to do something like GetExtantDocument
instead.
Assignee | ||
Comment 25•4 years ago
|
||
We nowadays always eagerly create the initial about:blank document in the BrowserChild
case in order to eagerly attach it to the provided WindowGlobalChild
which was passed when creating the PBrowser
actor. Because the vast majority of toplevel content we end up creating is remote these days, I'm skeptical that this still has a significant performance impact, though it is certainly gross.
I just filed bug 1708245 to track getting rid of tab-content.js
entirely, as it's getting fairly small at this point. Once the only remaining action which that frame script performs becomes initializing the initial about:blank document, I think we may want to move the eager-about:blank initialization for toplevel content BrowsingContexts logic into nsFrameLoader
or similar, rather than keeping it in frontend JS as a hackaround, as that will let us avoid loading the framescript completely.
Assignee | ||
Comment 26•4 years ago
|
||
Updated•4 years ago
|
Comment 27•4 years ago
|
||
bugherder |
Description
•