Skip to content

Commit a8bbf25

Browse files
committed
AC-12731 Issue#39020 Rendering the critical css inline event via csp inline secure render
1 parent 6f4805f commit a8bbf25

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

app/code/Magento/Theme/Controller/Result/AsyncCssPlugin.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\Theme\Controller\Result;
99

10+
use Magento\Csp\Api\InlineUtilInterface;
1011
use Magento\Framework\App\Config\ScopeConfigInterface;
1112
use Magento\Store\Model\ScopeInterface;
1213
use Magento\Framework\App\Response\Http;
@@ -26,12 +27,21 @@ class AsyncCssPlugin
2627
*/
2728
private $scopeConfig;
2829

30+
/**
31+
* @var InlineUtilInterface
32+
*/
33+
private $cspInlineUtil;
34+
2935
/**
3036
* @param ScopeConfigInterface $scopeConfig
37+
* @param InlineUtilInterface $cspInlineUtil
3138
*/
32-
public function __construct(ScopeConfigInterface $scopeConfig)
33-
{
39+
public function __construct(
40+
ScopeConfigInterface $scopeConfig,
41+
InlineUtilInterface $cspInlineUtil
42+
) {
3443
$this->scopeConfig = $scopeConfig;
44+
$this->cspInlineUtil = $cspInlineUtil;
3545
}
3646

3747
/**
@@ -99,10 +109,13 @@ private function extractLinkTags(string &$content): string
99109
$media = $mediaAttribute[2];
100110
}
101111
$media = $media ?? 'all';
102-
112+
$onload = $this->cspInlineUtil->renderEventListener(
113+
'onload',
114+
sprintf('this.onload=null;this.media=\'%s\'', $media)
115+
);
103116
$style = sprintf(
104-
'<link rel="stylesheet" media="print" onload="this.onload=null;this.media=\'%s\'" href="%s">',
105-
$media,
117+
'<link rel="stylesheet" media="print" %s href="%s">',
118+
$onload,
106119
$href
107120
);
108121
$styles .= "\n" . $style;

0 commit comments

Comments
 (0)