77
88namespace Magento \Theme \Controller \Result ;
99
10+ use Magento \Csp \Api \InlineUtilInterface ;
1011use Magento \Framework \App \Config \ScopeConfigInterface ;
1112use Magento \Store \Model \ScopeInterface ;
1213use 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