Skip to content

Commit 61cdbb6

Browse files
author
Neil Fraser
authored
chore: Setting style property to make CSP less grumpy. (#7503)
* Setting style property to make CSP less grumpy. "Content-Security-Policy: The page’s settings blocked the loading of a resource at inline (“style-src”)." The 'style' property should be set as an object, not as a string, according to CSP rules. Back-ported from Blockly Games.
1 parent 32c9daf commit 61cdbb6

7 files changed

Lines changed: 13 additions & 11 deletions

File tree

core/field_angle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ export class FieldAngle extends FieldInput<number> {
219219
'version': '1.1',
220220
'height': FieldAngle.HALF * 2 + 'px',
221221
'width': FieldAngle.HALF * 2 + 'px',
222-
'style': 'touch-action: none',
223222
});
223+
svg.style.touchAction = 'none';
224224
const circle = dom.createSvgElement(
225225
Svg.CIRCLE,
226226
{

core/flyout_base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,8 @@ export abstract class Flyout extends DeleteArea implements IFlyout {
340340
// hide/show code will set up proper visibility and size later.
341341
this.svgGroup_ = dom.createSvgElement(tagName, {
342342
'class': 'blocklyFlyout',
343-
'style': 'display: none',
344343
});
344+
this.svgGroup_.style.display = 'none';
345345
this.svgBackground_ = dom.createSvgElement(
346346
Svg.PATH,
347347
{'class': 'blocklyFlyoutBackground'},

core/renderers/common/marker_svg.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,6 @@ export class MarkerSvg {
641641
{
642642
'width': this.constants_.CURSOR_WS_WIDTH,
643643
'height': this.constants_.WS_CURSOR_HEIGHT,
644-
'style': 'display: none',
645644
},
646645
this.markerSvg_,
647646
);
@@ -653,15 +652,14 @@ export class MarkerSvg {
653652
'class': 'blocklyVerticalMarker',
654653
'rx': 10,
655654
'ry': 10,
656-
'style': 'display: none',
657655
},
658656
this.markerSvg_,
659657
);
660658

661659
// A filled in puzzle piece used to represent an input value.
662660
this.markerInput_ = dom.createSvgElement(
663661
Svg.PATH,
664-
{'transform': '', 'style': 'display: none'},
662+
{'transform': ''},
665663
this.markerSvg_,
666664
);
667665

@@ -671,13 +669,14 @@ export class MarkerSvg {
671669
Svg.PATH,
672670
{
673671
'transform': '',
674-
'style': 'display: none',
675672
'fill': 'none',
676673
'stroke-width': this.constants_.CURSOR_STROKE_WIDTH,
677674
},
678675
this.markerSvg_,
679676
);
680677

678+
this.hide();
679+
681680
// Markers and stack markers don't blink.
682681
if (this.isCursor()) {
683682
const blinkProperties = this.getBlinkProperties_();

core/renderers/zelos/marker_svg.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ export class MarkerSvg extends BaseMarkerSvg {
116116
Svg.CIRCLE,
117117
{
118118
'r': this.constants_.CURSOR_RADIUS,
119-
'style': 'display: none',
120119
'stroke-width': this.constants_.CURSOR_STROKE_WIDTH,
121120
},
122121
this.markerSvg_,
123122
);
123+
this.hide();
124124

125125
// Markers and stack cursors don't blink.
126126
if (this.isCursor()) {

core/utils/dom.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,10 @@ export function measureFontMetrics(
353353
block.style.height = '0';
354354

355355
const div = document.createElement('div');
356-
div.setAttribute('style', 'position: fixed; top: 0; left: 0; display: flex;');
356+
div.style.display = 'flex';
357+
div.style.position = 'fixed';
358+
div.style.top = '0';
359+
div.style.left = '0';
357360
div.appendChild(span);
358361
div.appendChild(block);
359362

demos/blockfactory/workspacefactory/wfactory_generator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ WorkspaceFactoryGenerator.prototype.generateToolboxXml = function() {
4545
// Create DOM for XML.
4646
var xmlDom = Blockly.utils.xml.createElement('xml');
4747
xmlDom.id = 'toolbox';
48-
xmlDom.setAttribute('style', 'display: none');
48+
xmlDom.style.display = 'none';
4949

5050
if (!this.model.hasElements()) {
5151
// Toolbox has no categories. Use XML directly from workspace.
@@ -111,7 +111,7 @@ WorkspaceFactoryGenerator.prototype.generateWorkspaceXml = function() {
111111
// Generate XML and set attributes.
112112
var xmlDom = Blockly.Xml.workspaceToDom(this.hiddenWorkspace);
113113
xmlDom.id = 'workspaceBlocks';
114-
xmlDom.setAttribute('style', 'display: none');
114+
xmlDom.style.display = 'none';
115115
return xmlDom;
116116
};
117117

tests/playgrounds/screenshot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function workspaceToSvg_(workspace, callback, customCss) {
8484
);
8585
svg.setAttribute('width', width);
8686
svg.setAttribute('height', height);
87-
svg.setAttribute('style', 'background-color: transparent');
87+
svg.style.backgroundColor = 'transparent';
8888

8989
const css = [].slice
9090
.call(document.head.querySelectorAll('style'))

0 commit comments

Comments
 (0)