7
7
8
8
namespace Magento \Theme \Controller \Result ;
9
9
10
+ use Magento \Csp \Api \InlineUtilInterface ;
10
11
use Magento \Framework \App \Config \ScopeConfigInterface ;
11
12
use Magento \Store \Model \ScopeInterface ;
12
13
use Magento \Framework \App \Response \Http ;
@@ -26,12 +27,21 @@ class AsyncCssPlugin
26
27
*/
27
28
private $ scopeConfig ;
28
29
30
+ /**
31
+ * @var InlineUtilInterface
32
+ */
33
+ private $ cspInlineUtil ;
34
+
29
35
/**
30
36
* @param ScopeConfigInterface $scopeConfig
37
+ * @param InlineUtilInterface $cspInlineUtil
31
38
*/
32
- public function __construct (ScopeConfigInterface $ scopeConfig )
33
- {
39
+ public function __construct (
40
+ ScopeConfigInterface $ scopeConfig ,
41
+ InlineUtilInterface $ cspInlineUtil
42
+ ) {
34
43
$ this ->scopeConfig = $ scopeConfig ;
44
+ $ this ->cspInlineUtil = $ cspInlineUtil ;
35
45
}
36
46
37
47
/**
@@ -99,10 +109,13 @@ private function extractLinkTags(string &$content): string
99
109
$ media = $ mediaAttribute [2 ];
100
110
}
101
111
$ media = $ media ?? 'all ' ;
102
-
112
+ $ onload = $ this ->cspInlineUtil ->renderEventListener (
113
+ 'onload ' ,
114
+ sprintf ('this.onload=null;this.media= \'%s \'' , $ media )
115
+ );
103
116
$ 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 ,
106
119
$ href
107
120
);
108
121
$ styles .= "\n" . $ style ;
0 commit comments