Closed Bug 1824886 Opened 2 years ago Closed 1 year ago

Investigate a way to use the shared, common browser stylesheets in Screenshots' overlay

Categories

(Firefox :: Screenshots, task)

task

Tracking

()

RESOLVED FIXED
117 Branch
Tracking Status
firefox117 --- fixed

People

(Reporter: sfoster, Assigned: emilio)

References

(Blocks 2 open bugs, Regressed 1 open bug)

Details

Attachments

(2 files)

Some of the Screenshots UI is in its overlay - an element cloned over to the content document's canvasFrame via document.insertAnonymousContent. This lets us draw the selection and highlight boxes while being opaque to the web content. (its the same technique used by devtools' highlighters) But it also means any CSS selectors to style that UI must be prefixed with :-moz-native-anonymous to match those elements (and to avoid our CSS bleeding into the content document.)

This in turn means we can't simply load the baseline, common stylesheets to give consistent style to the buttons and UI elements in the overlay. So we currently have to copy/paste the necessary rules over, manually inserting the prefix for every rule. There must be a better way.

My understanding is that its not possible to create a shadow root in the anonymous document - which would otherwise give us an easy, no-maintenance way to load in the shared CSS and have it be correctly scoped for the overlay UI.

We could of course do some post-processing to programatically adjust the stylesheet and insert the selector prefix. But as we don't already have this tooling in place for other browser components (about:newtab excepted) this seems a heavy-handed solution.

Any bright ideas :emilio?

Flags: needinfo?(emilio)

So the reason you can't use shadow dom is rather arbitrary, and is because this cloneNode call doesn't clone it. We could do that, but also maybe there's not so much of a reason this API needs to be so restrictive...

The API doesn't expose nodes on purpose, but given it is trusted code maybe we can rejigger it a bit.

I think reworking this API so that all nodes are in a shadow tree of the anonymous node makes sense. Then you can just drop stylesheets there as needed...

Flags: needinfo?(emilio)

(In reply to Emilio Cobos Álvarez (:emilio) from comment #2)

So the reason you can't use shadow dom is rather arbitrary, and is because this cloneNode call doesn't clone it. We could do that, but also maybe there's not so much of a reason this API needs to be so restrictive...

I don't want to 2nd guess a historical decision here, that was presumably made for lots of good reasons. Maybe this was more necessary with XUL addons and the landscape has changed. Or not, I'm not in position to say.

I think reworking this API so that all nodes are in a shadow tree of the anonymous node makes sense. Then you can just drop stylesheets there as needed...

By "this API" you mean Document::InsertAnonymousContent? Or that Screenshots could get to the same goal with a different technique? I know devtools makes heavy use of the anonymous content. I don't know who else might have a stake in how it works today.

The historical decision was made so that chrome JS couldn't mess with the anonymous trees directly, because we rely on a node "remaining" anonymous... But in a world of shadow DOM we could make the actual anonymous node just the shadow host, and give chrome JS the ShadowRoot to play with.

There's the issue that they could call .host and move the host around, but I think the risk is fairly less than if we just exposed the node directly... WDYT Olli?

Flags: needinfo?(smaug)

Giving a shadow root to the chrome JS sounds reasonable. I wonder if we could even add some MOZ_ASSERTs to ensure JS doesn't access the .host. Though, at least we should have already checks that NAC nodes aren't moved to be outside NAC.

Flags: needinfo?(smaug)
Flags: needinfo?(emilio)

WIP:

  • DevTools highlighters work.

  • Need to debug why accessiblecaret doesn't get the right height,
    probably something silly that I typoed.

  • Need to rewrite the screenshots overlay.

  • Need to rewrite the fancier find highlighter if we care about it (I
    suspect we don't).

Does something like comment 6 look appealing? If so I can finish it up, I just ran out of time r/n.

Flags: needinfo?(sfoster)

That looks really promising to me. It would definitely help eliminate a lot of the special cases, exceptions and maintenance headaches if we could reuse the same patterns and actual code we do elsewhere. :jdescottes, what do you think?

Flags: needinfo?(sfoster) → needinfo?(jdescottes)

In bug 1820015 I'm in the process of figuring out how to make the overlay UI keyboard navigable, so you can tab / F6 to that stuff, the underlying content document and our toolbar and panel. I don't have a solution there yet, I just want to make sure this shadowRoot / anonymous content change doesnt somehow make that more difficult.

Depends on: 1825390

(In reply to Sam Foster [:sfoster] (he/him) from comment #9)

In bug 1820015 I'm in the process of figuring out how to make the overlay UI keyboard navigable, so you can tab / F6 to that stuff, the underlying content document and our toolbar and panel. I don't have a solution there yet, I just want to make sure this shadowRoot / anonymous content change doesnt somehow make that more difficult.

It shouldn't.

Assignee: nobody → emilio
Attachment #9325802 - Attachment description: WIP: Bug 1824886 - Rewrite AnonymousContent to use a shadow tree. r=smaug → Bug 1824886 - Rewrite AnonymousContent to use a shadow tree. r=smaug!,TYLin!,sfoster!,#devtools-reviewers!
Status: NEW → ASSIGNED
Flags: needinfo?(emilio)

Nicolas, I see some failures on style inspector tests which are because of the new accessiblecaret.css files, which now show in the inspector because those are there by default.

This is a pre-existing issue, e.g., if I go to data:text/html,<video controls>, then I see videocontrols.css there even if by default I can't inspect the tree it applies to.

Do you know what's the best way to deal with them? I can special-case them / skip them in the tests but it feels rather weird they'd be there without showing the closed shadow trees etc (without the showAllAnonymousContent pref).

Flags: needinfo?(nchevobbe)

(In reply to Emilio Cobos Álvarez (:emilio) from comment #11)

Nicolas, I see some failures on style inspector tests which are because of the new accessiblecaret.css files, which now show in the inspector because those are there by default.

This is a pre-existing issue, e.g., if I go to data:text/html,<video controls>, then I see videocontrols.css there even if by default I can't inspect the tree it applies to.

Do you know what's the best way to deal with them? I can special-case them / skip them in the tests but it feels rather weird they'd be there without showing the closed shadow trees etc (without the showAllAnonymousContent pref).

Thanks for the ping Emilio, I can indeed see that we have the issue with <video> (which is not even consistent on reload)
One thing that comes to mind is that we have a setting in DevTools: Show Browser Styles, which is off by default
When you turn it on, it will show the user agent stylesheet (and the rules in the rule view)
Given how we phrase the setting, it wouldn't be shocking if we could show them based on this pref value (even if the pref name, devtools.inspector.showUserAgentStyles, could be changed)
In the styleEditor, we even call those system stylesheet, so we can prevent people from editing them
The system flag is added from https://searchfox.org/mozilla-central/rev/0907529ff72c456ddb47839f5f7ba16291f28dce/devtools/shared/inspector/css-logic.js#127-136 . It doesn't seem that the sheet we should consider have any other properties that could let us discriminate those (besides their chrome:// scheme, but this doesn't look like a good fit) ?

If we can't find/add anything to the sheet themselves, then we could still classify them as "system" on the devtools server (by having a simple array with the sheet URLs), but that feels quite brittle.

Flags: needinfo?(nchevobbe)

The videocontrols.css stylesheet shows up consistently for me.

It seems to be returned by InspectorUtils::GetAllStyleSheets when called for the document of the inspected page. And as Nicolas said, there's nothing which clearly tells us that this stylesheet should be avoided (it's not even flagged as a system stylesheet AFAICT?).

It could make sense to hide chrome:// and resource:// unless showUserAgentStyles or showAllAnonymousContent is enabled? But we'd still need to list them when opening the toolbox for chrome privileged pages (eg about: pages).

Note that we also have an exclusion "list" (only one sheet for now in it) at https://searchfox.org/mozilla-central/rev/e941c8a6d49b4f62f361446de7a80214fb899186/devtools/server/actors/utils/stylesheets-manager.js#822-831

If there are not too many failures for now, I guess updating the tests is fine, and we can address that in a follow up.

Then either we can make GetAllStyleSheets exclude those stylesheets when called for regular web content document (with a flag to override this in case the prefs listed above are enabled), or we need to add some filtering in devtools.

(In reply to Sam Foster [:sfoster] (he/him) from comment #8)

That looks really promising to me. It would definitely help eliminate a lot of the special cases, exceptions and maintenance headaches if we could reuse the same patterns and actual code we do elsewhere. :jdescottes, what do you think?

Simplifying the solution around highlighters sounds great and Alex and Emilio already seem to be on it. So sounds good on my end as well!

Flags: needinfo?(jdescottes)
Depends on: 1825825
Blocks: 1826538
Blocks: 1827977
Blocks: 1820015

:emilio - is this blocked or still feasible but needing time/priority to finish up? I'm building on this patch in bug 1820015. I'm still investigating there so I don't know yet if I'm blocked on this landing or not, but it would help to know the status here (and a rebase on current central would be a big help)

Flags: needinfo?(emilio)
Attachment #9325802 - Attachment description: Bug 1824886 - Rewrite AnonymousContent to use a shadow tree. r=smaug!,TYLin!,sfoster!,#devtools-reviewers! → WIP: Bug 1824886 - Rewrite AnonymousContent to use a shadow tree. r=smaug!,TYLin!,sfoster!,#devtools-reviewers!
Attachment #9325802 - Attachment description: WIP: Bug 1824886 - Rewrite AnonymousContent to use a shadow tree. r=smaug!,TYLin!,sfoster!,#devtools-reviewers! → Bug 1824886 - Rewrite AnonymousContent to use a shadow tree. r=smaug!,TYLin!,sfoster!,#devtools-reviewers!

(In reply to Sam Foster [:sfoster] (he/him) from comment #14)

:emilio - is this blocked or still feasible but needing time/priority to finish up?

Definitely feasible... I just didn't find the time to debug / address Nicolas' concerns, but that's done now. Also rebased. Try is busted atm tho...

Flags: needinfo?(emilio)

Hey emilio, sorry to bother you about this. This has been sitting for a while and I was wondering if you have time to wrap this up? It appears that this just needs to rebased but I could be wrong. Thanks!

Flags: needinfo?(emilio)

Yeah, sorry for the lag, I had a couple other failures to debug, but I think they are all sorted out now. Let me try to get this landed.

Flags: needinfo?(emilio)
Pushed by ealvarez@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/1c835137f532 Rewrite AnonymousContent to use a shadow tree. r=smaug,TYLin,sfoster,devtools-reviewers,nchevobbe
Backout by csabou@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/47cfdb7396a2 Backed out 2 changesets for causing failures on browser_all_files_referenced.js. CLOSED TREE
Flags: needinfo?(emilio)
Pushed by ealvarez@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/4c734e252630 Rewrite AnonymousContent to use a shadow tree. r=smaug,TYLin,sfoster,devtools-reviewers,nchevobbe

Backed out for causing multiple failures.


  • Push with failures - mochitests plain
  • Failure Log
  • Failure line: PROCESS-CRASH | MOZ_ASSERT(mInitialZoomConstraints->mPresShellID == aPresShellId) [@ libxul.so + 0x00000000048f60f4] | toolkit/components/extensions/test/mochitest/mochitest.ini:toolkit/components/extensions/test/mochitest/mochitest-common.ini

  • Push with failures - wpt
  • Failure Log
  • Failure line: TEST-UNEXPECTED-FAIL | /html/browsers/browsing-the-web/navigating-across-documents/empty-iframe-load-event.html | Check execution order from nested timeout - assert_equals: Expected nested setTimeout to run second expected true but got false
Flags: needinfo?(emilio)
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 117 Branch

This is still backed out, latest changeset backed out is actually https://hg.mozilla.org/integration/autoland/rev/4c734e252630

Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Target Milestone: 117 Branch → ---

This fixes the windows WPT failures in comment 23. The issue is that the
new accessiblecaret.css makes us delay the load event by a tick even in
about:blank.

Depends on D173998

Comment 26 also seems to fix the android assert.

Flags: needinfo?(emilio)
Pushed by ealvarez@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/f970de7b9443 Rewrite AnonymousContent to use a shadow tree. r=smaug,TYLin,sfoster,devtools-reviewers,nchevobbe https://hg.mozilla.org/integration/autoland/rev/60d4eb46c8b4 Don't make privileged sync loads block the document load event. r=TYLin,masayuki
Pushed by emilio@crisal.io: https://hg.mozilla.org/integration/autoland/rev/29f82336c736 Fix test_preferences, which relied on the load event firing one tick late.
Pushed by emilio@crisal.io: https://hg.mozilla.org/integration/autoland/rev/ecb86cb403ab Try to fix test_tree_scroll.xhtml on OSX.
Blocks: 1842473
Pushed by ctuns@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/76990d265adf Revert previous workaround and disable test_tree_scroll on macOS for now instead while we investigate, see bug 1842473. CLOSED TREE
Regressions: 1842500
Regressions: 1842608
Regressions: 1844274
Regressions: 1850007
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: