Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace most remaining Element.setAttribute("style", ...) usage with Element.style = ... instead #11569

Merged
merged 1 commit into from Feb 8, 2020

Conversation

Snuffleupagus
Copy link
Collaborator

@Snuffleupagus Snuffleupagus commented Feb 5, 2020

This should hopefully be useful in environments where restrictive CSPs are in effect.
In most cases the replacement is entirely straighforward, and there's only a couple of special cases:

  • For the src/display/font_loader.js and web/pdf_outline_viewer.js cases, since the elements aren't appended to the document yet, it shouldn't matter if the style properties are set one-by-one rather than all at once.
  • For the web/debugger.js case, there's really no need to set the padding inline at all and the definition was simply moved to web/viewer.css instead.

Please note: There's still a single case left, in web/toolbar.js for setting the width of the zoom dropdown, which is left intact for now.
The reasons are that this particular case shouldn't matter for users of the general PDF.js library, and that it'd make a lot more sense to just try and re-factor that very old code anyway (thus fixing the setAttribute usage in the process).

Fixes #11576

…h `Element.style = ...` instead

This should hopefully be useful in environments where restrictive CSPs are in effect.
In most cases the replacement is entirely straighforward, and there's only a couple of special cases:
 - For the `src/display/font_loader.js` and `web/pdf_outline_viewer.js `cases, since the elements aren't appended to the document yet, it shouldn't matter if the style properties are set one-by-one rather than all at once.
 - For the `web/debugger.js` case, there's really no need to set the `padding` inline at all and the definition was simply moved to `web/viewer.css` instead.

*Please note:* There's still *a single* case left, in `web/toolbar.js` for setting the width of the zoom dropdown, which is left intact for now.
The reasons are that this particular case shouldn't matter for users of the general PDF.js library, and that it'd make a lot more sense to just try and re-factor that very old code anyway (thus fixing the `setAttribute` usage in the process).
@Snuffleupagus
Copy link
Collaborator Author

/botio-linux preview

@pdfjsbot
Copy link

pdfjsbot commented Feb 6, 2020

From: Bot.io (Linux m4)


Received

Command cmd_preview from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.67.70.0:8877/567834b5676157a/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Feb 6, 2020

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/567834b5676157a/output.txt

Total script time: 1.77 mins

Published

@timvandermeij
Copy link
Contributor

/botio test

@pdfjsbot
Copy link

pdfjsbot commented Feb 6, 2020

From: Bot.io (Linux m4)


Received

Command cmd_test from @timvandermeij received. Current queue size: 0

Live output at: http://54.67.70.0:8877/ca6b359979868a9/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Feb 6, 2020

From: Bot.io (Windows)


Received

Command cmd_test from @timvandermeij received. Current queue size: 0

Live output at: http://54.215.176.217:8877/787f753c6cb741f/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Feb 6, 2020

From: Bot.io (Linux m4)


Failed

Full output at http://54.67.70.0:8877/ca6b359979868a9/output.txt

Total script time: 19.60 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: FAILED

Image differences available at: http://54.67.70.0:8877/ca6b359979868a9/reftest-analyzer.html#web=eq.log

@pdfjsbot
Copy link

pdfjsbot commented Feb 6, 2020

From: Bot.io (Windows)


Failed

Full output at http://54.215.176.217:8877/787f753c6cb741f/output.txt

Total script time: 26.78 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: FAILED

Image differences available at: http://54.215.176.217:8877/787f753c6cb741f/reftest-analyzer.html#web=eq.log

@timvandermeij timvandermeij merged commit a73a380 into mozilla:master Feb 8, 2020
@timvandermeij
Copy link
Contributor

Thank you for improving this! It's also more readable in my opinion.

@Snuffleupagus Snuffleupagus deleted the rm-most-setAttribute branch February 9, 2020 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CSP unsafe-inline CSS violations
3 participants