@@ -20,33 +20,33 @@ public class BaseHtmlProvider {
2020 private final Random random = new Random ();
2121 private final Map <String , String > colorCache = new HashMap <>();
2222 private String nonce = "" ;
23-
24- public String getCss () {
25- return "" ;
26- }
27-
28- public String getJs () {
29- return "" ;
30- }
31-
32- public String getInitScript () {
33- return "" ;
34- }
35-
36- public String getNonce () {
37- if (!nonce .isEmpty ()) {
38- return nonce ;
39- }
40- String allowedChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" ;
41- StringBuilder nonceBuilder = new StringBuilder (32 );
42- for (int i = 0 ; i < 32 ; i ++) {
43- nonceBuilder .append (allowedChars .charAt (random .nextInt (allowedChars .length ())));
44- }
45- nonce = nonceBuilder .toString ();
46- return nonce ;
47- }
48-
49- public String getNoDescriptionHtml () {
23+
24+ public String getCss () {
25+ return "" ;
26+ }
27+
28+ public String getJs () {
29+ return "" ;
30+ }
31+
32+ public String getInitScript () {
33+ return "" ;
34+ }
35+
36+ public String getNonce () {
37+ if (!nonce .isEmpty ()) {
38+ return nonce ;
39+ }
40+ String allowedChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" ;
41+ StringBuilder nonceBuilder = new StringBuilder (32 );
42+ for (int i = 0 ; i < 32 ; i ++) {
43+ nonceBuilder .append (allowedChars .charAt (random .nextInt (allowedChars .length ())));
44+ }
45+ nonce = nonceBuilder .toString ();
46+ return nonce ;
47+ }
48+
49+ public String getNoDescriptionHtml () {
5050 String snykWarningText = Platform .getResourceString (Platform .getBundle ("io.snyk.eclipse.plugin" ),
5151 "snyk.panel.auth.trust.warning.text" );
5252
@@ -75,7 +75,7 @@ public String getNoDescriptionHtml() {
7575 a {
7676 color: var(--link-color)
7777 }
78-
78+
7979 div {
8080 padding: 20px
8181 }
@@ -94,116 +94,126 @@ public String getNoDescriptionHtml() {
9494 return html ;
9595 }
9696
97+ public String replaceCssVariables (String html ) {
98+ // Build the CSS with the nonce
99+ String nonce = getNonce ();
100+ String css = "<style nonce=\" " + nonce + "\" >" + getCss () + "</style>" ;
101+ String htmlStyled = html .replace ("${ideStyle}" , css );
102+ htmlStyled = htmlStyled .replace ("<style nonce=\" ideNonce\" data-ide-style></style>" , css );
103+ htmlStyled = htmlStyled .replace ("var(--default-font)" ,
104+ " ui-sans-serif, \" SF Pro Text\" , \" Segoe UI\" , \" Ubuntu\" , Tahoma, Geneva, Verdana, sans-serif;" );
105+
106+ // Replace CSS variables with actual color values
107+ htmlStyled = htmlStyled .replace ("var(--text-color)" ,
108+ getColorAsHex ("org.eclipse.ui.workbench.ACTIVE_TAB_TEXT_COLOR" , "#000000" ));
109+
110+ htmlStyled = htmlStyled .replace ("var(--ide-background-color)" ,
111+ getColorAsHex ("org.eclipse.ui.workbench.ACTIVE_NOFOCUS_TAB_BG_START" , "#FFFFFF" ));
112+ htmlStyled = htmlStyled .replace ("var(--background-color)" ,
113+ getColorAsHex ("org.eclipse.ui.workbench.ACTIVE_TAB_BG_END" , "#FFFFFF" ));
114+ htmlStyled = htmlStyled .replace ("var(--code-background-color)" ,
115+ getColorAsHex ("org.eclipse.ui.workbench.INACTIVE_TAB_BG_START" , "#F0F0F0" ));
116+ htmlStyled = htmlStyled .replace ("var(--button-color)" ,
117+ getColorAsHex ("org.eclipse.ui.workbench.INACTIVE_TAB_BG_START" , "#F0F0F0" ));
118+ htmlStyled = htmlStyled .replace ("var(--circle-color)" ,
119+ getColorAsHex ("org.eclipse.ui.workbench.INACTIVE_TAB_BG_START" , "#F0F0F0" ));
120+
121+ htmlStyled = htmlStyled .replace ("var(--border-color)" ,
122+ getColorAsHex ("org.eclipse.ui.workbench.ACTIVE_TAB_OUTER_KEYLINE_COLOR" , "#CCCCCC" ));
123+ htmlStyled = htmlStyled .replace ("var(--link-color)" , getColorAsHex ("ACTIVE_HYPERLINK_COLOR" , "#0000FF" ));
124+ htmlStyled = htmlStyled .replace ("var(--horizontal-border-color)" ,
125+ getColorAsHex ("org.eclipse.ui.workbench.ACTIVE_TAB_OUTER_KEYLINE_COLOR" , "#CCCCCC" ));
126+
127+ htmlStyled = htmlStyled .replace ("${headerEnd}" , "" );
128+ htmlStyled = htmlStyled .replace ("${nonce}" , nonce );
129+ htmlStyled = htmlStyled .replace ("ideNonce" , nonce );
130+ htmlStyled = htmlStyled .replace ("${ideScript}" , "" );
131+
132+ return htmlStyled ;
133+ }
97134
98- public String replaceCssVariables (String html ) {
99- // Build the CSS with the nonce
100- String nonce = getNonce ();
101- String css = "<style nonce=\" " + nonce + "\" >" + getCss () + "</style>" ;
102- html = html .replace ("${ideStyle}" , css );
103- html = html .replace ("<style nonce=\" ideNonce\" data-ide-style></style>" , css );
104- html = html .replace ("var(--default-font)" , " ui-sans-serif, \" SF Pro Text\" , \" Segoe UI\" , \" Ubuntu\" , Tahoma, Geneva, Verdana, sans-serif;" );
105-
106-
107- // Replace CSS variables with actual color values
108- html = html .replace ("var(--text-color)" , getColorAsHex ("org.eclipse.ui.workbench.ACTIVE_TAB_TEXT_COLOR" , "#000000" ));
109- html = html .replace ("var(--background-color)" , getColorAsHex ("org.eclipse.ui.workbench.ACTIVE_TAB_BG_END" , "#FFFFFF" ));
110- html = html .replace ("var(--code-background-color)" , getColorAsHex ("org.eclipse.ui.workbench.INACTIVE_TAB_BG_START" , "#F0F0F0" ));
111- html = html .replace ("var(--button-color)" , getColorAsHex ("org.eclipse.ui.workbench.INACTIVE_TAB_BG_START" , "#F0F0F0" ));
112- html = html .replace ("var(--circle-color)" , getColorAsHex ("org.eclipse.ui.workbench.INACTIVE_TAB_BG_START" , "#F0F0F0" ));
113-
114- html = html .replace ("var(--border-color)" , getColorAsHex ("org.eclipse.ui.workbench.ACTIVE_TAB_OUTER_KEYLINE_COLOR" , "#CCCCCC" ));
115- html = html .replace ("var(--link-color)" , getColorAsHex ("ACTIVE_HYPERLINK_COLOR" , "#0000FF" ));
116- html = html .replace ("var(--horizontal-border-color)" , getColorAsHex ("org.eclipse.ui.workbench.ACTIVE_TAB_OUTER_KEYLINE_COLOR" , "#CCCCCC" ));
117-
118- html = html .replace ("${headerEnd}" , "" );
119- html = html .replace ("${nonce}" , nonce );
120- html = html .replace ("ideNonce" , nonce );
121- html = html .replace ("${ideScript}" , "" );
122-
123- return html ;
124- }
125-
126- public String getColorAsHex (String colorKey , String defaultColor ) {
127- if (Preferences .getInstance ().isTest ()) {
135+ public String getColorAsHex (String colorKey , String defaultColor ) {
136+ if (Preferences .getInstance ().isTest ()) {
128137 return "" ;
129138 }
130- return colorCache .computeIfAbsent (colorKey , key -> {
131- ColorRegistry colorRegistry = getColorRegistry ();
132- Color color = colorRegistry .get (colorKey );
133- if (color == null ) {
134- return defaultColor ;
135- } else {
136- RGB rgb = color .getRGB ();
137- return String .format ("#%02x%02x%02x" , rgb .red , rgb .green , rgb .blue );
138- }
139- });
140- }
141-
142- public Boolean isDarkTheme () {
143- var darkColor = getColorAsHex ("org.eclipse.ui.workbench.DARK_BACKGROUND" , "" );
144- return darkColor .equals ("true" );
145- }
146-
147- private ColorRegistry colorRegistry ;
148- private ColorRegistry getColorRegistry () {
149- if (colorRegistry != null ) {
150- return colorRegistry ;
151- }
152- ITheme currentTheme = getCurrentTheme ();
153- colorRegistry = currentTheme .getColorRegistry ();
154- return colorRegistry ;
155- }
156-
157-
158- private ITheme currentTheme ;
159- public ITheme getCurrentTheme () {
160- if (currentTheme != null ) {
161- return currentTheme ;
162- }
163- IThemeManager themeManager = PlatformUI .getWorkbench ().getThemeManager ();
164- currentTheme = themeManager .getCurrentTheme ();
165- return currentTheme ;
166- }
167-
168- public String getErrorHtml (String errorMessage , String path ) {
139+ return colorCache .computeIfAbsent (colorKey , key -> {
140+ ColorRegistry colorRegistry = getColorRegistry ();
141+ Color color = colorRegistry .get (colorKey );
142+ if (color == null ) {
143+ return defaultColor ;
144+ } else {
145+ RGB rgb = color .getRGB ();
146+ return String .format ("#%02x%02x%02x" , rgb .red , rgb .green , rgb .blue );
147+ }
148+ });
149+ }
150+
151+ public Boolean isDarkTheme () {
152+ var darkColor = getColorAsHex ("org.eclipse.ui.workbench.DARK_BACKGROUND" , "" );
153+ return Boolean .valueOf (darkColor );
154+ }
155+
156+ private ColorRegistry colorRegistry ;
157+
158+ private ColorRegistry getColorRegistry () {
159+ if (colorRegistry != null ) {
160+ return colorRegistry ;
161+ }
162+ ITheme currentTheme = getCurrentTheme ();
163+ colorRegistry = currentTheme .getColorRegistry ();
164+ return colorRegistry ;
165+ }
166+
167+ private ITheme currentTheme ;
168+
169+ public ITheme getCurrentTheme () {
170+ if (currentTheme != null ) {
171+ return currentTheme ;
172+ }
173+ IThemeManager themeManager = PlatformUI .getWorkbench ().getThemeManager ();
174+ currentTheme = themeManager .getCurrentTheme ();
175+ return currentTheme ;
176+ }
177+
178+ public String getErrorHtml (String errorMessage , String path ) {
169179 var html = """
170- <!DOCTYPE html>
171- <html lang="en">
172- <head>
173- <meta charset="UTF-8">
174- <meta name="viewport" content="width=device-width, initial-scale=1.0">
175- <title>Snyk for Eclipse</title>
176- <style>
177- body {
178- font-family: var(--default-font);
179- background-color: var(--background-color);
180- color: var(--text-color);
181- }
182- .container {
183- display: flex;
184- align-items: center;
185- }
186- .logo {
187- margin-right: 20px;
188- }
189- </style>
190- </head>
191- <body>
192- <div class="container">
193- <div>
194- <p><strong>An error occurred:</strong></p>
195- <p>
196- <table>
197- <tr><td width="150" >Error message:</td><td>%s</td></tr>
198- <tr></tr>
199- <tr><td>Path:</td><td>%s</td></tr>
200- </table>
201- </p>
202- </div>
203- </div>
204- </body>
205- </html>
206- """ .formatted (errorMessage , path );
180+ <!DOCTYPE html>
181+ <html lang="en">
182+ <head>
183+ <meta charset="UTF-8">
184+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
185+ <title>Snyk for Eclipse</title>
186+ <style>
187+ body {
188+ font-family: var(--default-font);
189+ background-color: var(--background-color);
190+ color: var(--text-color);
191+ }
192+ .container {
193+ display: flex;
194+ align-items: center;
195+ }
196+ .logo {
197+ margin-right: 20px;
198+ }
199+ </style>
200+ </head>
201+ <body>
202+ <div class="container">
203+ <div>
204+ <p><strong>An error occurred:</strong></p>
205+ <p>
206+ <table>
207+ <tr><td width="150" >Error message:</td><td>%s</td></tr>
208+ <tr></tr>
209+ <tr><td>Path:</td><td>%s</td></tr>
210+ </table>
211+ </p>
212+ </div>
213+ </div>
214+ </body>
215+ </html>
216+ """ .formatted (errorMessage , path );
207217 return replaceCssVariables (html );
208218 }
209219}
0 commit comments