Open Bug 1640533 Opened 5 years ago Updated 4 years ago

Audit whether MOZ_CAN_RUN_SCRIPT annotations for nsPrintJob functions are correct/necessary or not

Categories

(Core :: Printing: Setup, task)

task

Tracking

()

People

(Reporter: hiro, Unassigned)

References

Details

(Whiteboard: [print2020])

For example, nsPrintJob::SetupToPrintContent has MOZ_CAN_RUN_SCRIPT, indeed it flushes pending styles/layout whatever, BUT in the function we flush the static-cloned documents which means there is no script in the documents unless I am misunderstanding what CreateStaticClone does.

masayuki?

Flags: needinfo?(masayuki)

Some relevant questions;

  • Window.print() should explicitly flush the document? (It seems not to me IIUC the spec), but..
  • nsGlobalWindowInner::Print should be annotated as MOZ_CAN_RUN_SCRIPT since it fires beforeprint/afterprint events?

If the MOZ_CAN_RUN_SCRIPT is really safe, it may be fine to change it to MOZ_CAN_RUN_SCRIPT_BOUNDARY with comment explaining intentionally changed to it.

Flags: needinfo?(masayuki)

(but I don't know whether it's truly safe or not.)

Thank you, masayuki. I am mostly 100% sure functions in nsPrintJob shouldn't run script at all because they are used for the static-cloned documents. One thing I am wondering is whether Document::CreateStaticClone should flush pending styles or not (currently it doesn't), and I suppose it shouldn't since users want to see results what the user is seeing at that moment.

Hmm nsPrintJob::TurnScriptingOn turns on/off scripts in the cloned documents. It's confusing to me. Do we really want to run scripts in the cloned documents?

Olli, at the time you introduced nsScriptSuppressor machinery in bug 424377 we hadn't cloned documents for printing, but we've cloned documents for printing since you fixed bug 487667, now we don't need the script turn on/off machinery at all? Am I understanding correctly?

Flags: needinfo?(bugs)

Since it has been so long after those bugs, lots of the underlying code has changed possibly significantly, so one will need to check what all
https://searchfox.org/mozilla-central/rev/501eb4718d73870892d28f31a99b46f4783efaa0/layout/printing/nsPrintJob.cpp#2843,2858 do.
And with Fission I assume some of the clone-doc-for-printing will need to become asynchronous, so disabling scripting temporarily will be probably needed - maybe.

Flags: needinfo?(bugs)

(In reply to Olli Pettay [:smaug] from comment #8)

Since it has been so long after those bugs, lots of the underlying code has changed possibly significantly, so one will need to check what all
https://searchfox.org/mozilla-central/rev/501eb4718d73870892d28f31a99b46f4783efaa0/layout/printing/nsPrintJob.cpp#2843,2858 do.

Thank you Olli, I will check the what Suspend() and Resume() do.

And with Fission I assume some of the clone-doc-for-printing will need to become asynchronous, so disabling scripting temporarily will be probably needed - maybe.

Yep, that's the initial motivation on this. (I am assuming you mean disabling scripting temporarily in original documents by the time we finished cloning all descendant documents).

Blocks: 1557645
Whiteboard: [print2020_v79]
Whiteboard: [print2020_v79] → [print2020_v80]
Whiteboard: [print2020_v80] → [print2020_v81]
Whiteboard: [print2020_v81] → [print2020_v82]
Whiteboard: [print2020_v82] → [print2020_v88]
Whiteboard: [print2020_v88] → [print2020]
You need to log in before you can comment on or make changes to this bug.